Esempio n. 1
0
            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();
                        }
                    }
                }
            }
Esempio n. 2
0
            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);
                }
            }