private SceneNode CreateDataSource(SceneNode target, DataSchemaNodePath bindingPath, bool isSourcePathLess) { DocumentNode resourceKey = bindingPath.Schema.DataSource.ResourceKey; if (resourceKey == null) { if (!isSourcePathLess && !string.IsNullOrEmpty(bindingPath.Path)) { return((SceneNode)null); } DocumentNode documentNode = bindingPath.Schema.DataSource.DocumentNode; IProjectItem designDataFile = DesignDataHelper.GetDesignDataFile(documentNode); DocumentNode node; if (designDataFile != null) { node = DesignDataHelper.CreateDesignDataExtension(designDataFile, target.DocumentContext); } else { if (PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)bindingPath.Schema.DataSource.DocumentNode.Type)) { return((SceneNode)null); } node = documentNode.Clone(target.DocumentContext); } return(target.ViewModel.GetSceneNode(node)); } if (!this.EnsureDataSourceReachable(target, bindingPath.Schema.DataSource)) { return((SceneNode)null); } BindingSceneNode bindingSceneNode = BindingSceneNode.Factory.Instantiate(target.ViewModel); DocumentNode keyNode = resourceKey.Clone(target.DocumentContext); bindingSceneNode.Source = (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(keyNode.Context, keyNode); return((SceneNode)bindingSceneNode); }
public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { bool flag = viewNode.Instance != null; base.Instantiate(context, viewNode); if (flag) { return(false); } SampleDataSet sampleDataSet = SampleDataSet.SampleDataSetFromType(viewNode.DocumentNode.Type.RuntimeType); if (sampleDataSet == null) { return(!flag); } DocumentCompositeNode documentCompositeNode = sampleDataSet != null ? sampleDataSet.ValidRootNodeFromXamlDocument : (DocumentCompositeNode)null; if (documentCompositeNode == null || !PlatformTypes.PlatformsCompatible((IPlatformMetadata)context.Platform.Metadata, documentCompositeNode.PlatformMetadata) || (this.IsSampleDataXamlContext(context, documentCompositeNode.DocumentRoot) || DesignDataHelper.GetDesignDataFile(viewNode.DocumentNode) != null)) { return(!flag); } using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(context.DocumentContext, context)) { using (instanceBuilderContext.ChangeSerializationContext(context.SerializationContext)) { ViewNode viewNode1 = this.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, (DocumentNode)documentCompositeNode); viewNode1.Instance = viewNode.Instance; this.Initialize((IInstanceBuilderContext)instanceBuilderContext, viewNode1, true); viewNode1.Instance = (object)null; viewNode.InstanceState = InstanceState.Valid; } } context.DocumentRootResolver.GetDocumentRoot(documentCompositeNode.DocumentRoot.DocumentContext.DocumentUrl); IProperty index = context.DocumentContext.TypeResolver.ResolveProperty(DesignTimeProperties.SampleDataTagProperty); ViewNode referenceSource = new ViewNode(context.ViewNodeManager, (DocumentNode)documentCompositeNode); viewNode.Properties[index] = referenceSource; context.ViewNodeManager.AddRelatedDocumentRoot(referenceSource, documentCompositeNode.DocumentRoot); return(!flag); }
public ISchema GetSchemaForDataSourceInternal(DocumentNode dataSource, out string errorMessage) { errorMessage = string.Empty; ISchema schema = (ISchema)null; IProjectItem designDataFile = DesignDataHelper.GetDesignDataFile(dataSource); if (designDataFile != null) { return(this.GetSchemaForDesignDataFile(designDataFile)); } if (this.schemaCache.TryGetValue(dataSource, out schema)) { ClrObjectSchema clrObjectSchema = schema as ClrObjectSchema; if (clrObjectSchema != null && clrObjectSchema.Root.Type != DataContextHelper.GetDataType(clrObjectSchema.DataSource.DocumentNode).RuntimeType) { this.schemaCache.Remove(dataSource); schema = (ISchema)null; } if (schema != null) { return(schema); } } if (dataSource != null) { if (PlatformTypes.XmlDataProvider.IsAssignableFrom((ITypeId)dataSource.Type)) { Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema xmlSchema = (Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema)null; try { Uri uriPropertyValue1 = this.GetUriPropertyValue(dataSource, DesignTimeProperties.SchemaUriProperty); if (uriPropertyValue1 != (Uri)null) { xmlSchema = this.GetXmlSchemaFromSchemaFile(uriPropertyValue1, dataSource, out errorMessage); } else { Uri uriPropertyValue2 = this.GetUriPropertyValue(dataSource, XmlDataProviderSceneNode.SourceProperty); if (uriPropertyValue2 != (Uri)null) { using (XmlReader xmlReader = XmlReader.Create(uriPropertyValue2.AbsoluteUri)) xmlSchema = this.InferXmlSchemaFromXmlFile(xmlReader, dataSource, out errorMessage); } else { string inlineXmlData = this.GetInlineXmlData(dataSource); if (inlineXmlData != null) { using (StringReader stringReader = new StringReader(inlineXmlData)) { using (XmlReader xmlReader = XmlReader.Create((TextReader)stringReader)) xmlSchema = this.InferXmlSchemaFromXmlFile(xmlReader, dataSource, out errorMessage); } } } } } catch { } if (xmlSchema == null) { xmlSchema = new Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema(dataSource); } schema = (ISchema)xmlSchema; } else { schema = SchemaManager.GetSchemaForType(this.GetTypeForDataSource(dataSource), dataSource); } } if (schema == null) { schema = (ISchema) new EmptySchema(); } if (dataSource.DocumentRoot != null) { this.schemaCache[dataSource] = schema; } return(schema); }