Пример #1
0
        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);
        }
Пример #2
0
 public static IDocumentRoot GetSourceXamlDocument(DocumentCompositeNode designDataNode)
 {
     return(DesignDataInstanceBuilder.GetSourceXamlDocumentInternal(designDataNode, DesignDataInstanceBuilder.GetSourceFilePath(designDataNode)));
 }