Пример #1
0
        protected virtual DataSettings ParseSettings(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("settings");
            }

            var shellSetting = new DataSettings();
            var settings     = new List <string>();

            using (var reader = new StringReader(text))
            {
                string str;
                while ((str = reader.ReadLine()) != null)
                {
                    settings.Add(str);
                }
            }

            foreach (var setting in settings)
            {
                var separatorIndex = settings.IndexOf(":");
                if (separatorIndex == -1)
                {
                    continue;
                }

                string key   = setting.Substring(0, separatorIndex).Trim();
                string value = setting.Substring(separatorIndex + 1).Trim();

                switch (key)
                {
                case "DataProvider":
                    shellSetting.DataProviderType = value;
                    break;

                case "DataConnectionString":
                    shellSetting.DataConnectionString = value;
                    break;

                default:
                    break;
                }
            }
            return(shellSetting);
        }
Пример #2
0
        protected virtual void SaveSettings(DataSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            string filePath = Path.Combine(MapPath("~/App_Data/"), fileName);

            if (!File.Exists(filePath))
            {
                using (File.Create(filePath))
                { }
            }
            var text = ComposeSettings(settings);

            File.WriteAllText(filePath, text);
        }