This class represent a project item (usualy a file) and allow getting and setting attribute on it. This class allow us to keep the internal details of our items hidden from our derived classes. While the class itself is public so it can be manipulated by derived classes, its internal constructors make sure it can only be created from within the assembly.
Example #1
0
        public NemerleFileNode(ProjectNode root, ProjectElement element, bool isNonMemberItem)
            : base(root, element)
        {
            IsNonMemberItem = isNonMemberItem;

            _selectionChangedListener =
                    new SelectionElementValueChangedListener(
                            new ServiceProvider((IOleServiceProvider)root.GetService(typeof(IOleServiceProvider))), root);

            _selectionChangedListener.Init();

            //((FileNodeProperties)NodeProperties).OnCustomToolChanged		  += OnCustomToolChanged;
            //((FileNodeProperties)NodeProperties).OnCustomToolNameSpaceChanged += OnCustomToolNameSpaceChanged;

            // HasDesigner property is not virtual, so we have to set it up in the ctor.
            InferHasDesignerFromSubType();

            var url = this.Url;
            var ext = Path.GetExtension(url);

            //if (ext.Equals(".resx", StringComparison.InvariantCultureIgnoreCase))
            //{
            //  // TODO: ”далить это дело, так как теперь оповещени¤ должны быть реализованы в Engine.
            //  url = Path.GetFullPath(this.Url);
            //  var path = Path.GetDirectoryName(url);
            //  var name = Path.GetFileName(url);
            //  _watcher = new FileSystemWatcher(path, name);
            //  _watcher.NotifyFilter = NotifyFilters.LastWrite;
            //  _watcher.Changed += watcher_Changed;
            //  _watcher.EnableRaisingEvents = true;
            //}
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XSharpFileNode"/> class.
 /// </summary>
 /// <param name="root">The project node.</param>
 /// <param name="e">The project element node.</param>
 internal XSharpFileNode(ProjectNode root, ProjectElement e)
     : base(root, e)
 {
     //
     this.UpdateHasDesigner();
     this.UpdateItemType();
 }
Example #3
0
 public BooFileNode(ProjectNode root, ProjectElement e)
     : base(root, e)
 {
     results = new CompileResults(() => Url, GetCompilerInput, ()=>GlobalServices.LanguageService.GetLanguagePreferences().TabSize);
     languageService = (BooLanguageService)GetService(typeof(BooLanguageService));
     hidden = true;
 }
        /// <summary>
        /// Creates an assembly reference node from a project element.
        /// </summary>
        /// <returns>An assembly reference node</returns>
        protected override AssemblyReferenceNode CreateAssemblyReferenceNode(ProjectElement element)
        {
            SandcastleBuilderAssemblyReferenceNode node = null;

            try
            {
                node = new SandcastleBuilderAssemblyReferenceNode(this.ProjectMgr, element);
            }
            catch(ArgumentNullException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(FileNotFoundException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(BadImageFormatException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(FileLoadException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(System.Security.SecurityException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }

            return node;
        }
        /// <summary>
        /// Creates a file reference from the project configuration data.
        /// </summary>
        /// <param name="element">Project configuration element</param>
        /// <returns>Application reference node</returns>
        protected ApplicationReferenceNode CreateApplicationReferenceNode(ProjectElement element)
        {
            try
            {
                return new ApplicationReferenceNode( this.ProjectMgr, element );
            }
            catch(ArgumentNullException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(FileNotFoundException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(BadImageFormatException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(FileLoadException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            catch(System.Security.SecurityException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }

            return null;
        }
        public ProjectReferenceNode(ProjectNode root, ProjectElement element)
            : base(root, element)
        {
            this.referencedProjectRelativePath = this.ItemNode.GetMetadata(ProjectFileConstants.Include);
            Debug.Assert(!String.IsNullOrEmpty(this.referencedProjectRelativePath), "Could not retrive referenced project path form project file");

            string guidString = this.ItemNode.GetMetadata(ProjectFileConstants.Project);

            // Continue even if project setttings cannot be read.
            try
            {
                this.referencedProjectGuid = new Guid(guidString);

                this.buildDependency = new BuildDependency(this.ProjectMgr, this.referencedProjectGuid);
                this.ProjectMgr.AddBuildDependency(this.buildDependency);
            }
            finally
            {
                Debug.Assert(this.referencedProjectGuid != Guid.Empty, "Could not retrive referenced project guidproject file");

                this.referencedProjectName = this.ItemNode.GetMetadata(ProjectFileConstants.Name);

                Debug.Assert(!String.IsNullOrEmpty(this.referencedProjectName), "Could not retrive referenced project name form project file");
            }

            Uri uri = new Uri(this.ProjectMgr.BaseURI.Uri, this.referencedProjectRelativePath);

            if(uri != null)
            {
                this.referencedProjectFullPath = Microsoft.VisualStudio.Shell.Url.Unescape(uri.LocalPath, true);
            }
        }
Example #7
0
 public BaseSearchPathNode(CommonProjectNode project, string path, ProjectElement element)
     : base(project, path, element)
 {
     _project = project;
     this.VirtualNodeName = path;
     this.ExcludeNodeFromScc = true;
 }
Example #8
0
        public NemerleFolderNode(ProjectNode root, string directoryPath, ProjectElement element, bool isNonMemberItem)
            : base(root, directoryPath, element)
        {
            IsNonMemberItem = isNonMemberItem;

            // Folders do not participate in SCC.
            ExcludeNodeFromScc = true;
        }
Example #9
0
 /// <summary>
 /// Constructor for the FileNode
 /// </summary>
 /// <param name="root">Root of the hierarchy</param>
 /// <param name="e">Associated project element</param>
 public FileNode(ProjectNode root, ProjectElement element)
     : base(root, element)
 {
     if(this.ProjectMgr.NodeHasDesigner(this.ItemNode.GetMetadata(ProjectFileConstants.Include)))
     {
         this.HasDesigner = true;
     }
 }
 /// <summary>
 /// Create a folder node based on absolute folder path.
 /// </summary>
 public new virtual FolderNode CreateFolderNode(string absFolderPath)
 {
     //This code builds folder node in such a way that it won't be added to the
     //project as build item and the project won't be go dirty.
     var prjItem = GetExistingItem(absFolderPath) ?? BuildProject.AddItem("None", absFolderPath)[0];
     ProjectElement prjElem = new ProjectElement(this, prjItem, false);
     return new CommonFolderNode(this, absFolderPath, prjElem);
 }
Example #11
0
        public JarReferenceNode(ProjectNode root, ProjectElement element)
            : base(root, element)
        {
            Contract.Requires<ArgumentNullException>(root != null, "root");
            Contract.Requires<ArgumentNullException>(element != null, "element");

            _projectRelativeFilePath = element.Item.EvaluatedInclude;
            ProjectManager.ItemIdMap.UpdateCanonicalName(this);
        }
Example #12
0
        /// <summary>
        /// Constructor for IVSOutput2 implementation
        /// </summary>
        /// <param name="projectManager">Project that produce this output</param>
        /// <param name="outputAssembly">MSBuild generated item corresponding to the output assembly (by default, these would be of type MainAssembly</param>
        public Output(ProjectNode projectManager, ProjectElement outputAssembly)
        {
            if(projectManager == null)
                throw new ArgumentNullException("projectManager");
            if(outputAssembly == null)
                throw new ArgumentNullException("outputAssembly");

            project = projectManager;
            output = outputAssembly;
        }
Example #13
0
        /// <summary>
        /// Constructor for the FolderNode
        /// </summary>
        /// <param name="root">Root node of the hierarchy</param>
        /// <param name="relativePath">relative path from root i.e.: "NewFolder1\\NewFolder2\\NewFolder3</param>
        /// <param name="element">Associated project element</param>
        public FolderNode(ProjectNode root, string relativePath, ProjectElement element)
            : base(root, element)
        {
            if (relativePath == null)
            {
                throw new ArgumentNullException("relativePath");
            }

            this.VirtualNodeName = relativePath.TrimEnd('\\');
        }
Example #14
0
        public override FileNode CreateFileNode(ProjectElement item)
        {
            var node = new Mac65ProjectFileNode(this, item);

            node.OleServiceProvider.AddService(typeof(EnvDTE.Project), new OleServiceProvider.ServiceCreatorCallback(CreateServices), false);
            node.OleServiceProvider.AddService(typeof(ProjectItem), node.ServiceCreator, false);
            node.OleServiceProvider.AddService(typeof(VSProject), new OleServiceProvider.ServiceCreatorCallback(CreateServices), false);

            return node;
        }
Example #15
0
        public JarReferenceNode(ProjectNode root, ProjectElement element)
            : base(root, element)
        {
            if (root == null)
                throw new ArgumentNullException("root");
            if (element == null)
                throw new ArgumentNullException("element");

            _projectRelativeFilePath = element.Item.EvaluatedInclude;
            ProjectManager.ItemIdMap.UpdateCanonicalName(this);
        }
        public override FileNode CreateFileNode(ProjectElement item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var newNode = new ProjectionFileNode(this, item);

            return newNode;
        }
Example #17
0
        /// <summary>
        /// Constructor for the ReferenceNode
        /// </summary>
        public AssemblyReferenceNode(ProjectNode root, ProjectElement element)
            : base(root, element)
        {
            this.GetPathNameFromProjectFile();

            this.InitializeFileChangeEvents();

            string include = this.ItemNode.GetMetadata(ProjectFileConstants.Include);

            this.CreateFromAssemblyName(new System.Reflection.AssemblyName(include));
        }
Example #18
0
        public AssembleFileNode(ProjectNode root, ProjectElement e)
            :       base(root, e)
        {
            ExcludeNodeFromScc = true;

            // Give it a guid if it does not already have one.

            if (string.IsNullOrEmpty(ItemNode.GetMetadata(Constants.Project.Item.Assemble.Guid.Name)))
            {
                ItemNode.SetMetadata(Constants.Project.Item.Assemble.Guid.Name, System.Guid.NewGuid().ToString("B"));
            }
        }
Example #19
0
        public JavaFolderNode(ProjectNode root, string relativePath, ProjectElement element)
            : base(root, relativePath, element)
        {
            Contract.Requires(root != null);
            Contract.Requires(relativePath != null);
            Contract.Requires(element != null);

            if (element.IsVirtual)
            {
                string buildAction = element.GetMetadata(ProjectFileConstants.BuildAction);
                if (buildAction == ProjectFileConstants.Folder)
                    this.IsNonmemberItem = false;
            }
        }
Example #20
0
        /// <summary>
        /// Constructor for the ComReferenceNode. 
        /// </summary>
        public ComReferenceNode(ProjectNode root, ProjectElement element)
            : base(root, element)
        {
            this.typeName = this.ItemNode.GetMetadata(ProjectFileConstants.Include);
            string typeGuidAsString = this.ItemNode.GetMetadata(ProjectFileConstants.Guid);
            if(typeGuidAsString != null)
            {
                this.typeGuid = new Guid(typeGuidAsString);
            }

            this.majorVersionNumber = this.ItemNode.GetMetadata(ProjectFileConstants.VersionMajor);
            this.minorVersionNumber = this.ItemNode.GetMetadata(ProjectFileConstants.VersionMinor);
            this.lcid = this.ItemNode.GetMetadata(ProjectFileConstants.Lcid);
            this.SetProjectItemsThatRelyOnReferencesToBeResolved(false);
            this.SetInstalledFilePath();
        }
        protected override ReferenceNode CreateReferenceNode(string referenceType, ProjectElement element)
        {
            switch (referenceType)
            {
            case ProjectFileConstants.ProjectReference:
                return CreateProjectReferenceNode(element);

            case JavaProjectFileConstants.JarReference:
                return CreateJarReferenceNode(element);

            case JavaProjectFileConstants.MavenReference:
                return CreateMavenReferenceNode(element);

            default:
                return null;
            }
        }
Example #22
0
        public DartFolderNode(ProjectNode root, string relativePath, ProjectElement element)
            : base(root, relativePath, element)
        {
            if (root == null)
                throw new ArgumentNullException("root");
            if (relativePath == null)
                throw new ArgumentNullException("relativePath");
            if (element == null)
                throw new ArgumentNullException("element");

            if (element.IsVirtual)
            {
                string buildAction = element.GetMetadata(ProjectFileConstants.BuildAction);
                if (buildAction == ProjectFileConstants.Folder)
                    this.IsNonmemberItem = false;
            }
        }
Example #23
0
        public SimResultsNode(BlenXProjectNode root, ProjectElement element)
            : base(root, element)
        {
            simResultsFileName = root.ProjectFolder + Path.DirectorySeparatorChar + "Results.sim";
            package = root.BlenXPackage;
            bool simFilePresent = false;
            if (File.Exists(simResultsFileName))
            {
                try
                {
                    simResults = BetaSimResults.LoadFromFile(simResultsFileName);
                    if (simResults != null)
                        simFilePresent = true;
                }
                catch
                {
                    simFilePresent = false;
                }
            }
            if (!simFilePresent)
            {
                // create a new, empty one
                simResults = new BetaSimResults();
                BetaSimResults.SaveToFile(simResultsFileName, simResults);
            }

            Debug.Assert(simResults != null);

            // Refresh window
            var window = package.FindToolWindow(typeof(BetaSimToolWindow), 0, true) as BetaSimToolWindow;
            if (window != null)
            {
                // Add
                window.Update(simResults.ResultList);
            }
        }
        /// <summary>
        /// Links a reference node to the project and hierarchy.
        /// </summary>
        protected override void BindReferenceData()
        {
            Debug.Assert(AssemblyName != null, "The AssemblyName field has not been initialized");

            // If the item has not been set correctly like in case of a new reference added it now.
            // The constructor for the AssemblyReference node will create a default project item. In that case the Item is null.
            // We need to specify here the correct project element.
            if (ItemNode == null || ItemNode.Item == null)
                ItemNode = new ProjectElement(ProjectMgr, AssemblyName.FullName, NemerleConstants.MacroReference);

            // Set the basic information we know about
            ItemNode.SetMetadata(ProjectFileConstants.Name, AssemblyName.Name);
            ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, Path.GetFileName(Url));

            var fullFilePath = Path.GetFullPath(Url);
            var fullProjectPath = Path.GetFullPath(ProjectMgr.ProjectFolder);
            var relativePath = Utils.GetRelativePath(fullProjectPath, fullFilePath);

            // Set a default HintPath for msbuild to be able to resolve the reference.
            ItemNode.SetMetadata(ProjectFileConstants.HintPath, relativePath);

            // Предотвращаем копирование макро-сборки в каталог собираемого проекта
            ItemNode.SetMetadata(ProjectFileConstants.Private, "False");
        }
Example #25
0
 /// <summary>
 /// Override this method if you want to provide your own type of nodes.
 /// This would be the case if you derive a class from NestedProjectNode
 /// </summary>
 protected virtual NestedProjectNode CreateNestedProjectNode(ProjectElement element)
 {
     return new NestedProjectNode(this, element);
 }
Example #26
0
        /// <summary>
        /// This can be called directly or through RunVsTemplateWizard.
        /// This will clone a template project file and add it as a
        /// subproject to our hierarchy.
        /// If you want to create a project for which there exist a
        /// vstemplate, consider using RunVsTemplateWizard instead.
        /// </summary>
        protected internal virtual NestedProjectNode AddNestedProjectFromTemplate(string fileName, string destination, string projectName, ProjectElement element, __VSCREATEPROJFLAGS creationFlags)
        {
            // If this is project creation and the template specified a subproject in its project file, this.nestedProjectElement will be used
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if(elementToUse == null)
            {
                // If this is null, this means MSBuild does not know anything about our subproject so add an MSBuild item for it
                elementToUse = new ProjectElement(this, fileName, ProjectFileConstants.SubProject);
            }

            NestedProjectNode node = CreateNestedProjectNode(elementToUse);
            node.Init(fileName, destination, projectName, creationFlags);

            // In case that with did not have an existing element, or the nestedProjectelement was null
            //  and since Init computes the final path, set the MSBuild item to that path
            if(this.nestedProjectElement == null)
            {
                string relativePath = node.Url;
                if(Path.IsPathRooted(relativePath))
                {
                    relativePath = this.ProjectFolder;
                    if(!relativePath.EndsWith("/\\", StringComparison.Ordinal))
                    {
                        relativePath += Path.DirectorySeparatorChar;
                    }

                    relativePath = new Url(relativePath).MakeRelative(new Url(node.Url));
                }

                elementToUse.Rename(relativePath);
            }

            this.AddChild(node);
            return node;
        }
Example #27
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="XSharpFileNode"/> class.
        /// </summary>
        /// <param name="root">The project node.</param>
        /// <param name="e">The project element node.</param>
        internal XFileNode(XProjectNode root, ProjectElement element)
            : this(root, element, false)
        {
        }
        /// <summary>
        /// This can be called directly or through RunVsTemplateWizard.
        /// This will clone a template project file and add it as a
        /// subproject to our hierarchy.
        /// If you want to create a project for which there exist a
        /// vstemplate, consider using RunVsTemplateWizard instead.
        /// </summary>
        public virtual NestedProjectNode AddNestedProjectFromTemplate(string fileName, string destination, string projectName, ProjectElement element, __VSCREATEPROJFLAGS creationFlags)
        {
            // If this is project creation and the template specified a subproject in its project file, this.nestedProjectElement will be used
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if(elementToUse == null)
            {
                // If this is null, this means MSBuild does not know anything about our subproject so add an MSBuild item for it
                elementToUse = new ProjectElement(this, fileName, ProjectFileConstants.SubProject);
            }

            NestedProjectNode node = CreateNestedProjectNode(elementToUse);
            node.Init(fileName, destination, projectName, creationFlags);

            // In case that with did not have an existing element, or the nestedProjectelement was null
            //  and since Init computes the final path, set the MSBuild item to that path
            if(this.nestedProjectElement == null)
            {
                string relativePath = node.Url;
                if(Path.IsPathRooted(relativePath))
                {
                    relativePath = this.ProjectFolder;
                    if(!relativePath.EndsWith("/\\", StringComparison.Ordinal))
                    {
                        relativePath += Path.DirectorySeparatorChar;
                    }

                    relativePath = new Url(relativePath).MakeRelative(new Url(node.Url));
                }

                elementToUse.Rename(relativePath);
            }

            this.AddChild(node);
            return node;
        }
Example #29
0
 public XFileNode(XProjectNode root, ProjectElement element, bool isNonMemberItem)
     : base(root, element)
 {
     this.isNonMemberItem = isNonMemberItem;
 }
Example #30
0
        /// <summary>
        /// Reloads a nested project node by deleting it and readding it.
        /// </summary>
        /// <param name="node">The node to reload.</param>
        protected virtual void ReloadNestedProjectNode(NestedProjectNode node)
        {
            if(node == null)
            {
                throw new ArgumentNullException("node");
            }

            IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;

            if(solution == null)
            {
                throw new InvalidOperationException();
            }

            NestedProjectNode newNode = null;
            try
            {
                // (VS 2005 UPDATE) When deleting and re-adding the nested project,
                // we do not want SCC to see this as a delete and add operation.
                this.EventTriggeringFlag = ProjectNode.EventTriggering.DoNotTriggerTrackerEvents;

                // notify SolutionEvents listeners that we are about to add children
                IVsFireSolutionEvents fireSolutionEvents = solution as IVsFireSolutionEvents;

                if(fireSolutionEvents == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnBeforeUnloadProject(node.NestedHierarchy));

                int isDirtyAsInt = 0;
                this.IsDirty(out isDirtyAsInt);

                bool isDirty = (isDirtyAsInt == 0) ? false : true;

                ProjectElement element = node.ItemNode;
                node.CloseNestedProjectNode();

                // Remove from the solution
                this.RemoveChild(node);

                // Now readd it
                try
                {
                    __VSCREATEPROJFLAGS flags = __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE;
                    newNode = this.AddExistingNestedProject(element, flags);
                    newNode.AddVirtualProject();
                }
                catch(Exception e)
                {
                    // We get a System.Exception if anything failed, thus we have no choice but catch it.
                    // Exceptions are digested by VS. Show the error if not in automation.
                    if(!Utilities.IsInAutomationFunction(this.Site))
                    {
                        string message = (String.IsNullOrEmpty(e.Message)) ? SR.GetString(SR.NestedProjectFailedToReload, CultureInfo.CurrentUICulture) : e.Message;
                        string title = string.Empty;
                        OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL;
                        OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        Utilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                    }

                    // Do not digest exception. let the caller handle it. If in a later stage this exception is not digested then the above messagebox is not needed.
                    throw;
                }

#if DEBUG
                IVsHierarchy nestedHierarchy;
                solution.GetProjectOfUniqueName(newNode.GetMkDocument(), out nestedHierarchy);
                Debug.Assert(nestedHierarchy != null && Utilities.IsSameComObject(nestedHierarchy, newNode.NestedHierarchy), "The nested hierrachy was not reloaded correctly.");
#endif
                this.SetProjectFileDirty(isDirty);

                fireSolutionEvents.FireOnAfterLoadProject(newNode.NestedHierarchy);
            }
            finally
            {
                // In this scenario the nested project failed to unload or reload the nested project. We will unload the whole project, otherwise the nested project is lost.
                // This is similar to the scenario when one wants to open a project and the nested project cannot be loaded because for example the project file has xml errors.
                // We should note that we rely here that if the unload fails then exceptions are not digested and are shown to the user.
                if(newNode == null || newNode.NestedHierarchy == null)
                {
                    solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject | (uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, this, 0);
                }
                else
                {
                    this.EventTriggeringFlag = ProjectNode.EventTriggering.TriggerAll;
                }
            }
        }
        /// <summary>
        /// Let the wizard code execute and provide us the information we need.
        /// Our SolutionFolder automation object should be called back with the
        /// details at which point it will call back one of our method to add
        /// a nested project.
        /// If you are trying to add a new subproject this is probably the
        /// method you want to call. If you are just trying to clone a template
        /// project file, then AddNestedProjectFromTemplate is what you want.
        /// </summary>
        /// <param name="element">The project item to use as the base of the nested project.</param>
        /// <param name="silent">true if the wizard should run silently, otherwise false.</param>
        public void RunVSTemplateWizard(ProjectElement element, bool silent)
        {
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if(elementToUse == null)
            {
                throw new ArgumentNullException("element");
            }
            this.nestedProjectElement = elementToUse;

            Automation.OAProject oaProject = GetAutomationObject() as Automation.OAProject;
            if(oaProject == null || oaProject.ProjectItems == null)
                throw new System.InvalidOperationException(SR.GetString(SR.InvalidAutomationObject, CultureInfo.CurrentUICulture));
            Debug.Assert(oaProject.Object != null, "The project automation object should have set the Object to the SolutionFolder");
            Automation.OASolutionFolder<ProjectContainerNode> folder = oaProject.Object as Automation.OASolutionFolder<ProjectContainerNode>;

            // Prepare the parameters to pass to RunWizardFile
            string destination = elementToUse.GetFullPathForElement();
            string template = this.GetProjectTemplatePath(elementToUse);

            object[] wizParams = new object[7];
            wizParams[0] = EnvDTE.Constants.vsWizardAddSubProject;
            wizParams[1] = Path.GetFileNameWithoutExtension(destination);
            wizParams[2] = oaProject.ProjectItems;
            wizParams[3] = Path.GetDirectoryName(destination);
            wizParams[4] = Path.GetFileNameWithoutExtension(destination);
            wizParams[5] = Path.GetDirectoryName(folder.DTE.FullName); //VS install dir
            wizParams[6] = silent;

            IVsDetermineWizardTrust wizardTrust = this.GetService(typeof(SVsDetermineWizardTrust)) as IVsDetermineWizardTrust;
            if(wizardTrust != null)
            {
                Guid guidProjectAdding = Guid.Empty;

                // In case of a project template an empty guid should be added as the guid parameter. See env\msenv\core\newtree.h IsTrustedTemplate method definition.
                ErrorHandler.ThrowOnFailure(wizardTrust.OnWizardInitiated(template, ref guidProjectAdding));
            }

            try
            {
                // Make the call to execute the wizard. This should cause AddNestedProjectFromTemplate to be
                // called back with the correct set of parameters.
                EnvDTE.IVsExtensibility extensibilityService = (EnvDTE.IVsExtensibility)GetService(typeof(EnvDTE.IVsExtensibility));
                EnvDTE.wizardResult result = extensibilityService.RunWizardFile(template, 0, ref wizParams);
                if(result == EnvDTE.wizardResult.wizardResultFailure)
                    ErrorHandler.ThrowOnFailure(VSConstants.E_FAIL);
            }
            finally
            {
                if(wizardTrust != null)
                {
                    ErrorHandler.ThrowOnFailure(wizardTrust.OnWizardCompleted());
                }
            }
        }
Example #32
0
 public PackageFileNode(ProjectNode root, ProjectElement e)
     : base(root, e)
 {
     ExcludeNodeFromScc = true;
 }
        /// <summary>
        /// Based on the Template and TypeGuid properties of the
        /// element, generate the full template path.
        /// 
        /// TypeGuid should be the Guid of a registered project factory.
        /// Template can be a full path, a project template (for projects
        /// that support VsTemplates) or a relative path (for other projects).
        /// </summary>
        protected virtual string GetProjectTemplatePath(ProjectElement element)
        {
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if(elementToUse == null)
            {
                throw new ArgumentNullException("element");
            }

            string templateFile = elementToUse.GetMetadata(ProjectFileConstants.Template);
            Debug.Assert(!String.IsNullOrEmpty(templateFile), "No template file has been specified in the template attribute in the project file");

            string fullPath = templateFile;
            if(!Path.IsPathRooted(templateFile))
            {
                RegisteredProjectType registeredProjectType = this.GetRegisteredProject(elementToUse);

                // This is not a full path
                Debug.Assert(registeredProjectType != null && (!String.IsNullOrEmpty(registeredProjectType.DefaultProjectExtensionValue) || !String.IsNullOrEmpty(registeredProjectType.WizardTemplatesDirValue)), " Registered wizard directory value not set in the registry.");

                // See if this specify a VsTemplate file
                fullPath = registeredProjectType.GetVSTemplateFile(templateFile);
                if(String.IsNullOrEmpty(fullPath))
                {
                    // Default to using the WizardTemplateDir to calculate the absolute path
                    fullPath = Path.Combine(registeredProjectType.WizardTemplatesDirValue, templateFile);
                }
            }

            return fullPath;
        }
Example #34
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="XFolderNode"/> class.
        /// </summary>
        /// <param name="root">The root <see cref="XProjectNode"/> that contains this node.</param>
        /// <param name="directoryPath">Root of the hierarchy.</param>
        /// <param name="element">The element that contains MSBuild properties.</param>
        public XFolderNode(XProjectNode root, string directoryPath, ProjectElement element)
            : this(root, directoryPath, element, false)
        {
        }
Example #35
0
 public NestedProjectNode(ProjectNode root, ProjectElement element)
     : base(root, element)
 {
     this.IsExpanded = true;
 }
Example #36
0
 /// <summary>
 /// Constructor for the FolderNode
 /// </summary>
 /// <param name="root">Root node of the hierarchy</param>
 /// <param name="relativePath">relative path from root i.e.: "NewFolder1\\NewFolder2\\NewFolder3</param>
 /// <param name="element">Associated project element</param>
 public FolderNode(ProjectNode root, string relativePath, ProjectElement element)
     : base(root, element)
 {
     this.VirtualNodeName = relativePath.TrimEnd('\\');
 }
Example #37
0
 /// <summary>
 /// constructor for the ReferenceNode
 /// </summary>
 protected ReferenceNode(ProjectNode root, ProjectElement element)
     : base(root, element)
 {
     this.ExcludeNodeFromScc = true;
 }
Example #38
0
 /// <summary>
 /// Constructor for the DependentFileNode
 /// </summary>
 /// <param name="root">Root of the hierarchy</param>
 /// <param name="element">Associated project element</param>
 public DependentFileNode(ProjectNode root, ProjectElement element)
     : base(root, element)
 {
     this.HasParentNodeNameRelation = false;
 }
        /// <summary>
        /// This will clone a template project file and add it as a
        /// subproject to our hierarchy.
        /// If you want to create a project for which there exist a
        /// vstemplate, consider using RunVsTemplateWizard instead.
        /// </summary>
        public virtual NestedProjectNode AddNestedProjectFromTemplate(ProjectElement element, __VSCREATEPROJFLAGS creationFlags)
        {
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if(elementToUse == null)
            {
                throw new ArgumentNullException("element");
            }
            string destination = elementToUse.GetFullPathForElement();
            string template = this.GetProjectTemplatePath(elementToUse);

            return this.AddNestedProjectFromTemplate(template, Path.GetDirectoryName(destination), Path.GetFileName(destination), elementToUse, creationFlags);
        }
 /// <summary>
 /// Constructor for the ReferenceNode
 /// </summary>
 public ApplicationReferenceNode(ProjectNode root, ProjectElement element)
     : base(root, element)
 {
     this.path     = element.GetFullPathForElement();
     this.filename = Path.GetFileName(this.path);
 }
        /// <summary>
        /// This is used when loading the project to loop through all the items
        /// and for each SubProject it finds, it create the project and a node
        /// in our Hierarchy to hold the project.
        /// </summary>
        public virtual void CreateNestedProjectNodes()
        {
            // 1. Create a ProjectElement with the found item and then Instantiate a new Nested project with this ProjectElement.
            // 2. Link into the hierarchy.
            // Read subprojects from from msbuildmodel
            __VSCREATEPROJFLAGS creationFlags = __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT;

            if(this.IsNewProject)
            {
                creationFlags |= __VSCREATEPROJFLAGS.CPF_CLONEFILE;
            }
            else
            {
                creationFlags |= __VSCREATEPROJFLAGS.CPF_OPENFILE;
            }

            foreach (MSBuild.ProjectItem item in this.BuildProject.Items)
            {
                if(String.Equals(item.ItemType, ProjectFileConstants.SubProject, StringComparison.OrdinalIgnoreCase))
                {
                    this.nestedProjectElement = new ProjectElement(this, item, false);

                    if(!this.IsNewProject)
                    {
                        AddExistingNestedProject(null, creationFlags);
                    }
                    else
                    {
                        // If we are creating the subproject from a vstemplate/vsz file
                        bool isVsTemplate = Utilities.IsTemplateFile(GetProjectTemplatePath(null));
                        if(isVsTemplate)
                        {
                            RunVSTemplateWizard(null, true);
                        }
                        else
                        {
                            // We are cloning the specified project file
                            AddNestedProjectFromTemplate(null, creationFlags);
                        }
                    }
                }
            }

            this.nestedProjectElement = null;
        }
Example #42
0
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(MSBuild.Project buildProject)
        {
            XSharpProjectPackage.Instance.UIThread.MustBeCalledFromUIThread();
            List <ReferenceNode> duplicatedNode = new List <ReferenceNode>();
            BuildResult          buildResult    = this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences);

            var children = new List <ReferenceNode>();

            foreach (string referenceType in SupportedReferenceTypes)
            {
                bool isAssemblyReference = referenceType == ProjectFileConstants.Reference;
                if (isAssemblyReference && !buildResult.IsSuccessful)
                {
                    continue;
                }

                foreach (var item in MSBuildProject.GetItems(buildProject, referenceType))
                {
                    ProjectElement element = new ProjectElement(this.ProjectMgr, item, false);

                    ReferenceNode node = CreateReferenceNode(referenceType, element);

                    if (node != null)
                    {
                        // Make sure that we do not want to add the item twice to the ui hierarchy
                        // We are using here the UI representation of the Node namely the Caption to find that out, in order to
                        // avoid different representation problems.
                        // Example :<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                        //		  <Reference Include="EnvDTE80" />
                        bool found = false;
                        for (HierarchyNode n = this.FirstChild; n != null && !found; n = n.NextSibling)
                        {
                            if (String.Compare(n.Caption, node.Caption, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            this.AddChild(node);
                            children.Add(node);
                        }
                        else
                        {
                            duplicatedNode.Add(node);
                        }
                    }
                }
            }
            // Now manage duplicates
            if (duplicatedNode.Count > 0)
            {
                // Make a backup first
                string original   = buildProject.FullPath;
                string backupName = Path.ChangeExtension(original, ".backup");
                if (Utilities.DeleteFileSafe(backupName))
                {
                    File.Copy(original, backupName);
                }
                foreach (ReferenceNode node in duplicatedNode)
                {
                    //this.RemoveChild( node );
                    node.Remove(false);
                }
                buildProject.Save(original);
            }
            var references = buildResult.ProjectInstance.GetItems(ProjectFileConstants.ReferencePath);

            //var references = MSBuildProjectInstance.GetItems(buildResult.ProjectInstance, ProjectFileConstants.ReferencePath);
            foreach (var reference in references)
            {
                string fullName = MSBuildItem.GetEvaluatedInclude(reference);
                string name     = Path.GetFileNameWithoutExtension(fullName);
                foreach (var child in children)
                {
                    if (child is XSharpAssemblyReferenceNode && child.Caption == name)
                    {
                        var xChild = child as XSharpAssemblyReferenceNode;
                        xChild.AssemblyPath = fullName;
                        xChild.SetHintPathAndPrivateValue(buildResult.ProjectInstance, reference);
                    }
                }
            }
        }
 /// <summary>
 /// Override this method if you want to provide your own type of nodes.
 /// This would be the case if you derive a class from NestedProjectNode
 /// </summary>
 protected virtual NestedProjectNode CreateNestedProjectNode(ProjectElement element)
 {
     return new NestedProjectNode(this, element);
 }
Example #44
0
 /// <summary>
 /// Creates a project reference node given an existing project element.
 /// </summary>
 protected virtual ProjectReferenceNode CreateProjectReferenceNode(ProjectElement element)
 {
     return(new ProjectReferenceNode(this.ProjectMgr, element));
 }
        /// <summary>
        /// Get information from the registry based for the project 
        /// factory corresponding to the TypeGuid of the element
        /// </summary>
        protected virtual RegisteredProjectType GetRegisteredProject(ProjectElement element)
        {
            ProjectElement elementToUse = (element == null) ? this.nestedProjectElement : element;

            if(elementToUse == null)
            {
                throw new ArgumentNullException("element");
            }

            // Get the project type guid from project elementToUse
            string typeGuidString = elementToUse.GetMetadataAndThrow(ProjectFileConstants.TypeGuid, new Exception());
            Guid projectFactoryGuid = new Guid(typeGuidString);

            EnvDTE.DTE dte = this.ProjectManager.Site.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            Debug.Assert(dte != null, "Could not get the automation object from the services exposed by this project");

            if(dte == null)
                throw new InvalidOperationException();

            RegisteredProjectType registeredProjectType = RegisteredProjectType.CreateRegisteredProjectType(projectFactoryGuid);
            Debug.Assert(registeredProjectType != null, "Could not read the registry setting associated to this project.");
            if(registeredProjectType == null)
            {
                throw new InvalidOperationException();
            }
            return registeredProjectType;
        }
Example #46
0
 /// <summary>
 /// Creates a com reference node from the project element.
 /// </summary>
 protected virtual ComReferenceNode CreateComReferenceNode(ProjectElement reference)
 {
     return(new ComReferenceNode(this.ProjectMgr, reference));
 }