-
Notifications
You must be signed in to change notification settings - Fork 60
/
SaveAllModelsOnServer.cs
77 lines (70 loc) · 2.72 KB
/
SaveAllModelsOnServer.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
#r "Microsoft.AnalysisServices.Core.dll"
using ToM = Microsoft.AnalysisServices.Tabular;
string folderPath = @"C:\Desktop\MyFolder"; // Folder where the files are saved
string saveType = "B"; // Use 'B' for saving to .bim files, use 'F' for saving to folder structure
// If saving datasets from Power BI Premium, enter your Service Principal credentials in the 3 parameters below:
string appID = "";
string tenantID = "";
string appSecret = "";
string serverName = Model.Database.TOMDatabase.Server.ToString();
string cmdText = @"start /wait /d ""C:\Program Files (x86)\Tabular Editor"" TabularEditor.exe " + @"""";
bool pbiPrem = false;
if (Model.DefaultPowerBIDataSourceVersion == PowerBIDataSourceVersion.PowerBI_V3)
{
pbiPrem = true;
}
// Update cmdText for Power BI Premium datasets (v3)
if (pbiPrem)
{
cmdText = cmdText + @"Provider=MSOLAP;Data Source=powerbi://api.powerbi.com/v1.0/myorg/" + serverName + ";User ID=app:" + appID + "@" + tenantID + ";Password=" + appSecret + @"""";
}
else
{
cmdText = cmdText + serverName + @"""";
}
foreach (var x in Model.Database.TOMDatabase.Server.Databases)
{
string dbName = x.ToString();
string fullCmdText = cmdText + @" """ + dbName + @""" -" + saveType + " " + @"""" + folderPath + @"\" + dbName;
if (saveType == "B")
{
fullCmdText = fullCmdText + @".bim""";
}
if (pbiPrem && appID.Length == 0)
{
Error("Must enter the Application ID in the appID parameter.");
return;
}
else if (pbiPrem && tenantID.Length == 0)
{
Error("Must enter the Tenant ID in the tenantID parameter.");
return;
}
else if (pbiPrem && appSecret.Length == 0)
{
Error("Must enter the Application Secret in the appSecret parameter.");
return;
}
else if (saveType != "B" && saveType != "F")
{
Error("The saveType paramter must be a value of 'B' or 'F' only.");
return;
}
else
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("cmd");
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = fullCmdText;
process.StartInfo = startInfo;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.StandardInput.WriteLine(fullCmdText);
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
}
}