public DocumentNode GetThemeResourceFromProject(IProject project, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project);

            if (projectContext == null)
            {
                return((DocumentNode)null);
            }
            string rootDirectory = Path.Combine(project.ProjectRoot.Path, "Themes");

            foreach (string currentTheme in ThemeContentProvider.GetThemeNames(projectContext))
            {
                DocumentReference fileThemeReference = ThemeContentProvider.GetFileThemeReference(rootDirectory, currentTheme);
                IProjectItem      projectItem        = project.FindItem(fileThemeReference);
                if (projectItem != null)
                {
                    ResourceDictionaryContentProvider resourceDictionary = this.designerContext.ResourceManager.GetContentProviderForResourceDictionary(projectItem);
                    if (resourceDictionary != null)
                    {
                        DocumentNode projectResource = this.FindProjectResource(project, resourceDictionary, projectItem.DocumentReference.Path, resourceKey, out auxillaryResources);
                        if (projectResource != null)
                        {
                            return(projectResource);
                        }
                    }
                }
            }
            return((DocumentNode)null);
        }
 public DocumentNode GetThemeResourceFromAssembly(IProjectContext projectContext, IAssembly themeRuntimeAssembly, IAssembly themeTargetAssembly, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
 {
     using (TemporaryCursor.SetWaitCursor())
     {
         foreach (string str1 in ThemeContentProvider.GetThemeNames(projectContext))
         {
             string str2 = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "themes/{0}.xaml", new object[1]
             {
                 (object)str1.ToLowerInvariant()
             });
             IProjectContext   projectContext1  = (IProjectContext) new ThemeContentProvider.TargetThemeAssemblyProjectContext(projectContext, themeRuntimeAssembly, this.designerContext.AssemblyService);
             DocumentReference theme            = DocumentReference.Create(Path.Combine(themeTargetAssembly.Name, str2));
             DocumentNode      resourceInternal = this.GetResourceInternal(this.projectThemeCache, projectContext.Platform.ThemeManager, projectContext1, theme, themeTargetAssembly, str2, resourceKey, out auxillaryResources);
             if (resourceInternal != null)
             {
                 return(resourceInternal);
             }
         }
         if (projectContext.Platform.ThemeManager.AllowFallbackToPlatform)
         {
             return(this.GetThemeResourceFromPlatform(projectContext.Platform, resourceKey, out auxillaryResources));
         }
         auxillaryResources = (IList <DocumentCompositeNode>)null;
         return((DocumentNode)null);
     }
 }
        public DocumentNode GetThemeResourceFromPlatform(IPlatform platform, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            FolderBasedThemeManager basedThemeManager = platform.ThemeManager as FolderBasedThemeManager;

            if (basedThemeManager == null)
            {
                return((DocumentNode)null);
            }
            using (TemporaryCursor.SetWaitCursor())
            {
                Dictionary <ThemeContentProvider.PlatformSpecificDocumentReference, ThemeContentProvider.SystemThemeContentProvider> orCreateCache = DesignSurfacePlatformCaches.GetOrCreateCache <Dictionary <ThemeContentProvider.PlatformSpecificDocumentReference, ThemeContentProvider.SystemThemeContentProvider> >(platform.Metadata, DesignSurfacePlatformCaches.ThemeContentProviderCache);
                DocumentReference fileThemeReference = ThemeContentProvider.GetFileThemeReference(basedThemeManager.ThemeFolder, basedThemeManager.CurrentTheme);
                return(this.GetResourceInternal(orCreateCache, (ThemeManager)basedThemeManager, (IProjectContext)null, fileThemeReference, (IAssembly)null, (string)null, resourceKey, out auxillaryResources));
            }
        }
        private DocumentNode FindProjectResource(IProject project, ResourceDictionaryContentProvider currentThemeProvider, string currentThemePath, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            List <string> resolvedUris = new List <string>();

            return(ThemeContentProvider.FindResource(currentThemeProvider, currentThemePath, (Func <ResourceDictionaryContentProvider, Func <DocumentNode, object> >)(provider => (Func <DocumentNode, object>)(resourceKeyNode =>
            {
                DocumentNode rootNode = currentThemeProvider.Document.RootNode;
                using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(rootNode.Context, this.designerContext))
                {
                    using (instanceBuilderContext.DisablePostponedResourceEvaluation())
                    {
                        instanceBuilderContext.ViewNodeManager.RootNodePath = new DocumentNodePath(rootNode, resourceKeyNode);
                        instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root);
                        return instanceBuilderContext.ViewNodeManager.ValidRootInstance;
                    }
                }
            })), (Func <Uri, string, string>)((relativeUri, sourcePath) =>
            {
                Uri uri = project.MakeDesignTimeUri(relativeUri, sourcePath);
                if (!(uri != (Uri)null))
                {
                    return (string)null;
                }
                string originalString = uri.OriginalString;
                if (resolvedUris.Contains(originalString))
                {
                    return (string)null;
                }
                resolvedUris.Add(originalString);
                return originalString;
            }), (Func <string, ResourceDictionaryContentProvider>)(resolvedUri =>
            {
                if (!string.IsNullOrEmpty(resolvedUri))
                {
                    IProjectItem projectItem = project.FindItem(DocumentReference.Create(resolvedUri));
                    if (projectItem != null)
                    {
                        return this.designerContext.ResourceManager.GetContentProviderForResourceDictionary(projectItem);
                    }
                }
                return (ResourceDictionaryContentProvider)null;
            }), resourceKey, out auxillaryResources));
        }
        private DocumentNode GetResourceInternal(Dictionary <ThemeContentProvider.PlatformSpecificDocumentReference, ThemeContentProvider.SystemThemeContentProvider> themeCache, ThemeManager manager, IProjectContext projectContext, DocumentReference theme, IAssembly themeAssembly, string themeAssemblyPath, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            ThemeContentProvider.SystemThemeContentProvider cachedThemeContent = this.GetCachedThemeContent(themeCache, manager, projectContext, theme, themeAssembly, themeAssemblyPath, this.designerContext.TextBufferService);
            DocumentNode  documentNode = (DocumentNode)null;
            List <string> resolvedUris = new List <string>();

            if (cachedThemeContent != null)
            {
                documentNode = ThemeContentProvider.FindResource((ResourceDictionaryContentProvider)cachedThemeContent, themeAssemblyPath, (Func <ResourceDictionaryContentProvider, Func <DocumentNode, object> >)(i => new Func <DocumentNode, object>(((ThemeContentProvider.SystemThemeContentProvider)i).CreateInstance)), (Func <Uri, string, string>)((relativeUri, sourcePath) =>
                {
                    if (themeAssembly != null && relativeUri != (Uri)null)
                    {
                        string str1 = "pack://application:,,,/" + themeAssembly.Name + ";component/";
                        Uri uri1    = new Uri(str1);
                        Uri uri2    = KnownProjectBase.MakeDesignTimeUri(relativeUri, str1, sourcePath, themeAssembly.Name, (IEnumerable <IProject>)null);
                        if (uri2 != (Uri)null && uri2.IsAbsoluteUri)
                        {
                            Uri uri3 = uri1.MakeRelativeUri(uri2);
                            if (uri3 != (Uri)null)
                            {
                                string str2 = uri3.OriginalString.ToLowerInvariant();
                                if (resolvedUris.Contains(str2))
                                {
                                    return((string)null);
                                }
                                resolvedUris.Add(str2);
                                return(str2);
                            }
                        }
                    }
                    return((string)null);
                }), (Func <string, ResourceDictionaryContentProvider>)(resolvedUri =>
                {
                    if (themeAssembly != null && !string.IsNullOrEmpty(resolvedUri))
                    {
                        return((ResourceDictionaryContentProvider)this.GetCachedThemeContent(themeCache, manager, projectContext, DocumentReference.Create(Path.Combine(themeAssembly.Name, resolvedUri)), themeAssembly, resolvedUri, this.designerContext.TextBufferService));
                    }
                    return((ResourceDictionaryContentProvider)null);
                }), resourceKey, out auxillaryResources);
            }
            return(documentNode);
        }
        private ThemeContentProvider.SystemThemeContentProvider GetCachedThemeContent(Dictionary <ThemeContentProvider.PlatformSpecificDocumentReference, ThemeContentProvider.SystemThemeContentProvider> themeCache, ThemeManager manager, IProjectContext projectContext, DocumentReference reference, IAssembly themeAssembly, string themeAssemblyPath, ITextBufferService textBufferService)
        {
            ThemeContentProvider.PlatformSpecificDocumentReference key = new ThemeContentProvider.PlatformSpecificDocumentReference(reference, projectContext != null ? projectContext.TargetFramework : (FrameworkName)null);
            ThemeContentProvider.SystemThemeContentProvider        themeContentProvider;
            if (!themeCache.TryGetValue(key, out themeContentProvider))
            {
                Encoding    encoding;
                ITextBuffer textBuffer = themeAssembly != null?ThemeManager.LoadResource(themeAssembly, themeAssemblyPath, textBufferService, out encoding) : ThemeContentProvider.LoadReference(reference, textBufferService, out encoding);

                IDocumentLocator documentLocator = DocumentReferenceLocator.GetDocumentLocator(reference);
                IDocumentContext userContext     = projectContext == null ? (IDocumentContext)null : (IDocumentContext) new DocumentContext(projectContext, documentLocator);
                XamlDocument     theme           = manager.GetTheme(documentLocator, themeAssembly != null, userContext, textBuffer, encoding);
                if (theme != null)
                {
                    bool flag1 = false;
                    try
                    {
                        if (projectContext != null)
                        {
                            if (!projectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                            {
                                if (themeAssembly != null)
                                {
                                    bool flag2 = false;
                                    foreach (IAssembly assembly in (projectContext.Platform.Metadata as PlatformTypes).DefaultAssemblyReferences)
                                    {
                                        if (assembly == themeAssembly)
                                        {
                                            flag2 = true;
                                            break;
                                        }
                                    }
                                    if (flag2)
                                    {
                                        flag1 = true;
                                        AnimationEditor.ConvertFromToAnimations(theme.RootNode);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        if (flag1)
                        {
                            theme = manager.GetTheme(documentLocator, themeAssembly != null, userContext, textBuffer, encoding);
                        }
                    }
                    themeContentProvider = new ThemeContentProvider.SystemThemeContentProvider(this.designerContext, theme);
                    themeCache[key]      = themeContentProvider;
                }
            }
            return(themeContentProvider);
        }
        private static DocumentNode FindResource(ResourceDictionaryContentProvider themeContent, string originalThemePath, Func <ResourceDictionaryContentProvider, Func <DocumentNode, object> > provideInstanceForThemeContent, Func <Uri, string, string> provideResolvedUriForMergedDictionary, Func <string, ResourceDictionaryContentProvider> provideContentForMergedDictionary, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources)
        {
            DocumentNode root = (DocumentNode)null;

            auxillaryResources = (IList <DocumentCompositeNode>)null;
            Func <DocumentNode, object> func = provideInstanceForThemeContent(themeContent);

            foreach (DocumentNode documentNode1 in themeContent.Items)
            {
                DocumentCompositeNode entryNode = documentNode1 as DocumentCompositeNode;
                if (entryNode != null)
                {
                    DocumentNode documentNode2 = ResourceNodeHelper.GetResourceEntryKey(entryNode);
                    if (documentNode2 == null)
                    {
                        DocumentCompositeNode documentCompositeNode = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                        if (documentCompositeNode != null)
                        {
                            if (documentCompositeNode.Type.Metadata.ImplicitDictionaryKeyProperty != null)
                            {
                                documentNode2 = documentCompositeNode.Properties[documentCompositeNode.Type.Metadata.ImplicitDictionaryKeyProperty];
                            }
                            if (documentNode2 == null && documentCompositeNode.TypeResolver.IsCapabilitySet(PlatformCapability.NameSupportedAsKey))
                            {
                                documentNode2 = documentCompositeNode.Properties[(IPropertyId)documentCompositeNode.Type.Metadata.NameProperty];
                            }
                        }
                    }
                    if (documentNode2 != null)
                    {
                        object objB = func(documentNode2);
                        if (object.Equals(resourceKey, objB))
                        {
                            root = entryNode.Properties[DictionaryEntryNode.ValueProperty];
                            break;
                        }
                    }
                }
            }
            if (root == null && originalThemePath != null)
            {
                foreach (DocumentNode documentNode in themeContent.Items)
                {
                    DocumentCompositeNode documentCompositeNode = documentNode as DocumentCompositeNode;
                    if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                    {
                        Uri uriValue = documentCompositeNode.GetUriValue(ResourceDictionaryNode.SourceProperty);
                        if (uriValue != (Uri)null)
                        {
                            string originalThemePath1 = provideResolvedUriForMergedDictionary(uriValue, originalThemePath);
                            if (originalThemePath1 != null)
                            {
                                ResourceDictionaryContentProvider themeContent1 = provideContentForMergedDictionary(originalThemePath1);
                                if (themeContent1 != null)
                                {
                                    root = ThemeContentProvider.FindResource(themeContent1, originalThemePath1, provideInstanceForThemeContent, provideResolvedUriForMergedDictionary, provideContentForMergedDictionary, resourceKey, out auxillaryResources);
                                    if (root != null)
                                    {
                                        return(root);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (root != null)
            {
                auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(root);
            }
            return(root);
        }
 protected override bool UpdateAssets()
 {
     if (this.originalDocumentProvider == null)
     {
         Encoding encoding;
         this.originalDocumentProvider = new ResourceDictionaryContentProvider(this.designerContext, this.themeManager.GetTheme(DocumentReferenceLocator.GetDocumentLocator(this.documentReference), false, (IDocumentContext)null, ThemeContentProvider.LoadReference(this.documentReference, this.designerContext.TextBufferService, out encoding), encoding));
         this.ContentProvider          = this.GetProvider(this.designerContext.ActiveProject);
     }
     return(base.UpdateAssets());
 }