本文整理汇总了C#中IVsHierarchy.GetCanonicalName方法的典型用法代码示例。如果您正苦于以下问题:C# IVsHierarchy.GetCanonicalName方法的具体用法?C# IVsHierarchy.GetCanonicalName怎么用?C# IVsHierarchy.GetCanonicalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsHierarchy
的用法示例。
在下文中一共展示了IVsHierarchy.GetCanonicalName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCanonicalName
public static string GetCanonicalName(uint itemId, IVsHierarchy hierarchy)
{
string strRet = string.Empty;
int hr = hierarchy.GetCanonicalName(itemId, out strRet);
if (hr == VSConstants.E_NOTIMPL)
{
// Special case E_NOTIMLP to avoid perf hit to throw an exception.
return string.Empty;
}
else
{
try
{
ErrorHandler.ThrowOnFailure(hr);
}
catch (System.Runtime.InteropServices.COMException)
{
strRet = string.Empty;
}
// This could be in the case of S_OK, S_FALSE, etc.
return strRet;
}
}
示例2: GetCanonicalName
/// <summary>
/// Get the canonical name
/// </summary>
private static string GetCanonicalName(uint itemId, IVsHierarchy hierarchy) {
Debug.Assert(itemId != VSConstants.VSITEMID_NIL, "ItemId cannot be nill");
string strRet = string.Empty;
if (ErrorHandler.Failed(hierarchy.GetCanonicalName(itemId, out strRet))) {
return string.Empty;
}
return strRet;
}
示例3: GetFileNameFromHierarchy
public static string GetFileNameFromHierarchy(IVsHierarchy hierarchy)
{
string fileName;
var itemId = GetItemId(hierarchy);
hierarchy.GetCanonicalName(itemId, out fileName);
return fileName;
}
示例4: CollapseHierarchyItems
private void CollapseHierarchyItems(IVsUIHierarchyWindow toolWindow, IVsHierarchy hierarchy, uint itemid, bool hierIsSolution
, string[] captions)
{
IntPtr ptr;
uint num2;
Guid gUID = typeof(IVsHierarchy).GUID;
if ((hierarchy.GetNestedHierarchy(itemid, ref gUID, out ptr, out num2) == 0) && (IntPtr.Zero != ptr))
{
IVsHierarchy objectForIUnknown = Marshal.GetObjectForIUnknown(ptr) as IVsHierarchy;
Marshal.Release(ptr);
if (objectForIUnknown != null)
{
this.CollapseHierarchyItems(toolWindow, objectForIUnknown, num2, false, captions);
}
}
else
{
object obj2;
if (!hierIsSolution)
{
string canonicalname;
object captionobj;
hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Caption, out captionobj);
var caption = (string)captionobj;
if (captions.Contains(caption))
{
hierarchy.GetCanonicalName(itemid, out canonicalname);
ErrorHandler.ThrowOnFailure(toolWindow.ExpandItem(hierarchy as IVsUIHierarchy, itemid, EXPANDFLAGS.EXPF_CollapseFolder));
}
}
if (hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out obj2) == 0)
{
uint itemId = this.GetItemId(obj2);
while (itemId != uint.MaxValue)
{
this.CollapseHierarchyItems(toolWindow, hierarchy, itemId, false, captions);
int hr = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out obj2);
if (hr == 0)
{
itemId = this.GetItemId(obj2);
}
else
{
ErrorHandler.ThrowOnFailure(hr);
return;
}
}
}
}
}
示例5: TryGetFileName
public static bool TryGetFileName(IVsHierarchy hierarchy, uint itemID, out string fileName)
{
if (hierarchy != null)
{
string value;
if (ErrorHandler.Succeeded(hierarchy.GetCanonicalName(itemID, out value)))
{
fileName = value;
return true;
}
}
fileName = null;
return false;
}
示例6: SqlEditorPane
int IVsEditorFactory.CreateEditorInstance(uint grfCreateDoc, string pszMkDocument,
string pszPhysicalView, IVsHierarchy pvHier, uint itemid,
IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData,
out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW)
{
string s;
pvHier.GetCanonicalName(itemid, out s);
pgrfCDW = 0;
LastDocumentPath = pszMkDocument;
pguidCmdUI = VSConstants.GUID_TextEditorFactory;
SqlEditorPane editor = new SqlEditorPane(serviceProvider, this);
ppunkDocData = Marshal.GetIUnknownForObject(editor.Window);
ppunkDocView = Marshal.GetIUnknownForObject(editor);
pbstrEditorCaption = "";
return VSConstants.S_OK;
}
示例7: GetProjectFileName
private string GetProjectFileName(IVsHierarchy hierHierarchy)
{
if (!(hierHierarchy is IVsSccProject2)) return GetSolutionFileName();
var files = GetNodeFiles(hierHierarchy as IVsSccProject2, VSConstants.VSITEMID_ROOT);
string fileName = files.Count <= 0 ? null : files[0];
//try hierHierarchy.GetCanonicalName to get project name for web site
if (fileName == null)
{
if (hierHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out fileName) != VSConstants.S_OK) return null;
return GetCaseSensitiveFileName(fileName);
}
return fileName;
}
示例8: DetermineProjectFileInformation
/// <summary>
/// This is used to determine project and file information for a hierarchy node
/// </summary>
/// <param name="hierarchy">The hierarchy node to examine</param>
/// <param name="itemId">The item ID</param>
/// <remarks>This filters out the root solution node, project nodes, folder nodes, and any other
/// unrecognized nodes.</remarks>
private static SpellCheckFileInfo DetermineProjectFileInformation(IVsHierarchy hierarchy, uint itemId)
{
int result;
object value;
string projectName = "", name, canonicalName;
var project = hierarchy as IVsProject;
if(project != null)
{
result = project.GetMkDocument(VSConstants.VSITEMID_ROOT, out projectName);
// If there is no project name, it's probably a solution item
if(result != VSConstants.S_OK)
projectName = "Solution Items";
else
if(projectName.Length > 1 && projectName[projectName.Length - 1] == '\\')
projectName += Path.GetFileName(projectName.Substring(0, projectName.Length - 1));
result = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_Name, out value);
if(result == VSConstants.S_OK && value != null)
{
name = value.ToString();
result = hierarchy.GetCanonicalName(itemId, out canonicalName);
if(result == VSConstants.S_OK && !String.IsNullOrWhiteSpace(canonicalName) &&
canonicalName.IndexOfAny(Path.GetInvalidPathChars()) == -1 &&
Path.IsPathRooted(canonicalName) && !canonicalName.EndsWith("\\", StringComparison.Ordinal) &&
!canonicalName.Equals(projectName, StringComparison.OrdinalIgnoreCase))
{
return new SpellCheckFileInfo
{
ProjectFile = projectName,
Filename = name,
CanonicalName = canonicalName
};
}
}
}
return null;
}
示例9: GetSccFiles
//[CLSCompliant(false)]
public static bool GetSccFiles(IVsHierarchy hierarchy, IVsSccProject2 sccProject, uint id, out string[] files, out int[] flags, bool includeNoScc, IDictionary<string, uint> map)
{
if (hierarchy == null)
throw new ArgumentNullException("hierarchy");
int hr;
bool ok = false;
files = null;
flags = null;
try
{
if (sccProject != null)
{
CALPOLESTR[] str = new CALPOLESTR[1];
CADWORD[] dw = new CADWORD[1];
if (ErrorHandler.Succeeded(hr = sccProject.GetSccFiles(id, str, dw)))
{
files = GetFileNamesFromOleBuffer(str, true);
flags = GetFlagsFromOleBuffer(dw, true);
if (!includeNoScc || files.Length > 0)
return ok = true; // We have a result
else
ok = true; // Try the GetMkDocument route to find an alternative
}
else if (hr != VSConstants.E_NOTIMPL)
return false; //
}
// If sccProject2.GetSccFiles() returns E_NOTIMPL we must try GetMkDocument
// We also try this if the item does not implement IVsSccProject2
IVsProject project = hierarchy as IVsProject;
if (project != null)
{
string mkDocument;
if (ErrorHandler.Succeeded(project.GetMkDocument(id, out mkDocument)))
{
if (!IsValidPath(mkDocument))
files = new string[0];
else
files = new string[] { mkDocument };
return true;
}
return ok; // No need to check our interface for projects
}
if (hierarchy is IVsSolution)
{
return ok; // Will fail in GetCanonicalName in VS2008 SP1 Beta 1
}
string name;
try
{
if (ErrorHandler.Succeeded(hierarchy.GetCanonicalName(id, out name)))
{
if (IsValidPath(name, true))
{
files = new string[] { name };
return true;
}
}
}
catch { } // Ok, this seems to error in some managed tree implementations like TFS :(
return ok;
}
finally
{
if (ok && map != null && files != null)
{
foreach (string file in files)
map[file] = id;
}
}
}
示例10: GetFileName
private string GetFileName(IVsHierarchy hierHierarchy, uint itemidNode)
{
if (itemidNode == VSConstants.VSITEMID_ROOT)
{
if (hierHierarchy == null)
return GetSolutionFileName();
else
return GetProjectFileName(hierHierarchy);
}
else
{
string fileName = null;
if (hierHierarchy.GetCanonicalName(itemidNode, out fileName) != VSConstants.S_OK) return null;
return GetCaseSensitiveFileName(fileName);
}
}
示例11: UpdateServiceDefinition
/// <summary>
/// Updates the ServiceDefinition.csdef file in
/// <paramref name="project"/> to include the default startup and
/// runtime tasks for Python projects.
/// </summary>
/// <param name="project">
/// The Cloud Service project to update.
/// </param>
/// <param name="roleType">
/// The type of role being added, either "Web" or "Worker".
/// </param>
/// <param name="projectName">
/// The name of the role. This typically matches the Caption property.
/// </param>
/// <param name="site">
/// VS service provider.
/// </param>
internal static void UpdateServiceDefinition(
IVsHierarchy project,
string roleType,
string projectName,
System.IServiceProvider site
) {
Utilities.ArgumentNotNull("project", project);
object obj;
ErrorHandler.ThrowOnFailure(project.GetProperty(
(uint)VSConstants.VSITEMID.Root,
(int)__VSHPROPID.VSHPROPID_FirstChild,
out obj
));
uint id;
while (TryGetItemId(obj, out id)) {
Guid itemType;
string mkDoc;
if (ErrorHandler.Succeeded(project.GetGuidProperty(id, (int)__VSHPROPID.VSHPROPID_TypeGuid, out itemType)) &&
itemType == VSConstants.GUID_ItemType_PhysicalFile &&
ErrorHandler.Succeeded(project.GetProperty(id, (int)__VSHPROPID.VSHPROPID_Name, out obj)) &&
"ServiceDefinition.csdef".Equals(obj as string, StringComparison.InvariantCultureIgnoreCase) &&
ErrorHandler.Succeeded(project.GetCanonicalName(id, out mkDoc)) &&
!string.IsNullOrEmpty(mkDoc)
) {
// We have found the file
var rdt = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
IVsHierarchy docHier;
uint docId, docCookie;
IntPtr pDocData;
bool updateFileOnDisk = true;
if (ErrorHandler.Succeeded(rdt.FindAndLockDocument(
(uint)_VSRDTFLAGS.RDT_EditLock,
mkDoc,
out docHier,
out docId,
out pDocData,
out docCookie
))) {
try {
if (pDocData != IntPtr.Zero) {
try {
// File is open, so edit it through the document
UpdateServiceDefinition(
Marshal.GetObjectForIUnknown(pDocData) as IVsTextLines,
roleType,
projectName
);
ErrorHandler.ThrowOnFailure(rdt.SaveDocuments(
(uint)__VSRDTSAVEOPTIONS.RDTSAVEOPT_ForceSave,
docHier,
docId,
docCookie
));
updateFileOnDisk = false;
} catch (ArgumentException) {
} catch (InvalidOperationException) {
} catch (COMException) {
} finally {
Marshal.Release(pDocData);
}
}
} finally {
ErrorHandler.ThrowOnFailure(rdt.UnlockDocument(
(uint)_VSRDTFLAGS.RDT_Unlock_SaveIfDirty | (uint)_VSRDTFLAGS.RDT_RequestUnlock,
docCookie
));
}
}
if (updateFileOnDisk) {
// File is not open, so edit it on disk
FileStream stream = null;
try {
UpdateServiceDefinition(mkDoc, roleType, projectName);
} finally {
//.........这里部分代码省略.........
示例12: GetFileName
private async Task<string> GetFileName(IVsHierarchy hierHierarchy, uint itemidNode)
{
if (itemidNode == VSConstants.VSITEMID_ROOT)
{
if (hierHierarchy == null)
return await GetSolutionFileName();
else
return await GetProjectFileName(hierHierarchy);
}
else
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
string fileName = null;
if (hierHierarchy.GetCanonicalName(itemidNode, out fileName) != VSConstants.S_OK) return null;
return GetCaseSensitiveFileName(fileName);
}
}
示例13: GetCurrentSelectionGraphNode
int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
{
SelectedGraphNode = GetCurrentSelectionGraphNode(pSCNew);
SelectedFileName = null;
if (pHierNew != null)
{
string itemName;
pHierNew.GetCanonicalName(itemidNew, out itemName);
if (itemName != null)
SelectedFileName = itemName.ToString();
}
return VSConstants.S_OK;
}
示例14: GetProjectReferenceOnNodeForHierarchy
private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList<ReferenceNode> references,
IVsHierarchy inputHierarchy)
{
if (references == null)
{
return null;
}
Guid projectGuid;
ErrorHandler.ThrowOnFailure(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
(int) __VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid));
string canonicalName;
ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));
foreach (var refNode in references)
{
var projRefNode = refNode as ProjectReferenceNode;
if (projRefNode != null)
{
if (projRefNode.ReferencedProjectGuid == projectGuid)
{
return projRefNode;
}
// Try with canonical names, if the project that is removed is an unloaded project than the above criteria will not pass.
if (!string.IsNullOrEmpty(projRefNode.Url) &&
NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
{
return projRefNode;
}
}
}
return null;
}
示例15: ProcessSolutionNode
/// <summary>
/// This function diplays the name of the Hierarchy node. This function is passed to the
/// Hierarchy enumeration routines to process the current node.
/// </summary>
/// <param name="hierarchy">Hierarchy of the current node</param>
/// <param name="itemid">Itemid of the current node</param>
/// <param name="recursionLevel">Depth of recursion in hierarchy enumeration. We add one tab
/// for each level in the recursion.</param>
private void ProcessSolutionNode(IVsHierarchy hierarchy, uint itemid, int recursionLevel)
{
int hr;
// get name
object objName;
hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Name, out objName);
if (recursionLevel == 0) traversalState.CurrentSolutionName = (string)objName;
if (recursionLevel == 1) traversalState.CurrentProjectName = (string)objName;
// skip non-member items (dependencies, files not referenced by the solution)
object objIsNonMember;
hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out objIsNonMember);
if (objIsNonMember != null)
if ((bool)objIsNonMember)
return;
SolutionFile sr = new SolutionFile();
sr.Name = (string)objName;
sr.Project = traversalState.CurrentProjectName;
sr.ItemId = itemid;
// get canonical filename and last write time
if (recursionLevel > 0 && itemid != VSConstants.VSITEMID_NIL && itemid != VSConstants.VSITEMID_ROOT)
{
try
{
string filePath = "";
if (hierarchy.GetCanonicalName(itemid, out filePath) == VSConstants.S_OK)
{
if (!string.IsNullOrEmpty(filePath) && System.IO.Path.IsPathRooted(filePath))
{
if (File.Exists(filePath))
{
sr.FilePath = filePath;
sr.LastWriteTime = File.GetLastWriteTime(filePath);
}
}
}
}
catch (ArgumentException) { }
catch (System.Reflection.TargetInvocationException) { }
catch (Exception) { }
}
// Exclude empty names and paths (also non-existent files).
if (string.IsNullOrEmpty(sr.Name) || string.IsNullOrEmpty(sr.FilePath))
return;
// Exclude canonical names that appear to be directories
if (sr.FilePath.EndsWith("\\") || sr.FilePath.EndsWith("/"))
return;
// get icon
object objIconIndex;
hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IconIndex, out objIconIndex);
if (objIconIndex != null) sr.IconIndex = (int)objIconIndex;
// TODO: look how to obtain item's icons for display in the list view
// -> http://connect.microsoft.com/VisualStudio/feedback/details/520256/cannot-find-icon-for-vs2010-database-project
solutionFiles.Add(sr);
}