Ejemplo n.º 1
0
        private bool DoesNodeReferenceUrl(DocumentNode node, string url)
        {
            DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;

            if (documentCompositeNode != null)
            {
                Uri    uriValue  = documentCompositeNode.GetUriValue(ResourceDictionaryNode.SourceProperty);
                string uriString = uriValue != (Uri)null ? uriValue.OriginalString : (string)null;
                if (!string.IsNullOrEmpty(uriString))
                {
                    Uri uri = node.Context.MakeDesignTimeUri(new Uri(uriString, UriKind.RelativeOrAbsolute));
                    if (!uri.IsAbsoluteUri)
                    {
                        return(false);
                    }
                    string localPath = uri.LocalPath;
                    if (StringComparer.OrdinalIgnoreCase.Compare(localPath, url) == 0)
                    {
                        return(true);
                    }
                    return(StringComparer.OrdinalIgnoreCase.Compare(localPath.Replace("file:///", "").Replace("/", "\\"), url) == 0);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        private DocumentNode GetResolvedDocumentRootForSourceUri(IDocumentRootResolver documentRootResolver, DocumentCompositeNode resourceDictionaryNode, ICollection <string> warnings)
        {
            DocumentNode          documentNode;
            DocumentCompositeNode rootNode;
            DocumentCompositeNode documentCompositeNode = null;
            IDocumentRoot         documentRoot          = null;
            Uri uriValue = resourceDictionaryNode.GetUriValue(KnownProperties.ResourceDictionarySourceProperty);
            Uri uri      = uriValue;

            if (uri != null)
            {
                uri = this.documentContext.MakeDesignTimeUri(uri);
            }
            if (uri != null)
            {
                try
                {
                    documentRoot = documentRootResolver.GetDocumentRoot(uri.OriginalString);
                    if (documentRoot != null)
                    {
                        if (PlatformTypes.PlatformsCompatible(documentRoot.TypeResolver.PlatformMetadata, resourceDictionaryNode.TypeResolver.PlatformMetadata))
                        {
                            if (documentRoot.IsEditable)
                            {
                                rootNode = documentRoot.RootNode as DocumentCompositeNode;
                            }
                            else
                            {
                                rootNode = null;
                            }
                            documentCompositeNode = rootNode;
                        }
                        else
                        {
                            if (warnings != null)
                            {
                                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                                string      resourceDictionaryTargetFrameworkNotMatching = StringTable.ResourceDictionaryTargetFrameworkNotMatching;
                                object[]    fullName = new object[] { uriValue, documentRoot.TypeResolver.PlatformMetadata.TargetFramework.FullName, resourceDictionaryNode.TypeResolver.PlatformMetadata.TargetFramework.FullName };
                                warnings.Add(string.Format(currentCulture, resourceDictionaryTargetFrameworkNotMatching, fullName));
                            }
                            documentNode = null;
                            return(documentNode);
                        }
                    }
                    return(documentCompositeNode);
                }
                catch (IOException oException)
                {
                    return(documentCompositeNode);
                }
                catch (NotSupportedException notSupportedException)
                {
                    return(documentCompositeNode);
                }
                return(documentNode);
            }
            return(documentCompositeNode);
        }
Ejemplo n.º 3
0
        public static Uri GetUriValue(DocumentNode valueNode)
        {
            Uri uri = (Uri)null;
            DocumentPrimitiveNode documentPrimitiveNode = valueNode as DocumentPrimitiveNode;
            DocumentCompositeNode documentCompositeNode = valueNode as DocumentCompositeNode;

            if (documentPrimitiveNode != null)
            {
                uri = documentPrimitiveNode.GetUriValue();
            }
            else if (documentCompositeNode != null)
            {
                uri = documentCompositeNode.GetUriValue(documentCompositeNode.PlatformMetadata.KnownProperties.BitmapImageUriSource);
            }
            return(uri);
        }
Ejemplo n.º 4
0
        private static void FindReferencedDictionaryFromSource(DocumentCompositeNode resourceDictionaryNode, HashSet <Uri> dictionaries)
        {
            DocumentCompositeNode rootNode;
            Uri uriValue = resourceDictionaryNode.GetUriValue(KnownProperties.ResourceDictionarySourceProperty);

            if (uriValue != null)
            {
                uriValue = resourceDictionaryNode.Context.MakeDesignTimeUri(uriValue);
                if (uriValue != null && uriValue.IsAbsoluteUri && !dictionaries.Contains(uriValue))
                {
                    dictionaries.Add(uriValue);
                    DocumentCompositeNode documentCompositeNode = null;
                    IDocumentRoot         documentRoot          = null;
                    try
                    {
                        documentRoot = resourceDictionaryNode.Context.GetDocumentRoot(uriValue.OriginalString);
                        if (documentRoot != null)
                        {
                            if (documentRoot.IsEditable)
                            {
                                rootNode = documentRoot.RootNode as DocumentCompositeNode;
                            }
                            else
                            {
                                rootNode = null;
                            }
                            documentCompositeNode = rootNode;
                        }
                    }
                    catch (IOException oException)
                    {
                    }
                    catch (NotSupportedException notSupportedException)
                    {
                    }
                    if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(documentCompositeNode.Type))
                    {
                        ResourceNodeHelper.FindReferencedDictionariesInternal(documentCompositeNode, dictionaries);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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);
        }