Esempio n. 1
0
        public IInstanceBuilderContext GetViewContext(IDocumentRoot documentRoot)
        {
            IInstanceBuilderContext viewContext = this.viewRootResolver.GetViewContext(documentRoot);

            if (viewContext == null)
            {
                return(null);
            }
            ViewNode root = viewContext.ViewNodeManager.Root;

            if (root != null && root.InstanceState == InstanceState.Invalid)
            {
                using (IDisposable disposable = viewContext.ChangeCrossDocumentUpdateContext(this))
                {
                    viewContext.ViewNodeManager.UpdateInstances(null);
                }
                if (this.contexts != null)
                {
                    this.GetContextInfo(viewContext, true);
                }
            }
            return(viewContext);
        }
Esempio n. 2
0
        public static bool GetIsInlinedResourceWithoutNamescope(ViewNode viewNode)
        {
            bool     flag   = false;
            ViewNode parent = viewNode;

            do
            {
                if (parent == null || parent.Parent == null)
                {
                    break;
                }
                if (parent.Parent.DocumentNode == parent.DocumentNode.Parent || parent.DocumentNode.DocumentRoot == null)
                {
                    parent = parent.Parent;
                }
                else
                {
                    flag = true;
                    break;
                }
            }while (!parent.DocumentNode.TypeResolver.PlatformMetadata.GetIsTypeItsOwnNameScope(parent.Type));
            return(flag);
        }
 public override void UpdateChild(IInstanceBuilderContext context, ViewNode viewNode, int childIndex, DocumentNodeChangeAction action, DocumentNode childNode)
 {
     if (action == DocumentNodeChangeAction.Remove && childIndex < viewNode.Children.Count)
     {
         ViewNode item = viewNode.Children[childIndex];
         this.RemoveChildViewNodeFromInstance(viewNode, item);
         viewNode.Children.Remove(item);
     }
     if (action == DocumentNodeChangeAction.Add || action == DocumentNodeChangeAction.Replace)
     {
         IInstanceBuilder builder   = context.InstanceBuilderFactory.GetBuilder(childNode.TargetType);
         ViewNode         viewNode1 = builder.GetViewNode(context, childNode);
         if (action != DocumentNodeChangeAction.Replace)
         {
             viewNode.Children.Insert(childIndex, viewNode1);
         }
         else
         {
             this.RemoveChildViewNodeFromInstance(viewNode, viewNode.Children[childIndex]);
             viewNode.Children[childIndex] = viewNode1;
         }
         this.InstantiateChild(context, viewNode, viewNode1);
     }
 }
        private static bool IsEvaluatedResourceWithinNodePath(DocumentNodePath nodePath, ViewNode viewNode, IProperty propertyKey, DocumentNodePath evaluatedResource)
        {
            DocumentNodePath correspondingNodePath = null;

            if (nodePath != null && nodePath.Count > 1)
            {
                for (int i = nodePath.Count - 1; i >= 1; i--)
                {
                    if (nodePath[i].Container == evaluatedResource.Node && nodePath[i - 1].Target == viewNode.DocumentNode && nodePath[i].PropertyKey == propertyKey)
                    {
                        if (correspondingNodePath == null)
                        {
                            correspondingNodePath = viewNode.ViewNodeManager.GetCorrespondingNodePath(viewNode);
                        }
                        if (correspondingNodePath.Count == i && correspondingNodePath.IsAncestorOf(nodePath))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 5
0
 protected void PostAddInternal(ViewNode child, IProperty propertyKey)
 {
     child.parent      = this.Parent;
     child.propertyKey = propertyKey;
     this.Parent.OnViewNodeAdded(this.Parent, child);
 }
Esempio n. 6
0
 private void OnViewNodeAdded(ViewNode parent, ViewNode child)
 {
     this.manager.OnViewNodeAdded(parent, child);
 }
Esempio n. 7
0
 public override bool AllowPostponedResourceUpdate(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNodePath evaluatedResource)
 {
     return(false);
 }
Esempio n. 8
0
 public void Initialize(IInstanceBuilderContext context, ViewNode viewNode, bool isNewInstance)
 {
 }
Esempio n. 9
0
 public void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
 {
     throw new InvalidOperationException();
 }
Esempio n. 10
0
 public void UpdateChild(IInstanceBuilderContext context, ViewNode viewNode, int childIndex, DocumentNodeChangeAction action, DocumentNode childNode)
 {
     throw new InvalidOperationException();
 }
Esempio n. 11
0
 public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
 {
     InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
 }
        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 static bool ShouldInstantiatePreviewControl(IInstanceBuilderContext context, ViewNode viewNode, out XamlDocument sourceDocument, out string sourcePath)
 {
     sourceDocument = null;
     sourcePath     = null;
     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))
         {
             sourcePath = viewNode.Type.XamlSourcePath;
             if (!string.IsNullOrEmpty(sourcePath))
             {
                 if (context.CurrentlyInstantiatingUserControlPreviews.Contains(sourcePath))
                 {
                     return(false);
                 }
                 try
                 {
                     sourceDocument = (XamlDocument)context.DocumentRootResolver.GetDocumentRoot(sourcePath);
                 }
                 catch (FileNotFoundException fileNotFoundException)
                 {
                 }
                 if (sourceDocument != null && UserControlInstanceBuilderHelper.ShouldUseDocumentForPreview(context, sourceDocument))
                 {
                     return(true);
                 }
             }
         }
     }
     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);
        }
 protected abstract bool IsIncrementalChange(IInstanceBuilderContext context, ViewNode viewNode, IProperty property);
Esempio n. 16
0
 public void OnViewNodeInvalidating(IInstanceBuilderContext context, ViewNode target, ViewNode child, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots)
 {
 }
Esempio n. 17
0
 public bool ShouldTryExpandExpression(IInstanceBuilderContext context, ViewNode viewNode, IPropertyId propertyKey, DocumentNode expressionNode)
 {
     return(false);
 }
        protected virtual void InstantiateChild(IInstanceBuilderContext context, ViewNode dictionaryNode, ViewNode childNode)
        {
            context.ViewNodeManager.Instantiate(childNode);
            DictionaryEntry instance      = (DictionaryEntry)childNode.Instance;
            object          dictionaryKey = this.GetDictionaryKey(childNode.TypeResolver, instance);

            if (dictionaryKey != null)
            {
                this.AddEntry(dictionaryNode, dictionaryKey, instance.Value);
            }
        }
Esempio n. 19
0
 public void UpdateInstance(IInstanceBuilderContext context, ViewNode viewNode)
 {
     throw new InvalidOperationException();
 }
        private static object InstantiateConstructorArgument(IInstanceBuilderContext context, ViewNode viewNode, IParameter constructorArgument, IProperty constructorArgumentProperty, DocumentNode constructorArgumentNode)
        {
            object defaultValue;

            if (constructorArgumentProperty != null)
            {
                return(InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, constructorArgumentProperty, constructorArgumentNode).Instance);
            }
            if (constructorArgumentNode != null)
            {
                ViewNode viewNode1 = InstanceBuilderOperations.UpdateChildWithoutApply(context, viewNode, viewNode.Children.Count, DocumentNodeChangeAction.Add, constructorArgumentNode);
                return(viewNode1.Instance);
            }
            IDocumentContext documentContext = viewNode.DocumentNode.Context;
            Type             targetType      = viewNode.TargetType;
            Type             runtimeType     = constructorArgument.ParameterType.RuntimeType;
            ReferenceStep    referenceStep   = constructorArgumentProperty as ReferenceStep;

            if (referenceStep == null || !referenceStep.HasDefaultValue(targetType))
            {
                bool flag = documentContext.TypeResolver.InTargetAssembly(constructorArgument.ParameterType);
                defaultValue = InstanceBuilderOperations.InstantiateType(runtimeType, flag);
            }
            else
            {
                defaultValue = referenceStep.GetDefaultValue(targetType);
            }
            if (context.IsSerializationScope)
            {
                defaultValue = documentContext.CreateNode(runtimeType, defaultValue);
            }
            return(defaultValue);
        }
Esempio n. 21
0
 public AttachmentOrder GetAttachmentOrder(IInstanceBuilderContext context, ViewNode viewNode)
 {
     return(AttachmentOrder.PostInitialization);
 }
        public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
        {
            IConstructorArgumentNodeCollection constructorArgumentNodeCollections;

            if (viewNode.Instance == null)
            {
                DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode;
                if (documentNode == null)
                {
                    return(base.Instantiate(context, viewNode));
                }
                IType        type            = documentNode.Type;
                IConstructor bestConstructor = documentNode.GetBestConstructor(out constructorArgumentNodeCollections);
                if (bestConstructor == null)
                {
                    CultureInfo currentCulture = CultureInfo.CurrentCulture;
                    string      instanceBuilderCannotInstantiateType = ExceptionStringTable.InstanceBuilderCannotInstantiateType;
                    object[]    name = new object[] { type.Name };
                    throw new InstanceBuilderException(string.Format(currentCulture, instanceBuilderCannotInstantiateType, name), documentNode);
                }
                IConstructorArgumentProperties constructorArgumentProperties = type.GetConstructorArgumentProperties();
                IPropertyId[] propertyIdArray  = new IPropertyId[constructorArgumentNodeCollections.Count];
                IPropertyId[] propertyIdArray1 = propertyIdArray;
                propertyIdArray1 = propertyIdArray;
                if (!context.IsSerializationScope)
                {
                    object[] objArray = new object[constructorArgumentNodeCollections.Count];
                    for (int i = 0; i < constructorArgumentNodeCollections.Count; i++)
                    {
                        IParameter item     = bestConstructor.Parameters[i];
                        IProperty  property = constructorArgumentProperties[item.Name];
                        propertyIdArray1[i] = property;
                        objArray[i]         = MarkupExtensionInstanceBuilderBase.InstantiateConstructorArgument(context, viewNode, item, property, constructorArgumentNodeCollections[i]);
                    }
                    try
                    {
                        viewNode.Instance = bestConstructor.Invoke(objArray);
                    }
                    catch (Exception exception1)
                    {
                        Exception   exception   = exception1;
                        CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                        string      str         = ExceptionStringTable.InstanceBuilderCannotInstantiateType;
                        object[]    name1       = new object[] { type.Name };
                        throw new InstanceBuilderException(string.Format(cultureInfo, str, name1), exception, documentNode);
                    }
                }
                else
                {
                    DocumentNode[] documentNodeArray = new DocumentNode[constructorArgumentNodeCollections.Count];
                    for (int j = 0; j < constructorArgumentNodeCollections.Count; j++)
                    {
                        IParameter parameter = bestConstructor.Parameters[j];
                        IProperty  item1     = constructorArgumentProperties[parameter.Name];
                        propertyIdArray1[j]  = item1;
                        documentNodeArray[j] = (DocumentNode)MarkupExtensionInstanceBuilderBase.InstantiateConstructorArgument(context, viewNode, parameter, item1, constructorArgumentNodeCollections[j]);
                    }
                    type = (IType)type.Clone(context.DocumentContext.TypeResolver);
                    DocumentCompositeNode documentCompositeNode = context.DocumentContext.CreateNode(type);
                    documentCompositeNode.SetConstructor(bestConstructor, documentNodeArray);
                    viewNode.Instance = documentCompositeNode;
                }
                if (viewNode.Instance != null)
                {
                    List <DocumentNode> documentNodes = null;
                    foreach (IProperty property1 in context.GetProperties(viewNode))
                    {
                        if (Array.IndexOf <IPropertyId>(propertyIdArray1, property1) >= 0)
                        {
                            continue;
                        }
                        if (documentNodes == null)
                        {
                            documentNodes = new List <DocumentNode>();
                        }
                        documentNodes.Add(documentNode.Properties[property1]);
                    }
                    if (documentNodes != null)
                    {
                        documentNodes.Sort(MarkupExtensionInstanceBuilderBase.DocumentNodeComparer);
                        foreach (DocumentNode documentNode1 in documentNodes)
                        {
                            this.UpdateProperty(context, viewNode, documentNode1.SitePropertyKey, documentNode1);
                        }
                    }
                }
            }
            viewNode.InstanceState = InstanceState.Valid;
            return(true);
        }
Esempio n. 23
0
        public bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
        {
            DocumentNode          documentNode          = viewNode.DocumentNode;
            DocumentCompositeNode documentCompositeNode = documentNode as DocumentCompositeNode;
            bool flag = false;

            if (!PlatformTypes.FrameworkElement.IsAssignableFrom(viewNode.Type))
            {
                if (documentCompositeNode != null && documentCompositeNode.SupportsChildren && documentCompositeNode.Children.Count > 0)
                {
                    IList listAdapter = InstanceBuilderOperations.GetListAdapter(viewNode.Instance);
                    if (listAdapter != null)
                    {
                        listAdapter.Clear();
                    }
                }
                flag = true;
                viewNode.Instance = null;
            }
            else
            {
                IPlatformMetadata platformMetadata = documentNode.TypeResolver.PlatformMetadata;
                if (!context.IsSerializationScope)
                {
                    try
                    {
                        ViewNode            viewNode1           = viewNode;
                        FallbackControlType fallbackControlType = default(FallbackControlType);
                        viewNode1.Instance = (fallbackControlType == null ? Activator.CreateInstance <FallbackControlType>() : default(FallbackControlType));
                    }
                    catch (Exception exception)
                    {
                        viewNode.Instance = null;
                        flag = true;
                    }
                }
                else
                {
                    DocumentCompositeNode documentCompositeNode1 = context.DocumentContext.CreateNode(typeof(FallbackControlType));
                    ViewNodeId            id = context.SerializationContext.GetId(viewNode);
                    documentCompositeNode1.Properties[DesignTimeProperties.ViewNodeIdProperty] = context.DocumentContext.CreateNode(typeof(string), ViewNodeManager.ViewNodeIdConverter.ConvertToInvariantString(id));
                    viewNode.Instance = documentCompositeNode1;
                }
                if (viewNode.Instance != null && documentCompositeNode != null)
                {
                    if (documentCompositeNode != null)
                    {
                        DocumentNode exceptionSource = context.ExceptionDictionary.GetExceptionSource(viewNode);
                        Type         runtimeType     = documentNode.TypeResolver.ResolveType(PlatformTypes.FrameworkElement).RuntimeType;
                        foreach (IProperty property in context.GetProperties(viewNode))
                        {
                            try
                            {
                                ViewNode viewNode2 = InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, property, documentCompositeNode.Properties[property]);
                                if (viewNode2 != null && viewNode2.Instance != null && viewNode2.DocumentNode != exceptionSource)
                                {
                                    Type          type          = (context.IsSerializationScope ? ((DocumentNode)viewNode2.Instance).TargetType : viewNode2.Instance.GetType());
                                    ReferenceStep referenceStep = property as ReferenceStep;
                                    if (referenceStep != null && referenceStep.TargetType.IsAssignableFrom(runtimeType) && PlatformTypeHelper.GetPropertyType(referenceStep).IsAssignableFrom(type))
                                    {
                                        InstanceBuilderOperations.SetValue(viewNode.Instance, referenceStep, viewNode2.Instance);
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                    IProperty property1 = platformMetadata.ResolveProperty(KnownProperties.FrameworkElementMinWidthProperty);
                    InstanceBuilderOperations.SetValue(viewNode.Instance, property1, FallbackInstanceBuilder <FallbackControlType> .MinSize(context));
                    IProperty property2 = platformMetadata.ResolveProperty(KnownProperties.FrameworkElementMinHeightProperty);
                    InstanceBuilderOperations.SetValue(viewNode.Instance, property2, FallbackInstanceBuilder <FallbackControlType> .MinSize(context));
                }
            }
            if (flag)
            {
                viewNode.Instance = ClrObjectInstanceBuilder.InvalidObjectSentinel;
            }
            viewNode.InstanceState = InstanceState.Valid;
            return(true);
        }
Esempio n. 24
0
 public void ModifyValue(IInstanceBuilderContext context, ViewNode target, object onlyThisInstance, IProperty propertyKey, object value, PropertyModification modification)
 {
 }
Esempio n. 25
0
 public override void OnViewNodeInvalidating(IInstanceBuilderContext context, ViewNode target, ViewNode child, ref bool doesInvalidRootsContainTarget, List <ViewNode> invalidRoots)
 {
     InstanceBuilderOperations.SetInvalid(context, target, ref doesInvalidRootsContainTarget, invalidRoots);
     base.OnViewNodeInvalidating(context, target, child, ref doesInvalidRootsContainTarget, invalidRoots);
 }
Esempio n. 26
0
 public void OnChildRemoving(IInstanceBuilderContext context, ViewNode parent, ViewNode child)
 {
 }
Esempio n. 27
0
 public ViewNodeCollectionBase(ViewNode parent)
 {
     this.Parent = parent;
 }
Esempio n. 28
0
 public void OnDescendantUpdated(IInstanceBuilderContext context, ViewNode viewNode, ViewNode child, InstanceState childState)
 {
 }
Esempio n. 29
0
 protected void PreRemoveInternal(ViewNode child)
 {
     this.Parent.OnViewNodeRemoving(this.Parent, child);
     child.Dispose();
 }
Esempio n. 30
0
 public void OnInitialized(IInstanceBuilderContext context, ViewNode target, object instance)
 {
 }