private static void EnsureType(IType type, ReplaceStyleTemplateCommand.ExtraReferences references)
 {
     if (!type.IsResolvable)
     {
         references.AddUndesolvedType(type);
     }
     else
     {
         if (type.RuntimeAssembly.IsLoaded && ((IPlatformTypes)type.PlatformMetadata).IsDesignToolAssembly(type.RuntimeAssembly))
         {
             return;
         }
         if (PlatformTypes.IsPlatformType((ITypeId)type))
         {
             IAssembly targetAssembly = PlatformTypeHelper.GetTargetAssembly(type);
             if (targetAssembly == null)
             {
                 return;
             }
             string name = targetAssembly.Name;
             if (string.IsNullOrEmpty(name))
             {
                 return;
             }
             references.AddPlatformAssembly(name);
         }
         else
         {
             references.AddAssembly(type.RuntimeAssembly);
         }
     }
 }
        private void ResolveDefaultStyle(SceneElement targetElement, object defaultStyleKey, bool allowDefaultStyle, out DocumentNode currentStyle, out bool isThemeStyle, out IList <DocumentCompositeNode> auxillaryResources)
        {
            IProjectContext      projectContext1      = this.SceneViewModel.ProjectContext;
            ThemeContentProvider themeContentProvider = this.DesignerContext.ThemeContentProvider;

            currentStyle       = (DocumentNode)null;
            isThemeStyle       = false;
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            if (defaultStyleKey == null)
            {
                return;
            }
            IAssembly runtimeAssembly = targetElement.Type.RuntimeAssembly;
            IAssembly targetAssembly  = PlatformTypeHelper.GetTargetAssembly(targetElement.Type);
            Type      type1           = defaultStyleKey as Type;

            if (type1 != (Type)null)
            {
                ITypeId typeId = (ITypeId)projectContext1.GetType(type1);
                if (typeId != null)
                {
                    IType type2 = projectContext1.ResolveType(typeId);
                    runtimeAssembly = type2.RuntimeAssembly;
                    targetAssembly  = PlatformTypeHelper.GetTargetAssembly(type2);
                }
            }
            IAssembly designAssembly = projectContext1.GetDesignAssembly(runtimeAssembly);

            if (designAssembly != null)
            {
                currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, designAssembly, designAssembly, defaultStyleKey, out auxillaryResources);
                if (currentStyle != null)
                {
                    return;
                }
            }
            if (!PlatformTypes.IsPlatformType((ITypeId)this.Type))
            {
                foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects)
                {
                    IProjectContext projectContext2 = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
                    if (projectContext2 != null && runtimeAssembly.Equals((object)projectContext2.ProjectAssembly))
                    {
                        currentStyle = themeContentProvider.GetThemeResourceFromProject(project, defaultStyleKey, out auxillaryResources);
                        if (currentStyle != null)
                        {
                            return;
                        }
                    }
                }
            }
            else if (!allowDefaultStyle || projectContext1.PlatformMetadata.TargetFramework.Identifier == ".NETFramework" && projectContext1.PlatformMetadata.TargetFramework.Version < projectContext1.PlatformMetadata.RuntimeFramework.Version)
            {
                currentStyle = themeContentProvider.GetThemeResourceFromPlatform(projectContext1.Platform, defaultStyleKey, out auxillaryResources);
                if (currentStyle != null)
                {
                    isThemeStyle = true;
                    return;
                }
            }
            if (!projectContext1.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, runtimeAssembly, targetAssembly, defaultStyleKey, out auxillaryResources);
                isThemeStyle = currentStyle != null;
            }
            else
            {
                object resource = this.SceneViewModel.FindResource(defaultStyleKey);
                if (resource == null)
                {
                    return;
                }
                if (projectContext1 != null && projectContext1.IsCapabilitySet(PlatformCapability.VsmInToolkit) && (projectContext1.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager) && projectContext1.PlatformMetadata.IsNullType((ITypeId)projectContext1.ResolveType(ProjectNeutralTypes.VisualStateManager))))
                {
                    IAssembly usingAssemblyName = projectContext1.Platform.Metadata.GetPlatformAssemblyUsingAssemblyName(targetElement.Type.RuntimeAssembly);
                    if (usingAssemblyName == null || !AssemblyHelper.IsPlatformAssembly(usingAssemblyName))
                    {
                        IDocumentContext documentContext = (IDocumentContext) new DocumentContext((IProjectContext) new ToolkitProjectContext(projectContext1), ((DocumentContext)this.SceneViewModel.Document.DocumentContext).DocumentLocator);
                        DocumentNode     node            = documentContext.CreateNode(resource.GetType(), resource);
                        if (ProjectAttributeHelper.GetDefaultStateRecords(this.Type, (ITypeResolver)(documentContext.TypeResolver as ProjectContext)).Count > 0 || (DocumentCompositeNode)node.FindFirst(new Predicate <DocumentNode>(this.SelectVisualStateGroupPredicate)) != null)
                        {
                            ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext1, this.DesignerContext.ViewUpdateManager);
                        }
                    }
                }
                SceneNode sceneNode = this.SceneViewModel.CreateSceneNode(resource);
                if (!PlatformTypes.Style.IsAssignableFrom((ITypeId)sceneNode.Type))
                {
                    return;
                }
                currentStyle = sceneNode.DocumentNode;
            }
        }
Exemplo n.º 3
0
        protected virtual DocumentNode ResolveDefaultStyleAsDocumentNode(IType targetType, IPropertyId propertyKey)
        {
            DocumentNode node      = (DocumentNode)null;
            IViewStyle   viewStyle = (IViewStyle)null;

            if (this.IsViewObjectValid)
            {
                ReferenceStep referenceStep = propertyKey as ReferenceStep;
                if (referenceStep != null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                {
                    viewStyle = this.Platform.ViewObjectFactory.Instantiate(referenceStep.GetCurrentValue(this.ViewObject.PlatformSpecificObject)) as IViewStyle;
                    if (viewStyle != null && viewStyle.StyleTargetType != targetType.RuntimeType)
                    {
                        viewStyle = (IViewStyle)null;
                    }
                    if (viewStyle != null)
                    {
                        node = this.ViewModel.DefaultView.GetCorrespondingDocumentNode((IViewObject)viewStyle, true);
                        if (node == null && this.DesignerContext.DesignerDefaultPlatformService.DefaultPlatform == this.Platform)
                        {
                            node = this.CreateNode(viewStyle.PlatformSpecificObject);
                        }
                    }
                }
            }
            for (IType type = this.ProjectContext.GetType(this.MetadataFactory.GetMetadata(targetType.RuntimeType).GetStylePropertyTargetType(propertyKey)); node == null && type != null && !PlatformTypes.Object.Equals((object)type); type = type.BaseType)
            {
                IList <DocumentCompositeNode> auxillaryResources = (IList <DocumentCompositeNode>)null;
                if (PlatformTypes.IsPlatformType((ITypeId)type))
                {
                    node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromPlatform(this.Platform, (object)type.RuntimeType, out auxillaryResources);
                }
                else
                {
                    foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects)
                    {
                        IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
                        if (projectContext != null && type.RuntimeAssembly.Equals((object)projectContext.ProjectAssembly))
                        {
                            node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromProject(project, (object)type.RuntimeType, out auxillaryResources);
                            if (node == null && !this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                            {
                                node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromAssembly(this.ProjectContext, type.RuntimeAssembly, type.RuntimeAssembly, (object)type.RuntimeType, out auxillaryResources);
                            }
                        }
                    }
                }
                if (node != null)
                {
                    node = node.Clone(this.DocumentContext);
                    if (auxillaryResources != null && auxillaryResources.Count > 0)
                    {
                        StyleNode styleNode = (StyleNode)this.ViewModel.GetSceneNode(node);
                        if (styleNode.AreResourcesSupported)
                        {
                            if (styleNode.Resources == null)
                            {
                                styleNode.Resources = (ResourceDictionaryNode)this.ViewModel.CreateSceneNode(PlatformTypes.ResourceDictionary);
                            }
                            for (int index = auxillaryResources.Count - 1; index >= 0; --index)
                            {
                                DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)this.ViewModel.GetSceneNode(auxillaryResources[index].Clone(this.DocumentContext));
                                styleNode.Resources.Insert(0, dictionaryEntryNode);
                            }
                        }
                    }
                }
            }
            if (viewStyle == null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                ReferenceStep referenceStep = propertyKey as ReferenceStep;
                if (referenceStep != null)
                {
                    System.Windows.Style style = referenceStep.GetDefaultValue(targetType.RuntimeType) as System.Windows.Style;
                    if (style != null)
                    {
                        node = this.CreateNode((object)style);
                    }
                }
            }
            return(node);
        }