本文整理汇总了C#中HierarchyNode.GetMkDocument方法的典型用法代码示例。如果您正苦于以下问题:C# HierarchyNode.GetMkDocument方法的具体用法?C# HierarchyNode.GetMkDocument怎么用?C# HierarchyNode.GetMkDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HierarchyNode
的用法示例。
在下文中一共展示了HierarchyNode.GetMkDocument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFolderFromOtherProject
/// <summary>
/// This is used to recursively add a folder from an other project.
/// Note that while we copy the folder content completely, we only
/// add to the project items which are part of the source project.
/// </summary>
/// <param name="folderToAdd">Project reference (from data object) using the format: {Guid}|project|folderPath</param>
/// <param name="targetNode">Node to add the new folder to</param>
protected internal virtual bool AddFolderFromOtherProject(string folderToAdd, HierarchyNode targetNode, bool drop)
{
Utilities.ArgumentNotNullOrEmpty(folderToAdd, "folderToAdd");
Utilities.ArgumentNotNull("targetNode", targetNode);
var targetFolderNode = targetNode.GetDragTargetHandlerNode();
// Split the reference in its 3 parts
int index1 = Guid.Empty.ToString("B").Length;
if (index1 + 1 >= folderToAdd.Length)
throw new ArgumentOutOfRangeException("folderToAdd");
// Get the Guid
string guidString = folderToAdd.Substring(1, index1 - 2);
Guid projectInstanceGuid = new Guid(guidString);
// Get the project path
int index2 = folderToAdd.IndexOf('|', index1 + 1);
if (index2 < 0 || index2 + 1 >= folderToAdd.Length)
throw new ArgumentOutOfRangeException("folderToAdd");
// Finally get the source path
string folder = folderToAdd.Substring(index2 + 1);
// Get the target path
string folderName = Path.GetFileName(Path.GetDirectoryName(folder));
string targetPath = Path.Combine(GetBaseDirectoryForAddingFiles(targetFolderNode), folderName);
// Retrieve the project from which the items are being copied
IVsHierarchy sourceHierarchy;
IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution));
ErrorHandler.ThrowOnFailure(solution.GetProjectOfGuid(ref projectInstanceGuid, out sourceHierarchy));
// Then retrieve the item ID of the item to copy
uint itemID = VSConstants.VSITEMID_ROOT;
ErrorHandler.ThrowOnFailure(sourceHierarchy.ParseCanonicalName(folder, out itemID));
string name = folderName;
// Ensure we don't end up in an endless recursion
if (Utilities.IsSameComObject(this, sourceHierarchy))
{
// copy file onto its self, we should make a copy of the folder
if (String.Equals(folder, targetNode.GetMkDocument(), StringComparison.OrdinalIgnoreCase))
{
if (drop)
{
// cancelled drag and drop
return false;
}
string newDir;
string baseName = folder;
folder = CommonUtils.TrimEndSeparator(folder);
int copyCount = 0;
do
{
name = folderName + " - Copy";
if (copyCount != 0)
{
name += " (" + copyCount + ")";
}
copyCount++;
newDir = Path.Combine(Path.GetDirectoryName(folder), name);
} while (Directory.Exists(newDir));
targetPath = newDir;
targetFolderNode = targetNode.Parent;
}
else
{
HierarchyNode cursorNode = targetFolderNode;
while (cursorNode != null)
{
if (String.Equals(folder, cursorNode.GetMkDocument(), StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(String.Format("Cannot copy '{0}'. The destination folder is a subfolder of the source folder.", folderName));
}
cursorNode = cursorNode.Parent;
}
}
}
// Recursively copy the directory to the new location
Utilities.RecursivelyCopyDirectory(folder, targetPath);
// Now walk the source project hierarchy to see which node needs to be added.
WalkSourceProjectAndAdd(sourceHierarchy, itemID, targetFolderNode, false, name);
return true;
}