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
        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());
                }
        }