/// <summary>
        /// Converts the provided dictionary into an object of the specified type.
        /// </summary>
        /// <param name="dictionary">An <see cref="T:System.Collections.Generic.IDictionary`2" /> instance of property data stored as name/value pairs.</param>
        /// <param name="type">The type of the resulting object.</param>
        /// <param name="serializer">The <see cref="T:System.Web.Script.Serialization.JavaScriptSerializer" /> instance.</param>
        /// <returns>
        /// The deserialized object.
        /// </returns>
        /// <exception cref="ArgumentNullException">dictionary</exception>
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }
            if (type != typeof(GameInfo))
            {
                return(null);
            }

            GameInfo info = new GameInfo();

            info.Hero         = dictionary.ReadValue <string>("Hero");
            info.Child        = dictionary.ReadValue <string>("Child");
            info.IsHeroQuest  = dictionary.ReadValue <bool>("IsHeroQuest");
            info.IsLinkedGame = dictionary.ReadValue <bool>("IsLinkedGame");
            info.GameID       = dictionary.ReadValue <short>("GameID");
            info.Rings        = (Rings)dictionary.ReadValue <long>("Rings");
            info.Game         = dictionary.ReadValue <Game>("Game");
            info.Animal       = dictionary.ReadValue <Animal>("Animal");
            info.Behavior     = dictionary.ReadValue <ChildBehavior>("Behavior");

            return(info);
        }
Exemplo n.º 2
0
        private static Assembly ReadAssemblyCore(this IDictionary <string, object> cache)
        {
            Assumes.NotNull(cache);

            // NOTE : we load assembly with the full name AND codebase
            // This will force the loader to look for the default probing path - local directories, GAC, etc - and only after that fallback onto the path
            // if we want the reverse behavior, we will need to try loading from codebase first, and of that fails load from the defualt context
            string assemblyName = cache.ReadValue <string>(AttributedCacheServices.CacheKeys.AssemblyFullName);
            string codeBase     = cache.ReadValue <string>(AttributedCacheServices.CacheKeys.AssemblyLocation);

            return(ReflectionResolver.ResolveAssembly(assemblyName, codeBase));
        }
Exemplo n.º 3
0
        public GitHubRelease Deserialize(IDictionary <string, object> dictionary)
        {
            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            GitHubRelease release = new GitHubRelease();

            release.Name         = dictionary.ReadValue <string>("name");
            release.TagName      = dictionary.ReadValue <string>("tag_name");
            release.Body         = dictionary.ReadValue <string>("body");
            release.HtmlUrl      = dictionary.ReadValue <string>("html_url");
            release.IsDraft      = dictionary.ReadValue <bool>("draft");
            release.IsPreRelease = dictionary.ReadValue <bool>("prerelease");
            if (dictionary.ContainsKey("created_at"))
            {
                release.CreatedAt = dictionary.ReadValue <DateTime>("created_at");
            }
            if (dictionary.ContainsKey("published_at"))
            {
                release.PublishedAt = dictionary.ReadValue <DateTime>("published_at");
            }

            return(release);
        }
Exemplo n.º 4
0
        private static Func <MemberInfo[]> ReadAccessors(this IDictionary <string, object> cache, string key, Lazy <Type> defaultType)
        {
            Assumes.NotNull(cache);
            object accessorsValue = cache.ReadValue <object>(key);

            int[]             metadataTokensArray = null;
            IEnumerable <int> metadataTokens      = accessorsValue as IEnumerable <int>;

            if (metadataTokens != null)
            {
                metadataTokensArray = metadataTokens.ToArray();
            }
            else if ((accessorsValue != null) && (accessorsValue.GetType() == ReflectionCacheServices.Int32Type))
            {
                metadataTokensArray = new int[] { (int)accessorsValue };
            }

            if (metadataTokensArray == null)
            {
                return(cache.Read((c) => ReadAccessorsCore(c, defaultType), key));
            }
            else
            {
                return(ReadFastAccessorsCore(metadataTokensArray, defaultType));
            }
        }
Exemplo n.º 5
0
        public static bool IsAssemblyIdentityStored(this IDictionary <string, object> cache)
        {
            Assumes.NotNull(cache);

            cache = cache.ReadDictionary <object>(AttributedCacheServices.CacheKeys.Assembly);
            return(cache.ReadValue <string>(AttributedCacheServices.CacheKeys.AssemblyFullName) != null);
        }
Exemplo n.º 6
0
        private static T ReadMember <T>(this IDictionary <string, object> cache, string key, Type defaultType, Func <Assembly> assemblyLoader) where T : MemberInfo
        {
            // first check if this an abbreviated version of member
            object cacheValue = cache.ReadValue <object>(key);
            IDictionary <string, object> cacheValueAsDictionary = cacheValue as IDictionary <string, object>;

            if (cacheValueAsDictionary != null)
            {
                return(ReadMemberCore <T>(cacheValueAsDictionary, defaultType));
            }
            else if ((cacheValue != null) && (defaultType != null))
            {
                int metadataToken = (int)cacheValue;
                return((T)ReflectionResolver.ResolveMember(defaultType.Assembly.ManifestModule, metadataToken));
            }
            else if ((cacheValue != null) && (assemblyLoader != null))
            {
                int metadataToken = (int)cacheValue;
                return((T)ReflectionResolver.ResolveMember(assemblyLoader.Invoke().ManifestModule, metadataToken));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        private static Module ReadModuleCore(this IDictionary <string, object> cache, Assembly assembly)
        {
            Assumes.NotNull(cache, assembly);

            int metadataToken = cache.ReadValue <int>(AttributedCacheServices.CacheKeys.MetadataToken);

            return(ReflectionResolver.ResolveModule(assembly, metadataToken));
        }
Exemplo n.º 8
0
        private static T ReadMemberCore <T>(IDictionary <string, object> cache, Type defaultType) where T : MemberInfo
        {
            Assumes.NotNull(cache);

            int      metadataToken = cache.ReadValue <int>(AttributedCacheServices.CacheKeys.MetadataToken);
            Assembly assembly      = cache.ReadAssembly(defaultType == null ? null : defaultType.Assembly);
            Module   module        = cache.ReadModule(assembly);

            return((T)ReflectionResolver.ResolveMember(module, metadataToken));
        }
Exemplo n.º 9
0
        public static bool IsAssemblyCacheUpToDate(this IDictionary <string, object> cache)
        {
            Assumes.NotNull(cache);

            cache = cache.ReadDictionary <object>(AttributedCacheServices.CacheKeys.Assembly);

            string assemblyLocation  = cache.ReadValue <string>(AttributedCacheServices.CacheKeys.AssemblyLocation);
            long   assemblyTimeStamp = cache.ReadValue <long>(AttributedCacheServices.CacheKeys.AssemblyTimeStamp);

            if (!File.Exists(assemblyLocation))
            {
                return(false);
            }
            if (File.GetLastWriteTimeUtc(assemblyLocation).Ticks != assemblyTimeStamp)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Converts the provided dictionary into an object of the specified type.
        /// </summary>
        /// <param name="dictionary">An <see cref="T:System.Collections.Generic.IDictionary`2" /> instance of property data stored as name/value pairs.</param>
        /// <returns>
        /// The deserialized object.
        /// </returns>
        /// <exception cref="ArgumentNullException">dictionary</exception>
        public GameInfo Deserialize(IDictionary<string, object> dictionary)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            GameInfo info = new GameInfo();

            info.Hero = dictionary.ReadValue<string>("Hero");
            info.Child = dictionary.ReadValue<string>("Child");
            info.IsHeroQuest = dictionary.ReadValue<bool>("IsHeroQuest");
            info.IsLinkedGame = dictionary.ReadValue<bool>("IsLinkedGame");
            info.WasGivenFreeRing = dictionary.ReadValue<bool>("WasGivenFreeRing");
            info.GameID = dictionary.ReadValue<short>("GameID");
            info.Rings = (Rings)dictionary.ReadValue<long>("Rings");
            info.Game = dictionary.ReadValue<Game>("Game");
            info.Animal = dictionary.ReadValue<Animal>("Animal");
            info.Behavior = dictionary.ReadValue<ChildBehavior>("Behavior");

            return info;
        }
Exemplo n.º 11
0
        private static ParameterInfo ReadParameterCore(IDictionary <string, object> cache, Lazy <Type> defaultType)
        {
            int             parameterPosition = cache.ReadValue <int>(AttributedCacheServices.CacheKeys.ParameterPosition);
            ConstructorInfo constructor       = cache.ReadMember <ConstructorInfo>(AttributedCacheServices.CacheKeys.ParameterConstructor, defaultType.Value);

            Assumes.IsTrue(parameterPosition >= 0);

            ParameterInfo[] parameters = constructor.GetParameters();

            Assumes.IsTrue(parameterPosition < parameters.Length);

            return(parameters[parameterPosition]);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Converts the provided dictionary into an object of the specified type.
        /// </summary>
        /// <param name="dictionary">An <see cref="T:System.Collections.Generic.IDictionary`2" /> instance of property data stored as name/value pairs.</param>
        /// <param name="type">The type of the resulting object.</param>
        /// <param name="serializer">The <see cref="T:System.Web.Script.Serialization.JavaScriptSerializer" /> instance.</param>
        /// <returns>
        /// The deserialized object.
        /// </returns>
        /// <exception cref="ArgumentNullException">dictionary</exception>
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");
            if (type != typeof(GameInfo))
                return null;

            GameInfo info = new GameInfo();

            info.Hero = dictionary.ReadValue<string>("Hero");
            info.Child = dictionary.ReadValue<string>("Child");
            info.IsHeroQuest = dictionary.ReadValue<bool>("IsHeroQuest");
            info.IsLinkedGame = dictionary.ReadValue<bool>("IsLinkedGame");
            info.GameID = dictionary.ReadValue<short>("GameID");
            info.Rings = (Rings)dictionary.ReadValue<long>("Rings");
            info.Game = dictionary.ReadValue<Game>("Game");
            info.Animal = dictionary.ReadValue<Animal>("Animal");
            info.Behavior = dictionary.ReadValue<ChildBehavior>("Behavior");

            return info;
        }
        public static ExportDefinition ReadExportDefinition(ComposablePartDefinition owner, IDictionary<string, object> cache)
        {
            Assumes.NotNull(owner);
            Assumes.NotNull(cache);

            LazyMemberInfo exportingMemberInfo = new LazyMemberInfo(
                cache.ReadValue<MemberTypes>(AttributedCacheServices.CacheKeys.MemberType, MemberTypes.TypeInfo),
                cache.ReadLazyAccessors(ReflectionModelServices.GetPartType(owner)));
                

            return ReflectionModelServices.CreateExportDefinition(
                exportingMemberInfo,
                cache.ReadContractName(),
                cache.ReadLazyMetadata(),
                owner as ICompositionElement);
        }
        public static ExportDefinition ReadExportDefinition(ComposablePartDefinition owner, IDictionary <string, object> cache)
        {
            Assumes.NotNull(owner);
            Assumes.NotNull(cache);

            LazyMemberInfo exportingMemberInfo = new LazyMemberInfo(
                cache.ReadValue <MemberTypes>(AttributedCacheServices.CacheKeys.MemberType, MemberTypes.TypeInfo),
                cache.ReadLazyAccessors(ReflectionModelServices.GetPartType(owner)));


            return(ReflectionModelServices.CreateExportDefinition(
                       exportingMemberInfo,
                       cache.ReadContractName(),
                       cache.ReadLazyMetadata(),
                       owner as ICompositionElement));
        }
        public static ComposablePartDefinition ReadPartDefinition(IDictionary <string, object> cache, Func <ComposablePartDefinition, IEnumerable <ImportDefinition> > importsCreator, Func <ComposablePartDefinition, IEnumerable <ExportDefinition> > exportsCreator, Func <Assembly> assemblyLoader)
        {
            Assumes.NotNull(cache);

            Lazy <Type> partType = cache.ReadLazyTypeForPart(assemblyLoader);

            ComposablePartDefinition part = null;

            part = ReflectionModelServices.CreatePartDefinition(
                partType,
                cache.ReadValue <bool>(AttributedCacheServices.CacheKeys.IsDisposalRequired, false),
                LazyServices.MakeLazy(() => importsCreator(part)),
                LazyServices.MakeLazy(() => exportsCreator(part)),
                cache.ReadLazyMetadata(),
                null);

            return(part);
        }
Exemplo n.º 16
0
        public static IDictionary <string, T> ReadDictionary <T>(this IDictionary <string, object> cache, string key)
        {
            IDictionary <string, T> result = cache.ReadValue <IDictionary <string, T> >(key, null);

            if (result != null)
            {
                return(result);
            }

            if (typeof(object) == typeof(T))
            {
                return((IDictionary <string, T>)(object) MetadataServices.EmptyMetadata);
            }
            else
            {
                return(new Dictionary <string, T>());
            }
        }
        public static ContractBasedImportDefinition ReadImportDefinition(ComposablePartDefinition owner, IDictionary <string, object> cache)
        {
            Assumes.NotNull(owner);
            Assumes.NotNull(cache);

            Lazy <Type>         partType = ReflectionModelServices.GetPartType(owner);
            ICompositionElement origin   = owner as ICompositionElement;

            if (cache.ReadValue <string>(AttributedCacheServices.CacheKeys.ImportType) == AttributedCacheServices.ImportTypes.Parameter)
            {
                return(ReflectionModelServices.CreateImportDefinition(
                           cache.ReadLazyParameter(partType),
                           cache.ReadContractName(),
                           cache.ReadValue <string>(AttributedCacheServices.CacheKeys.RequiredTypeIdentity),
                           cache.ReadRequiredMetadata(),
                           cache.ReadValue <ImportCardinality>(AttributedCacheServices.CacheKeys.Cardinality, ImportCardinality.ExactlyOne),
                           cache.ReadValue <CreationPolicy>(AttributedCacheServices.CacheKeys.RequiredCreationPolicy, CreationPolicy.Any),
                           origin));
            }
            else
            {
                LazyMemberInfo importingMemberInfo = new LazyMemberInfo(
                    cache.ReadValue <MemberTypes>(AttributedCacheServices.CacheKeys.MemberType, MemberTypes.Property),
                    cache.ReadLazyAccessors(partType));

                return(ReflectionModelServices.CreateImportDefinition(
                           importingMemberInfo,
                           cache.ReadContractName(),
                           cache.ReadValue <string>(AttributedCacheServices.CacheKeys.RequiredTypeIdentity),
                           cache.ReadRequiredMetadata(),
                           cache.ReadValue <ImportCardinality>(AttributedCacheServices.CacheKeys.Cardinality, ImportCardinality.ExactlyOne),
                           cache.ReadValue <bool>(AttributedCacheServices.CacheKeys.IsRecomposable, false),
                           cache.ReadValue <CreationPolicy>(AttributedCacheServices.CacheKeys.RequiredCreationPolicy, CreationPolicy.Any),
                           origin));
            }
        }
Exemplo n.º 18
0
 public static string ReadContractName(this IDictionary <string, object> cache)
 {
     Assumes.NotNull(cache);
     return(cache.ReadValue <string>(AttributedCacheServices.CacheKeys.ContractName));
 }
        /// <summary>
        /// Loads process-dependent settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadProcessDependentSettings(IDictionary<string, string> settings)
        {
            base.LoadProcessDependentSettings(settings);

            using (new AutoSaveSuppressor(this))
            {
                var kpiGuid = settings.ReadValue(SelectedKPIKey, string.Empty);
                SelectedKPI = KPIs.FirstOrDefault(x => x.Guid.ToString() == kpiGuid);

                SetupSubTitle();

                if (SelectedTab != null)
                    SelectedTab.RefreshView();
            }
        }
Exemplo n.º 20
0
        public static string GetAssemblyName(this IDictionary <string, object> cache)
        {
            cache = cache.ReadDictionary <object>(AttributedCacheServices.CacheKeys.Assembly);

            return(cache.ReadValue <string>(AttributedCacheServices.CacheKeys.AssemblyFullName));
        }
        /// <summary>
        /// Loads process-dependent settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadProcessDependentSettings(IDictionary<string, string> settings)
        {
            base.LoadProcessDependentSettings(settings);

            using (new AutoSaveSuppressor(this))
            {
                var kpisGuid = settings.ReadValue(SelectedKPIKey, string.Empty);
                foreach (var kpi in KPIs)
                    kpi.IsSelected = false;

                foreach (var kpi in kpisGuid.Split(';').Select(guid => KPIs.FirstOrDefault(x => x.Kpi.Guid.ToString() == guid)).Where(kpi => kpi != null))
                    kpi.IsSelected = true;

                SelectedKPIs = KPIs.Where(x => x.IsSelected).Select(x => x.Kpi).ToList();

                if (SelectedTab != null)
                    SelectedTab.RefreshView();

                SetupSubTitle();
            }
        }
Exemplo n.º 22
0
 public static IEnumerable <T> ReadEnumerable <T>(this IDictionary <string, object> cache, string key)
 {
     return(cache.ReadValue <IEnumerable <T> >(key, Enumerable.Empty <T>()));
 }
Exemplo n.º 23
0
 public static T ReadValue <T>(this IDictionary <string, object> cache, string key)
 {
     return(cache.ReadValue <T>(key, default(T)));
 }
        /// <summary>
        /// The load settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        public override void LoadSettings(IDictionary<string, string> settings)
        {
            base.LoadSettings(settings);

            if (settings == null)
                return;

            var descriptor = FilterDescriptor.GetFilterList(settings.ReadValue(MerticFilter, string.Empty));

            if (descriptor == null)
                return;

            Gadget.FilterList.AddRange(descriptor);
        }
        /// <summary>
        /// Loads gadget settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadSettings(IDictionary<string, string> settings)
        {
            base.LoadSettings(settings);

            if (settings == null)
                return;

            using (new AutoSaveSuppressor(this))
            {
                SelectedKPIs = settings.ReadValue(SelectedKPIKey, string.Empty).Split(';').SelectMany(x => KPIs.Where(kpi => kpi.Kpi.Guid.ToString() == x).Select(y => y.Kpi)).ToList();

                foreach (var kpi in SelectedKPIs.Select(kpi => KPIs.FirstOrDefault(x => x.Kpi.Guid == kpi.Guid)).Where(kpiSelectorViewModel => kpiSelectorViewModel != null))
                    kpi.IsSelected = true;
            }
        }
        public static ComposablePartDefinition ReadPartDefinition(IDictionary<string, object> cache, Func<ComposablePartDefinition, IEnumerable<ImportDefinition>> importsCreator, Func<ComposablePartDefinition, IEnumerable<ExportDefinition>> exportsCreator, Func<Assembly> assemblyLoader)
        {
            Assumes.NotNull(cache);

            Lazy<Type> partType = cache.ReadLazyTypeForPart(assemblyLoader);

            ComposablePartDefinition part = null;
            part = ReflectionModelServices.CreatePartDefinition(
                partType,
                cache.ReadValue<bool>(AttributedCacheServices.CacheKeys.IsDisposalRequired, false),
                LazyServices.MakeLazy(() => importsCreator(part)),
                LazyServices.MakeLazy(() => exportsCreator(part)),
                cache.ReadLazyMetadata(),
                null);

            return part;
        }
        /// <summary>
        /// Loads gadget settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadSettings(IDictionary<string, string> settings)
        {
            base.LoadSettings(settings);

            if (settings == null)
                return;

            using (new AutoSaveSuppressor(this))
            {
                ChartType = settings.ReadValue(ChartTypeKey, GadgetChartTypes.Column);

                var selectedMetricGuid = settings.ReadValue(SelectedMetricKey, Guid.Empty);
                SelectedMetric = Metrics.FirstOrDefault(m => m.Guid.Equals(selectedMetricGuid));

                var filterName = settings.ReadValue(SelectedFilterKey, string.Empty);
                SelectedFilter = Filters.FirstOrDefault(x => x.Name == filterName);
            }
        }
        public static ContractBasedImportDefinition ReadImportDefinition(ComposablePartDefinition owner, IDictionary<string, object> cache)
        {
            Assumes.NotNull(owner);
            Assumes.NotNull(cache);
  
            Lazy<Type> partType = ReflectionModelServices.GetPartType(owner);
            ICompositionElement origin = owner as ICompositionElement;
            if (cache.ReadValue<string>(AttributedCacheServices.CacheKeys.ImportType) == AttributedCacheServices.ImportTypes.Parameter)
            {
                return ReflectionModelServices.CreateImportDefinition(
                    cache.ReadLazyParameter(partType),
                    cache.ReadContractName(),
                    cache.ReadValue<string>(AttributedCacheServices.CacheKeys.RequiredTypeIdentity),
                    cache.ReadRequiredMetadata(),
                    cache.ReadValue<ImportCardinality>(AttributedCacheServices.CacheKeys.Cardinality, ImportCardinality.ExactlyOne),
                    cache.ReadValue<CreationPolicy>(AttributedCacheServices.CacheKeys.RequiredCreationPolicy, CreationPolicy.Any),
                    origin);
            }
            else
            {
                LazyMemberInfo importingMemberInfo = new LazyMemberInfo(
                    cache.ReadValue<MemberTypes>(AttributedCacheServices.CacheKeys.MemberType, MemberTypes.Property),
                    cache.ReadLazyAccessors(partType));

                return ReflectionModelServices.CreateImportDefinition(
                    importingMemberInfo,
                    cache.ReadContractName(),
                    cache.ReadValue<string>(AttributedCacheServices.CacheKeys.RequiredTypeIdentity),
                    cache.ReadRequiredMetadata(),
                    cache.ReadValue<ImportCardinality>(AttributedCacheServices.CacheKeys.Cardinality, ImportCardinality.ExactlyOne),
                    cache.ReadValue<bool>(AttributedCacheServices.CacheKeys.IsRecomposable, false),
                    cache.ReadValue<CreationPolicy>(AttributedCacheServices.CacheKeys.RequiredCreationPolicy, CreationPolicy.Any),
                    origin);
            }
        }
        /// <summary>
        /// Loads gadget settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadSettings(IDictionary<string, string> settings)
        {
            base.LoadSettings(settings);

            if (settings == null)
                return;

            using (new AutoSaveSuppressor(this))
                SelectedKPI = KPIs.FirstOrDefault(kpi => kpi.Guid.ToString() == settings.ReadValue(SelectedKPIKey, string.Empty));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Loads gadget settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadSettings(IDictionary<string, string> settings)
        {
            base.LoadSettings(settings);

            if (settings == null)
                return;

            using (new AutoSaveSuppressor(this))
            {
                _settings = settings;
                SelectedProcess = settings.ReadValue(SelectedProcessKey, string.Empty);
                SelectedFilter = settings.ReadValue(SelectedFilterKey, string.Empty);
            }
        }
        /// <summary>
        /// Loads process-dependent settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadProcessDependentSettings(IDictionary<string, string> settings)
        {
            base.LoadProcessDependentSettings(settings);

            using (new AutoSaveSuppressor(this))
            {
                var metricGuid = settings.ReadValue(SelectedMetricKey, string.Empty);
                SelectedMetric = Metrics.FirstOrDefault(x => x.Guid.ToString() == metricGuid);

                var filterName = settings.ReadValue(SelectedFilterKey, string.Empty);
                SelectedFilter = Filters.FirstOrDefault(x => x.Name == filterName);

                var filterDef = settings.ReadValue(ProcessedFilterKey, string.Empty);
                if (!string.IsNullOrWhiteSpace(filterDef))
                    PopulateUdp(filterDef);

                SetupSubTitle();

                if (SelectedTab != null)
                    SelectedTab.RefreshView();
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Converts the provided dictionary into an object of the specified type.
        /// </summary>
        /// <param name="dictionary">An <see cref="T:System.Collections.Generic.IDictionary`2" /> instance of property data stored as name/value pairs.</param>
        /// <returns>
        /// The deserialized game data.
        /// </returns>
        /// <exception cref="ArgumentNullException">dictionary</exception>
        public GameInfo Deserialize(IDictionary <string, object> dictionary)
        {
            if (dictionary is null)
            {
                throw new ArgumentNullException(nameof(dictionary));
            }

            var info = new GameInfo
            {
                Region           = dictionary.ReadValue <GameRegion>("Region"),
                Game             = dictionary.ReadValue <Game>("Game"),
                GameID           = dictionary.ReadValue <short>("GameID"),
                Hero             = dictionary.ReadValue <string>("Hero"),
                Child            = dictionary.ReadValue <string>("Child"),
                Animal           = dictionary.ReadValue <Animal>("Animal"),
                Behavior         = dictionary.ReadValue <byte>("Behavior"),
                IsHeroQuest      = dictionary.ReadValue <bool>("IsHeroQuest"),
                IsLinkedGame     = dictionary.ReadValue <bool>("IsLinkedGame"),
                WasGivenFreeRing = dictionary.ReadValue <bool>("WasGivenFreeRing"),
                Rings            = (Rings)dictionary.ReadValue <long>("Rings")
            };

            return(info);
        }
        /// <summary>
        /// Loads process-dependent settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        protected override void LoadProcessDependentSettings(IDictionary<string, string> settings)
        {
            base.LoadProcessDependentSettings(settings);

            using (new AutoSaveSuppressor(this))
            {
                var filterMode = settings.ReadValue(SelectedFilterModeKey, string.Empty);
                FilterType selectedFilterMode;
                SelectedFilterMode = Enum.TryParse(filterMode, out selectedFilterMode) ? selectedFilterMode : FilterType.NoFilter;

                var filterDefinition = settings.ReadValue(ProcessedFilterKey, string.Empty);
                if (!string.IsNullOrWhiteSpace(filterDefinition))
                    _processedFilter = FilterDescriptor.FromJSON(filterDefinition);

                var filter = settings.ReadValue(ChosenFilterKey, string.Empty);
                if (CommonFilterList != null)
                    ChosenFilter = CommonFilterList.FirstOrDefault(x => x.Name == filter);

                bool useDefaultLayout;
                if (Boolean.TryParse(settings.ReadValue(UseDefaultLayoutKey, string.Empty), out useDefaultLayout))
                {
                    UseDefaultLayout = useDefaultLayout;
                }

                if (!ShouldUseDefaultLayout() && LayoutList != null)
                {
                    int layoutId;
                    if (Int32.TryParse(settings.ReadValue(SelectedLayoutKey, string.Empty), out layoutId))
                    {
                        SetSelectedLayout(LayoutList.FirstOrDefault(x => x.Id == layoutId));
                    }

                    int origLayoutId;
                    if (Int32.TryParse(settings.ReadValue(OriginalSelectedLayoutKey, string.Empty), out origLayoutId))
                    {
                        _originalSelectedLayout = LayoutList.FirstOrDefault(x => x.Id == origLayoutId);
                    }
                }

                if (SelectedLayout == null)
                        SetDefaultLayout();

                SetupSubTitle();

                if (SelectedTab != null)
                    SelectedTab.RefreshView();
            }
        }