Update of /cvsroot/wix/wix/src/votive/sdk_vs2008/common/source/csharp/project/automation In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19110/src/votive/sdk_vs2008/common/source/csharp/project/automation Added Files: oafileitem.cs oafolderitem.cs oanavigableprojectitems.cs oanestedprojectitem.cs oanullproperty.cs oaproject.cs oaprojectitem.cs oaprojectitems.cs oaproperties.cs oaproperty.cs oareferencefolderitem.cs oareferenceitem.cs oasolutionfolder.cs Log Message: AaronSte: Creating separate Votive and Sconce DLLs for VS 2005 and VS 2008. Adding the VS 2008 SDK source code that is needed to build the VS 2008 Votive and Sconce dlls. HeathS: SFBUG:1789825 - CreationTimeUTC documents wrong format SFFEATURE:1768845 - Patch element should support MinorUpdateTargetRTM attribute SFFEATURE:1735295 - Patch build should add PATCHNEW* properties to patch transform Added support for ignorables to CompareUnit in WixUnit HeathS: SFBUG:1768842 - PatchProperty does not allow Company RobMen: Ensure RegistryKey element never ends up as KeyPath because MSI SDK says it isn't allowed. RobMen: Component guid generation. RobMen: SFBUG:1795309 - respect the rollback flag for the last SQL string like all the other strings. RobMen: SFBUG:1787888 - correctly handle certificates that are in Components that are conditioned out. RobMen: SFBUG:1675194 - loop through all server bindings when searching for a match. --- NEW FILE: oafileitem.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.IO; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; using EnvDTE; namespace Microsoft.VisualStudio.Package.Automation { [ComVisible(true), CLSCompliant(false)] public class OAFileItem : OAProjectItem<FileNode> { #region ctors public OAFileItem(OAProject proj, FileNode node) : base(proj, node) { } #endregion #region overridden methods /// <summary> /// Returns the dirty state of the document. /// </summary> /// <exception cref="InvalidOperationException">Is thrown if the project is closed or it the service provider attached to the project is invalid.</exception> /// <exception cref="ComException">Is thrown if the dirty state cannot be retrived.</exception> public override bool IsDirty { get { if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } bool isDirty = false; extensibility.EnterAutomationFunction(); try { DocumentManager manager = this.Node.GetDocumentManager(); if (manager == null) { throw new InvalidOperationException(); } bool isOpen, isOpenedByUs; uint docCookie; IVsPersistDocData persistDocData; manager.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out persistDocData); } finally { extensibility.ExitAutomationFunction(); } return isDirty; } } /// <summary> /// Gets the Document associated with the item, if one exists. /// </summary> public override EnvDTE.Document Document { get { if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } EnvDTE.Document document = null; extensibility.EnterAutomationFunction(); try { IVsUIHierarchy hier; uint itemid; IVsWindowFrame windowFrame; VsShellUtilities.IsDocumentOpen(this.Node.ProjectMgr.Site, this.Node.Url, NativeMethods.LOGVIEWID_Any, out hier, out itemid, out windowFrame); if (windowFrame != null) { object var; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); object documentAsObject; extensibility.GetDocumentFromDocCookie((int)var, out documentAsObject); if (documentAsObject == null) { throw new InvalidOperationException(); } else { document = (Document)documentAsObject; } } } finally { extensibility.ExitAutomationFunction(); } return document; } } /// <summary> /// Opens the file item in the specified view. /// </summary> /// <param name="ViewKind">Specifies the view kind in which to open the item (file)</param> /// <returns>Window object</returns> public override EnvDTE.Window Open(string viewKind) { if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } // tell extensibility we are entering automation IServiceProvider serviceProvider = this.Node.ProjectMgr.Site; IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } IVsWindowFrame windowFrame = null; IntPtr docData = IntPtr.Zero; extensibility.EnterAutomationFunction(); try { // Validate input params Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary; try { if (!(String.IsNullOrEmpty(viewKind))) { logicalViewGuid = new Guid(viewKind); } } catch (FormatException) { // Not a valid guid throw new ArgumentException(SR.GetString(SR.ParameterMustBeAValidGuid), "ViewKind"); } uint itemid; IVsHierarchy ivsHierarchy; uint docCookie; IVsRunningDocumentTable rdt = this.Node.ProjectMgr.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; Debug.Assert(rdt != null, " Could not get running document table from the services exposed by this project"); if (rdt == null) { throw new InvalidOperationException(); } ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, this.Node.Url, out ivsHierarchy, out itemid, out docData, out docCookie)); // Open the file using the IVsProject3 interface ErrorHandler.ThrowOnFailure(this.Node.ProjectMgr.OpenItem(this.Node.ID, ref logicalViewGuid, docData, out windowFrame)); } finally { // make sure we tell extensibility that we have left automation extensibility.ExitAutomationFunction(); if (docData != IntPtr.Zero) { Marshal.Release(docData); } } // Get the automation object and return it return ((windowFrame != null) ? VsShellUtilities.GetWindowObject(windowFrame) : null); } /// <summary> /// Saves the project item. /// </summary> /// <param name="fileName">The name with which to save the project or project item.</param> /// <exception cref="InvalidOperationException">Is thrown if the save operation failes.</exception> /// <exception cref="ArgumentNullException">Is thrown if fileName is null.</exception> public override void Save(string fileName) { this.DoSave(false, fileName); } /// <summary> /// Saves the project item. /// </summary> /// <param name="fileName">The file name with which to save the solution, project, or project item. If the file exists, it is overwritten</param> /// <returns>true if the rename was successful. False if Save as failes</returns> public override bool SaveAs(string fileName) { try { this.DoSave(true, fileName); } catch (InvalidOperationException) { return false; } catch (COMException) { return false; } return true; } /// <summary> /// Gets a value indicating whether the project item is open in a particular view type. /// </summary> /// <param name="viewKind">A Constants.vsViewKind* indicating the type of view to check./param> /// <returns>A Boolean value indicating true if the project is open in the given view type; false if not. </returns> public override bool get_IsOpen(string viewKind) { if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } // Validate input params Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary; try { if (!(String.IsNullOrEmpty(viewKind))) { logicalViewGuid = new Guid(viewKind); } } catch (FormatException) { // Not a valid guid throw new ArgumentException(SR.GetString(SR.ParameterMustBeAValidGuid), "viewKind"); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } bool isOpen = false; extensibility.EnterAutomationFunction(); try { IVsUIHierarchy hier; uint itemid; IVsWindowFrame windowFrame; isOpen = VsShellUtilities.IsDocumentOpen(this.Node.ProjectMgr.Site, this.Node.Url, logicalViewGuid, out hier, out itemid, out windowFrame); } finally { extensibility.ExitAutomationFunction(); } return isOpen; } /// <summary> /// Gets the ProjectItems for the object. /// </summary> public override ProjectItems ProjectItems { get { if (this.Project.Project.CanFileNodesHaveChilds) return new OAProjectItems(this.Project, this.Node); else return base.ProjectItems; } } #endregion #region helpers /// <summary> /// Saves or Save As the file /// </summary> /// <param name="isCalledFromSaveAs">Flag determining which Save method called , the SaveAs or the Save.</param> /// <param name="fileName">The name of the project file.</param> private void DoSave(bool isCalledFromSaveAs, string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } extensibility.EnterAutomationFunction(); IntPtr docData = IntPtr.Zero; try { IVsRunningDocumentTable rdt = this.Node.ProjectMgr.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; Debug.Assert(rdt != null, " Could not get running document table from the services exposed by this project"); if (rdt == null) { throw new InvalidOperationException(); } // First we see if someone else has opened the requested view of the file. uint itemid; IVsHierarchy ivsHierarchy; uint docCookie; IntPtr projectPtr = IntPtr.Zero; int canceled; string url = this.Node.Url; ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, url, out ivsHierarchy, out itemid, out docData, out docCookie)); // If an empty file name is passed in for Save then make the file name the project name. if (!isCalledFromSaveAs && fileName.Length == 0) { ErrorHandler.ThrowOnFailure(this.Node.ProjectMgr.SaveItem(VSSAVEFLAGS.VSSAVE_SilentSave, url, this.Node.ID, docData, out canceled)); } else { Utilities.ValidateFileName(this.Node.ProjectMgr.Site, fileName); // Compute the fullpath from the directory of the existing Url. string fullPath = fileName; if (!Path.IsPathRooted(fileName)) { string directory = Path.GetDirectoryName(url); fullPath = Path.Combine(directory, fileName); } if (!isCalledFromSaveAs) { if (!NativeMethods.IsSamePath(this.Node.Url, fullPath)) { throw new InvalidOperationException(); } ErrorHandler.ThrowOnFailure(this.Node.ProjectMgr.SaveItem(VSSAVEFLAGS.VSSAVE_SilentSave, fullPath, this.Node.ID, docData, out canceled)); } else { ErrorHandler.ThrowOnFailure(this.Node.ProjectMgr.SaveItem(VSSAVEFLAGS.VSSAVE_SilentSave, fullPath, this.Node.ID, docData, out canceled)); } } if (canceled == 1) { throw new InvalidOperationException(); } } catch (COMException e) { throw new InvalidOperationException(e.Message); } finally { extensibility.ExitAutomationFunction(); if (docData != IntPtr.Zero) { Marshal.Release(docData); } } } #endregion } } --- NEW FILE: oareferenceitem.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; namespace Microsoft.VisualStudio.Package.Automation { [ComVisible(true), CLSCompliant(false)] public class OAReferenceItem : OAProjectItem<ReferenceNode> { #region ctors public OAReferenceItem(OAProject proj, ReferenceNode node) : base(proj, node) { } #endregion #region overridden methods /// <summary> /// Not implemented. If called throws invalid operation exception. /// </summary> public override void Delete() { throw new InvalidOperationException(); } /// <summary> /// Not implemented. If called throws invalid operation exception. /// </summary> /// <param name="viewKind"> A Constants. vsViewKind indicating the type of view to use.</param> /// <returns></returns> public override EnvDTE.Window Open(string viewKind) { throw new InvalidOperationException(); } /// <summary> /// Gets or sets the name of the object. /// </summary> public override string Name { get { return base.Name; } set { throw new InvalidOperationException(); } } /// <summary> /// Gets the ProjectItems collection containing the ProjectItem object supporting this property. /// </summary> public override EnvDTE.ProjectItems Collection { get { // Get the parent node (ReferenceContainerNode) ReferenceContainerNode parentNode = this.Node.Parent as ReferenceContainerNode; Debug.Assert(parentNode != null, "Failed to get the parent node"); // Get the ProjectItems object for the parent node if (parentNode != null) { // The root node for the project return ((OAReferenceFolderItem)parentNode.GetAutomationObject()).ProjectItems; } return null; } } #endregion } } --- NEW FILE: oaprojectitem.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; using EnvDTE; namespace Microsoft.VisualStudio.Package.Automation { [ComVisible(true), CLSCompliant(false)] public class OAProjectItem<T> : EnvDTE.ProjectItem where T : HierarchyNode { #region fields private T node; private OAProject project; #endregion #region properties protected T Node { get { return this.node; } } /// <summary> /// Returns the automation project /// </summary> protected OAProject Project { get { return this.project; } } #endregion #region ctors public OAProjectItem(OAProject proj, T node) { this.node = node; this.project = proj; } #endregion #region EnvDTE.ProjectItem /// <summary> /// Gets the requested Extender if it is available for this object /// </summary> /// <param name="extenderName">The name of the extender.</param> /// <returns>The extender object.</returns> public virtual object get_Extender(string extenderName) { return null; } /// <summary> /// Gets an object that can be accessed by name at run time. /// </summary> public virtual object Object { get { return this.node.Object; } } /// <summary> /// Gets the Document associated with the item, if one exists. /// </summary> public virtual EnvDTE.Document Document { get { return null; } } /// <summary> /// Gets the number of files associated with a ProjectItem. /// </summary> public virtual short FileCount { get { return (short)1; } } /// <summary> /// Gets a collection of all properties that pertain to the object. /// </summary> public virtual EnvDTE.Properties Properties { get { if (this.node.NodeProperties == null) { return null; } return new OAProperties(this.node.NodeProperties); } } /// <summary> /// Gets the FileCodeModel object for the project item. /// </summary> public virtual EnvDTE.FileCodeModel FileCodeModel { get { return null; } } /// <summary> /// Gets a ProjectItems for the object. /// </summary> public virtual EnvDTE.ProjectItems ProjectItems { get { return null; } } /// <summary> /// Gets a GUID string indicating the kind or type of the object. /// </summary> public virtual string Kind { get { Guid guid; ErrorHandler.ThrowOnFailure(this.node.GetGuidProperty((int)__VSHPROPID.VSHPROPID_TypeGuid, out guid)); return guid.ToString("B"); } } /// <summary> /// Saves the project item. /// </summary> /// <param name="fileName">The name with which to save the project or project item.</param> /// <remarks>Implemented by subclasses.</remarks> public virtual void Save(string fileName) { throw new NotImplementedException(); } /// <summary> /// Gets the top-level extensibility object. /// </summary> public virtual EnvDTE.DTE DTE { get { return (EnvDTE.DTE)this.project.DTE; } } /// <summary> /// Gets the ProjectItems collection containing the ProjectItem object supporting this property. /// </summary> public virtual EnvDTE.ProjectItems Collection { get { // Get the parent node HierarchyNode parentNode = this.node.Parent; Debug.Assert(parentNode != null, "Failed to get the parent node"); // Get the ProjectItems object for the parent node if (parentNode is ProjectNode) { // The root node for the project return ((OAProject)parentNode.GetAutomationObject()).ProjectItems; } else if (parentNode is FileNode && parentNode.FirstChild != null) { // The item has children return ((OAProjectItem<FileNode>)parentNode.GetAutomationObject()).ProjectItems; } else if (parentNode is FolderNode) { return ((OAProjectItem<FolderNode>)parentNode.GetAutomationObject()).ProjectItems; } else { // Not supported. Override this method in derived classes to return appropriate collection object throw new NotImplementedException(); } } } /// <summary> /// Gets a list of available Extenders for the object. /// </summary> public virtual object ExtenderNames { get { return null; } } /// <summary> /// Gets the ConfigurationManager object for this ProjectItem. /// </summary> /// <remarks>We do not support config management based per item.</remarks> public virtual EnvDTE.ConfigurationManager ConfigurationManager { get { return null; } } /// <summary> /// Gets the project hosting the ProjectItem. /// </summary> public virtual EnvDTE.Project ContainingProject { get { return this.project; } } /// <summary> /// Gets or sets a value indicating whether or not the object has been modified since last being saved or opened. /// </summary> public virtual bool Saved { get { return !this.IsDirty; } set { throw new NotImplementedException(); } } /// <summary> /// Gets the Extender category ID (CATID) for the object. /// </summary> public virtual string ExtenderCATID { get { return null; } } /// <summary> /// If the project item is the root of a subproject, then the SubProject property returns the Project object for the subproject. /// </summary> public virtual EnvDTE.Project SubProject { get { return null; } } /// <summary> /// Microsoft Internal Use Only. Checks if the document associated to this item is dirty. /// </summary> public virtual bool IsDirty { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } /// <summary> /// Gets or sets the name of the object. /// </summary> public virtual string Name { get { return this.node.Caption; } set { if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } extensibility.EnterAutomationFunction(); try { this.node.SetEditLabel(value); } finally { extensibility.ExitAutomationFunction(); } } } /// <summary> /// Removes the project item from hierarchy. /// </summary> public virtual void Remove() { if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } extensibility.EnterAutomationFunction(); try { this.node.Remove(false); } finally { extensibility.ExitAutomationFunction(); } } /// <summary> /// Removes the item from its project and its storage. /// </summary> public virtual void Delete() { if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } extensibility.EnterAutomationFunction(); try { this.node.Remove(true); } finally { extensibility.ExitAutomationFunction(); } } /// <summary> /// Saves the project item. /// </summary> /// <param name="newFileName">The file name with which to save the solution, project, or project item. If the file exists, it is overwritten.</param> /// <returns>true if save was successful</returns> /// <remarks>This method is implemented on subclasses.</remarks> public virtual bool SaveAs(string newFileName) { throw new NotImplementedException(); } /// <summary> /// Gets a value indicating whether the project item is open in a particular view type. /// </summary> /// <param name="viewKind">A Constants.vsViewKind* indicating the type of view to check./param> /// <returns>A Boolean value indicating true if the project is open in the given view type; false if not. </returns> public virtual bool get_IsOpen(string viewKind) { throw new NotImplementedException(); } /// <summary> /// Gets the full path and names of the files associated with a project item. /// </summary> /// <param name="index"> The index of the item</param> /// <returns>The full path of the associated item</returns> /// <exception cref="ArgumentOutOfRangeException">Is thrown if index is not one</exception> public virtual string get_FileNames(short index) { // This method should really only be called with 1 as the parameter, but // there used to be a bug in VB/C# that would work with 0. To avoid breaking // existing automation they are still accepting 0. To be compatible with them // we accept it as well. Debug.Assert(index > 0, "Index is 1 based."); if (index < 0) { throw new ArgumentOutOfRangeException(); } return this.node.Url; } /// <summary> /// Expands the view of Solution Explorer to show project items. /// </summary> public virtual void ExpandView() { if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null) { throw new InvalidOperationException(); } IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } extensibility.EnterAutomationFunction(); try { IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer); if (uiHierarchy == null) { throw new InvalidOperationException(); } uiHierarchy.ExpandItem(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder); } finally { extensibility.ExitAutomationFunction(); } } /// <summary> /// Opens the project item in the specified view. Not implemented because this abstract class dont know what to open /// </summary> /// <param name="ViewKind">Specifies the view kind in which to open the item</param> /// <returns>Window object</returns> public virtual EnvDTE.Window Open(string ViewKind) { throw new NotImplementedException(); } #endregion } } --- NEW FILE: oasolutionfolder.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; namespace Microsoft.VisualStudio.Package.Automation { [ComVisible(true), CLSCompliant(false)] public class OASolutionFolder<T> : EnvDTE80.SolutionFolder where T : HierarchyNode { bool hidden = false; T node; public OASolutionFolder(T associatedNode) { if (associatedNode == null) { throw new ArgumentNullException("associatedNode"); } Debug.Assert(associatedNode.ProjectMgr is ProjectContainerNode, "Expecting obejct of type" + typeof(ProjectContainerNode).Name); if (!(associatedNode.ProjectMgr is ProjectContainerNode)) throw new ArgumentException(SR.GetString(SR.InvalidParameter), "associatedNode"); this.node = associatedNode; } #region SolutionFolder Members public virtual EnvDTE.Project AddFromFile(string fileName) { ProjectContainerNode projectContainer = (ProjectContainerNode)this.node.ProjectMgr; ProjectElement newElement = new ProjectElement(projectContainer, fileName, ProjectFileConstants.SubProject); NestedProjectNode newNode = projectContainer.AddExistingNestedProject(newElement, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE); if (newNode == null) return null; // Now that the sub project was created, get its extensibility object so we can return it object newProject = null; if (ErrorHandler.Succeeded(newNode.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newProject))) return newProject as EnvDTE.Project; else return null; } public virtual EnvDTE.Project AddFromTemplate(string fileName, string destination, string projectName) { bool isVSTemplate = Utilities.IsTemplateFile(fileName); NestedProjectNode newNode = null; if (isVSTemplate) { // Get the wizard to run, we will get called again and use the alternate code path ProjectElement newElement = new ProjectElement(this.node.ProjectMgr, System.IO.Path.Combine(destination, projectName), ProjectFileConstants.SubProject); newElement.SetMetadata(ProjectFileConstants.Template, fileName); ((ProjectContainerNode)this.node.ProjectMgr).RunVsTemplateWizard(newElement, false); } else { if ((String.IsNullOrEmpty(System.IO.Path.GetExtension(projectName)))) { string targetExtension = System.IO.Path.GetExtension(fileName); projectName = System.IO.Path.ChangeExtension(projectName, targetExtension); } ProjectContainerNode projectContainer = (ProjectContainerNode)this.node.ProjectMgr; newNode = projectContainer.AddNestedProjectFromTemplate(fileName, destination, projectName, null, __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_CLONEFILE); } if (newNode == null) return null; // Now that the sub project was created, get its extensibility object so we can return it object newProject = null; if (ErrorHandler.Succeeded(newNode.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out newProject))) return newProject as EnvDTE.Project; else return null; } public virtual EnvDTE.Project AddSolutionFolder(string Name) { throw new NotImplementedException(); } public virtual EnvDTE.Project Parent { get { throw new NotImplementedException(); } } public virtual bool Hidden { get { return hidden; } set { hidden = value; } } public virtual EnvDTE.DTE DTE { get { return (EnvDTE.DTE)this.node.ProjectMgr.Site.GetService(typeof(EnvDTE.DTE)); } } #endregion } } --- NEW FILE: oafolderitem.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.IO; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; using EnvDTE; namespace Microsoft.VisualStudio.Package.Automation { [ComVisible(true), CLSCompliant(false)] public class OAFolderItem : OAProjectItem<FolderNode> { #region ctors public OAFolderItem(OAProject proj, FolderNode node) : base(proj, node) { } #endregion #region overridden methods public override ProjectItems Collection { get { ProjectItems items = new OAProjectItems(this.Project, this.Node); return items; } } public override ProjectItems ProjectItems { get { return this.Collection; } } #endregion } } --- NEW FILE: oanavigableprojectitems.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; namespace Microsoft.VisualStudio.Package.Automation { /// <summary> /// This can navigate a collection object only (partial implementation of ProjectItems interface) /// </summary> [ComVisible(true), CLSCompliant(false)] public class OANavigableProjectItems : EnvDTE.ProjectItems { #region fields private OAProject project; private IList<EnvDTE.ProjectItem> items; private HierarchyNode nodeWithItems; #endregion #region properties /// <summary> /// Defines an internal list of project items /// </summary> internal IList<EnvDTE.ProjectItem> Items { get { return this.items; } } /// <summary> /// Defines a relationship to the associated project. /// </summary> internal OAProject Project { get { return this.project; } } /// <summary> /// Defines the node that contains the items /// </summary> internal HierarchyNode NodeWithItems { get { return this.nodeWithItems; } } #endregion #region ctor /// <summary> /// Constructor. /// </summary> /// <param name="proj">The associated project.</param> /// <param name="nodeWithItems">The node that defines the items.</param> public OANavigableProjectItems(OAProject proj, HierarchyNode nodeWithItems) { this.project = proj; this.nodeWithItems = nodeWithItems; this.items = this.GetListOfProjectItems(); } /// <summary> /// Constructor. /// </summary> /// <param name="proj">The associated project.</param> /// <param name="items">A list of items that will make up the items defined by this object.</param> /// <param name="nodeWithItems">The node that defines the items.</param> public OANavigableProjectItems(OAProject proj, IList<EnvDTE.ProjectItem> items, HierarchyNode nodeWithItems) { this.items = items; this.project = proj; this.nodeWithItems = nodeWithItems; } #endregion #region EnvDTE.ProjectItems /// <summary> /// Gets a value indicating the number of objects in the collection. /// </summary> public virtual int Count { get { return items.Count; } } /// <summary> /// Gets the immediate parent object of a ProjectItems collection. /// </summary> public virtual object Parent { get { return this.nodeWithItems.GetAutomationObject(); } } /// <summary> /// Gets an enumeration indicating the type of object. /// </summary> public virtual string Kind { get { // TODO: Add OAProjectItems.Kind getter implementation return null; } } /// <summary> /// Gets the top-level extensibility object. /// </summary> public virtual EnvDTE.DTE DTE { get { return (EnvDTE.DTE)this.project.DTE; } } /// <summary> /// Gets the project hosting the project item or items. /// </summary> public virtual EnvDTE.Project ContainingProject { get { return this.project; } } /// <summary> /// Adds one or more ProjectItem objects from a directory to the ProjectItems collection. /// </summary> /// <param name="directory">The directory from which to add the project item.</param> /// <returns>A ProjectItem object.</returns> public virtual EnvDTE.ProjectItem AddFromDirectory(string directory) { throw new NotImplementedException(); } /// <summary> /// Creates a new project item from an existing item template file and adds it to the project. /// </summary> /// <param name="fileName">The full path and file name of the template project file.</param> /// <param name="name">The file name to use for the new project item.</param> /// <returns>A ProjectItem object. </returns> public virtual EnvDTE.ProjectItem AddFromTemplate(string fileName, string name) { throw new NotImplementedException(); } /// <summary> /// Creates a new folder in Solution Explorer. /// </summary> /// <param name="name">The name of the folder node in Solution Explorer.</param> /// <param name="kind">The type of folder to add. The available values are based on vsProjectItemsKindConstants and vsProjectItemKindConstants</param> /// <returns>A ProjectItem object.</returns> public virtual EnvDTE.ProjectItem AddFolder(string name, string kind) { throw new NotImplementedException(); } /// <summary> /// Copies a source file and adds it to the project. /// </summary> /// <param name="filePath">The path and file name of the project item to be added.</param> /// <returns>A ProjectItem object. </returns> public virtual EnvDTE.ProjectItem AddFromFileCopy(string filePath) { throw new NotImplementedException(); } /// <summary> /// Adds a project item from a file that is installed in a project directory structure. /// </summary> /// <param name="fileName">The file name of the item to add as a project item. </param> /// <returns>A ProjectItem object. </returns> public virtual EnvDTE.ProjectItem AddFromFile(string fileName) { throw new NotImplementedException(); } /// <summary> /// Get Project Item from index /// </summary> /// <param name="index">Either index by number (1-based) or by name can be used to get the item</param> /// <returns>Project Item. null is return if invalid index is specified</returns> public virtual EnvDTE.ProjectItem Item(object index) { if (index is int) { int realIndex = (int)index - 1; if (realIndex >= 0 && realIndex < this.items.Count) { return (EnvDTE.ProjectItem)items[realIndex]; } return null; } else if (index is string) { string name = (string)index; foreach (EnvDTE.ProjectItem item in items) { if (String.Compare(item.Name, name, StringComparison.OrdinalIgnoreCase) == 0) { return item; } } } return null; } /// <summary> /// Returns an enumeration for items in a collection. /// </summary> /// <returns>An IEnumerator for this object.</returns> public virtual IEnumerator GetEnumerator() { if (this.items == null) { yield return null; } int count = items.Count; for (int i = 0; i < count; i++) { yield return items[i]; } } #endregion #region virtual methods /// <summary> /// Retrives a list of items associated with the current node. /// </summary> /// <returns>A List of project items</returns> protected IList<EnvDTE.ProjectItem> GetListOfProjectItems() { List<EnvDTE.ProjectItem> list = new List<EnvDTE.ProjectItem>(); for (HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling) { EnvDTE.ProjectItem item = child.GetAutomationObject() as EnvDTE.ProjectItem; if (null != item) { list.Add(item); } } return list; } #endregion } } --- NEW FILE: oanullproperty.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; namespace Microsoft.VisualStudio.Package.Automation { /// <summary> /// This object defines a so called null object that is returned as instead of null. This is because callers in VSCore usually crash if a null propery is returned for them. /// </summary> [CLSCompliant(false), ComVisible(true)] public class OANullProperty : EnvDTE.Property { #region fields private OAProperties parent; #endregion #region ctors public OANullProperty(OAProperties parent) { this.parent = parent; } #endregion #region EnvDTE.Property public object Application { get { return String.Empty; } } public EnvDTE.Properties Collection { get { //todo: EnvDTE.Property.Collection return this.parent; } } public EnvDTE.DTE DTE { get { return null; } } public object get_IndexedValue(object index1, object index2, object index3, object index4) { return String.Empty; } public void let_Value(object value) { //todo: let_Value } public string Name { get { return String.Empty; } } public short NumIndices { get { return 0; } } public object Object { get { return this.parent.Target; } set { } } public EnvDTE.Properties Parent { get { return this.parent; } } public void set_IndexedValue(object index1, object index2, object index3, object index4, object value) { } public object Value { get { return String.Empty; } set { } } #endregion } } --- NEW FILE: oaprojectitems.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; using EnvDTE; using System.IO; namespace Microsoft.VisualStudio.Package.Automation { /// <summary> /// This class has a full implementation of ProjectItems interface /// </summary> [ComVisible(true), CLSCompliant(false)] public class OAProjectItems : OANavigableProjectItems { #region ctor public OAProjectItems(OAProject proj, HierarchyNode nodeWithItems) : base(proj, nodeWithItems) { } #endregion #region EnvDTE.ProjectItems /// <summary> /// Creates a new project item from an existing item template file and adds it to the project. /// </summary> /// <param name="fileName">The full path and file name of the template project file.</param> /// <param name="name">The file name to use for the new project item.</param> /// <returns>A ProjectItem object. </returns> public override EnvDTE.ProjectItem AddFromTemplate(string fileName, string name) { if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed) { throw new InvalidOperationException(); } ProjectNode proj = this.Project.Project; IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } EnvDTE.ProjectItem itemAdded = null; extensibility.EnterAutomationFunction(); try { // Determine the operation based on the extension of the filename. // We should run the wizard only if the extension is vstemplate // otherwise it's a clone operation VSADDITEMOPERATION op; if (Utilities.IsTemplateFile(fileName)) { op = VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD; } else { op = VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE; } VSADDRESULT[] result = new VSADDRESULT[1]; // It is not a very good idea to throw since the AddItem might return Cancel or Abort. // The problem is that up in the call stack the wizard code does not check whether it has received a ProjectItem or not and will crash. // The other problem is that we cannot get add wizard dialog back if a cancel or abort was returned because we throw and that code will never be executed. Typical catch 22. ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, name, 0, new string[1] { fileName }, IntPtr.Zero, result)); string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems); string templateFilePath = System.IO.Path.Combine(fileDirectory, name); itemAdded = this.EvaluateAddResult(result[0], templateFilePath); } finally { extensibility.ExitAutomationFunction(); } return itemAdded; } /// <summary> /// Adds a folder to the collection of ProjectItems with the given name. /// /// The kind must be null, empty string, or the string value of vsProjectItemKindPhysicalFolder. /// Virtual folders are not supported by this implementation. /// </summary> /// <param name="name">The name of the new folder to add</param> /// <param name="kind">A string representing a Guid of the folder kind.</param> /// <returns>A ProjectItem representing the newly added folder.</returns> public override ProjectItem AddFolder(string name, string kind) { if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed) { throw new InvalidOperationException(); } //Verify name is not null or empty Utilities.ValidateFileName(this.Project.Project.Site, name); //Verify that kind is null, empty, or a physical folder if (!(string.IsNullOrEmpty(kind) || kind.Equals(EnvDTE.Constants.vsProjectItemKindPhysicalFolder))) throw new ArgumentException(); for (HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling) { if(child.Caption.Equals(name, StringComparison.InvariantCultureIgnoreCase)) throw new ArgumentException(); } ProjectNode proj = this.Project.Project; IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } HierarchyNode newFolder = null; extensibility.EnterAutomationFunction(); //In the case that we are adding a folder to a folder, we need to build up //the path to the project node. name = Path.Combine(this.NodeWithItems.VirtualNodeName, name); try { newFolder = proj.CreateFolderNodes(name); } finally { extensibility.ExitAutomationFunction(); } return newFolder.GetAutomationObject() as ProjectItem; } /// <summary> /// Copies a source file and adds it to the project. /// </summary> /// <param name="filePath">The path and file name of the project item to be added.</param> /// <returns>A ProjectItem object. </returns> public override EnvDTE.ProjectItem AddFromFileCopy(string filePath) { return this.AddItem(filePath, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE); } /// <summary> /// Adds a project item from a file that is installed in a project directory structure. /// </summary> /// <param name="fileName">The file name of the item to add as a project item. </param> /// <returns>A ProjectItem object. </returns> public override EnvDTE.ProjectItem AddFromFile(string fileName) { // TODO: VSADDITEMOP_LINKTOFILE return this.AddItem(fileName, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE); } #endregion #region helper methods /// <summary> /// Adds an item to the project. /// </summary> /// <param name="path">The full path of the item to add.</param> /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param> /// <returns>A ProjectItem object. </returns> protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op) { if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed) { throw new InvalidOperationException(); } ProjectNode proj = this.Project.Project; IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3; if (extensibility == null) { throw new InvalidOperationException(); } EnvDTE.ProjectItem itemAdded = null; extensibility.EnterAutomationFunction(); try { VSADDRESULT[] result = new VSADDRESULT[1]; ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] { path }, IntPtr.Zero, result)); string fileName = System.IO.Path.GetFileName(path); string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems); string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName); itemAdded = this.EvaluateAddResult(result[0], filePathInProject); } finally { extensibility.ExitAutomationFunction(); } return itemAdded; } /// <summary> /// Evaluates the result of an add operation. /// </summary> /// <param name="result">The <paramref name="VSADDRESULT"/> returned by the Add methods</param> /// <param name="path">The full path of the item added.</param> /// <returns>A ProjectItem object.</returns> protected virtual EnvDTE.ProjectItem EvaluateAddResult(VSADDRESULT result, string path) { if (result == VSADDRESULT.ADDRESULT_Success) { HierarchyNode nodeAdded = this.NodeWithItems.FindChild(path); Debug.Assert(nodeAdded != null, "We should have been able to find the new element in the hierarchy"); if (nodeAdded != null) { EnvDTE.ProjectItem item = null; if (nodeAdded is FileNode) { item = new OAFileItem(this.Project, nodeAdded as FileNode); } else if (nodeAdded is NestedProjectNode) { item = new OANestedProjectItem(this.Project, nodeAdded as NestedProjectNode); } else { item = new OAProjectItem<HierarchyNode>(this.Project, nodeAdded); } this.Items.Add(item); return item; } } return null; } #endregion } } --- NEW FILE: oanestedprojectitem.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; namespace Microsoft.VisualStudio.Package.Automation { [ComVisible(true), CLSCompliant(false)] public class OANestedProjectItem : OAProjectItem<NestedProjectNode> { #region fields EnvDTE.Project nestedProject = null; #endregion #region ctors public OANestedProjectItem(OAProject proj, NestedProjectNode node) : base(proj, node) { object project = null; if (ErrorHandler.Succeeded(node.NestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out project))) { this.nestedProject = project as EnvDTE.Project; } } #endregion #region overridden methods /// <summary> /// Returns the collection of project items defined in the nested project /// </summary> public override EnvDTE.ProjectItems ProjectItems { get { if (this.nestedProject != null) { return this.nestedProject.ProjectItems; } return null; } } /// <summary> /// Returns the nested project. /// </summary> public override EnvDTE.Project SubProject { get { return this.nestedProject; } } #endregion } } --- NEW FILE: oareferencefolderitem.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; namespace Microsoft.VisualStudio.Package.Automation { [ComVisible(true), CLSCompliant(false)] public class OAReferenceFolderItem : OAProjectItem<ReferenceContainerNode> { #region ctors public OAReferenceFolderItem(OAProject proj, ReferenceContainerNode node) : base(proj, node) { } #endregion #region overridden methods /// <summary> /// Returns the project items collection of all the references defined for this project. /// </summary> public override EnvDTE.ProjectItems ProjectItems { get { return new OANavigableProjectItems(this.Project, this.GetListOfProjectItems(), this.Node); } } #endregion #region Helper methods private List<EnvDTE.ProjectItem> GetListOfProjectItems() { List<EnvDTE.ProjectItem> list = new List<EnvDTE.ProjectItem>(); for (HierarchyNode child = this.Node.FirstChild; child != null; child = child.NextSibling) { if (child is ReferenceNode) { list.Add(new OAReferenceItem(this.Project, child as ReferenceNode)); } } return list; } #endregion } } --- NEW FILE: oaproperty.cs --- /*************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. This code is licensed under the Visual Studio SDK license terms. THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. ***************************************************************************/ using System; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Collections; using System.Diagnostics; using System.Runtime.Serialization; using System.Reflection; using IServiceProvider = System.IServiceProvider; using Microsoft.VisualStudio.OLE.Interop; using EnvDTE; namespace Microsoft.VisualStudio.Package.Automation { [CLSCompliant(false), ComVisible(true)] public class OAProperty : EnvDTE.Property { #region fields private OAProperties parent; private PropertyInfo pi; #endregion #region ctors public OAProperty(OAProperties parent, PropertyInfo pi) { this.parent = parent; this.pi = pi; } #endregion #region EnvDTE.Property /// <summary> /// Microsoft Internal Use Only. /// </summary> public object Application { get { return null; } } /// <summary> /// Gets the Collection containing the Property object supporting this property. /// </summary> public EnvDTE.Properties Collection { get { //todo: EnvDTE.Property.Collection return this.parent; } } /// <summary> /// Gets the top-level extensibility object. /// </summary> public EnvDTE.DTE DTE { get { return this.parent.DTE; } } /// <summary> /// Returns one element of a list. /// </summary> /// <param name="index1">The index of the item to display.</param> /// <param name="index2">The index of the item to display. Reserved for future use.</param> /// <param name="index3">The index of the item to display. Reserved for future use.</param> /// <param name="index4">The index of the item to display. Reserved for future use.</param> /// <returns>The value of a property</returns> public object get_IndexedValue(object index1, object index2, object index3, object index4) { ParameterInfo[] par = pi.GetIndexParameters(); int len = Math.Min(par.Length, 4); if (len == 0) return this.Value; object[] index = new object[len]; Array.Copy(new object[4] { index1, index2, index3, index4 }, index, len); return this.pi.GetValue(this.parent.Target, index); } /// <summary> /// Setter function to set properties values. /// </summary> /// <param name="value"></param> public void let_Value(object value) { this.Value = value; } /// <summary> /// Gets the name of the object. /// </summary> public string Name ... [truncated message content] |