Пример #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);
                    }
                }
            }
        }
Пример #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);
        }
Пример #3
0
        public static string GetStudy(string agency, Guid id)
        {
            try
            {
                MultilingualString.CurrentCulture = "en-GB";

                var client = ToolkitHelper.RestClient();

                // Retrieve the requested item from the Repository.
                // Populate the item's children, so we can display information about them.
                IVersionable item = client.client.GetLatestItem(id, agency,
                                                                ChildReferenceProcessing.Populate);
                // Use a graph search to find a list of all items that
                // directly reference this item.
                GraphSearchFacet facet = new GraphSearchFacet();
                facet.TargetItem            = item.CompositeId;
                facet.UseDistinctResultItem = true;
                var references = client.client.GetRepositoryItemDescriptionsByObject(facet);
                var referencingItemDescription = (from a in references
                                                  where a.ItemType == new Guid("0a63fcf6-ffdd-4214-b38c-147d6689d6a1")
                                                  select a).FirstOrDefault();
                for (int i = 1; i < 3; i++)
                {
                    if (referencingItemDescription != null)
                    {
                        referencingItemDescription = GetReference(referencingItemDescription.AgencyId, referencingItemDescription.Identifier);
                    }
                }
                if (referencingItemDescription == null)
                {
                    return(null);
                }
                else
                {
                    return(referencingItemDescription.DisplayLabel);
                }
            }
            catch
            {
                return(null);
            }
        }
Пример #4
0
        public static List <RepositoryItemMetadata> GetReferences(string agency, Guid id)
        {
            MultilingualString.CurrentCulture = "en-GB";

            var client = ToolkitHelper.RestClient();

            // Retrieve the requested item from the Repository.
            // Populate the item's children, so we can display information about them.
            IVersionable item = client.client.GetLatestItem(id, agency,
                                                            ChildReferenceProcessing.Populate);
            // Use a graph search to find a list of all items that
            // directly reference this item.
            GraphSearchFacet facet = new GraphSearchFacet();

            facet.TargetItem            = item.CompositeId;
            facet.UseDistinctResultItem = true;

            var referencingItemDescriptions = client.client.GetRepositoryItemDescriptionsByObject(facet).ToList();

            return(referencingItemDescriptions);
        }
Пример #5
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);
 }
        public override void Execute(object arg)
        {
            DesignerContext designerContext      = this.DesignerContext;
            SceneViewModel  activeSceneViewModel = designerContext.ActiveSceneViewModel;
            ITypeId         type = this.Type;

            if (type is ProjectNeutralTypeId)
            {
                bool flag = activeSceneViewModel.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)this.DesignerContext.ActiveSceneViewModel.ProjectContext, type);
                if (!flag && this.IsDragDropContainer)
                {
                    IMessageDisplayService messageDisplayService = activeSceneViewModel.DesignerContext.MessageDisplayService;
                    flag = ToolkitHelper.EnsureSilverlightToolkitTypeAvailable((ITypeResolver)activeSceneViewModel.ProjectContext, type, messageDisplayService, StringTable.SilverlightToolkitDragDropNotInstalled, StringTable.SilverlightToolkitDragDropIncorrectVersion);
                }
                if (!flag)
                {
                    return;
                }
            }
            using (SceneEditTransaction editTransaction = designerContext.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitGroupIntoLayoutType, new object[1]
            {
                (object)this.Type.Name
            })))
            {
                List <SceneElement> list1    = new List <SceneElement>();
                List <SceneNode>    elements = new List <SceneNode>();
                list1.AddRange((IEnumerable <SceneElement>)designerContext.SelectionManager.ElementSelectionSet.Selection);
                GroupIntoLayoutTypeCommand.OrientationHelper orientationHelper = new GroupIntoLayoutTypeCommand.OrientationHelper();
                list1.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(this.SceneViewModel.RootNode));
                List <LayoutCacheRecord> list2 = new List <LayoutCacheRecord>(list1.Count);
                Rect empty = Rect.Empty;
                for (int index = 0; index < list1.Count; ++index)
                {
                    list2.Add((LayoutCacheRecord)null);
                    BaseFrameworkElement element = list1[index] as BaseFrameworkElement;
                    if (element != null)
                    {
                        ILayoutDesigner designerForChild   = element.ViewModel.GetLayoutDesignerForChild((SceneElement)element, true);
                        Rect            roundedUpChildRect = LayoutRoundingHelper.GetRoundedUpChildRect(designerForChild, element);
                        empty.Union(roundedUpChildRect);
                        orientationHelper.AddChildRect((SceneNode)element, roundedUpChildRect);
                        LayoutCacheRecord layoutCacheRecord = designerForChild.CacheLayout(element);
                        list2[index] = layoutCacheRecord;
                        elements.Add((SceneNode)element);
                    }
                }
                Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null;
                using (this.SceneViewModel.ForceBaseValue())
                {
                    using (this.SceneViewModel.DisableDrawIntoState())
                    {
                        SceneElement sceneElement1 = (SceneElement)null;
                        SceneElement sceneElement2 = (SceneElement)activeSceneViewModel.CreateSceneNode(type);
                        Orientation? nullable      = orientationHelper.ApplyOrientation(sceneElement2);
                        if (nullable.HasValue)
                        {
                            orientationHelper.SortElements(elements, nullable.Value);
                        }
                        int num;
                        if (list1.Count == 1 && list1[0] is BaseFrameworkElement)
                        {
                            int?fixedCapacity = sceneElement2.DefaultContent.FixedCapacity;
                            num = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false);
                        }
                        else
                        {
                            num = 0;
                        }
                        bool flag = num != 0;
                        if (sceneElement2 != null)
                        {
                            activeSceneViewModel.GetLayoutDesignerForParent(sceneElement2, true);
                        }
                        foreach (SceneElement sceneElement3 in list1)
                        {
                            if (sceneElement3 != null)
                            {
                                BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement;
                                ILayoutDesigner      layoutDesigner   = frameworkElement == null ? (ILayoutDesigner)null : sceneElement3.ViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true);
                                if (flag)
                                {
                                    properties = SceneElementHelper.StoreProperties((SceneNode)sceneElement3, layoutDesigner.GetLayoutProperties(), true);
                                }
                                if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == sceneElement3)
                                {
                                    sceneElement1 = sceneElement3;
                                }
                            }
                        }
                        if (list1.Count == 1)
                        {
                            VisualStateManagerSceneNode.MoveStates(list1[0], sceneElement2);
                        }
                        using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove())
                        {
                            SceneElement primarySelection = designerContext.SelectionManager.ElementSelectionSet.PrimarySelection;
                            designerContext.SelectionManager.ElementSelectionSet.Clear();
                            Dictionary <IPropertyId, List <SceneNode> > storedChildren = new Dictionary <IPropertyId, List <SceneNode> >();
                            storedChildren.Add((IPropertyId)sceneElement2.DefaultContentProperty, elements);
                            ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer();
                            foreach (SceneElement sceneElement3 in list1)
                            {
                                if (sceneElement3 != primarySelection)
                                {
                                    sceneElement3.Remove();
                                }
                            }
                            int index1 = collectionContainer.IndexOf((SceneNode)primarySelection);
                            primarySelection.Remove();
                            collectionContainer.Insert(index1, (SceneNode)sceneElement2);
                            ChangeLayoutTypeCommand.ApplyChildren(sceneElement2, storedChildren, empty.Size);
                            if (flag)
                            {
                                SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)list1[0], (SceneNode)sceneElement2, properties);
                                SceneElementHelper.ApplyProperties((SceneNode)sceneElement2, properties);
                            }
                            else
                            {
                                ILayoutDesigner designerForChild = sceneElement2.ViewModel.GetLayoutDesignerForChild(sceneElement2, true);
                                if (sceneElement2.IsViewObjectValid)
                                {
                                    LayoutOverrides layoutOverrides   = LayoutOverrides.None;
                                    LayoutOverrides overridesToIgnore = LayoutOverrides.None;
                                    if (nullable.HasValue && nullable.Value == Orientation.Horizontal)
                                    {
                                        layoutOverrides |= LayoutOverrides.Width;
                                    }
                                    else
                                    {
                                        overridesToIgnore |= LayoutOverrides.Width;
                                    }
                                    if (nullable.HasValue && nullable.Value == Orientation.Vertical)
                                    {
                                        layoutOverrides |= LayoutOverrides.Height;
                                    }
                                    else
                                    {
                                        overridesToIgnore |= LayoutOverrides.Height;
                                    }
                                    designerForChild.SetChildRect((BaseFrameworkElement)sceneElement2, empty, layoutOverrides, overridesToIgnore, LayoutOverrides.None);
                                }
                            }
                            editTransaction.Update();
                            if (sceneElement2.IsViewObjectValid)
                            {
                                this.SceneViewModel.DefaultView.UpdateLayout();
                                SceneElement    parentElement     = primarySelection.ParentElement;
                                ILayoutDesigner designerForParent = activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true);
                                for (int index2 = 0; index2 < list1.Count; ++index2)
                                {
                                    SceneElement         sceneElement3    = list1[index2];
                                    BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement;
                                    if (frameworkElement != null)
                                    {
                                        LayoutCacheRecord layoutCacheRecord = list2[index2];
                                        Rect rect = LayoutRoundingHelper.RoundUpLayoutRect(frameworkElement, layoutCacheRecord.Rect);
                                        rect.Location = (Point)(rect.Location - empty.Location);
                                        designerForParent.ClearUnusedLayoutProperties(frameworkElement);
                                        designerForParent.SetChildRect(frameworkElement, rect, flag ? LayoutOverrides.None : layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None);
                                        if (this.IsDragDropContainer)
                                        {
                                            sceneElement3.SetValue(Base2DElement.AllowDropProperty, (object)true);
                                        }
                                    }
                                }
                            }
                            if (sceneElement1 != null)
                            {
                                this.SceneViewModel.SetLockedInsertionPoint(sceneElement1);
                            }
                        }
                        designerContext.SelectionManager.ElementSelectionSet.SetSelection(sceneElement2);
                        editTransaction.Commit();
                    }
                }
            }
        }
        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;
            }
        }