From 1f8dc324a94770d1f6107f2da6dd436cc69beb76 Mon Sep 17 00:00:00 2001 From: Christian Wade Date: Sat, 7 Dec 2019 19:53:15 -0800 Subject: [PATCH] Launch from Desktop --- BismNormalizer/AlmToolkit/ComparisonForm.cs | 84 +++++++++++-------- BismNormalizer/AlmToolkit/Program.cs | 36 +++++--- BismNormalizer/AlmToolkit/Utils.cs | 2 - .../TabularCompare/UI/ConnectionsAlmt.cs | 73 +++++++++------- 4 files changed, 116 insertions(+), 79 deletions(-) diff --git a/BismNormalizer/AlmToolkit/ComparisonForm.cs b/BismNormalizer/AlmToolkit/ComparisonForm.cs index d702b9b..0e0e17b 100644 --- a/BismNormalizer/AlmToolkit/ComparisonForm.cs +++ b/BismNormalizer/AlmToolkit/ComparisonForm.cs @@ -78,13 +78,16 @@ namespace AlmToolkit private void ComparisonForm_Load(object sender, EventArgs e) { - _comparisonInfo = new ComparisonInfo(); - _comparisonInfo.AppName = Utils.AssemblyProduct; + if (_comparisonInfo == null) + { + _comparisonInfo = new ComparisonInfo(); + _comparisonInfo.AppName = Utils.AssemblyProduct; - GetFromAutoCompleteSource(); - GetFromAutoCompleteTarget(); + //GetFromAutoCompleteSource(); + //GetFromAutoCompleteTarget(); - SetNotComparedState(); + SetNotComparedState(); + } //hdpi Rescale(); @@ -307,19 +310,19 @@ namespace AlmToolkit - private void GetFromAutoCompleteSource() - { - string serverNameSource = ReverseArray(Settings.Default.SourceServerAutoCompleteEntries.Substring(0, - Settings.Default.SourceServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0]; //.Reverse().ToArray(); - //_connectionInfoSource = new ConnectionInfo(serverNameSource, Settings.Default.SourceCatalog); - } + //private void GetFromAutoCompleteSource() + //{ + // string serverNameSource = ReverseArray(Settings.Default.SourceServerAutoCompleteEntries.Substring(0, + // Settings.Default.SourceServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0]; //.Reverse().ToArray(); + // _connectionInfoSource = new ConnectionInfo(serverNameSource, Settings.Default.SourceCatalog); + //} - private void GetFromAutoCompleteTarget() - { - string serverNameTarget = ReverseArray(Settings.Default.TargetServerAutoCompleteEntries.Substring(0, - Settings.Default.TargetServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0]; - //_connectionInfoTarget = new ConnectionInfo(serverNameTarget, Settings.Default.TargetCatalog); - } + //private void GetFromAutoCompleteTarget() + //{ + // string serverNameTarget = ReverseArray(Settings.Default.TargetServerAutoCompleteEntries.Substring(0, + // Settings.Default.TargetServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0]; + // //_connectionInfoTarget = new ConnectionInfo(serverNameTarget, Settings.Default.TargetCatalog); + //} internal static T[] ReverseArray(T[] array) { @@ -351,7 +354,7 @@ namespace AlmToolkit Settings.Default.SourceCatalog = _comparisonInfo.ConnectionInfoSource.DatabaseName; Settings.Default.Save(); - GetFromAutoCompleteSource(); + //GetFromAutoCompleteSource(); } if (!_comparisonInfo.ConnectionInfoTarget.UseProject && !_comparisonInfo.ConnectionInfoTarget.UseDesktop && !_comparisonInfo.ConnectionInfoTarget.UseBimFile) @@ -367,7 +370,7 @@ namespace AlmToolkit Settings.Default.TargetCatalog = _comparisonInfo.ConnectionInfoTarget.DatabaseName; Settings.Default.Save(); - GetFromAutoCompleteTarget(); + //GetFromAutoCompleteTarget(); } } @@ -724,22 +727,19 @@ namespace AlmToolkit catch { } } - private void SetFileNameTitle(bool unsaved) + public void LoadFromDesktop(string serverName, string databaseName) { - _unsaved = unsaved; + _comparisonInfo = new ComparisonInfo(); + _comparisonInfo.AppName = Utils.AssemblyProduct; - if (String.IsNullOrEmpty(_fileName)) - { - this.Text = Utils.AssemblyProduct; - } - else - { - this.Text = Utils.AssemblyProduct + " - " + Path.GetFileName(_fileName); - if (unsaved) - { - this.Text += " *"; - } - } + _comparisonInfo.ConnectionInfoSource.UseDesktop = true; + _comparisonInfo.ConnectionInfoSource.ServerName = serverName; + _comparisonInfo.ConnectionInfoSource.DatabaseName = databaseName; + + //GetFromAutoCompleteSource(); + //GetFromAutoCompleteTarget(); + + SetNotComparedState(); } public void LoadFile(string fileName) @@ -762,6 +762,24 @@ namespace AlmToolkit } } + private void SetFileNameTitle(bool unsaved) + { + _unsaved = unsaved; + + if (String.IsNullOrEmpty(_fileName)) + { + this.Text = Utils.AssemblyProduct; + } + else + { + this.Text = Utils.AssemblyProduct + " - " + Path.GetFileName(_fileName); + if (unsaved) + { + this.Text += " *"; + } + } + } + public void SaveFile(string fileName) { try diff --git a/BismNormalizer/AlmToolkit/Program.cs b/BismNormalizer/AlmToolkit/Program.cs index a3a0cbf..1dafadf 100644 --- a/BismNormalizer/AlmToolkit/Program.cs +++ b/BismNormalizer/AlmToolkit/Program.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.AnalysisServices; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -18,28 +19,37 @@ namespace AlmToolkit Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - //with args(user open file with the program) if (args != null && args.Length > 0) { - string fileName = args[0]; - //Check file exists - if (File.Exists(fileName)) + if (args.Length > 1) + //User opened from Desktop with server/db name { + string serverName = args[0]; + string databaseName = args[1]; + ComparisonForm MainFrom = new ComparisonForm(); - MainFrom.LoadFile(fileName); + MainFrom.LoadFromDesktop(serverName, databaseName); Application.Run(MainFrom); + return; } - //The file does not exist else + //User opened file with the program { - Application.Run(new ComparisonForm()); + string fileName = args[0]; + //Check file exists, if not will run without args below + if (File.Exists(fileName)) + { + ComparisonForm MainFrom = new ComparisonForm(); + MainFrom.LoadFile(fileName); + Application.Run(MainFrom); + return; + } } } - //without args - else - { - Application.Run(new ComparisonForm()); - } + + //Without valid args + Application.Run(new ComparisonForm()); + } } } diff --git a/BismNormalizer/AlmToolkit/Utils.cs b/BismNormalizer/AlmToolkit/Utils.cs index d0ff2db..a64a513 100644 --- a/BismNormalizer/AlmToolkit/Utils.cs +++ b/BismNormalizer/AlmToolkit/Utils.cs @@ -21,7 +21,5 @@ namespace AlmToolkit return ((AssemblyProductAttribute)attributes[0]).Product; } } - - } } diff --git a/BismNormalizer/BismNormalizer/TabularCompare/UI/ConnectionsAlmt.cs b/BismNormalizer/BismNormalizer/TabularCompare/UI/ConnectionsAlmt.cs index fd848e3..01400c4 100644 --- a/BismNormalizer/BismNormalizer/TabularCompare/UI/ConnectionsAlmt.cs +++ b/BismNormalizer/BismNormalizer/TabularCompare/UI/ConnectionsAlmt.cs @@ -78,6 +78,8 @@ namespace BismNormalizer.TabularCompare.UI cboSourceDatabase.Text = Settings.Default.SourceCatalog; cboTargetDatabase.Text = Settings.Default.TargetCatalog; + #region Prep Desktop/SSDT instances + cboSourceDesktop.Items.Clear(); cboTargetDesktop.Items.Clear(); @@ -105,15 +107,17 @@ namespace BismNormalizer.TabularCompare.UI cboTargetDesktop.DataSource = desktopBindingTarget; cboTargetDesktop.ValueMember = "Port"; cboTargetDesktop.DisplayMember = "Name"; - - BindSourceConnectionInfo(); - BindTargetConnectionInfo(); } else { rdoSourceDesktop.Enabled = false; rdoTargetDesktop.Enabled = false; } + + #endregion + + BindSourceConnectionInfo(); + BindTargetConnectionInfo(); } private bool BindSourceConnectionInfo() @@ -136,26 +140,29 @@ namespace BismNormalizer.TabularCompare.UI } else if (_comparisonInfo.ConnectionInfoSource.UseDesktop) { - rdoSourceDesktop.Checked = true; - - pnlSourceDataset.Enabled = false; - pnlSourceDesktop.Enabled = true; - pnlSourceFile.Enabled = false; - - int portFromConnectionInfo = -1; - if (_comparisonInfo.ConnectionInfoSource.ServerName != null && - int.TryParse(_comparisonInfo.ConnectionInfoSource.ServerName.ToUpper().Replace("localhost:".ToUpper(), ""), out portFromConnectionInfo)) + if (_powerBIInstances.Count > 0) { - for (int i = 0; i < ((BindingSource)cboSourceDesktop.DataSource).Count; i++) + rdoSourceDesktop.Checked = true; + + pnlSourceDataset.Enabled = false; + pnlSourceDesktop.Enabled = true; + pnlSourceFile.Enabled = false; + + int portFromConnectionInfo = -1; + if (_comparisonInfo.ConnectionInfoSource.ServerName != null && + int.TryParse(_comparisonInfo.ConnectionInfoSource.ServerName.ToUpper().Replace("localhost:".ToUpper(), ""), out portFromConnectionInfo)) { - if (((PowerBIInstance)((BindingSource)cboSourceDesktop.DataSource)[i]).Port == portFromConnectionInfo) + for (int i = 0; i < ((BindingSource)cboSourceDesktop.DataSource).Count; i++) { - cboSourceDesktop.SelectedIndex = i; - break; + if (((PowerBIInstance)((BindingSource)cboSourceDesktop.DataSource)[i]).Port == portFromConnectionInfo) + { + cboSourceDesktop.SelectedIndex = i; + break; + } } } + boundSuccessfully = true; } - boundSuccessfully = true; } else if (!String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoSource.ServerName) && !String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoSource.DatabaseName)) { @@ -193,26 +200,30 @@ namespace BismNormalizer.TabularCompare.UI } else if (_comparisonInfo.ConnectionInfoTarget.UseDesktop) { - rdoTargetDesktop.Checked = true; - - pnlTargetDataset.Enabled = false; - pnlTargetDesktop.Enabled = true; - pnlTargetFile.Enabled = false; - - int portFromConnectionInfo = -1; - if (_comparisonInfo.ConnectionInfoTarget.ServerName != null && - int.TryParse(_comparisonInfo.ConnectionInfoTarget.ServerName.ToUpper().Replace("localhost:".ToUpper(), ""), out portFromConnectionInfo)) + if (_powerBIInstances.Count > 0) { - for (int i = 0; i < ((BindingSource)cboTargetDesktop.DataSource).Count; i++) + + rdoTargetDesktop.Checked = true; + + pnlTargetDataset.Enabled = false; + pnlTargetDesktop.Enabled = true; + pnlTargetFile.Enabled = false; + + int portFromConnectionInfo = -1; + if (_comparisonInfo.ConnectionInfoTarget.ServerName != null && + int.TryParse(_comparisonInfo.ConnectionInfoTarget.ServerName.ToUpper().Replace("localhost:".ToUpper(), ""), out portFromConnectionInfo)) { - if (((PowerBIInstance)((BindingSource)cboTargetDesktop.DataSource)[i]).Port == portFromConnectionInfo) + for (int i = 0; i < ((BindingSource)cboTargetDesktop.DataSource).Count; i++) { - cboTargetDesktop.SelectedIndex = i; - break; + if (((PowerBIInstance)((BindingSource)cboTargetDesktop.DataSource)[i]).Port == portFromConnectionInfo) + { + cboTargetDesktop.SelectedIndex = i; + break; + } } } + boundSuccessfully = true; } - boundSuccessfully = true; } else if (!String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoTarget.ServerName) && !String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoTarget.DatabaseName)) {