Exemplo n.º 1
0
        public static UserConfigOptionsModel LoadConfigData()
        {
            var response = new UserConfigOptionsModel();

            var configFilename = ConfigurationManager.AppSettings["UserConfigFileName"];
            var currentDir     = Directory.GetCurrentDirectory();

            var di = new DirectoryInfo(currentDir).GetFiles().Where(x => x.Name == configFilename).ToList();

            if (!di.Any())
            {
                response = GetDefaultUserOptions(currentDir);

                using (var fileStream = new FileStream(String.Format("{0}\\{1}", currentDir, configFilename), FileMode.Create))
                    using (var fileWriter = new StreamWriter(fileStream))
                    {
                        fileWriter.Write(response.ToXML());
                    }
            }
            else
            {
                using (var fileStream = new FileStream(String.Format("{0}\\{1}", currentDir, configFilename), FileMode.Open))
                    using (var fileReader = new StreamReader(fileStream))
                    {
                        var xmlData = fileReader.ReadToEnd();

                        response = UserConfigOptionsModel.LoadFromXMLString(xmlData);
                    }
            }

            return(response);
        }
Exemplo n.º 2
0
        private static UserConfigOptionsModel GetDefaultUserOptions(string currentWorkingDirectory)
        {
            var response = new UserConfigOptionsModel();

            response.ResourceLocation = String.Format("{0}\\{1}", currentWorkingDirectory, ConfigurationManager.AppSettings["DefaultBaseResourceLocation"]);
            response.TestingFlag      = ConfigurationManager.AppSettings["DefaultTestingFlag"];

            return(response);
        }
Exemplo n.º 3
0
        public static void SaveUserConfigOptions(UserConfigOptionsModel userConfigOptions)
        {
            var configFilename = ConfigurationManager.AppSettings["UserConfigFileName"];

            using (var fileStream = new FileStream(String.Format("{0}\\{1}", LoggingUtility.CurrentWorkingDirectory, configFilename), FileMode.Create))
                using (var fileWriter = new StreamWriter(fileStream))
                {
                    fileWriter.Write(userConfigOptions.ToXML());
                }
        }
Exemplo n.º 4
0
        public static ConfigForm GetInstance(UserConfigOptionsModel userConfigOptions)
        {
            if (_configForm == null)
            {
                _configForm             = new ConfigForm(userConfigOptions);
                _configForm.FormClosed += delegate { _configForm = null; }; // When the form gets closed: run the code in the delegate
            }

            _configForm.BringToFront();

            return(_configForm);
        }
Exemplo n.º 5
0
        private ConfigForm(UserConfigOptionsModel userConfigOptions)
        {
            UserConfigOptions = userConfigOptions;

            InitializeComponent();
        }