public static DesignDataMode GetDesignDataMode(IProject project, string path)
 {
     if (project == null || string.IsNullOrEmpty(path))
     {
         return(DesignDataMode.None);
     }
     return(DocumentContextHelper.GetDesignDataMode(project.FindItem(DocumentReference.Create(path))));
 }
        public static DocumentContext CreateDocumentContext(IProject project, IProjectContext projectContext, IDocumentLocator documentLocator, bool isLooseXaml)
        {
            string path = documentLocator != null ? documentLocator.Path : (string)null;

            if (DocumentContextHelper.GetDesignDataMode(project, path) == DesignDataMode.Reflectable && !(projectContext is TypeReflectingProjectContext))
            {
                projectContext = (IProjectContext) new TypeReflectingProjectContext(projectContext);
            }
            return(new DocumentContext(projectContext, documentLocator, isLooseXaml));
        }
        public static DocumentNode GetParsedOrSniffedRootNode(IProjectItem projectItem, IProjectContext projectContext)
        {
            if (projectItem.Document != null)
            {
                SceneDocument sceneDocument = projectItem.Document as SceneDocument;
                if (sceneDocument != null && sceneDocument.DocumentRoot != null)
                {
                    return(sceneDocument.DocumentRoot.RootNode);
                }
            }
            DocumentContext documentContext = DocumentContextHelper.CreateDocumentContext((IProject)projectContext.GetService(typeof(IProject)), projectContext, DocumentReferenceLocator.GetDocumentLocator(projectItem.DocumentReference));
            IType           type            = DocumentContextHelper.SniffRootNodeType(projectItem, documentContext);

            if (type != null && type.RuntimeType != (Type)null)
            {
                return((DocumentNode)documentContext.CreateNode((ITypeId)type));
            }
            return((DocumentNode)null);
        }
示例#4
0
        internal SceneDocument CreateDocument(IProject project, IProjectItem projectItem, ITextBuffer textBuffer, bool isReadOnly, Encoding encoding)
        {
            IProjectContext   projectContext    = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
            DocumentReference documentReference = projectItem.DocumentReference;
            DocumentContext   documentContext   = DocumentContextHelper.CreateDocumentContext(project, projectContext, DocumentReferenceLocator.GetDocumentLocator(documentReference), projectItem.Properties["BuildAction"] == "Content");
            SceneXamlDocument xamlDocument      = new SceneXamlDocument((IDocumentContext)documentContext, (IUndoService) new UndoService(), PlatformTypes.Object, textBuffer, encoding);

            if (xamlDocument.ParseErrorsCount > 0)
            {
                IErrorService errorManager = this.designerContext.ErrorManager;
                if (errorManager != null)
                {
                    errorManager.DisplayErrors();
                }
            }
            SceneDocument sceneDocument = this.CreateSceneDocument(documentReference, xamlDocument, isReadOnly, this.designerContext);

            documentContext.DocumentLocator = (IDocumentLocator)sceneDocument;
            return(sceneDocument);
        }
 public static DocumentContext CreateDocumentContext(IProject project, IProjectContext projectContext, IDocumentLocator documentLocator)
 {
     return(DocumentContextHelper.CreateDocumentContext(project, projectContext, documentLocator, false));
 }