Пример #1
0
        private void AddProjectContextHandlers(IProjectContext projectContext)
        {
            if (this.watchedProjectContexts.Contains(projectContext))
            {
                return;
            }
            this.watchedProjectContexts.Add(projectContext);
            projectContext.DocumentClosing += new EventHandler <ProjectDocumentEventArgs>(this.OnProjectContextDocumentClosedEarly);
            projectContext.DocumentClosed  += new EventHandler <ProjectDocumentEventArgs>(this.OnProjectContextDocumentClosedLate);
            projectContext.DocumentOpened  += new EventHandler <ProjectDocumentEventArgs>(this.OnProjectContextDocumentOpened);
            INotifyCollectionChanged collectionChanged = projectContext.Documents as INotifyCollectionChanged;

            if (collectionChanged != null)
            {
                collectionChanged.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnProjectContextDocumentsCollectionChanged);
            }
            INotifyCollectionChanges collectionChanges = projectContext.AssemblyReferences as INotifyCollectionChanges;

            if (collectionChanges != null)
            {
                collectionChanges.CollectionChanging += new NotifyCollectionChangedEventHandler(this.AssemblyCollection_CollectionChanging);
            }
            IProject project = (IProject)projectContext.GetService(typeof(IProject));

            if (project == null)
            {
                return;
            }
            project.ItemAdded   += new EventHandler <ProjectItemEventArgs>(this.Project_ItemAdded);
            project.ItemRemoved += new EventHandler <ProjectItemEventArgs>(this.Project_ItemRemoved);
        }
Пример #2
0
 public static ProjectContext GetProjectContext(IProjectContext projectContext)
 {
     if (projectContext == null)
     {
         return(null);
     }
     return((ProjectContext)projectContext.GetService(typeof(ProjectContext)));
 }
Пример #3
0
 private static bool IsDisposingOrDisposed(IProjectContext projectContext)
 {
     if (projectContext != null)
     {
         return(ProjectBase.IsDisposingOrDisposed((IProject)projectContext.GetService(typeof(IProject))));
     }
     return(false);
 }
Пример #4
0
        public static IProjectItem CreateDesignDataFile(Type type, string dataSourceName, IProjectContext projectContext, bool isDesignTimeCreatable)
        {
            string path1   = Path.Combine(Path.GetDirectoryName(projectContext.ProjectPath), DataSetContext.SampleData.DataRootFolder);
            string str     = dataSourceName ?? type.Name;
            string path2_1 = str + ".xaml";
            string path2   = Path.Combine(path1, path2_1);
            int    num     = 1;

            while (File.Exists(path2))
            {
                string path2_2 = str + num.ToString((IFormatProvider)CultureInfo.InvariantCulture) + ".xaml";
                path2 = Path.Combine(path1, path2_2);
                ++num;
            }
            string          path3           = Path.GetTempFileName() + ".xaml";
            IProjectContext projectContext1 = projectContext;

            if (!isDesignTimeCreatable)
            {
                projectContext1 = (IProjectContext)(projectContext as TypeReflectingProjectContext) ?? (IProjectContext) new TypeReflectingProjectContext(projectContext);
            }
            DocumentContext documentContext = new DocumentContext(projectContext1, (IDocumentLocator) new DocumentLocator(path2), false);
            IType           type1           = documentContext.TypeResolver.GetType(type);
            DocumentNode    node            = new DesignDataGenerator(type1, (IDocumentContext)documentContext).Build();

            try
            {
                using (StreamWriter text = File.CreateText(path3))
                {
                    using (XamlDocument xamlDocument = new XamlDocument((IDocumentContext)documentContext, (ITypeId)type1, (ITextBuffer) new SimpleTextBuffer(), DocumentEncodingHelper.DefaultEncoding, (IXamlSerializerFilter) new DefaultXamlSerializerFilter()))
                        new XamlSerializer((IDocumentRoot)xamlDocument, (IXamlSerializerFilter) new DefaultXamlSerializerFilter()).Serialize(node, (TextWriter)text);
                }
                BuildTaskInfo        buildTaskInfo = new BuildTaskInfo(DocumentContextHelper.DesignDataBuildTask, (IDictionary <string, string>) new Dictionary <string, string>());
                DocumentCreationInfo creationInfo  = new DocumentCreationInfo()
                {
                    BuildTaskInfo   = buildTaskInfo,
                    TargetFolder    = path1,
                    TargetPath      = path2,
                    SourcePath      = path3,
                    CreationOptions = CreationOptions.SilentlyOverwrite | CreationOptions.SilentlyOverwriteReadOnly | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath
                };
                return(((IProject)projectContext.GetService(typeof(IProject))).AddItem(creationInfo));
            }
            finally
            {
                try
                {
                    File.Delete(path3);
                }
                catch
                {
                }
            }
        }
Пример #5
0
        public static bool RemoveDesignData(IProjectItem designDataFile, IProjectContext projectContext, IExpressionInformationService service)
        {
            IProject project = (IProject)projectContext.GetService(typeof(IProject));
            string   path    = designDataFile.DocumentReference.Path;

            if (!project.RemoveItems(1 != 0, designDataFile))
            {
                return(false);
            }
            new DesignDataRemovalProcessor((IAsyncMechanism) new CurrentDispatcherAsyncMechanism(DispatcherPriority.Background), path, projectContext, ChangeProcessingModes.CollectChanges | ChangeProcessingModes.ApplyChanges).Process(service);
            return(true);
        }
Пример #6
0
        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);
        }