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);
        }
Exemple #2
0
        public DataSourceMatchCriteria CompareSources(DataSourceInfo other)
        {
            if (this == other)
            {
                return(DataSourceMatchCriteria.Exact);
            }
            if (this.Category == DataSourceCategory.Invalid || this.Category != other.Category || !DesignDataHelper.CompareDataSources(this.SourceNode, other.SourceNode))
            {
                return(DataSourceMatchCriteria.Ignore);
            }
            DataSourceMatchCriteria sourceMatchCriteria = DataSourceMatchCriteria.Ignore;

            if (this.Category == DataSourceCategory.Clr)
            {
                sourceMatchCriteria = DataSourceInfo.CompareClrPaths(this.Path, other.Path);
            }
            else if (this.Category == DataSourceCategory.Xml)
            {
                sourceMatchCriteria = DataSourceInfo.CompareXmlPaths(XmlSchema.NormalizeXPath(this.Path), XmlSchema.NormalizeXPath(other.Path));
            }
            return(sourceMatchCriteria);
        }
        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);
        }