77b65bea-e766-4e3c-a1ed-c4c2534b6019
true
D0001-SQL-01.sdt.local
jazz dev master
true
<ProgramFilesX64>\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll
Amazon.Lambda.S3Events
AWSSDK.Core
AWSSDK.S3
Amazon
Amazon.Auth.AccessControlPolicy
Amazon.Auth.AccessControlPolicy.ActionIdentifiers
Amazon.Internal
Amazon.Lambda.S3Events
Amazon.MissingTypes
Amazon.Runtime
Amazon.Runtime.CredentialManagement
Amazon.Runtime.CredentialManagement.Internal
Amazon.Runtime.EventStreams
Amazon.Runtime.EventStreams.Internal
Amazon.Runtime.Internal
Amazon.Runtime.Internal.Auth
Amazon.Runtime.Internal.Settings
Amazon.Runtime.Internal.Transform
Amazon.Runtime.Internal.Util
Amazon.Runtime.SharedInterfaces
Amazon.Runtime.SharedInterfaces.Internal
Amazon.S3
Amazon.S3.Encryption
Amazon.S3.Encryption.Internal
Amazon.S3.Internal
Amazon.S3.IO
Amazon.S3.Model
Amazon.S3.Model.Internal.MarshallTransformations
Amazon.S3.Transfer
Amazon.S3.Util
Amazon.Util
Amazon.Util.Internal
Amazon.Util.Internal.PlatformServices
Newtonsoft.Json
Newtonsoft.Json.Converters
Newtonsoft.Json.Linq
Newtonsoft.Json.Schema
Newtonsoft.Json.Serialization
System
System.ComponentModel.Composition
System.ComponentModel.Composition.Hosting
System.ComponentModel.Composition.Primitives
System.ComponentModel.Composition.ReflectionModel
System.Diagnostics
System.Diagnostics.Tracing
System.IO.Compression
System.Net.Http
System.Net.Http.Headers
System.Numerics
ThirdParty.BouncyCastle.Asn1
ThirdParty.BouncyCastle.Asn1.Utilities
ThirdParty.BouncyCastle.Math
ThirdParty.BouncyCastle.OpenSsl
ThirdParty.BouncyCastle.Utilities.IO.Pem
ThirdParty.Ionic.Zlib
ThirdParty.Json.LitJson
ThirdParty.MD5
private string accessKeyID = "AKIAIZZXT7LVCPR5COFA";
private string secretKey = "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";
void Main()
{
var process = 3;
var version = (from s in DBSettings where s.Name == "GENERAL_APPVERSION" select s.Setting).SingleOrDefault();
switch (process)
{
case 1:
var reports = (from rr in REReports
join f in Folders on rr.FolderGUID equals f.FolderGuid
join up in UserProfiles on rr.AuthorUserGUID equals up.UserGUID into ups
from up in ups.DefaultIfEmpty()
where rr.IsPublished == true
orderby f.Name, rr.Name
select new reportBase(rr.ReportGUID, f.Name, rr.Name, rr.Description, up == null ? rr.AuthorFullName : up.UserName, rr.DateCreated, version))
.ToList();
PushReportsJson(reports);
break;
case 2:
PullReportsJson();
break;
case 3:
JsonConvert.SerializeObject(from rr in REReports
join f in Folders on rr.FolderGUID equals f.FolderGuid
join up in UserProfiles on rr.AuthorUserGUID equals up.UserGUID into ups
from up in ups.DefaultIfEmpty()
where rr.IsPublished == true
orderby f.Name, rr.Name
select new reportBase(rr.ReportGUID, f.Name, rr.Name, rr.Description, up == null ? rr.AuthorFullName : up.UserName, rr.DateCreated, version), Newtonsoft.Json.Formatting.Indented)
.Dump();
break;
case 4:
var test = (JArray)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(from rr in REReports
join f in Folders on rr.FolderGUID equals f.FolderGuid
join up in UserProfiles on rr.AuthorUserGUID equals up.UserGUID into ups
from up in ups.DefaultIfEmpty()
where rr.IsPublished == true
orderby f.Name, rr.Name
select new reportBase(rr.ReportGUID, f.Name, rr.Name, rr.Description, up == null ? rr.AuthorFullName : up.UserName, rr.DateCreated, version), Newtonsoft.Json.Formatting.Indented));
var modules = (from t in test select (string)t["Module"]).Distinct().ToList();
modules.Dump();
// var result = ((JArray)test["Module"]).Distinct().ToList();
// result.Dump();
test.Dump();
break;
default:
var migrations = (from rr in REReports
join f in Folders on rr.FolderGUID equals f.FolderGuid
join up in UserProfiles on rr.AuthorUserGUID equals up.UserGUID into ups
from up in ups.DefaultIfEmpty()
where rr.IsPublished == true
orderby f.Name, rr.Name
select new report(rr.ReportGUID, f.Name, rr.Name, rr.Description, up == null ? rr.AuthorFullName : up.UserName, rr.DateCreated, version))
.ToList();
migrations.ForEach(r =>
{
var migration = new StringBuilder();
((SqlConnection)Connection).InfoMessage += (sender, args) => migration.AppendLine(args.Message);
procMigrateGenerateAdHocMigration(r.ReportGUID);
r.Migration = migration.ToString();
});
UploadReports(migrations);
DumpReports();
break;
}
}
void PullReportsJson()
{
var credentials = new BasicAWSCredentials(accessKeyID, secretKey);
using (var client = new AmazonS3Client(credentials, RegionEndpoint.USEast1))
{
var getRequest = new GetObjectRequest
{
BucketName = "stratasphere",
Key = "Reports.json"
};
var response = client.GetObject(getRequest);
var reader = new StreamReader(response.ResponseStream);
//reader.ReadToEnd().Dump();
//reader = new StreamReader(response.ResponseStream);
var reports = JsonConvert.DeserializeObject>(reader.ReadToEnd());
reports.Select(r => new reportBase(r)).Dump();
}
}
void PushReportsJson(List reports)
{
var credentials = new BasicAWSCredentials(accessKeyID, secretKey);
using (var client = new AmazonS3Client(credentials, RegionEndpoint.USEast1))
{
var putRequest = new PutObjectRequest
{
BucketName = "stratasphere",
Key = "Reports.json",
ContentType = "text/plain",
ContentBody = JsonConvert.SerializeObject(reports, Newtonsoft.Json.Formatting.None)
};
client.PutObject(putRequest);
}
}
void DeleteReports(List reportQuery)
{
var credentials = new BasicAWSCredentials(accessKeyID, secretKey);
using (var client = new AmazonS3Client(credentials, RegionEndpoint.USEast1))
{
reportQuery.Select(q => q.Category).Distinct().ToList()
.ForEach(r =>
{
var request = new DeleteObjectRequest
{
BucketName = "stratasphere",
Key = r,
};
try
{
client.DeleteObject(request);
}
catch (Exception e)
{
e.Dump();
}
});
}
}
void UploadReports(List reportQuery)
{
$"reports: {reportQuery.Count()}".Dump();
var credentials = new BasicAWSCredentials(accessKeyID, secretKey);
using (var client = new AmazonS3Client(credentials, RegionEndpoint.USEast1))
{
var response = client.ListBuckets();
response.Buckets.ForEach(b => $"{b.BucketName} {b.CreationDate}".Dump());
}
using (var client = new AmazonS3Client(credentials, RegionEndpoint.USEast1))
{
reportQuery.ToList().ForEach(r =>
{
var putRequest = new PutObjectRequest
{
BucketName = "stratasphere",
Key = $"{r.Category}/{r.Module}/{r.ReportGUID}",
ContentType = "text/plain",
ContentBody = JsonConvert.SerializeObject(r, Newtonsoft.Json.Formatting.Indented)
};
client.PutObject(putRequest);
});
}
}
void DumpReports()
{
var credentials = new BasicAWSCredentials(accessKeyID, secretKey);
using (var client = new AmazonS3Client(credentials, RegionEndpoint.USEast1))
{
var request = new Amazon.S3.Model.ListObjectsRequest
{
BucketName = "stratasphere"
};
do
{
var response = client.ListObjects(request);
response.Dump();
response.S3Objects.Dump();
response.S3Objects.Where(obj => obj.Key == "Reports.json").Dump();
if (response.IsTruncated)
{
request.Marker = response.NextMarker;
}
else
{
request = null;
}
} while (request != null);
}
}
class reportBase
{
public Guid ReportGUID { get; set; }
public string Category { get; set; }
public string Module { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string UserName { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime UploadDate { get; set; }
public string DbVersion { get; set; }
public reportBase(Guid reportGuid, string module, string name, string description, string userName, DateTime createdDate, string dbVersion)
{
ReportGUID = reportGuid;
Module = module;
Name = name;
Description = description;
Category = "Report";
UserName = userName;
CreatedDate = createdDate;
UploadDate = DateTime.Now;
DbVersion = dbVersion;
}
public reportBase(report r)
{
ReportGUID = r.ReportGUID;
Module = r.Module;
Name = r.Name;
Description = r.Description;
Category = r.Category;
UserName = r.UserName;
CreatedDate = r.CreatedDate;
UploadDate = r.UploadDate;
DbVersion = r.DbVersion;
}
}
class report : reportBase
{
public string Migration { get; set; }
public report(Guid reportGuid, string module, string name, string description, string userName, DateTime createdDate, string dbVersion)
: base(reportGuid, module, name, description, userName, createdDate, dbVersion)
{
Migration = string.Empty;
}
};