private static object CreateXmlDataContext(DataSourceInfo dataSource, SceneViewModel viewModel) { DocumentNode sourceNode = dataSource.SourceNode; object obj = (object)null; using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(viewModel.Document.DocumentContext, viewModel.DesignerContext)) { try { IInstanceBuilder builder = instanceBuilderContext.InstanceBuilderFactory.GetBuilder(sourceNode.TargetType); ViewNode viewNode = builder.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, sourceNode); obj = (object)(bool)(builder.Instantiate((IInstanceBuilderContext)instanceBuilderContext, viewNode) ? true : false); } catch { } } ReferenceStep referenceStep = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(XmlDataProviderSceneNode.XPathProperty); string inheritedXPath = referenceStep.GetValue(obj) as string; if (string.IsNullOrEmpty(inheritedXPath)) { inheritedXPath = dataSource.Path; } else if (!string.IsNullOrEmpty(dataSource.Path)) { inheritedXPath = XmlSchema.CombineXPaths(inheritedXPath, dataSource.Path); } if (!string.IsNullOrEmpty(inheritedXPath)) { referenceStep.SetValue(obj, (object)inheritedXPath); } return(obj); }
public override void Initialize(IInstanceBuilderContext context, ViewNode viewNode, bool isNewInstance) { if (context.IsSerializationScope || viewNode.Instance == null || viewNode.InstanceState != InstanceState.Uninitialized) { base.Initialize(context, viewNode, isNewInstance); return; } DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode; DocumentCompositeNode documentCompositeNode = documentNode; if (documentNode != null) { this.InstantiateProperties(context, viewNode, documentCompositeNode); if (documentCompositeNode.SupportsChildren) { for (int i = 0; i < documentCompositeNode.Children.Count; i++) { DocumentNode item = documentCompositeNode.Children[i]; IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(item.TargetType); ViewNode viewNode1 = builder.GetViewNode(context, item); viewNode.Children.Add(viewNode1); this.InstantiateChild(context, viewNode, viewNode1); } } } viewNode.InstanceState = InstanceState.Valid; this.OnInitialized(context, viewNode, viewNode.Instance); }
public static ViewNode UpdateChildWithoutApply(IInstanceBuilderContext context, ViewNode viewNode, int childIndex, DocumentNodeChangeAction action, DocumentNode childNode) { ViewNode viewNode1 = null; if (action == DocumentNodeChangeAction.Remove) { ViewNode item = viewNode.Children[childIndex]; viewNode.Children.Remove(item); } if (action == DocumentNodeChangeAction.Add || action == DocumentNodeChangeAction.Replace) { IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(childNode.TargetType); viewNode1 = builder.GetViewNode(context, childNode); if (action != DocumentNodeChangeAction.Replace) { viewNode.Children.Insert(childIndex, viewNode1); } else { viewNode.Children[childIndex] = viewNode1; } context.ViewNodeManager.Instantiate(viewNode1); } return(viewNode1); }
public static ViewNode UpdatePropertyWithoutApply(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) { ViewNode item = viewNode.Properties[propertyKey]; ViewNode viewNode1 = null; if (item != null) { viewNode.Properties[propertyKey] = null; } if (valueNode != null) { IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(valueNode.TargetType); viewNode1 = builder.GetViewNode(context, valueNode); viewNode.Properties[propertyKey] = viewNode1; context.ViewNodeManager.Instantiate(viewNode1); } return(viewNode1); }
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 object CreateClrDataContext(DataSourceInfo dataSource, SceneViewModel viewModel) { DocumentNode sourceNode = dataSource.SourceNode; if (PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)sourceNode.Type)) { return((object)null); } object obj1 = (object)null; using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(viewModel.Document.DocumentContext, viewModel.DesignerContext)) { try { IInstanceBuilder builder = instanceBuilderContext.InstanceBuilderFactory.GetBuilder(sourceNode.TargetType); ViewNode viewNode = builder.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, sourceNode); if (builder.Instantiate((IInstanceBuilderContext)instanceBuilderContext, viewNode)) { obj1 = DataContextEvaluator.GetEvaluatedValue(viewNode.Instance); } } catch { } } if (obj1 == null || string.IsNullOrEmpty(dataSource.Path)) { return(obj1); } object instance = obj1; try { IList <ClrPathPart> list1 = ClrPropertyPathHelper.SplitPath(dataSource.Path); if (list1 == null) { return((object)null); } for (int index = 0; index < list1.Count; ++index) { if (instance != null) { Type type = instance.GetType(); object obj2 = (object)null; ClrPathPart clrPathPart = list1[index]; if (clrPathPart.Category == ClrPathPartCategory.PropertyName) { PropertyInfo property = type.GetProperty(clrPathPart.Path); if (property != (PropertyInfo)null) { obj2 = property.GetValue(instance, (object[])null); } } else { CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type); if (adapterDescription != null) { IList list2 = adapterDescription.GetCollectionAdapter(instance) as IList; if (list2 != null) { int result = 0; if (clrPathPart.Category == ClrPathPartCategory.IndexStep) { if (!int.TryParse(clrPathPart.Path.Trim('[', ']'), out result)) { goto label_23; } } obj2 = list2[result]; } } } label_23: instance = obj2; } else { break; } } } catch { instance = (object)null; } return(instance); }
public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { string str; DocumentNode rootNode; if (viewNode.Instance == null) { DesignDataExtension instance = null; using (IDisposable disposable = context.ChangeSerializationContext(null)) { base.Instantiate(context, viewNode); instance = viewNode.Instance as DesignDataExtension; } instance.Instance = null; if (instance.Source != null) { DocumentCompositeNode documentNode = (DocumentCompositeNode)viewNode.DocumentNode; string sourceFilePath = DesignDataInstanceBuilder.GetSourceFilePath(documentNode); IDocumentRoot sourceXamlDocumentInternal = DesignDataInstanceBuilder.GetSourceXamlDocumentInternal(documentNode, sourceFilePath); if (sourceXamlDocumentInternal == null && sourceFilePath != null) { if (!File.Exists(sourceFilePath)) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; string designDataNotFound = ExceptionStringTable.DesignDataNotFound; object[] objArray = new object[] { sourceFilePath }; str = string.Format(invariantCulture, designDataNotFound, objArray); } else { CultureInfo cultureInfo = CultureInfo.InvariantCulture; string designDataHasErrors = ExceptionStringTable.DesignDataHasErrors; object[] objArray1 = new object[] { sourceFilePath }; str = string.Format(cultureInfo, designDataHasErrors, objArray1); } context.WarningDictionary.SetWarning(viewNode, documentNode, str); } if (sourceXamlDocumentInternal != null) { rootNode = sourceXamlDocumentInternal.RootNode; } else { rootNode = null; } DocumentNode documentNode1 = rootNode; if (documentNode1 != null) { context.DocumentRootResolver.GetDocumentRoot(documentNode1.DocumentRoot.DocumentContext.DocumentUrl); context.ViewNodeManager.AddRelatedDocumentRoot(viewNode, documentNode1.DocumentRoot); IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(documentNode1.TargetType); ViewNode viewNode1 = builder.GetViewNode(context, documentNode1); try { builder.Initialize(context, viewNode1, builder.Instantiate(context, viewNode1)); instance.Instance = viewNode1.Instance; } catch (Exception exception) { instance.Instance = null; CultureInfo invariantCulture1 = CultureInfo.InvariantCulture; string designDataHasErrors1 = ExceptionStringTable.DesignDataHasErrors; object[] objArray2 = new object[] { sourceFilePath }; string str1 = string.Format(invariantCulture1, designDataHasErrors1, objArray2); context.WarningDictionary.SetWarning(viewNode, documentNode, str1); } if (context.IsSerializationScope) { viewNode.Instance = instance.Instance; viewNode.InstanceState = InstanceState.Valid; } else { viewNode.Instance = instance; viewNode.InstanceState = InstanceState.Valid; } } } if (viewNode.Instance == instance && instance.Instance == null) { viewNode.Instance = null; viewNode.InstanceState = InstanceState.Valid; } } return(viewNode.Instance != null); }