예제 #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);
        }
예제 #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);
        }