コード例 #1
0
ファイル: App.Runtime.cs プロジェクト: hmaster20/mRemoteNC
            public static void LoadConnections(bool WithDialog = false, bool Update = false)
            {
                Load conL = new Load();

                try
                {
                    bool tmrWasEnabled = false;
                    if (TimerSqlWatcher != null)
                    {
                        tmrWasEnabled = TimerSqlWatcher.Enabled;

                        if (TimerSqlWatcher.Enabled == true)
                        {
                            TimerSqlWatcher.Stop();
                        }
                    }

                    if (ConnectionList != null && ContainerList != null)
                    {
                        PreviousConnectionList = ConnectionList.Copy();
                        //PreviousContainerList = ContainerList.Copy;
                    }

                    ConnectionList = new Connection.List();
                    ContainerList = new Container.List();

                    if (Settings.Default.UseSQLServer == false)
                    {
                        if (WithDialog)
                        {
                            OpenFileDialog lD = Controls.ConnectionsLoadDialog();

                            if (lD.ShowDialog() == DialogResult.OK)
                            {
                                conL.ConnectionFileName = lD.FileName;
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            conL.ConnectionFileName = GetStartupConnectionFileName();
                        }

                        if (File.Exists((string)conL.ConnectionFileName) == false)
                        {
                            if (WithDialog)
                            {
                                MessageCollector.AddMessage(MessageClass.WarningMsg,
                                                            string.Format(
                                                                Language.strConnectionsFileCouldNotBeLoaded,
                                                                conL.ConnectionFileName));
                            }
                            else
                            {
                                MessageCollector.AddMessage(MessageClass.InformationMsg,
                                                            string.Format(
                                                                Language.
                                                                    strConnectionsFileCouldNotBeLoadedNew,
                                                                conL.ConnectionFileName));
                                NewConnections(conL.ConnectionFileName);
                            }

                            return;
                        }

                        CreateBackupFile(conL.ConnectionFileName);
                    }

                    conL.ConnectionList = ConnectionList;
                    conL.ContainerList = ContainerList;

                    if (PreviousConnectionList != null && PreviousContainerList != null)
                    {
                        conL.PreviousConnectionList = PreviousConnectionList;
                        conL.PreviousContainerList = PreviousContainerList;
                    }

                    if (Update)
                    {
                        conL.PreviousSelected = LastSelected;
                    }

                    conL.Import = false;

                    Node.ResetTree();

                    conL.RootTreeNode = Windows.treeForm.tvConnections.Nodes[0];

                    conL.UseSQL = Settings.Default.UseSQLServer;
                    conL.SQLHost = Settings.Default.SQLHost;
                    conL.SQLDatabaseName = Settings.Default.SQLDatabaseName;
                    conL.SQLUsername = Settings.Default.SQLUser;
                    conL.SQLPassword = Crypt.Decrypt((string)Settings.Default.SQLPass,
                                                     (string)General.EncryptionKey);
                    conL.SQLUpdate = Update;

                    conL.LoadConnections();

                    if (Settings.Default.UseSQLServer == true)
                    {
                        LastSqlUpdate = DateTime.Now;
                    }
                    else
                    {
                        if (conL.ConnectionFileName ==
                            Connections.DefaultConnectionsPath + "\\" +
                            Connections.DefaultConnectionsFile)
                        {
                            Settings.Default.LoadConsFromCustomLocation = false;
                        }
                        else
                        {
                            Settings.Default.LoadConsFromCustomLocation = true;
                            Settings.Default.CustomConsPath = conL.ConnectionFileName;
                        }
                    }

                    if (tmrWasEnabled && TimerSqlWatcher != null)
                    {
                        TimerSqlWatcher.Start();
                    }
                }
                catch (Exception ex)
                {
                    MessageCollector.AddMessage(MessageClass.ErrorMsg,
                                                string.Format(
                                                    Language.strConnectionsFileCouldNotBeLoaded +
                                                    Constants.vbNewLine + ex.Message + ex.StackTrace,
                                                    conL.ConnectionFileName));
                    if (Settings.Default.UseSQLServer == false)
                    {
                        if (conL.ConnectionFileName != GetStartupConnectionFileName())
                        {
                            LoadConnections();
                            return;
                        }
                        else
                        {
                            Interaction.MsgBox(
                                string.Format(Language.strErrorStartupConnectionFileLoad, Constants.vbNewLine,
                                              Application.ProductName, GetStartupConnectionFileName(), ex.Message),
                                MsgBoxStyle.OkOnly, null);
                            Application.Exit();
                        }
                    }
                }
            }
コード例 #2
0
ファイル: App.Runtime.cs プロジェクト: hmaster20/mRemoteNC
            public static void ImportConnections()
            {
                try
                {
                    OpenFileDialog lD = Controls.ConnectionsLoadDialog();
                    lD.Multiselect = true;

                    if (lD.ShowDialog() == DialogResult.OK)
                    {
                        TreeNode nNode = null;

                        for (int i = 0; i <= lD.FileNames.Length - 1; i++)
                        {
                            nNode = Node.AddNode(Node.Type.Container, "Import #" + i.ToString());

                            Container.Info nContI = new Container.Info();
                            nContI.TreeNode = nNode;
                            nContI.ConnectionInfo = new Connection.Info(nContI);

                            if (Node.SelectedNode != null)
                            {
                                if (Node.GetNodeType(Node.SelectedNode) == Node.Type.Container)
                                {
                                    nContI.Parent = Node.SelectedNode.Tag;
                                }
                            }

                            nNode.Tag = nContI;
                            ContainerList.Add(nContI);

                            Load conL = new Load
                                            {
                                                ConnectionFileName = lD.FileNames[i],
                                                RootTreeNode = nNode,
                                                Import = true,
                                                ConnectionList = ConnectionList,
                                                ContainerList = ContainerList
                                            };

                            conL.LoadConnections();

                            Windows.treeForm.tvConnections.SelectedNode.Nodes.Add(nNode);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageCollector.AddMessage(MessageClass.ErrorMsg,
                                                Language.strConnectionsFileCouldNotBeImported +
                                                Constants.vbNewLine + ex.Message);
                }
            }
コード例 #3
0
ファイル: App.Runtime.cs プロジェクト: hmaster20/mRemoteNC
            public static void NewConnections(string filename)
            {
                try
                {
                    ConnectionList = new Connection.List();
                    ContainerList = new Container.List();

                    Load conL = new Load();

                    Settings.Default.LoadConsFromCustomLocation = false;

                    Directory.CreateDirectory(Path.GetDirectoryName(filename));
                    XmlTextWriter xW = new XmlTextWriter(filename, Encoding.UTF8);
                    xW.Formatting = Formatting.Indented;
                    xW.Indentation = 4;

                    xW.WriteStartDocument();
                    xW.WriteStartElement("Connections"); // Do not localize
                    xW.WriteAttributeString("Name", Language.strConnections);
                    xW.WriteAttributeString("Export", "", "False");
                    xW.WriteAttributeString("Protected", "",
                                            "GiUis20DIbnYzWPcdaQKfjE2H5jh//L5v4RGrJMGNXuIq2CttB/d/BxaBP2LwRhY");
                    xW.WriteAttributeString("ConfVersion", "", "2.4");

                    xW.WriteEndElement();
                    xW.WriteEndDocument();

                    xW.Close();

                    conL.ConnectionList = ConnectionList;
                    conL.ContainerList = ContainerList;
                    conL.Import = false;

                    Node.ResetTree();

                    conL.RootTreeNode = Windows.treeForm.tvConnections.Nodes[0];

                    // Load config
                    conL.ConnectionFileName = filename;
                    conL.LoadConnections();

                    Windows.treeForm.tvConnections.SelectedNode = conL.RootTreeNode;
                }
                catch (Exception ex)
                {
                    MessageCollector.AddMessage(MessageClass.ErrorMsg,
                                                Language.strCouldNotCreateNewConnectionsFile +
                                                Constants.vbNewLine + ex.Message);
                }
            }