public override void OnViewNodeInvalidating(IInstanceBuilderContext context, ViewNode target, ViewNode child, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots)
        {
            InstanceState instanceState = target.InstanceState;

            if (target.Instance is DocumentNode && instanceState.IsPropertyInvalid && !instanceState.IsChildInvalid && !instanceState.IsDescendantInvalid)
            {
                IInstantiatedElementViewNode instantiatedElementViewNode = target as IInstantiatedElementViewNode;
                if (instantiatedElementViewNode != null && instantiatedElementViewNode.InstantiatedElements.First != null)
                {
                    bool flag = true;
                    using (IEnumerator <IProperty> enumerator = instanceState.InvalidProperties.GetEnumerator())
                    {
                        do
                        {
                            if (!enumerator.MoveNext())
                            {
                                break;
                            }
                            flag = this.IsIncrementalChange(context, target, enumerator.Current);
                        }while (flag);
                    }
                    if (flag)
                    {
                        return;
                    }
                }
            }
            bool flag1 = false;

            if (instanceState != InstanceState.Valid)
            {
                T instance = (T)(target.Instance as T);
                if (instance != null && this.IsSealed(instance))
                {
                    flag1 = true;
                }
                IInstantiatedElementViewNode instantiatedElementViewNode1 = target as IInstantiatedElementViewNode;
                if (instantiatedElementViewNode1 != null && instantiatedElementViewNode1.InstantiatedElements.First != null)
                {
                    foreach (object instantiatedElement in instantiatedElementViewNode1.InstantiatedElements)
                    {
                        instance = (T)(instantiatedElement as T);
                        if (instance == null || !this.IsSealed(instance))
                        {
                            continue;
                        }
                        flag1 = true;
                        break;
                    }
                }
            }
            if (flag1)
            {
                InstanceBuilderOperations.SetInvalid(context, target, ref doesInvalidRootsContainTarget, invalidRoots);
            }
            base.OnViewNodeInvalidating(context, target, child, ref doesInvalidRootsContainTarget, invalidRoots);
        }
예제 #2
0
        public static bool UseDesignTimeSize(object target, IInstanceBuilderContext context)
        {
            bool documentNode = false;

            if (context != null && context.ContainerRoot != null && context.ContainerRoot.DocumentNode != null && context.ContainerRoot.DocumentNode.DocumentRoot != null && context.ViewNodeManager != null && context.ViewNodeManager.Root != null)
            {
                ViewNode viewNode = context.InstanceDictionary.GetViewNode(target, true);
                if ((viewNode == null ? true : viewNode.Parent != null))
                {
                    documentNode = context.ViewNodeManager.Root.DocumentNode != context.ContainerRoot.DocumentNode.DocumentRoot.RootNode;
                    IInstantiatedElementViewNode root = context.ViewNodeManager.Root as IInstantiatedElementViewNode;
                    if (documentNode && root != null)
                    {
                        object first = root.InstantiatedElements.First;
                        if (first != null && (bool)(context.DocumentContext.TypeResolver.ResolveProperty(DesignTimeProperties.IsEnhancedOutOfPlaceRootProperty) as DependencyPropertyReferenceStep).GetValue(first))
                        {
                            documentNode = false;
                        }
                    }
                    if (documentNode && viewNode != null)
                    {
                        DocumentNodePath containerNodePath = context.ViewNodeManager.GetCorrespondingNodePath(viewNode).GetContainerNodePath();
                        if (PlatformTypes.ControlTemplate.Equals(containerNodePath.Node.Type) && containerNodePath.Node != context.ViewNodeManager.Root.DocumentNode)
                        {
                            DocumentNodePath parent = containerNodePath.GetParent();
                            if (parent.Node.Type.Equals(PlatformTypes.Setter) && parent.Node is DocumentCompositeNode)
                            {
                                IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember((DocumentCompositeNode)parent.Node, Microsoft.Expression.DesignModel.Metadata.KnownProperties.SetterPropertyProperty);
                                if (valueAsMember.Equals(Microsoft.Expression.DesignModel.Metadata.KnownProperties.ControlTemplateProperty) || valueAsMember.Equals(Microsoft.Expression.DesignModel.Metadata.KnownProperties.PageTemplateProperty))
                                {
                                    containerNodePath = parent.GetContainerNodePath();
                                }
                            }
                        }
                        if (containerNodePath.Node != context.ViewNodeManager.Root.DocumentNode)
                        {
                            documentNode = false;
                        }
                    }
                }
                else
                {
                    documentNode = true;
                }
            }
            return(documentNode);
        }
        protected virtual void AddEntry(ViewNode dictionaryNode, object resourceKey, object value)
        {
            IInstantiatedElementViewNode instantiatedElementViewNode = dictionaryNode as IInstantiatedElementViewNode;

            if (instantiatedElementViewNode != null)
            {
                foreach (IDictionary instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                {
                    instantiatedElement[resourceKey] = value;
                }
            }
            IDictionary instance = dictionaryNode.Instance as IDictionary;

            if (instance != null)
            {
                instance[resourceKey] = value;
            }
        }
 protected virtual void RemoveEntry(ViewNode dictionaryNode, object resourceKey)
 {
     if (resourceKey != null)
     {
         IInstantiatedElementViewNode instantiatedElementViewNode = dictionaryNode as IInstantiatedElementViewNode;
         if (instantiatedElementViewNode != null)
         {
             foreach (IDictionary instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
             {
                 instantiatedElement.Remove(resourceKey);
             }
         }
         IDictionary instance = dictionaryNode.Instance as IDictionary;
         if (instance != null)
         {
             instance.Remove(resourceKey);
         }
     }
 }
        public static bool NeedsRebuild(IInstanceBuilderContext context, ViewNode viewNode, string closedDocumentPath)
        {
            bool flag;
            bool flag1;

            if (!PlatformTypes.UserControl.Equals(viewNode.Type))
            {
                DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode;
                IProperty             property     = documentNode.TypeResolver.ResolveProperty(DesignTimeProperties.ClassProperty);
                if (documentNode != null && !documentNode.Properties.Contains(property))
                {
                    string xamlSourcePath = viewNode.Type.XamlSourcePath;
                    if (!string.IsNullOrEmpty(xamlSourcePath))
                    {
                        if (closedDocumentPath != null && closedDocumentPath.Equals(xamlSourcePath))
                        {
                            return(true);
                        }
                        uint?           changeStampWhenInstantiated = null;
                        IPreviewControl instance = viewNode.Instance as IPreviewControl;
                        if (instance != null)
                        {
                            changeStampWhenInstantiated = instance.ChangeStampWhenInstantiated;
                        }
                        IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode;
                        if (instantiatedElementViewNode != null)
                        {
                            foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                            {
                                instance = instantiatedElement as IPreviewControl;
                                if (instance == null)
                                {
                                    continue;
                                }
                                if (changeStampWhenInstantiated.HasValue && instance.ChangeStampWhenInstantiated.HasValue)
                                {
                                    uint?nullable = changeStampWhenInstantiated;
                                    uint?changeStampWhenInstantiated1 = instance.ChangeStampWhenInstantiated;
                                    if ((nullable.GetValueOrDefault() != changeStampWhenInstantiated1.GetValueOrDefault() ? true : nullable.HasValue != changeStampWhenInstantiated1.HasValue))
                                    {
                                        flag = true;
                                        return(flag);
                                    }
                                }
                                if (changeStampWhenInstantiated.HasValue)
                                {
                                    continue;
                                }
                                changeStampWhenInstantiated = instance.ChangeStampWhenInstantiated;
                            }
                        }
                        try
                        {
                            XamlDocument documentRoot = (XamlDocument)context.DocumentRootResolver.GetDocumentRoot(xamlSourcePath);
                            if (documentRoot == null)
                            {
                                return(false);
                            }
                            else
                            {
                                bool flag2 = UserControlInstanceBuilderHelper.ShouldUseDocumentForPreview(context, documentRoot);
                                if (changeStampWhenInstantiated.HasValue != flag2)
                                {
                                    flag1 = true;
                                }
                                else if (!changeStampWhenInstantiated.HasValue)
                                {
                                    flag1 = false;
                                }
                                else
                                {
                                    uint?nullable1   = changeStampWhenInstantiated;
                                    uint changeStamp = documentRoot.ChangeStamp;
                                    flag1 = (nullable1.GetValueOrDefault() != changeStamp ? true : !nullable1.HasValue);
                                }
                                flag = flag1;
                            }
                        }
                        catch (IOException oException)
                        {
                            return(false);
                        }
                        return(flag);
                    }
                }
            }
            return(false);
        }
        public override void ModifyValue(IInstanceBuilderContext context, ViewNode target, object onlyThisInstance, IProperty propertyKey, object value, PropertyModification modification)
        {
            IProperty shadowProperty;

            if (!context.IsSerializationScope)
            {
                IInstantiatedElementViewNode instantiatedElementViewNode = target as IInstantiatedElementViewNode;
                if (instantiatedElementViewNode != null && onlyThisInstance == null && instantiatedElementViewNode.InstantiatedElements.First != null)
                {
                    if (context.UseShadowProperties)
                    {
                        shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, target.DocumentNode.Type);
                    }
                    else
                    {
                        shadowProperty = null;
                    }
                    IProperty property = shadowProperty;
                    if (property != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(target.TypeResolver, property))
                    {
                        propertyKey = property;
                    }
                    ReferenceStep referenceStep = propertyKey as ReferenceStep;
                    if (referenceStep != null)
                    {
                        foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                        {
                            if (modification != PropertyModification.Set)
                            {
                                referenceStep.ClearValue(instantiatedElement);
                            }
                            else
                            {
                                InstanceBuilderOperations.SetValue(instantiatedElement, referenceStep, value);
                            }
                        }
                        return;
                    }
                }
            }
            if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey))
            {
                string valueAsString = null;
                if (context.IsSerializationScope)
                {
                    DocumentPrimitiveNode documentPrimitiveNode = value as DocumentPrimitiveNode;
                    if (documentPrimitiveNode != null)
                    {
                        valueAsString = DocumentPrimitiveNode.GetValueAsString(documentPrimitiveNode);
                    }
                }
                else
                {
                    valueAsString = value as string;
                    if (string.IsNullOrEmpty(valueAsString) && (ProjectNeutralTypes.VisualStateGroup.IsAssignableFrom(target.Type) || ProjectNeutralTypes.VisualState.IsAssignableFrom(target.Type)))
                    {
                        valueAsString = ((DocumentCompositeNode)target.DocumentNode).GetValueAsString(target.DocumentNode.NameProperty);
                    }
                }
                if (valueAsString != null && string.IsNullOrEmpty(valueAsString))
                {
                    CultureInfo currentCulture = CultureInfo.CurrentCulture;
                    string      instanceBuilderNamePropertyNotValid = ExceptionStringTable.InstanceBuilderNamePropertyNotValid;
                    object[]    objArray = new object[] { valueAsString };
                    throw new InstanceBuilderException(string.Format(currentCulture, instanceBuilderNamePropertyNotValid, objArray), target.DocumentNode);
                }
            }
            base.ModifyValue(context, target, onlyThisInstance, propertyKey, value, modification);
        }
        public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
        {
            string        instance;
            string        str;
            IPropertyId   shadowProperty;
            ReferenceStep referenceStep = propertyKey as ReferenceStep;
            ViewNode      item          = viewNode.Properties[propertyKey];

            if (item != null && DocumentNodeUtilities.IsBinding(item.DocumentNode) && referenceStep != null)
            {
                ReferenceStep referenceStep1 = referenceStep;
                if (context.UseShadowProperties)
                {
                    shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, viewNode.DocumentNode.Type);
                }
                else
                {
                    shadowProperty = null;
                }
                IPropertyId propertyId = shadowProperty;
                if (propertyId != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, propertyId))
                {
                    referenceStep1 = propertyId as ReferenceStep;
                }
                if (referenceStep1 != null)
                {
                    IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode;
                    if (instantiatedElementViewNode == null)
                    {
                        referenceStep1.ClearValue(viewNode.Instance);
                    }
                    else
                    {
                        foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                        {
                            referenceStep1.ClearValue(instantiatedElement);
                        }
                    }
                }
            }
            if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey) && InstanceBuilderOperations.GetIsInlinedResourceWithoutNamescope(viewNode))
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
                return;
            }
            INameScope nameScope = context.NameScope;
            bool       flag      = (nameScope == null ? false : propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey));

            if (flag)
            {
                ViewNode item1 = viewNode.Properties[propertyKey];
                if (item1 != null)
                {
                    str = item1.Instance as string;
                }
                else
                {
                    str = null;
                }
                string str1 = str;
                if (!string.IsNullOrEmpty(str1) && nameScope.FindName(str1) != null)
                {
                    context.NameScope.UnregisterName(str1);
                }
            }
            if ((!context.IsSerializationScope || !(propertyKey is Event)) && (context.IsSerializationScope || !DesignTimeProperties.IsDocumentOnlyDesignTimeProperty(propertyKey)))
            {
                base.UpdateProperty(context, viewNode, propertyKey, valueNode);
            }
            else
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
            }
            if (flag)
            {
                ViewNode viewNode1 = viewNode.Properties[propertyKey];
                if (viewNode1 != null)
                {
                    instance = viewNode1.Instance as string;
                }
                else
                {
                    instance = null;
                }
                string str2 = instance;
                if (!string.IsNullOrEmpty(str2))
                {
                    try
                    {
                        if (!str2.StartsWith("~", StringComparison.Ordinal) && !str2.Contains("."))
                        {
                            if (nameScope.FindName(str2) != null)
                            {
                                nameScope.UnregisterName(str2);
                            }
                            nameScope.RegisterName(str2, viewNode.Instance);
                        }
                    }
                    catch (ArgumentException argumentException1)
                    {
                        ArgumentException argumentException = argumentException1;
                        ViewNodeManager   viewNodeManager   = viewNode1.ViewNodeManager;
                        CultureInfo       currentCulture    = CultureInfo.CurrentCulture;
                        string            instanceBuilderUnableToRegisterName = ExceptionStringTable.InstanceBuilderUnableToRegisterName;
                        object[]          objArray = new object[] { str2 };
                        viewNodeManager.OnException(viewNode1, new InstanceBuilderException(string.Format(currentCulture, instanceBuilderUnableToRegisterName, objArray), argumentException, viewNode1.DocumentNode, viewNode), false);
                    }
                }
            }
        }