//==========================================================================================
 // Constructors
 //==========================================================================================
 public ProjectConfiguration(Project project, string name)
 {
     Tracer.VerifyNonNullArgument(project, "project");
     Tracer.VerifyStringArgument(name, "name");
     this.project = project;
     this.name = name;
 }
 //==========================================================================================
 // Constructors
 //==========================================================================================
 public ConfigurationProvider(Project project)
 {
     Tracer.VerifyNonNullArgument(project, "project");
     this.project = project;
 }
        /// <summary>
        /// Creates a deep copy of this object with the new project instead of the cloned project.
        /// </summary>
        /// <returns>A deep copy of this object.</returns>
        public ConfigurationProvider Clone(Project newProject)
        {
            ConfigurationProvider clone = new ConfigurationProvider(newProject);

            // Clone the configurations collection.
            clone.projectConfigurations = (ProjectConfigurationCollection)this.ProjectConfigurations.Clone();
            clone.projectConfigurations.CollectionChanged += new CollectionChangeEventHandler(clone.ConfigCollectionChanged);
            foreach (ProjectConfiguration config in clone.projectConfigurations)
            {
                config.Project = newProject;
            }

            // Clone the listeners collection.
            clone.eventListeners = (VsCfgProviderEventListenerCollection)this.eventListeners.Clone();

            return clone;
        }
 //==========================================================================================
 // Constructors
 //==========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectDocumentsTracker"/> class.
 /// </summary>
 /// <param name="project">The project whose documents we want to track.</param>
 public ProjectDocumentsTracker(Project project)
 {
     Tracer.VerifyNonNullArgument(project, "project");
     this.project = project;
 }
예제 #5
0
 /// <summary>
 /// Recursively copies all of the child file nodes from the source parent to the destination parent. Also copies the physical files.
 /// </summary>
 /// <param name="sourceParent">The node to copy from.</param>
 /// <param name="destinationProject">The project to place the copied nodes into.</param>
 /// <param name="destinationParent">The node to copy to.</param>
 private bool CopyNodeFiles(FolderNode sourceParent, Project destinationProject, FolderNode destinationParent)
 {
     bool canceled;
     foreach (Node sourceNode in sourceParent.Children)
     {
         if (sourceNode is FileNode)
         {
             string fileName = Path.GetFileName(sourceNode.AbsolutePath);
             string destinationPath = Path.Combine(destinationParent.AbsoluteDirectory, fileName);
             Node addedNode = destinationProject.AddCopyOfFile(sourceNode.AbsolutePath, destinationPath, out canceled);
             if (addedNode == null || canceled)
             {
                 return false;
             }
         }
         else if (sourceNode is FolderNode && !(sourceNode is ReferenceFolderNode))
         {
             FolderNode destNode = destinationProject.CreateAndAddFolder(destinationParent, sourceNode.Caption);
             // Recure
             return this.CopyNodeFiles((FolderNode)sourceNode, destinationProject, destNode);
         }
     }
     return true;
 }
예제 #6
0
 /// <summary>
 /// Gives subclasses a chance to create a type-specific project configuration object.
 /// </summary>
 /// <param name="project">The parent <see cref="Project"/> of the configuration.</param>
 /// <param name="name">The name of the configuration.</param>
 /// <returns>A newly created <see cref="ProjectConfiguration"/> object.</returns>
 protected virtual ProjectConfiguration CreateProjectConfiguration(Project project, string name)
 {
     return new ProjectConfiguration(project, name);
 }
예제 #7
0
        /// <summary>
        /// Loads a project template file, serializing it into the specified project at the specified destination.
        /// </summary>
        /// <param name="templatePath">The absolute path of the template project file to load.</param>
        /// <param name="destinationPath">The absolute path to the new project file.</param>
        /// <returns>true if the project file was loaded correctly; otherwise, false.</returns>
        public bool LoadFromTemplate(string templatePath, string destinationPath)
        {
            Tracer.VerifyStringArgument(templatePath, "templatePath");
            Tracer.VerifyStringArgument(destinationPath, "destinationPath");

            bool successful = false;

            // Load the template project.
            if (this.Load(templatePath))
            {
                // Copy the loaded template to the real location of the new project.
                this.project = this.CopyTo(destinationPath);
                successful = (this.project != null);
            }

            return successful;
        }
예제 #8
0
        /// <summary>
        /// Loads a project file from disk.
        /// </summary>
        /// <param name="filePath">The absolute path of the project file to load.</param>
        /// <returns>true if the project file was loaded correctly; otherwise, false.</returns>
        public bool Load(string filePath)
        {
            Tracer.VerifyStringArgument(filePath, "filePath");

            // Create a new project.
            this.project = this.CreateProject(this);

            // Set the project's file path to the one being loaded in. Do this first in case we have
            // to make the project unavailable it can still display the correct caption in Solution Explorer.
            this.Project.FilePath = filePath;

            // Make sure the file exists.
            if (!File.Exists(filePath))
            {
                if (!this.SilentFailures)
                {
                    string message = SconceStrings.FileDoesNotExist(filePath);
                    Package.Instance.Context.ShowErrorMessageBox(message);
                }
                this.Project.Unavailable = true;
                Tracer.WriteLine(classType, "Load", Tracer.Level.Warning, "The project file '{0}' does not exist.", filePath);
                return false;
            }

            try
            {
                using (StreamReader stream = new StreamReader(filePath))
                {
                    XmlTextReader reader = new XmlTextReader(stream);
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(reader);
                    XmlNode node = xmlDoc.DocumentElement;

                    // <VisualStudioProject>
                    if (!this.VerifyNode(node, ElementNames.VisualStudioProject))
                    {
                        this.Project.Unavailable = true;
                        return false;
                    }
                    node = node.FirstChild;

                    if (!this.ReadProjectNode(node))
                    {
                        this.Project.Unavailable = true;
                        return false;
                    }
                }
            }
            catch (XmlException e)
            {
                if (!this.SilentFailures)
                {
                    string projectFileName = Path.GetFileName(filePath);
                    string title = Package.Instance.Context.NativeResources.GetString(ResId.IDS_E_INVALIDPROJECTFILE_TITLE);
                    string message = Package.Instance.Context.NativeResources.GetString(ResId.IDS_E_INVALIDPROJECTFILE, projectFileName);
                    Package.Instance.Context.ShowErrorMessageBox(title, message);
                }
                this.Project.Unavailable = true;
                Tracer.Fail("There was an error parsing '{0}': {1}", filePath, e.ToString());
                return false;
            }

            // Once the project has been loaded, it's not dirty anymore.
            this.Project.ClearDirty();

            return true;
        }
예제 #9
0
        /// <summary>
        /// The environment calls this to set the currently selected objects that the property page should show.
        /// </summary>
        /// <param name="cObjects">The count of elements in <paramref name="ppunk"/>.</param>
        /// <param name="ppunk">An array of <b>IUnknown</b> objects to show in the property page.</param>
        /// <remarks>
        /// We are supposed to cache these objects until we get another call with <paramref name="cObjects"/> = 0.
        /// Also, the environment is supposed to call this before calling <see cref="IPropertyPage.Activate"/>,
        /// but like all things when interacting with Visual Studio, don't trust that and code defensively.
        /// </remarks>
        void IPropertyPage.SetObjects(uint cObjects, object[] ppunk)
        {
            if (ppunk == null || ppunk.Length == 0 || cObjects == 0)
            {
                this.project = null;
                this.UnbindObject();
                return;
            }

            // Check the incoming parameters
            Tracer.WriteLineIf(classType, "IPropertyPage.SetObjects", Tracer.Level.Verbose, cObjects != ppunk.Length, "Visual Studio passed us a ppunk array of size {0} but the count is {1}.", ppunk.Length, cObjects);

            // We get called when the user selects "Properties" from the context menu on the project node
            if (ppunk[0] is NodeProperties)
            {
                if (this.project == null)
                {
                    this.project = ((NodeProperties)ppunk[0]).Node.Hierarchy.AttachedProject;
                }
            }

            // Refresh the page with the new settings
            if (this.Project != null)
            {
                this.BindObject();
            }
        }
 /// <summary>
 /// Creates a new <see cref="WixProjectConfiguration"/> object.
 /// </summary>
 /// <param name="project">The parent <see cref="Project"/> of the configuration.</param>
 /// <param name="name">The name of the configuration.</param>
 /// <returns>A newly created <see cref="ProjectConfiguration"/> object.</returns>
 protected override ProjectConfiguration CreateProjectConfiguration(Project project, string name)
 {
     Tracer.Assert(project is WixProject, "Somehow we're not getting the right type of project here.");
     return new WixProjectConfiguration((WixProject)project, name);
 }
 //==========================================================================================
 // Constructors
 //==========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectConfigurationCollection"/> class.
 /// </summary>
 /// <param name="project">The project that owns this collection (indirectly through the <see cref="ConfigurationProvider"/>.</param>
 public ProjectConfigurationCollection(Project project)
     : base(new ProjectConfigurationComparer())
 {
     this.project = project;
 }