Launch from Desktop

This commit is contained in:
Christian Wade 2019-12-07 19:53:15 -08:00
parent 7b6526a516
commit 1f8dc324a9
4 changed files with 116 additions and 79 deletions

View File

@ -78,13 +78,16 @@ namespace AlmToolkit
private void ComparisonForm_Load(object sender, EventArgs e) private void ComparisonForm_Load(object sender, EventArgs e)
{ {
_comparisonInfo = new ComparisonInfo(); if (_comparisonInfo == null)
_comparisonInfo.AppName = Utils.AssemblyProduct; {
_comparisonInfo = new ComparisonInfo();
_comparisonInfo.AppName = Utils.AssemblyProduct;
GetFromAutoCompleteSource(); //GetFromAutoCompleteSource();
GetFromAutoCompleteTarget(); //GetFromAutoCompleteTarget();
SetNotComparedState(); SetNotComparedState();
}
//hdpi //hdpi
Rescale(); Rescale();
@ -307,19 +310,19 @@ namespace AlmToolkit
private void GetFromAutoCompleteSource() //private void GetFromAutoCompleteSource()
{ //{
string serverNameSource = ReverseArray<string>(Settings.Default.SourceServerAutoCompleteEntries.Substring(0, // string serverNameSource = ReverseArray<string>(Settings.Default.SourceServerAutoCompleteEntries.Substring(0,
Settings.Default.SourceServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0]; //.Reverse().ToArray(); // Settings.Default.SourceServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0]; //.Reverse().ToArray();
//_connectionInfoSource = new ConnectionInfo(serverNameSource, Settings.Default.SourceCatalog); // _connectionInfoSource = new ConnectionInfo(serverNameSource, Settings.Default.SourceCatalog);
} //}
private void GetFromAutoCompleteTarget() //private void GetFromAutoCompleteTarget()
{ //{
string serverNameTarget = ReverseArray<string>(Settings.Default.TargetServerAutoCompleteEntries.Substring(0, // string serverNameTarget = ReverseArray<string>(Settings.Default.TargetServerAutoCompleteEntries.Substring(0,
Settings.Default.TargetServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0]; // Settings.Default.TargetServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray()))[0];
//_connectionInfoTarget = new ConnectionInfo(serverNameTarget, Settings.Default.TargetCatalog); // //_connectionInfoTarget = new ConnectionInfo(serverNameTarget, Settings.Default.TargetCatalog);
} //}
internal static T[] ReverseArray<T>(T[] array) internal static T[] ReverseArray<T>(T[] array)
{ {
@ -351,7 +354,7 @@ namespace AlmToolkit
Settings.Default.SourceCatalog = _comparisonInfo.ConnectionInfoSource.DatabaseName; Settings.Default.SourceCatalog = _comparisonInfo.ConnectionInfoSource.DatabaseName;
Settings.Default.Save(); Settings.Default.Save();
GetFromAutoCompleteSource(); //GetFromAutoCompleteSource();
} }
if (!_comparisonInfo.ConnectionInfoTarget.UseProject && !_comparisonInfo.ConnectionInfoTarget.UseDesktop && !_comparisonInfo.ConnectionInfoTarget.UseBimFile) if (!_comparisonInfo.ConnectionInfoTarget.UseProject && !_comparisonInfo.ConnectionInfoTarget.UseDesktop && !_comparisonInfo.ConnectionInfoTarget.UseBimFile)
@ -367,7 +370,7 @@ namespace AlmToolkit
Settings.Default.TargetCatalog = _comparisonInfo.ConnectionInfoTarget.DatabaseName; Settings.Default.TargetCatalog = _comparisonInfo.ConnectionInfoTarget.DatabaseName;
Settings.Default.Save(); Settings.Default.Save();
GetFromAutoCompleteTarget(); //GetFromAutoCompleteTarget();
} }
} }
@ -724,22 +727,19 @@ namespace AlmToolkit
catch { } 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)) _comparisonInfo.ConnectionInfoSource.UseDesktop = true;
{ _comparisonInfo.ConnectionInfoSource.ServerName = serverName;
this.Text = Utils.AssemblyProduct; _comparisonInfo.ConnectionInfoSource.DatabaseName = databaseName;
}
else //GetFromAutoCompleteSource();
{ //GetFromAutoCompleteTarget();
this.Text = Utils.AssemblyProduct + " - " + Path.GetFileName(_fileName);
if (unsaved) SetNotComparedState();
{
this.Text += " *";
}
}
} }
public void LoadFile(string fileName) 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) public void SaveFile(string fileName)
{ {
try try

View File

@ -1,4 +1,5 @@
using System; using Microsoft.AnalysisServices;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -18,28 +19,37 @@ namespace AlmToolkit
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
//with args(user open file with the program)
if (args != null && args.Length > 0) if (args != null && args.Length > 0)
{ {
string fileName = args[0]; if (args.Length > 1)
//Check file exists //User opened from Desktop with server/db name
if (File.Exists(fileName))
{ {
string serverName = args[0];
string databaseName = args[1];
ComparisonForm MainFrom = new ComparisonForm(); ComparisonForm MainFrom = new ComparisonForm();
MainFrom.LoadFile(fileName); MainFrom.LoadFromDesktop(serverName, databaseName);
Application.Run(MainFrom); Application.Run(MainFrom);
return;
} }
//The file does not exist
else 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 //Without valid args
{ Application.Run(new ComparisonForm());
Application.Run(new ComparisonForm());
}
} }
} }
} }

View File

@ -21,7 +21,5 @@ namespace AlmToolkit
return ((AssemblyProductAttribute)attributes[0]).Product; return ((AssemblyProductAttribute)attributes[0]).Product;
} }
} }
} }
} }

View File

@ -78,6 +78,8 @@ namespace BismNormalizer.TabularCompare.UI
cboSourceDatabase.Text = Settings.Default.SourceCatalog; cboSourceDatabase.Text = Settings.Default.SourceCatalog;
cboTargetDatabase.Text = Settings.Default.TargetCatalog; cboTargetDatabase.Text = Settings.Default.TargetCatalog;
#region Prep Desktop/SSDT instances
cboSourceDesktop.Items.Clear(); cboSourceDesktop.Items.Clear();
cboTargetDesktop.Items.Clear(); cboTargetDesktop.Items.Clear();
@ -105,15 +107,17 @@ namespace BismNormalizer.TabularCompare.UI
cboTargetDesktop.DataSource = desktopBindingTarget; cboTargetDesktop.DataSource = desktopBindingTarget;
cboTargetDesktop.ValueMember = "Port"; cboTargetDesktop.ValueMember = "Port";
cboTargetDesktop.DisplayMember = "Name"; cboTargetDesktop.DisplayMember = "Name";
BindSourceConnectionInfo();
BindTargetConnectionInfo();
} }
else else
{ {
rdoSourceDesktop.Enabled = false; rdoSourceDesktop.Enabled = false;
rdoTargetDesktop.Enabled = false; rdoTargetDesktop.Enabled = false;
} }
#endregion
BindSourceConnectionInfo();
BindTargetConnectionInfo();
} }
private bool BindSourceConnectionInfo() private bool BindSourceConnectionInfo()
@ -136,26 +140,29 @@ namespace BismNormalizer.TabularCompare.UI
} }
else if (_comparisonInfo.ConnectionInfoSource.UseDesktop) else if (_comparisonInfo.ConnectionInfoSource.UseDesktop)
{ {
rdoSourceDesktop.Checked = true; if (_powerBIInstances.Count > 0)
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))
{ {
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; if (((PowerBIInstance)((BindingSource)cboSourceDesktop.DataSource)[i]).Port == portFromConnectionInfo)
break; {
cboSourceDesktop.SelectedIndex = i;
break;
}
} }
} }
boundSuccessfully = true;
} }
boundSuccessfully = true;
} }
else if (!String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoSource.ServerName) && !String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoSource.DatabaseName)) 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) else if (_comparisonInfo.ConnectionInfoTarget.UseDesktop)
{ {
rdoTargetDesktop.Checked = true; if (_powerBIInstances.Count > 0)
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))
{ {
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; if (((PowerBIInstance)((BindingSource)cboTargetDesktop.DataSource)[i]).Port == portFromConnectionInfo)
break; {
cboTargetDesktop.SelectedIndex = i;
break;
}
} }
} }
boundSuccessfully = true;
} }
boundSuccessfully = true;
} }
else if (!String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoTarget.ServerName) && !String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoTarget.DatabaseName)) else if (!String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoTarget.ServerName) && !String.IsNullOrEmpty(_comparisonInfo.ConnectionInfoTarget.DatabaseName))
{ {