void LoadModelFromFile(string file) { // File argument provided (either alone or with switches), i.e.: // TabularEditor.exe myfile.bim // TabularEditor.exe myfile.bim -... if (!File.Exists(argList[1]) && !File.Exists(argList[1] + "\\database.json")) { Error("File not found: {0}", argList[1]); throw new CommandLineException(); } else { // If nothing else was specified on the command-line, open the UI: if (argList.Count == 2) { LaunchUi = true; throw new CommandLineException(); } } try { // Load model: Console.WriteLine("Loading model..."); var settings = new TabularModelHandlerSettings { AutoFixup = true, ChangeDetectionLocalServers = false, PBIFeaturesOnly = false }; Handler = new TOMWrapper.TabularModelHandler(argList[1], settings); } catch (Exception e) { Error("Error loading file: " + e.Message); throw new CommandLineException(); } }
void LoadModelFromServer(string server, string database) { // Server + Database argument provided (either alone or with switches), i.e.: // TabularEditor.exe localhost AdventureWorks // TabularEditor.exe localhost AdventureWorks -... // If nothing else was specified on the command-line, open the UI: if (argList.Count == 3 && !argList[2].StartsWith("-")) { LaunchUi = true; throw new CommandLineException(); } try { // Load model: var settings = new TabularModelHandlerSettings { AutoFixup = true, ChangeDetectionLocalServers = false, PBIFeaturesOnly = false }; if (IsLocalSwitch(server)) { var localInstances = PowerBIHelper.Instances; if (localInstances.Count == 1 && string.IsNullOrEmpty(database)) { server = $"localhost:{localInstances[0].Port}"; database = ""; } else if (localInstances.Count == 0) { Error("No local instances of Power BI Desktop detected."); throw new CommandLineException(); } else { if (string.IsNullOrEmpty(database)) { Error("Multiple instances of Power BI Desktop detected. Please specify instance name. Available instances:"); foreach (var instance in localInstances) { Console.WriteLine($" localhost:{instance.Port}.{instance.Name}"); } throw new CommandLineException(); } var targetInstance = localInstances.FirstOrDefault(i => i.Name.EqualsI(database)); if (targetInstance == null) { Error($"No instance of Power BI Desktop with name {database} detected. Available instances:"); foreach (var instance in localInstances) { Console.WriteLine($" localhost:{instance.Port}.{instance.Name}"); } throw new CommandLineException(); } server = $"localhost:{targetInstance.Port}"; database = ""; } } Console.WriteLine($"Loading model from server {server}..."); Handler = new TabularModelHandler(server, database, settings); } catch (Exception e) { if (!(e is CommandLineException)) { Error("Error loading model: " + e.Message); } throw new CommandLineException(); } }