Esempio n. 1
0
        public IContext LoadContext(Type contextType)
        {
            JsonInit.InitConverter();

            IConfigProvider configProvider = Provider.Get();
            IConfigSection  section        = configProvider.LoadSingleSetting(SectionId, contextType.FullName);

            if (section.ContainsSetting(contextType.FullName))
            {
                var jsonString = section.GetSetting <string>(contextType.FullName, null).Value;
                try
                {
                    if (!string.IsNullOrEmpty(jsonString))
                    {
                        return((IContext)JsonConvert.DeserializeObject(jsonString, contextType));
                    }
                    return(null);
                }
                catch (JsonSerializationException e)
                {
                    throw new JsonSerializationException(string.Format("Error deserializing type {0}", contextType), e);
                }
            }
            return(null);
        }
Esempio n. 2
0
        public void SaveContext(IContext context)
        {
            JsonInit.InitConverter();

            IConfigProvider configProvider = Provider.Get();
            IConfigSection  section        = configProvider.LoadSingleSetting(SectionId, context.GetType().FullName);

            section.GetSetting <string>(context.GetType().FullName, null, true).Value =
                JsonConvert.SerializeObject(context);
            configProvider.SaveSection(section);
        }
Esempio n. 3
0
        public virtual void SaveLayoutToDataStore(Stream layoutStream)
        {
            layoutStream.SeekToBegin();
            string layoutData = new StreamReader(layoutStream).ReadToEnd();

            IConfigProvider configProvider = Provider.Get();
            IConfigSection  section        = configProvider.LoadSingleSetting(GetLayoutSectionId(), GetLayoutId());

            section.GetSetting <string>(GetLayoutId(), null, true).Value = layoutData;
            configProvider.SaveSection(section);
        }
Esempio n. 4
0
        private static T GetSetting <T>(string settingName)
        {
            if (Section.ContainsSetting(settingName))
            {
                return(Section.GetSetting(settingName, default(T), false).Value);
            }

            throw new HelpProviderException(
                      "Setting '{0}' in section [{1}] does not exist. Please create this setting in settings.", settingName,
                      SectionId);
        }
Esempio n. 5
0
        public virtual void ResetLayout()
        {
            Debug.Assert(HostForm != null, "HostForm is null");
            Debug.Assert(LayoutNameInternal != null, "_layoutName is null");

            string sectionId = GetLayoutSectionId();
            string layoutId  = GetLayoutId();

            IConfigProvider configProvider = Provider.Get();
            IConfigSection  section        = configProvider.LoadSingleSetting(sectionId, layoutId);

            if (section.ContainsSetting(layoutId))
            {
                section.GetSetting <string>(GetLayoutId(), null).Value = null;
                configProvider.SaveSection(section);
            }
        }
Esempio n. 6
0
        public virtual Stream RestoreLayoutFromDataStore()
        {
            IConfigProvider configProvider = Provider.Get();
            IConfigSection  section        = configProvider.LoadSingleSetting(GetLayoutSectionId(), GetLayoutId());

            if (section.ContainsSetting(GetLayoutId()))
            {
                string layoutData = section.GetSetting <string>(GetLayoutId(), null).Value;
                if (!string.IsNullOrEmpty(layoutData))
                {
                    byte[] byteArray    = Encoding.Unicode.GetBytes(layoutData);
                    var    layoutStream = new MemoryStream(byteArray);
                    return(layoutStream);
                }
            }
            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Migrates settings values
        /// </summary>
        public void MigrateSettingValues()
        {
            IConfigProvider configProvider = Provider.Get();
            IConfigSection  section        = configProvider.LoadSection(_sectionId);

            foreach (SettingsProperty oldSetting in _oldSettings.Properties)
            {
                Debug.Assert(section.ContainsSetting(oldSetting.Name),
                             string.Format("Setting {0} existiert nicht", oldSetting.Name));

                if (section.ContainsSetting(oldSetting.Name))
                {
                    if (oldSetting.PropertyType == typeof(string))
                    {
                        section.GetSetting <string>(oldSetting.Name).Value = (string)_oldSettings[oldSetting.Name];
                    }
                    else if (oldSetting.PropertyType == typeof(bool))
                    {
                        section.GetSetting <bool>(oldSetting.Name).Value = (bool)_oldSettings[oldSetting.Name];
                    }
                    else if (oldSetting.PropertyType == typeof(int))
                    {
                        section.GetSetting <int>(oldSetting.Name).Value = (int)_oldSettings[oldSetting.Name];
                    }
                    else if (oldSetting.PropertyType == typeof(decimal))
                    {
                        section.GetSetting <decimal>(oldSetting.Name).Value = (decimal)_oldSettings[oldSetting.Name];
                    }
                    else if (oldSetting.PropertyType == typeof(float))
                    {
                        section.GetSetting <float>(oldSetting.Name).Value = (float)_oldSettings[oldSetting.Name];
                    }
                    else if (oldSetting.PropertyType == typeof(Color))
                    {
                        section.GetSetting <Color>(oldSetting.Name).Value = (Color)_oldSettings[oldSetting.Name];
                    }
                }
            }

            configProvider.SaveSection(section);
        }