-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathExportReportObjects.cs
2469 lines (2226 loc) · 114 KB
/
ExportReportObjects.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#r "System.IO"
#r "System.IO.Compression.FileSystem"
using System.IO;
using System.IO.Compression;
/************************************************************************************************************
Instructions:
1. Paste this code into the Advanced Scripting window of Tabular Editor.
2. Create a new model in Tabular Editor (File -> New Model) (Compatibility Level does not matter).
3. Choose a method below and follow its respective steps.
Method 1: For a single Power BI Desktop (.pbix) or Power BI Template (.pbit) file:
1. Enter the folder location of the file in the 'pbiFolderName' parameter.
2. Enter the file name (including the extension) in the 'pbiFile' parameter.
// You must open the model/dataset (behind the Power BI Report) in Tabular Editor in order for the following steps to work properly.
3. Setting the 'addPersp' parameter to 'true' will create a new perspective which contains all of the objects used in the Power BI report including object dependencies.
4. (Optional) Set the 'perspName' parameter to set the name of the perspective referenced in Step 3.
Method 2: For looping through multiple .pbix or .pbit files within a folder:
1. Enter the location of the folder in the 'pbiFolderName' parameter.
2. Ensure that the pbiFile parameter is empty (should be this: @""; ).
Setting the 'saveToFile' parameter to 'true' will save the output text files to the respective folder.
Setting the 'saveToFile' parameter to 'false' will generate the output within pop-up windows.
************************************************************************************************************/
// User Parameters
string pbiFolderName = @"C:\Desktop\MyReport";
string pbiFile = @"MyReport.pbix";
bool saveToFile = true;
bool addPersp = false;
string perspName = "RptObj";
// Do not modify these parameters
string newline = Environment.NewLine;
string savePrefix = "ReportObjects";
bool singleFile = true;
bool createPersp = false;
if (pbiFile.Length == 0)
{
singleFile = false;
}
if (singleFile && addPersp)
{
createPersp = true;
if (Model.Perspectives.Any(a => a.Name == perspName))
{
Model.Perspectives[perspName].Delete();
}
Model.AddPerspective(perspName);
}
List<string> FileList = new List<string>();
var sb_CustomVisuals = new System.Text.StringBuilder();
sb_CustomVisuals.Append("ReportName" + '\t' + "CustomVisualName" + newline);
var sb_ReportFilters = new System.Text.StringBuilder();
sb_ReportFilters.Append("ReportName" + '\t' + "FilterName" + '\t' + "TableName" + '\t' + "ObjectName" + '\t' + "ObjectType" + '\t' + "FilterType" + newline);
var sb_VisualObjects = new System.Text.StringBuilder();
sb_VisualObjects.Append("ReportName" + '\t' + "PageName" + '\t' + "VisualId" + '\t' + "VisualType" + '\t' + "CustomVisualFlag" + '\t' + "TableName" + '\t' + "ObjectName" + '\t' + "ObjectType" + '\t' + "Source" + newline);
var sb_VisualFilters = new System.Text.StringBuilder();
sb_VisualFilters.Append("ReportName" + '\t' + "PageName" + '\t' + "VisualId" + '\t' + "TableName" + '\t' + "ObjectName" + '\t' + "ObjectType" + '\t' + "FilterType" + newline);
var sb_PageFilters = new System.Text.StringBuilder();
sb_PageFilters.Append("ReportName" + '\t' + "PageId" + '\t' + "PageName" + '\t' + "FilterName" + '\t' + "TableName" + '\t' + "ObjectName" + '\t' + "ObjectType" + '\t' + "FilterType" + newline);
var sb_Bookmarks = new System.Text.StringBuilder();
sb_Bookmarks.Append("ReportName" + '\t' + "BookmarkName" + '\t' + "BookmarkId" + '\t' + "PageId" + '\t' + "VisualId" + '\t' + "VisualHiddenFlag" + newline);
var sb_Pages = new System.Text.StringBuilder();
sb_Pages.Append("ReportName" + '\t' + "PageId" + '\t' + "PageName" + '\t' + "PageNumber" + '\t' + "PageWidth" + '\t' + "PageHeight" + '\t' + "PageHiddenFlag" + '\t' + "VisualCount" + '\t' + "PageBackgroundImage" + '\t' + "PageWallpaperImage" + '\t' + "PageType" + newline);
var sb_Visuals = new System.Text.StringBuilder();
sb_Visuals.Append("ReportName" + '\t' + "PageName" + '\t' + "VisualId" + '\t' + "VisualName" + '\t' + "VisualType" + '\t' + "CustomVisualFlag" + '\t' + "VisualHiddenFlag" + '\t' + "X_Coordinate" + '\t' + "Y_Coordinate" + '\t' + "Z_Coordinate" + '\t' + "VisualWidth" + '\t' + "VisualHeight" + '\t' + "ObjectCount" + '\t' + "ShowItemsNoDataFlag" + '\t' + "SlicerType" + '\t' + "ParentGroup" + newline);
var sb_Connections = new System.Text.StringBuilder();
sb_Connections.Append("ReportName" + '\t' + "ServerName" + '\t' + "DatabaseName" + '\t' + "ReportId" + '\t' + "ConnectionType" + newline);
var sb_VisualInteractions = new System.Text.StringBuilder();
sb_VisualInteractions.Append("ReportName" + '\t' + "PageName" + '\t' + "SourceVisualID" + '\t' + "TargetVisualID" + '\t' + "TypeID" + '\t' + "Type" + newline);
if (pbiFile.Length > 0 && pbiFolderName.Length == 0)
{
Error("If specifying the 'pbiFile' you must also specify the 'pbiFolderName'.");
return;
}
else if (pbiFile.Length == 0 && pbiFolderName.Length > 0)
{
foreach (var x in System.IO.Directory.GetFiles(pbiFolderName, "*.pbi*"))
{
FileList.Add(x);
}
}
else
{
FileList.Add(pbiFolderName + @"\" + pbiFile);
}
foreach (var rpt in FileList)
{
var CustomVisuals = new List<CustomVisual>();
var Bookmarks = new List<Bookmark>();
var ReportFilters = new List<ReportFilter>();
var Visuals = new List<Visual>();
var VisualObjects = new List<VisualObject>();
var VisualFilters = new List<VisualFilter>();
var PageFilters = new List<PageFilter>();
var Pages = new List<Page>();
var Connections = new List<Connection>();
var VisualInteractions = new List<VisualInteraction>();
string fileExt = Path.GetExtension(rpt);
string fileName = Path.GetFileNameWithoutExtension(rpt);
string folderName = Path.GetDirectoryName(rpt) + @"\";
string zipPath = folderName + fileName + ".zip";
string unzipPath = folderName + fileName;
if (! (fileExt == ".pbix" || fileExt == ".pbit"))
{
Error("'" +rpt+ "is not a valid file. File(s) must be a valid .pbix or .pbit.");
return;
}
try
{
// Make a copy of a pbi and turn it into a zip file
File.Copy(rpt, zipPath);
// Unzip file
System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, unzipPath);
// Delete zip file
File.Delete(zipPath);
}
catch
{
Error("File does not exist. Must use a valid .pbix or .pbit file");
return;
}
// Layout file
string layoutPath = unzipPath + @"\Report\Layout";
string jsonFilePath = Path.ChangeExtension(layoutPath, ".json");
File.Move(layoutPath, jsonFilePath);
string unformattedJson = File.ReadAllText(jsonFilePath,System.Text.UnicodeEncoding.Unicode);
string formattedJson = Newtonsoft.Json.Linq.JToken.Parse(unformattedJson).ToString();
dynamic json = Newtonsoft.Json.Linq.JObject.Parse(formattedJson);
// Connections file
string svName = string.Empty;
string dbName = string.Empty;
string rptId = string.Empty;
string connType = string.Empty;
string connPath = unzipPath + @"\Connections";
if (File.Exists(connPath))
{
string jsonconnFilePath = Path.ChangeExtension(connPath, ".json");
File.Move(connPath, jsonconnFilePath);
string unformattedconnJson = File.ReadAllText(jsonconnFilePath,System.Text.Encoding.UTF8);
string formattedconnJson = Newtonsoft.Json.Linq.JToken.Parse(unformattedconnJson).ToString();
dynamic connjson = Newtonsoft.Json.Linq.JObject.Parse(formattedconnJson);
// Connection info
try
{
foreach (var o in connjson["Connections"].Children())
{
connType = (string)o["ConnectionType"];
try
{
dbName = (string)o["PbiModelDatabaseName"];
}
catch
{
}
if (connType != "pbiServiceLive")
{
try
{
string x = (string)o["ConnectionString"];
string dsCatch = "Data Source=";
string icCatch = ";Initial Catalog=";
int dsCatchLen = dsCatch.Length;
int icCatchLen = icCatch.Length;
svName = x.Substring(x.IndexOf(dsCatch)+dsCatchLen,x.IndexOf(";")-x.IndexOf(dsCatch)-dsCatchLen);
int svNameLen = svName.Length;
dbName = x.Substring(x.IndexOf(icCatch)+icCatchLen);
}
catch
{
}
}
}
}
catch
{
try
{
dbName = (string)connjson["RemoteArtifacts"][0]["DatasetId"];
rptId = (string)connjson["RemoteArtifacts"][0]["ReportId"];
connType = "localPowerQuery";
}
catch
{
}
}
Connections.Add(new Connection {ServerName = svName, DatabaseName = dbName, Type = connType, ReportID = rptId});
}
//Delete previously created folder
try
{
Directory.Delete(folderName + fileName,true);
}
catch
{
}
// Custom Visuals
try
{
foreach (var o in json["resourcePackages"].Children())
{
int resType = (int)o["resourcePackage"]["type"];
string visualName = (string)o["resourcePackage"]["name"];
if (resType == 0)
{
CustomVisuals.Add( new CustomVisual {Name = visualName});
}
else if (resType == 1)
{
try
{
// Create list of images used
foreach (var o2 in o["resourcePackage"]["items"].Children())
{
string imageName = o2["path"];
}
}
catch
{
}
}
}
}
catch
{
}
// Report-Level Filters
string rptFilters = json["filters"];
try
{
string formattedrptfiltersJson = Newtonsoft.Json.Linq.JToken.Parse(rptFilters).ToString();
dynamic rptFiltersJson = Newtonsoft.Json.Linq.JArray.Parse(formattedrptfiltersJson);
foreach (var o in rptFiltersJson.Children())
{
string filterName = (string)o["name"];
string filterType = (string)o["type"];
string objectType = string.Empty;
string objectName = string.Empty;
string tableName = string.Empty;
// Note: Add filter conditions
try
{
objectName = (string)o["expression"]["Column"]["Property"];
objectType = "Column";
tableName = (string)o["expression"]["Column"]["Expression"]["SourceRef"]["Entity"];
if (createPersp)
{
try
{
Model.Tables[tableName].Columns[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
}
catch
{
}
try
{
objectName = (string)o["expression"]["Measure"]["Property"];
objectType = "Measure";
tableName = (string)o["expression"]["Measure"]["Expression"]["SourceRef"]["Entity"];
if (createPersp)
{
try
{
Model.Tables[tableName].Measures[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
}
catch
{
}
try
{
string levelName = (string)o["expression"]["HierarchyLevel"]["Level"];
string hierName = (string)o["expression"]["HierarchyLevel"]["Expression"]["Hierarchy"]["Hierarchy"];
objectName = hierName + "." + levelName;
objectType = "Hierarchy";
tableName = (string)o["expression"]["HierarchyLevel"]["Expression"]["Hierarchy"]["Expression"]["SourceRef"]["Entity"];
if (createPersp)
{
try
{
Model.Tables[tableName].Hierarchies[hierName].InPerspective[perspName] = true;
}
catch
{
}
}
}
catch
{
}
ReportFilters.Add(new ReportFilter {FilterName = filterName, TableName = tableName, ObjectName = objectName, ObjectType = objectType, FilterType = filterType});
}
}
catch
{
}
// Pages
foreach (var o in json["sections"].Children())
{
string pageId = (string)o["name"];
string pageName = (string)o["displayName"];
string pageFlt = (string)o["filters"];
int pageNumber = 0;
try
{
pageNumber = (int)o["ordinal"];
}
catch
{
}
int pageWidth = (int)o["width"];
int pageHeight = (int)o["height"];
int visualCount = (int)o["visualContainers"].Count;
string pageBkgrd = "";
string pageWall = "";
string formattedpagfltJson = Newtonsoft.Json.Linq.JToken.Parse(pageFlt).ToString();
dynamic pageFltJson = Newtonsoft.Json.Linq.JArray.Parse(formattedpagfltJson);
int displayOpt = (int)o["displayOption"];
bool pageHid = false;
string pageType = string.Empty;
string pageConfig = (string)o["config"];
string formattedpagconfigJson = Newtonsoft.Json.Linq.JToken.Parse(pageConfig).ToString();
dynamic pageConfigJson = Newtonsoft.Json.Linq.JObject.Parse(formattedpagconfigJson);
try
{
int pageV = (int)pageConfigJson["visibility"];
if (pageV == 1)
{
pageHid = true;
}
}
catch
{
}
// Visual Interactions
try
{
foreach (var o2 in pageConfigJson["relationships"].Children())
{
string sourceViz = (string)o2["source"];
string targetViz = (string)o2["target"];
int typeID = (int)o2["type"];
string[] typeAr = {"blank", "Filter", "Highlight", "None"};
string type = typeAr[typeID];
VisualInteractions.Add(new VisualInteraction {PageName = pageName, SourceVisualID = sourceViz, TargetVisualID = targetViz, TypeID = typeID, Type = type});
}
}
catch
{
}
// Page Background
try
{
pageBkgrd = pageConfigJson["objects"]["background"][0]["properties"]["image"]["image"]["url"]["expr"]["ResourcePackageItem"]["ItemName"];
}
catch
{
}
// Page Wallpaper
try
{
pageWall = pageConfigJson["objects"]["outspace"][0]["properties"]["image"]["image"]["url"]["expr"]["ResourcePackageItem"]["ItemName"];
}
catch
{
}
// Page Type
if (displayOpt == 3 && pageWidth == 320 && pageHeight == 240)
{
pageType = "Tooltip";
}
else if (pageWidth == 816 && pageHeight == 1056)
{
pageType = "Letter";
}
else if (pageWidth == 960 && pageHeight == 720)
{
pageType = "4:3";
}
else if (pageWidth == 1280 && pageHeight == 720)
{
pageType = "16:9";
}
else
{
pageType = "Custom";
}
Pages.Add(new Page {Id = pageId, Name = pageName, Number = pageNumber, Width = pageWidth, Height = pageHeight, HiddenFlag = pageHid, VisualCount = visualCount, BackgroundImage = pageBkgrd, WallpaperImage = pageWall, Type = pageType });
// Page-Level Filters
foreach (var o2 in pageFltJson.Children())
{
string pgFltName = (string)o2["name"];
string pgFltType = (string)o2["type"];
string objType = string.Empty;
string objName = string.Empty;
string tblName = string.Empty;
// Note: Add filter conditions
try
{
objName = (string)o2["expression"]["Column"]["Property"];
objType = "Column";
tblName = (string)o2["expression"]["Column"]["Expression"]["SourceRef"]["Entity"];
if (createPersp)
{
try
{
Model.Tables[tblName].Columns[objName].InPerspective[perspName] = true;
}
catch
{
}
}
}
catch
{
}
try
{
objName = (string)o2["expression"]["Measure"]["Property"];
objType = "Measure";
tblName = (string)o2["expression"]["Measure"]["Expression"]["SourceRef"]["Entity"];
if (createPersp)
{
try
{
Model.Tables[tblName].Measures[objName].InPerspective[perspName] = true;
}
catch
{
}
}
}
catch
{
}
try
{
string levelName = (string)o2["expression"]["HierarchyLevel"]["Level"];
string hierName = (string)o2["expression"]["HierarchyLevel"]["Expression"]["Hierarchy"]["Hierarchy"];
objName = hierName + "." + levelName;
objType = "Hierarchy";
tblName = (string)o2["expression"]["HierarchyLevel"]["Expression"]["Hierarchy"]["Expression"]["SourceRef"]["Entity"];
if (createPersp)
{
try
{
Model.Tables[tblName].Hierarchies[hierName].InPerspective[perspName] = true;
}
catch
{
}
}
}
catch
{
}
PageFilters.Add(new PageFilter {PageId = pageId, PageName = pageName, FilterName = pgFltName, TableName = tblName, ObjectName = objName, ObjectType = objType, FilterType = pgFltType });
}
// Visuals
foreach (var vc in o["visualContainers"].Children())
{
string config = (string)vc["config"];
string formattedconfigJson = Newtonsoft.Json.Linq.JToken.Parse(config).ToString();
dynamic configJson = Newtonsoft.Json.Linq.JObject.Parse(formattedconfigJson);
string visualId = (string)configJson["name"];
int cx = Convert.ToInt32(Math.Ceiling((double)vc["x"]));
int cy = Convert.ToInt32(Math.Ceiling((double)vc["y"]));
int cz = Convert.ToInt32(Math.Ceiling((double)vc["z"]));
int cw = Convert.ToInt32(Math.Ceiling((double)vc["width"]));
int ch = Convert.ToInt32(Math.Ceiling((double)vc["height"]));
string visualType = string.Empty;
string visualName = string.Empty;
bool customVisualFlag = false;
int objCount = 0;
bool visHid = false;
bool showItemsNoData = false;
string slicerType = "N/A";
string parentGroup = string.Empty;
try
{
parentGroup = (string)configJson["parentGroupName"];
}
catch
{
}
// Show Items With No Data
try
{
string sInd = (string)configJson["singleVisual"]["showAllRoles"][0];
if (sInd == "Values")
{
showItemsNoData = true;
}
}
catch
{
}
try
{
visualType = (string)configJson["singleVisual"]["visualType"];
}
catch
{
visualType = "visualGroup";
}
if (CustomVisuals.Exists(a => a.Name == visualType))
{
customVisualFlag = true;
}
// Visual Name
try
{
visualName = (string)configJson["singleVisualGroup"]["displayName"];
}
catch
{
}
try
{
visualName = (string)configJson["singleVisual"]["vcObjects"]["title"][0]["properties"]["text"]["expr"]["Literal"]["Value"];
visualName = visualName.Substring(1,visualName.Length-2);
}
catch
{
}
if (visualName.Length == 0)
{
visualName = visualType;
}
// Visual Hidden
try
{
string visH = (string)configJson["singleVisual"]["display"]["mode"];
if (visH == "hidden")
{
visHid = true;
}
}
catch
{
}
if (visualType == "slicer")
{
try
{
string sT = (string)configJson["singleVisual"]["objects"]["data"][0]["properties"]["mode"]["expr"]["Literal"]["Value"];
if (sT == "'Basic'")
{
slicerType = "List";
}
else if (sT == "'Dropdown'")
{
slicerType = "Dropdown";
}
}
catch
{
}
}
try
{
bool visH = (bool)configJson["singleVisualGroup"]["isHidden"];
if (visH)
{
visHid = true;
}
}
catch
{
}
// Visual Objects
try
{
objCount = configJson["singleVisual"]["prototypeQuery"]["Select"].Count;
foreach (var o2 in configJson["singleVisual"]["prototypeQuery"]["Select"].Children())
{
string objectType = string.Empty;
string tableName = string.Empty;
string objectName = string.Empty;
string src = string.Empty;
bool isSpark = false;
string sourceLabel = "Standard";
try
{
objectName = (string)o2["Column"]["Property"];
objectType = "Column";
src = (string)o2["Column"]["Expression"]["SourceRef"]["Source"];
}
catch
{
}
try
{
objectName = (string)o2["Measure"]["Property"];
objectType = "Measure";
src = (string)o2["Measure"]["Expression"]["SourceRef"]["Source"];
}
catch
{
}
try
{
string levelName = (string)o2["HierarchyLevel"]["Level"];
string hierName = (string)o2["HierarchyLevel"]["Expression"]["Hierarchy"]["Hierarchy"];
objectName = hierName + "." + levelName;
objectType = "Hierarchy";
src = (string)o2["HierarchyLevel"]["Expression"]["Hierarchy"]["Expression"]["SourceRef"]["Source"];
}
catch
{
}
try
{
objectName = (string)o2["Aggregation"]["Expression"]["Column"]["Property"];
objectType = "Column";
src = (string)o2["Aggregation"]["Expression"]["Column"]["Expression"]["SourceRef"]["Source"];
}
catch
{
}
// Sparklines
try
{
objectName = (string)o2["SparklineData"]["Measure"]["Measure"]["Property"];
objectType = "Measure";
src = (string)o2["SparklineData"]["Measure"]["Measure"]["Expression"]["SourceRef"]["Source"];
isSpark = true;
}
catch
{
}
try
{
objectName = (string)o2["SparklineData"]["Measure"]["Aggregation"]["Expression"]["Column"]["Property"];
objectType = "Column";
src = (string)o2["SparklineData"]["Measure"]["Aggregation"]["Expression"]["Column"]["Expression"]["SourceRef"]["Source"];
isSpark = true;
}
catch
{
}
foreach (var t in configJson["singleVisual"]["prototypeQuery"]["From"].Children())
{
string n = (string)t["Name"];
string tbl = (string)t["Entity"];
if (src == n)
{
tableName = tbl;
}
}
if (createPersp)
{
if (objectType == "Column")
{
try
{
Model.Tables[tableName].Columns[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
else if (objectType == "Measure")
{
try
{
Model.Tables[tableName].Measures[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
else if (objectType == "Hierarchy")
{
try
{
Model.Tables[tableName].Hierarchies[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
}
if (isSpark)
{
sourceLabel = "Sparkline";
}
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sourceLabel});
if (isSpark)
{
try
{
objectName = (string)o2["SparklineData"]["Groupings"][0]["Column"]["Property"];
objectType = "Column";
src = (string)o2["SparklineData"]["Groupings"][0]["Column"]["Expression"]["SourceRef"]["Source"];
isSpark = true;
foreach (var t in configJson["singleVisual"]["prototypeQuery"]["From"].Children())
{
string n = (string)t["Name"];
string tbl = (string)t["Entity"];
if (src == n)
{
tableName = tbl;
}
}
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sourceLabel});
if (createPersp)
{
if (objectType == "Column")
{
try
{
Model.Tables[tableName].Columns[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
else if (objectType == "Measure")
{
try
{
Model.Tables[tableName].Measures[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
else if (objectType == "Hierarchy")
{
try
{
Model.Tables[tableName].Hierarchies[objectName].InPerspective[perspName] = true;
}
catch
{
}
}
}
}
catch
{
}
}
}
}
catch
{
}
// VisualObjects in Labels
try
{
string sc = "Label";
// Gradient
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["labels"].Children())
{
// labels
string tableName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["FillRule"]["Input"]["Measure"]["Expression"]["SourceRef"]["Entity"];
string objectName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["FillRule"]["Input"]["Measure"]["Property"];
string objectType = "Measure";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
// Rules
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["labels"].Children())
{
string objectName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["Conditional"]["Cases"][0]["Condition"]["And"]["Left"]["Comparison"]["Left"]["Measure"]["Property"];
string tableName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["Conditional"]["Cases"][0]["Condition"]["And"]["Left"]["Comparison"]["Left"]["Measure"]["Expression"]["SourceRef"]["Entity"];
string objectType = "Measure";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
// Field value (Column)
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["labels"].Children())
{
string objectName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["Aggregation"]["Expression"]["Column"]["Property"];
string tableName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["Aggregation"]["Expression"]["Column"]["Expression"]["SourceRef"]["Entity"];
string objectType = "Column";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
// Field Value (Measure)
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["labels"].Children())
{
string tableName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["Measure"]["Expression"]["SourceRef"]["Entity"];
string objectName = (string)o2["properties"]["color"]["solid"]["color"]["expr"]["Measure"]["Property"];
string objectType = "Measure";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
}
catch
{
}
// VisualObjects in CategoryAxis
try
{
string sc = "X Axis Color";
// Gradient
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["categoryAxis"].Children())
{
// labels
string tableName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["FillRule"]["Input"]["Measure"]["Expression"]["SourceRef"]["Entity"];
string objectName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["FillRule"]["Input"]["Measure"]["Property"];
string objectType = "Measure";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
// Rules
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["categoryAxis"].Children())
{
string objectName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["Conditional"]["Cases"][0]["Condition"]["And"]["Left"]["Comparison"]["Left"]["Measure"]["Property"];
string tableName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["Conditional"]["Cases"][0]["Condition"]["And"]["Left"]["Comparison"]["Left"]["Measure"]["Expression"]["SourceRef"]["Entity"];
string objectType = "Measure";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
// Field value (Column)
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["categoryAxis"].Children())
{
string objectName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["Aggregation"]["Expression"]["Column"]["Property"];
string tableName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["Aggregation"]["Expression"]["Column"]["Expression"]["SourceRef"]["Entity"];
string objectType = "Column";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
// Field Value (Measure)
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["categoryAxis"].Children())
{
string tableName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["Measure"]["Expression"]["SourceRef"]["Entity"];
string objectName = (string)o2["properties"]["labelColor"]["solid"]["color"]["expr"]["Measure"]["Property"];
string objectType = "Measure";
VisualObjects.Add(new VisualObject {PageName = pageName, VisualId = visualId, VisualType = visualType, CustomVisualFlag = customVisualFlag, ObjectName = objectName, TableName = tableName, ObjectType = objectType, Source = sc});
}
}
catch
{
}
}
catch
{
}
// VisualObjects in CategoryAxis Title Color
try
{
string sc = "X Axis Title Color";
// Gradient
try
{
foreach (var o2 in configJson["singleVisual"]["objects"]["categoryAxis"].Children())
{
// labels
string tableName = (string)o2["properties"]["titleColor"]["solid"]["color"]["expr"]["FillRule"]["Input"]["Measure"]["Expression"]["SourceRef"]["Entity"];