private void GetUpdateInfoCompleted(object sender, AsyncCompletedEventArgs e) { if (InvokeRequired) { AsyncCompletedEventHandler myDelegate = GetUpdateInfoCompleted; Invoke(myDelegate, sender, e); return; } try { _appUpdate.GetUpdateInfoCompletedEvent -= GetUpdateInfoCompleted; btnTestProxy.Enabled = true; btnTestProxy.Text = Language.strButtonTestProxy; if (e.Cancelled) { return; } if (e.Error != null) { throw e.Error; } CTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName), Language.strProxyTestSucceeded, "", Language.strButtonOK, false); } catch (Exception ex) { CTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName), Language.strProxyTestFailed, MiscTools.GetExceptionMessageRecursive(ex), "", "", "", Language.strButtonOK, false, ESysIcons.Error, 0); } }
private static TreeNode GetParentTreeNode(TreeNode rootTreeNode, TreeNode selectedTreeNode, bool alwaysUseSelectedTreeNode = false) { TreeNode parentTreeNode; selectedTreeNode = GetContainerTreeNode(selectedTreeNode); if (selectedTreeNode == null || selectedTreeNode == rootTreeNode) { parentTreeNode = rootTreeNode; } else { if (alwaysUseSelectedTreeNode) { parentTreeNode = GetContainerTreeNode(selectedTreeNode); } else { CTaskDialog.ShowCommandBox(Application.ProductName, Language.strImportLocationMainInstruction, Language.strImportLocationContent, "", "", "", string.Format(Language.strImportLocationCommandButtons, Environment.NewLine, rootTreeNode.Text, selectedTreeNode.Text), true, ESysIcons.Question, 0); switch (CTaskDialog.CommandButtonResult) { case 0: // Root parentTreeNode = rootTreeNode; break; case 1: // Selected Folder parentTreeNode = GetContainerTreeNode(selectedTreeNode); break; default: // Cancel parentTreeNode = null; break; } } } return(parentTreeNode); }
public static void LoadConnections(bool withDialog = false, bool update = false) { var connectionsLoader = new ConnectionsLoader(); try { // disable sql update checking while we are loading updates RemoteConnectionsSyncronizer?.Disable(); if (!Settings.Default.UseSQLServer) { if (withDialog) { var loadDialog = Controls.ConnectionsLoadDialog(); if (loadDialog.ShowDialog() != DialogResult.OK) { return; } connectionsLoader.ConnectionFileName = loadDialog.FileName; } else { connectionsLoader.ConnectionFileName = GetStartupConnectionFileName(); } CreateBackupFile(Convert.ToString(connectionsLoader.ConnectionFileName)); } connectionsLoader.UseDatabase = Settings.Default.UseSQLServer; ConnectionTreeModel = connectionsLoader.LoadConnections(false); Windows.TreeForm.ConnectionTreeModel = ConnectionTreeModel; if (Settings.Default.UseSQLServer) { LastSqlUpdate = DateTime.Now; } else { if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName()) { Settings.Default.LoadConsFromCustomLocation = false; } else { Settings.Default.LoadConsFromCustomLocation = true; Settings.Default.CustomConsPath = connectionsLoader.ConnectionFileName; } } // re-enable sql update checking after updates are loaded RemoteConnectionsSyncronizer?.Enable(); } catch (Exception ex) { if (Settings.Default.UseSQLServer) { MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex); var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName)); CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error); switch (CTaskDialog.CommandButtonResult) { case 0: LoadConnections(withDialog, update); return; case 1: Settings.Default.UseSQLServer = false; LoadConnections(true, update); return; default: Application.Exit(); return; } } if (ex is FileNotFoundException && !withDialog) { MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg); NewConnections(Convert.ToString(connectionsLoader.ConnectionFileName)); return; } MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex); if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName()) { LoadConnections(withDialog, update); } else { MessageBox.Show(frmMain.Default, string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)), @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } } }
/// <summary> /// /// </summary> /// <param name="withDialog"> /// Should we show the file selection dialog to allow the user to select /// a connection file /// </param> public static void LoadConnections(bool withDialog = false) { var connectionFileName = ""; try { // disable sql update checking while we are loading updates ConnectionsService.RemoteConnectionsSyncronizer?.Disable(); if (withDialog) { var loadDialog = DialogFactory.BuildLoadConnectionsDialog(); if (loadDialog.ShowDialog() != DialogResult.OK) { return; } connectionFileName = loadDialog.FileName; Settings.Default.UseSQLServer = false; Settings.Default.Save(); } else if (!Settings.Default.UseSQLServer) { connectionFileName = ConnectionsService.GetStartupConnectionFileName(); } ConnectionsService.LoadConnections(Settings.Default.UseSQLServer, false, connectionFileName); if (Settings.Default.UseSQLServer) { ConnectionsService.LastSqlUpdate = DateTime.Now; } // re-enable sql update checking after updates are loaded ConnectionsService.RemoteConnectionsSyncronizer?.Enable(); } catch (Exception ex) { if (Settings.Default.UseSQLServer) { MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex); var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName)); CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error); switch (CTaskDialog.CommandButtonResult) { case 0: LoadConnections(withDialog); return; case 1: Settings.Default.UseSQLServer = false; LoadConnections(true); return; default: Application.Exit(); return; } } if (ex is FileNotFoundException && !withDialog) { MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), ex, MessageClass.InformationMsg); string[] commandButtons = { Language.ConfigurationCreateNew, Language.ConfigurationCustomPath, Language.ConfigurationImportFile, Language.strMenuExit }; var answered = false; while (!answered) { try { CTaskDialog.ShowTaskDialogBox( GeneralAppInfo.ProductName, Language.ConnectionFileNotFound, "", "", "", "", "", string.Join(" | ", commandButtons), ETaskDialogButtons.None, ESysIcons.Question, ESysIcons.Question); switch (CTaskDialog.CommandButtonResult) { case 0: ConnectionsService.NewConnectionsFile(connectionFileName); answered = true; break; case 1: LoadConnections(true); answered = true; break; case 2: ConnectionsService.NewConnectionsFile(connectionFileName); Import.ImportFromFile(ConnectionsService.ConnectionTreeModel.RootNodes[0]); answered = true; break; case 3: Application.Exit(); answered = true; break; } } catch (Exception exc) { MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), exc, MessageClass.InformationMsg); } } return; } MessageCollector.AddExceptionStackTrace(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionFileName), ex); if (connectionFileName != ConnectionsService.GetStartupConnectionFileName()) { LoadConnections(withDialog); } else { MessageBox.Show(FrmMain.Default, string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, ConnectionsService.GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)), @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } } }
public static void LoadConnections(bool withDialog = false, bool update = false) { var connectionsLoader = new ConnectionsLoader(); try { // disable sql update checking while we are loading updates SQLConnProvider?.Disable(); if (ConnectionList != null && ContainerList != null) { PreviousConnectionList = ConnectionList.Copy(); PreviousContainerList = ContainerList.Copy(); } ConnectionList = new ConnectionList(); ContainerList = new ContainerList(); if (!Settings.Default.UseSQLServer) { if (withDialog) { var loadDialog = Tools.Controls.ConnectionsLoadDialog(); if (loadDialog.ShowDialog() != DialogResult.OK) { return; } connectionsLoader.ConnectionFileName = loadDialog.FileName; } else { connectionsLoader.ConnectionFileName = GetStartupConnectionFileName(); } CreateBackupFile(Convert.ToString(connectionsLoader.ConnectionFileName)); } connectionsLoader.ConnectionList = ConnectionList; connectionsLoader.ContainerList = ContainerList; if (PreviousConnectionList != null && PreviousContainerList != null) { connectionsLoader.PreviousConnectionList = PreviousConnectionList; connectionsLoader.PreviousContainerList = PreviousContainerList; } if (update) { connectionsLoader.PreviousSelected = LastSelected; } ConnectionTree.ResetTree(); connectionsLoader.RootTreeNode = Windows.treeForm.tvConnections.Nodes[0]; connectionsLoader.UseDatabase = Settings.Default.UseSQLServer; connectionsLoader.DatabaseHost = Settings.Default.SQLHost; connectionsLoader.DatabaseName = Settings.Default.SQLDatabaseName; connectionsLoader.DatabaseUsername = Settings.Default.SQLUser; var cryptographyProvider = new LegacyRijndaelCryptographyProvider(); connectionsLoader.DatabasePassword = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.SQLPass), GeneralAppInfo.EncryptionKey); connectionsLoader.DatabaseUpdate = update; connectionsLoader.LoadConnections(false); if (Settings.Default.UseSQLServer) { LastSqlUpdate = DateTime.Now; } else { if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName()) { Settings.Default.LoadConsFromCustomLocation = false; } else { Settings.Default.LoadConsFromCustomLocation = true; Settings.Default.CustomConsPath = connectionsLoader.ConnectionFileName; } } // re-enable sql update checking after updates are loaded SQLConnProvider?.Enable(); } catch (Exception ex) { if (Settings.Default.UseSQLServer) { MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex); var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName)); CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error); switch (CTaskDialog.CommandButtonResult) { case 0: LoadConnections(withDialog, update); return; case 1: Settings.Default.UseSQLServer = false; LoadConnections(true, update); return; default: Application.Exit(); return; } } if (ex is FileNotFoundException && !withDialog) { MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg); NewConnections(Convert.ToString(connectionsLoader.ConnectionFileName)); return; } MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex); if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName()) { LoadConnections(withDialog, update); } else { MessageBox.Show(frmMain.Default, string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)), "Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } } }