Ejemplo n.º 1
0
        public static void AddDefaultStates(SceneNode ownerNode, SceneNode rootNode, ITypeId controlTypeId)
        {
            IType           controlType    = ownerNode.ProjectContext.ResolveType(controlTypeId);
            IProjectContext projectContext = ownerNode.ProjectContext;

            if (projectContext != null && projectContext.IsCapabilitySet(PlatformCapability.VsmInToolkit) && (projectContext.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager) && projectContext.PlatformMetadata.IsNullType((ITypeId)projectContext.ResolveType(ProjectNeutralTypes.VisualStateManager))))
            {
                IAssembly usingAssemblyName = ((PlatformTypes)projectContext.Platform.Metadata).GetPlatformAssemblyUsingAssemblyName(controlType.RuntimeAssembly);
                if (usingAssemblyName == null || !AssemblyHelper.IsPlatformAssembly(usingAssemblyName))
                {
                    ToolkitProjectContext toolkitProjectContext = new ToolkitProjectContext(projectContext);
                    if (ProjectAttributeHelper.GetDefaultStateRecords(controlType, (ITypeResolver)toolkitProjectContext).Count > 0)
                    {
                        ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext, ownerNode.DesignerContext.ViewUpdateManager);
                    }
                }
            }
            foreach (DefaultStateRecord defaultStateRecord in ProjectAttributeHelper.GetDefaultStateRecords(controlType, (ITypeResolver)ownerNode.ProjectContext.GetService(typeof(ProjectContext))))
            {
                IList <VisualStateGroupSceneNode> stateGroups          = VisualStateManagerSceneNode.GetStateGroups(ownerNode);
                VisualStateGroupSceneNode         stateGroupSceneNode1 = (VisualStateGroupSceneNode)null;
                foreach (VisualStateGroupSceneNode stateGroupSceneNode2 in (IEnumerable <VisualStateGroupSceneNode>)stateGroups)
                {
                    if (stateGroupSceneNode2.Name == defaultStateRecord.GroupName)
                    {
                        stateGroupSceneNode1 = stateGroupSceneNode2;
                    }
                }
                if (stateGroupSceneNode1 == null)
                {
                    VisualStateManagerSceneNode.EnsureNameAvailable(rootNode, defaultStateRecord.GroupName);
                    stateGroupSceneNode1 = VisualStateManagerSceneNode.AddStateGroup(ownerNode, rootNode, defaultStateRecord.GroupName);
                    stateGroupSceneNode1.ShouldSerialize = false;
                }
                VisualStateSceneNode visualStateSceneNode1 = (VisualStateSceneNode)null;
                if (stateGroupSceneNode1 != null)
                {
                    foreach (VisualStateSceneNode visualStateSceneNode2 in (IEnumerable <VisualStateSceneNode>)stateGroupSceneNode1.States)
                    {
                        if (visualStateSceneNode2.Name == defaultStateRecord.StateName)
                        {
                            visualStateSceneNode1 = visualStateSceneNode2;
                        }
                    }
                    if (visualStateSceneNode1 == null)
                    {
                        VisualStateManagerSceneNode.EnsureNameAvailable(rootNode, defaultStateRecord.StateName);
                        stateGroupSceneNode1.AddState(rootNode, defaultStateRecord.StateName);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static VisualStateGroupSceneNode AddStateGroup(SceneNode ownerNode, SceneNode rootNode, string groupName)
        {
            ProjectContext projectContext = (ProjectContext)ownerNode.ProjectContext.GetService(typeof(ProjectContext));

            ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext, ownerNode.DesignerContext.ViewUpdateManager);
            IType type = projectContext.ResolveType(ProjectNeutralTypes.VisualStateGroup);

            if (type == null || projectContext.PlatformMetadata.IsNullType((ITypeId)type))
            {
                return((VisualStateGroupSceneNode)null);
            }
            VisualStateGroupSceneNode stateGroupSceneNode = VisualStateGroupSceneNode.Factory.Instantiate(ownerNode.ViewModel);

            VisualStateManagerSceneNode.GetStateGroups(ownerNode).Add(stateGroupSceneNode);
            string validElementId = new SceneNodeIDHelper(ownerNode.ViewModel, rootNode).GetValidElementID((SceneNode)stateGroupSceneNode, groupName);

            stateGroupSceneNode.Name = validElementId;
            return(stateGroupSceneNode);
        }
Ejemplo n.º 3
0
 public static bool EnsureExtendedAssemblyReferences(ITypeResolver typeResolver, IAssemblyService assemblyService, ViewUpdateManager viewUpdateManager)
 {
     ToolkitHelper.AddToolkitReferenceIfNeeded(typeResolver, viewUpdateManager);
     if (assemblyService != null)
     {
         string   assemblyFullName1 = ((PlatformTypes)typeResolver.PlatformMetadata).InteractivityAssemblyFullName;
         string   assemblyFullName2 = ((PlatformTypes)typeResolver.PlatformMetadata).InteractionsAssemblyFullName;
         Assembly assembly1         = assemblyService.ResolveLibraryAssembly(new AssemblyName(assemblyFullName1));
         if (assembly1 != (Assembly)null)
         {
             Assembly assembly2 = assemblyService.ResolveLibraryAssembly(new AssemblyName(assemblyFullName2));
             if (assembly2 != (Assembly)null)
             {
                 bool flag = typeResolver.EnsureAssemblyReferenced(assembly1.Location) && typeResolver.EnsureAssemblyReferenced(assembly2.Location);
                 if (flag)
                 {
                     viewUpdateManager.RebuildPostponedViews();
                 }
                 return(flag);
             }
         }
     }
     return(false);
 }
        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;
            }
        }