Пример #1
0
        public void AppConfigWriteTest()
        {
            UserConfigWriter.m_TestUserConfigName = Path.GetTempPath() + "user_v6.config";
            AppConfigWriter.m_TestAppConfigName   = Path.GetTempPath() + "app_v6.config";
            if (File.Exists(AppConfigWriter.m_TestAppConfigName))
            {
                File.Delete(AppConfigWriter.m_TestAppConfigName);
            }
            var config = new ConfigWriter();

            config.Read(AppConfigWriter.m_TestAppConfigName);
            Assert.AreEqual("", config.GetItem("DocumentPrinter"));
            string expected = "test printer";
            //Assert.AreEqual(AppConfigWriter.Instance.FileName, AppConfigWriter.m_TestAppConfigName);
            //AppConfigWriter.Instance.SetItem("DocumentPrinter", expected);
            //AppConfigWriter.Instance.SetItem("SomeItem", "true");
            //AppConfigWriter.Instance.Save();
            //config.Read(AppConfigWriter.m_TestAppConfigName);
            //Assert.AreEqual(expected, config.GetItem("DocumentPrinter"));
            //Assert.AreEqual("", config.GetItem("SomeItem"));
            ConfigWriter target = AppConfigWriter.CreateConfigWriter();

            target.SetItem("DocumentPrinter", expected);
            target.SetItem("SomeItem", "false");
            target.Save();
            config.Read(AppConfigWriter.m_TestAppConfigName);
            Assert.AreEqual(expected, config.GetItem("DocumentPrinter"));
            Assert.AreEqual("", config.GetItem("SomeItem"));
        }
Пример #2
0
        private bool Save(string fileName = null)
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                if (!ValidateConnection() || !ValidateArchiveConnection() || !ValidateLanguages() || !ValidateConnectionForAvr())
                {
                    return(false);
                }

                SaveDbConnection();
                SaveArchiveConnection();
                SaveReportsServiceSettings();
                SaveWebSettings();
                SaveWebAdvancedSettings();
                SaveMiscellaneousSettings();

                if (fileName == null)
                {
                    m_config.Save(true, true);
                }
                else
                {
                    m_config.SaveAs(fileName, true, true);
                }
                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(this, "Can't save configuration file: " + e.Message);
                return(false);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }