Files
linqpad/Dashboard extrapolation.linq
T

148 lines
6.6 KiB
C#

<Query Kind="Statements">
<Connection>
<ID>77b65bea-e766-4e3c-a1ed-c4c2534b6019</ID>
<Persist>true</Persist>
<Server>D0001-SQL-11.sdt.local</Server>
<Database>jazz dev master</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.ComponentModel.Composition</Namespace>
<Namespace>System.ComponentModel.Composition.Hosting</Namespace>
<Namespace>System.ComponentModel.Composition.Primitives</Namespace>
<Namespace>System.ComponentModel.Composition.ReflectionModel</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>System.Net.Http</Namespace>
<Namespace>System.Net.Http.Headers</Namespace>
<Namespace>System.Numerics</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
<Namespace>System.Dynamic</Namespace>
</Query>
var emptyGuid = Guid.Empty.ToString();
var dashboards = (from dashboard in DesktopTemplates
join module in SystemCenterModules on dashboard.ModuleGUID equals module.ModuleGUID
join solution in SystemCenterSolutions on module.SolutionGUID equals solution.SolutionGUID
where dashboard.IsLegacy == false && solution.IsStatusDisabled == false
select new
{
solution = solution.Name,
primarySort = solution.SortOrder,
module = module.Name,
categories = module.SystemCenterCategories
.Where(c => c.IsMaintenanceMode == true).OrderBy(c => c.SortOrder)
.Select(c => new { c.Name, SortOrder = c.SortOrder.ToString() }).ToList(),
secondarySort = module.SortOrder,
dashboard.DesktopTemplateGUID,
dashboard.Name,
dashboard.Description,
parameters = dashboard.DesktopParameters.Any()
? dashboard.DesktopParameters.Select(p => new
{
p.Name,
p.ColumnName,
p.DimensionName,
p.AttributeName,
p.DataSourceGUID,
ExcludedWidgetGuids = string.IsNullOrEmpty(p.ExcludedWidgetGuidsCSV) ? null : p.ExcludedWidgetGuidsCSV.Split(',')
}).Distinct().ToList()
: null,
// columns = dashboard.DesktopColumns.Any() ? dashboard.DesktopColumns.ToList() : null,
widgets = dashboard.DashboardWidgets.Any()
? dashboard.DashboardWidgets.Select(w => new
{
w.Name,
w.Row,
w.Col,
w.Height,
w.Width,
w.WidgetClassName,
DataSourceGUID = w.DataSourceGUID.ToString() == "00000000-0000-0000-0000-000000000000" ? "" : w.DataSourceGUID.ToString(),
WidgetJSON = (JsonConvert.DeserializeObject<ExpandoObject>(w.WidgetJSON) as IDictionary<string, object>)
})
.Select(w => new
{
w.Name,
w.Row,
w.Col,
w.Height,
w.Width,
w.WidgetClassName,
w.DataSourceGUID,
w.WidgetJSON,
ReportGuid = w.WidgetClassName == "Grid" || w.WidgetClassName == "Chart" ||
(w.WidgetClassName == "Metric" && w.WidgetJSON["ReportGuid"] != emptyGuid)
? w.WidgetJSON["ReportGuid"]
: null
})
.OrderBy(w => w.Row).ThenBy(w => w.Col).ToList()
: null,
desktop = dashboard.DesktopWidgets.Any()
? dashboard.DesktopWidgets.Select(w => new
{
w.Name,
w.Height,
w.DesktopTemplateGUID,
w.WidgetFullName,
w.WidgetXML
}).ToList()
: null
})
.OrderBy(x => x.primarySort).ThenBy(x => x.secondarySort).ThenBy(x => x.Name).ToList();
dashboards.Dump();
dashboards.Where(d => d.parameters != null).SelectMany(d => d.parameters)
.OrderBy(d => d.DimensionName).ThenBy(d => d.AttributeName).Dump();
dashboards.SelectMany(d => d.widgets.Where(w => w.WidgetClassName == "Report" || w.WidgetClassName == "Chart")
.Select(w => new {Dashboard = d.Name, Report = w.Name, w.Row, w.Col, w.Height, w.Width, w.WidgetClassName, w.DataSourceGUID, w.ReportGuid}))
.OrderBy(d => d.Dashboard).ThenBy(d => d.Report).Dump();
dashboards.SelectMany(d => d.widgets.Where(w => w.WidgetClassName == "Metric")
.Select(w => new { Dashboard = d.Name, Report = w.Name, w.Row, w.Col, w.Height, w.Width, w.WidgetClassName, w.DataSourceGUID, w.WidgetJSON }))
.OrderBy(d => d.Dashboard).ThenBy(d => d.Report).Dump();