convert big if-else to switch

This commit is contained in:
Sean Kaim
2017-03-05 14:43:25 -05:00
parent e824886e19
commit a3e436e42d

View File

@@ -16,77 +16,87 @@ namespace mRemoteNG.App
private static UltraVNCWindow _ultravncscForm;
private static ComponentsCheckWindow _componentscheckForm;
public static ConnectionTreeWindow TreeForm { get; set; } = new ConnectionTreeWindow();
public static ConfigWindow ConfigForm { get; set; } = new ConfigWindow();
public static ErrorAndInfoWindow ErrorsForm { get; set; } = new ErrorAndInfoWindow();
public static ScreenshotManagerWindow ScreenshotForm { get; set; } = new ScreenshotManagerWindow();
public static UpdateWindow UpdateForm { get; set; } = new UpdateWindow();
public static SSHTransferWindow SshtransferForm { get; set; }
internal static ConnectionTreeWindow TreeForm { get; set; } = new ConnectionTreeWindow();
internal static ConfigWindow ConfigForm { get; set; } = new ConfigWindow();
internal static ErrorAndInfoWindow ErrorsForm { get; set; } = new ErrorAndInfoWindow();
internal static ScreenshotManagerWindow ScreenshotForm { get; set; } = new ScreenshotManagerWindow();
private static UpdateWindow UpdateForm { get; set; } = new UpdateWindow();
internal static SSHTransferWindow SshtransferForm { get; private set; } = new SSHTransferWindow();
public static void Show(WindowType windowType)
{
try
{
if (windowType.Equals(WindowType.About))
// ReSharper disable once SwitchStatementMissingSomeCases
switch (windowType)
{
if (_aboutForm == null || _aboutForm.IsDisposed)
_aboutForm = new AboutWindow();
_aboutForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.ActiveDirectoryImport))
{
if (_adimportForm == null || _adimportForm.IsDisposed)
_adimportForm = new ActiveDirectoryImportWindow();
_adimportForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.Options))
{
using (var optionsForm = new frmOptions())
{
optionsForm.ShowDialog(FrmMain.Default.pnlDock);
}
}
else if (windowType.Equals(WindowType.SSHTransfer))
{
SshtransferForm = new SSHTransferWindow();
SshtransferForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.Update))
{
if (UpdateForm == null || UpdateForm.IsDisposed)
UpdateForm = new UpdateWindow();
UpdateForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.Help))
{
if (_helpForm == null || _helpForm.IsDisposed)
_helpForm = new HelpWindow();
_helpForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.ExternalApps))
{
if (_externalappsForm == null || _externalappsForm.IsDisposed)
_externalappsForm = new ExternalToolsWindow();
_externalappsForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.PortScan))
{
_portscanForm = new PortScanWindow();
_portscanForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.UltraVNCSC))
{
if (_ultravncscForm == null || _ultravncscForm.IsDisposed)
_ultravncscForm = new UltraVNCWindow();
_ultravncscForm.Show(FrmMain.Default.pnlDock);
}
else if (windowType.Equals(WindowType.ComponentsCheck))
{
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Showing ComponentsCheck window", true);
if (_componentscheckForm == null || _componentscheckForm.IsDisposed)
_componentscheckForm = new ComponentsCheckWindow();
_componentscheckForm.Show(FrmMain.Default.pnlDock);
case WindowType.About:
if (_aboutForm == null || _aboutForm.IsDisposed)
_aboutForm = new AboutWindow();
_aboutForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.ActiveDirectoryImport:
if (_adimportForm == null || _adimportForm.IsDisposed)
_adimportForm = new ActiveDirectoryImportWindow();
_adimportForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.Options:
using (var optionsForm = new frmOptions())
{
optionsForm.ShowDialog(FrmMain.Default.pnlDock);
}
break;
case WindowType.SSHTransfer:
if (SshtransferForm == null || SshtransferForm.IsDisposed)
SshtransferForm = new SSHTransferWindow();
SshtransferForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.Update:
if (UpdateForm == null || UpdateForm.IsDisposed)
UpdateForm = new UpdateWindow();
UpdateForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.Help:
if (_helpForm == null || _helpForm.IsDisposed)
_helpForm = new HelpWindow();
_helpForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.ExternalApps:
if (_externalappsForm == null || _externalappsForm.IsDisposed)
_externalappsForm = new ExternalToolsWindow();
_externalappsForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.PortScan:
_portscanForm = new PortScanWindow();
_portscanForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.UltraVNCSC:
if (_ultravncscForm == null || _ultravncscForm.IsDisposed)
_ultravncscForm = new UltraVNCWindow();
_ultravncscForm.Show(FrmMain.Default.pnlDock);
break;
case WindowType.ComponentsCheck:
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Showing ComponentsCheck window", true);
if (_componentscheckForm == null || _componentscheckForm.IsDisposed)
_componentscheckForm = new ComponentsCheckWindow();
_componentscheckForm.Show(FrmMain.Default.pnlDock);
break;
/*
case WindowType.Tree:
break;
case WindowType.Connection:
break;
case WindowType.Config:
break;
case WindowType.ErrorsAndInfos:
break;
case WindowType.ScreenshotManager:
break;
default:
throw new ArgumentOutOfRangeException(nameof(windowType), windowType, null);
*/
}
}
catch (Exception ex)