Ejemplo n.º 1
0
 private PropModelType FetchPropModel(string resourceKey)
 {
     try
     {
         if (CanFindPropBagTemplateWithJustKey)
         {
             PropBagTemplate pbt = _propBagTemplateBuilder.GetPropBagTemplate(resourceKey);
             PropModelType   pm  = _pbtParser.ParsePropModel(pbt);
             FixUpPropFactory(pm, _propFactoryFactory);
             return(pm);
         }
         else if (HasPbtLookupResources)
         {
             throw new InvalidOperationException($"A call providing only a ResourceKey can only be done, " +
                                                 $"if this PropModelBuilder was supplied with a PropBagTemplateBuilder upon construction. " +
                                                 $"No class implementing: {nameof(IPropBagTemplateBuilder)} was provided. " +
                                                 $"Please supply a PropBagTemplate object.");
         }
         else
         {
             throw new InvalidOperationException($"A call providing only a ResourceKey can only be done, " +
                                                 $"if this PropModelBuilder was supplied with the necessary resources upon construction. " +
                                                 $"A {_propBagTemplateBuilder.GetType()} was provided, but it does not have the necessary resources. " +
                                                 $"Please supply a ResourceDictionary and ResourceKey or a ProbBagTemplate object.");
         }
     }
     catch (System.Exception e)
     {
         throw new ApplicationException($"PropBagTemplate for ResourceKey = {resourceKey} was not found.", e);
     }
 }
Ejemplo n.º 2
0
        public IDictionary <string, PropModelType> LoadPropModels(string basePath, string[] filenames)
        {
            Dictionary <string, PropModelType> result = new Dictionary <string, PropModelType>();

            Thread thread = new Thread(() =>
            {
                ResourceDictionary rd = _resourceDictionaryProvider.Load(basePath, filenames);

                foreach (ResourceDictionary rdChild in rd.MergedDictionaries)
                {
                    foreach (DictionaryEntry kvp in rdChild)
                    {
                        if (kvp.Value is PropBagTemplate pbt)
                        {
                            PropModelType propModel = _pbtParser.ParsePropModel(pbt);

                            result.Add((string)kvp.Key, propModel);
                            _propModelCache.Add((string)kvp.Key, propModel);
                        }
                    }
                }
            });

            thread.SetApartmentState(ApartmentState.STA);

            thread.Start();
            thread.Join();

            thread = null;

            _propModelCache = result;
            return(result);
        }