public RemoteConnectionsSyncronizer(IConnectionsUpdateChecker updateChecker) { _updateChecker = updateChecker; _updateTimer = new Timer(3000); _connectionsLoader = new ConnectionsLoader { UseDatabase = mRemoteNG.Settings.Default.UseSQLServer }; _connectionsSaver = new ConnectionsSaver { SaveFormat = ConnectionsSaver.Format.SQL }; SetEventListeners(); }
public static void NewConnections(string filename) { try { ConnectionList = new ConnectionList(); ContainerList = new ContainerList(); ConnectionsLoader connectionsLoader = new ConnectionsLoader(); if (filename == GetDefaultStartupConnectionFileName()) { Settings.Default.LoadConsFromCustomLocation = false; } else { Settings.Default.LoadConsFromCustomLocation = true; Settings.Default.CustomConsPath = filename; } var dirname = GetDirectoryName(filename); if (dirname != null) { Directory.CreateDirectory(dirname); } // Use File.Open with FileMode.CreateNew so that we don't overwrite an existing file using (FileStream fileStream = File.Open(filename, FileMode.CreateNew, FileAccess.Write, FileShare.None)) { using (XmlTextWriter xmlTextWriter = new XmlTextWriter(fileStream, System.Text.Encoding.UTF8)) { xmlTextWriter.Formatting = Formatting.Indented; xmlTextWriter.Indentation = 4; xmlTextWriter.WriteStartDocument(); xmlTextWriter.WriteStartElement("Connections"); // Do not localize xmlTextWriter.WriteAttributeString("Name", Language.strConnections); xmlTextWriter.WriteAttributeString("Export", "", "False"); xmlTextWriter.WriteAttributeString("Protected", "", "GiUis20DIbnYzWPcdaQKfjE2H5jh//L5v4RGrJMGNXuIq2CttB/d/BxaBP2LwRhY"); xmlTextWriter.WriteAttributeString("ConfVersion", "", "2.5"); xmlTextWriter.WriteEndElement(); xmlTextWriter.WriteEndDocument(); xmlTextWriter.Close(); } } connectionsLoader.ConnectionList = ConnectionList; connectionsLoader.ContainerList = ContainerList; ConnectionTree.ResetTree(); connectionsLoader.RootTreeNode = Windows.treeForm.tvConnections.Nodes[0]; // Load config connectionsLoader.ConnectionFileName = filename; connectionsLoader.LoadConnections(false); Windows.treeForm.tvConnections.SelectedNode = connectionsLoader.RootTreeNode; } catch (Exception ex) { MessageCollector.AddExceptionMessage(Language.strCouldNotCreateNewConnectionsFile, ex); } }
/// <summary> /// Get available connection list /// </summary> public List <ConnectionGroupInfo> GetAvailableConnections() { var filenames = this._filesProvider.GetConnectionsFilenames(); var connections = new List <ConnectionGroupInfo>(); foreach (var filename in filenames) { connections.AddRange(ConnectionsLoader.LoadFromXml(filename)); } return(connections); }
private void mnuAddLicense_Click(object sender, EventArgs e) { List <ConnectionGroupInfo> licenses; using (var dlg = new OpenFileDialog { Filter = @"XML|*.xml" }) { if (dlg.ShowDialog() != DialogResult.OK) { return; } try { licenses = ConnectionsLoader.LoadFromXml(dlg.FileName).ToList(); } catch (Exception ex) { licenses = new List <ConnectionGroupInfo>(); log.Error(ex); } } if (licenses.Count == 0) { MessageBox.Show( this._model.LocaleManager.GetLocalizedText(this.Name, @"msgNoLicenseFound"), LicensesLocalizedText(), MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } ConnectionsLoader.SaveToXml(this._model.FilesProvider.ComposeNewFileNameForAddedConnection(), licenses); var form = new frmLicenseErrors { StartPosition = FormStartPosition.CenterParent, Text = this._model.LocaleManager.GetLocalizedText(this.Name, @"msgLicenseSuccessfulyAdded") }; form.IgnoreLocalizationProperties.Add("Text"); form.SetLicenseProblems(licenses.SelectMany(cnn => cnn.Connections.Select(l => l.ValidateLicense(true))).ToList()); form.ShowDialog(); //MessageBox.Show(this._model.LocaleManager.GetLocalizedText(this.Name, @"msgLicenseSuccessfulyAdded"), LicensesLocalizedText(), // MessageBoxButtons.OK, MessageBoxIcon.Information); }
public static void Import(string fileName, TreeNode parentTreeNode) { var name = Path.GetFileNameWithoutExtension(fileName); var treeNode = new TreeNode(name); parentTreeNode.Nodes.Add(treeNode); var containerInfo = new ContainerInfo { TreeNode = treeNode, Name = name }; var connectionInfo = new ConnectionInfo(); connectionInfo.Inheritance = new ConnectionInfoInheritance(connectionInfo); connectionInfo.Name = name; connectionInfo.TreeNode = treeNode; connectionInfo.Parent = containerInfo; connectionInfo.IsContainer = true; containerInfo.ConnectionInfo = connectionInfo; // We can only inherit from a container node, not the root node or connection nodes if (ConnectionTreeNode.GetNodeType(parentTreeNode) == TreeNodeType.Container) { containerInfo.Parent = (ContainerInfo)parentTreeNode.Tag; } else { connectionInfo.Inheritance.DisableInheritance(); } treeNode.Name = name; treeNode.Tag = containerInfo; treeNode.ImageIndex = (int)TreeImageType.Container; treeNode.SelectedImageIndex = (int)TreeImageType.Container; var connectionsLoad = new ConnectionsLoader { ConnectionFileName = fileName, RootTreeNode = treeNode, ConnectionList = Runtime.ConnectionList, ContainerList = Runtime.ContainerList }; connectionsLoad.LoadConnections(true); Runtime.ContainerList.Add(containerInfo); }
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(); } } }
private void Awake() { this.config = ConnectionsLoader.loadConfig(); FB.Init(OnInitComplete, OnHideUnity, null); }
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(); } } }