using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Specialized;
using Microsoft.VisualStudio.Shell.Interop;
namespace AnticipatingMinds.VisualStudioServices{
/// <summary>
/// Summary description for VsProject.
/// </summary>
public class VsProject : VsHierarchy
{
public VsProject(IVsProject vsProject,IServiceProvider site):base(vsProject as IVsHierarchy,site)
{
this.enumHierarchyItemsFactory = enumHierarchyItemsFactory;
this.vsProject = vsProject;
}
public string FileName
{
get
{
string fileName;
vsProject.GetMkDocument(VsHierarchy.VSITEMID_ROOT,out fileName);
return fileName;
}
}
public VsProject[] GetSubProjects()
{
Hashtable projectFileNames = new Hashtable();
VSITEMSELECTION[] items = GetItems(VSEHI.VSEHI_Branch | VSEHI.VSEHI_Nest);
foreach(VSITEMSELECTION item in items)
{
if(item.itemid == VSITEMID_ROOT && (item.pHier as IVsProject) != null)
{
string projectFileName;
IVsProject project = item.pHier as IVsProject;
project.GetMkDocument(VSITEMID_ROOT,out projectFileName);
if(!projectFileNames.Contains(projectFileName))
projectFileNames[projectFileName] = new VsProject(project,Site);
}
}
VsProject[] projects = new VsProject[projectFileNames.Count];
projectFileNames.Values.CopyTo(projects,0);
return projects;
}
public StringCollection GetReferences()
{
StringCollection projectReferences = new StringCollection();
VSITEMSELECTION[] items = GetItems(VSEHI.VSEHI_Leaf | VSEHI.VSEHI_Nest);
IVsHierarchy projectHierarchy = (vsProject as IVsHierarchy);
foreach(VSITEMSELECTION item in items)
{
if(item.itemid != VSITEMID_ROOT)
{
object value;
(vsProject as IVsHierarchy).GetProperty(item.itemid,(int)__VSHPROPID.VSHPROPID_ExtObject,out value);
VSLangProj.Reference reference = value as VSLangProj.Reference;
if(reference != null && reference.Path != null && reference.Path.Length != 0)
projectReferences.Add(reference.Path);
}
}
return projectReferences;
}
public StringCollection GetFiles()
{
StringCollection projectFiles = new StringCollection();
VSITEMSELECTION[] items = GetItems(VSEHI.VSEHI_Leaf | VSEHI.VSEHI_Nest);
IVsHierarchy projectHierarchy = (vsProject as IVsHierarchy);
foreach(VSITEMSELECTION item in items)
{
if(item.itemid != VSITEMID_ROOT)
{
Guid typeGuid;
projectHierarchy.GetGuidProperty(item.itemid,(int)__VSHPROPID.VSHPROPID_TypeGuid,out typeGuid);
if(typeGuid != GUID_ItemType_PhysicalFile)
continue;
object value;
EnvDTE.ProjectItem projectItem;
projectHierarchy.GetProperty(item.itemid,(int) __VSHPROPID.VSHPROPID_ExtObject,out value);
projectItem = value as EnvDTE.ProjectItem;
if(projectItem.FileCount != 0)
projectFiles.Add(projectItem.get_FileNames(1));
}
}
return projectFiles;
}
public EnvDTE.Project Project
{
get
{
object value;
(vsProject as IVsHierarchy).GetProperty(VSITEMID_ROOT,(int)__VSHPROPID.VSHPROPID_ExtObject,out value);
return value as EnvDTE.Project;
}
}
private IVsProject vsProject;
private IVsEnumHierarchyItemsFactory enumHierarchyItemsFactory;
}
}
|