本文整理汇总了C#中FileNode.GetMkDocument方法的典型用法代码示例。如果您正苦于以下问题:C# FileNode.GetMkDocument方法的具体用法?C# FileNode.GetMkDocument怎么用?C# FileNode.GetMkDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileNode
的用法示例。
在下文中一共展示了FileNode.GetMkDocument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeGenerator
/// <summary>
/// Invokes the specified generator
/// </summary>
/// <param name="fileNode">The node on which to invoke the generator.</param>
/*protected internal, but public for FSharp.Project.dll*/
public virtual void InvokeGenerator(FileNode fileNode)
{
if (fileNode == null)
{
throw new ArgumentNullException("node");
}
SingleFileGeneratorNodeProperties nodeproperties = fileNode.NodeProperties as SingleFileGeneratorNodeProperties;
if (nodeproperties == null)
{
throw new InvalidOperationException();
}
string customToolProgID = nodeproperties.CustomTool;
if (string.IsNullOrEmpty(customToolProgID))
{
return;
}
string customToolNamespace = nodeproperties.CustomToolNamespace;
try
{
if (!this.runningGenerator)
{
//Get the buffer contents for the current node
string moniker = fileNode.GetMkDocument();
this.runningGenerator = true;
//Get the generator
IVsSingleFileGenerator generator;
int generateDesignTimeSource;
int generateSharedDesignTimeSource;
int generateTempPE;
SingleFileGeneratorFactory factory = new SingleFileGeneratorFactory(this.projectMgr.ProjectGuid, this.projectMgr.Site);
ErrorHandler.ThrowOnFailure(factory.CreateGeneratorInstance(customToolProgID, out generateDesignTimeSource, out generateSharedDesignTimeSource, out generateTempPE, out generator));
//Check to see if the generator supports siting
IObjectWithSite objWithSite = generator as IObjectWithSite;
if (objWithSite != null)
{
objWithSite.SetSite(fileNode.OleServiceProvider);
}
//Determine the namespace
if (string.IsNullOrEmpty(customToolNamespace))
{
customToolNamespace = this.ComputeNamespace(moniker);
}
//Run the generator
IntPtr[] output = new IntPtr[1];
output[0] = IntPtr.Zero;
uint outPutSize;
string extension;
ErrorHandler.ThrowOnFailure(generator.DefaultExtension(out extension));
//Find if any dependent node exists
string dependentNodeName = Path.GetFileNameWithoutExtension(fileNode.FileName) + extension;
HierarchyNode dependentNode = fileNode.FirstChild;
while (dependentNode != null)
{
if (string.Compare(dependentNode.ItemNode.GetMetadata(ProjectFileConstants.DependentUpon), fileNode.FileName, StringComparison.OrdinalIgnoreCase) == 0)
{
dependentNodeName = ((FileNode)dependentNode).FileName;
break;
}
dependentNode = dependentNode.NextSibling;
}
//If you found a dependent node.
if (dependentNode != null)
{
//Then check out the node and dependent node from SCC
if (!this.CanEditFile(dependentNode.GetMkDocument()))
{
throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
}
}
else //It is a new node to be added to the project
{
// Check out the project file if necessary.
if (!this.projectMgr.QueryEditProjectFile(false))
{
throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
}
}
IVsTextStream stream;
string inputFileContents = this.GetBufferContents(moniker, out stream);
ErrorHandler.ThrowOnFailure(generator.Generate(moniker, inputFileContents, customToolNamespace, output, out outPutSize, this));
byte[] data = new byte[outPutSize];
//.........这里部分代码省略.........
示例2: UpdateGeneratedCodeFile
/// <summary>
/// This is called after the single file generator has been invoked to create or update the code file.
/// </summary>
/// <param name="fileNode">The node associated to the generator</param>
/// <param name="data">data to update the file with</param>
/// <param name="size">size of the data</param>
/// <param name="fileName">Name of the file to update or create</param>
/// <returns>full path of the file</returns>
/*protected, but public for FSharp.Project.dll*/
public virtual string UpdateGeneratedCodeFile(FileNode fileNode, byte[] data, int size, string fileName)
{
string filePath = Path.Combine(Path.GetDirectoryName(fileNode.GetMkDocument()), fileName);
IVsRunningDocumentTable rdt = this.projectMgr.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
// (kberes) Shouldn't this be an InvalidOperationException instead with some not to annoying errormessage to the user?
if (rdt == null)
{
ErrorHandler.ThrowOnFailure(VSConstants.E_FAIL);
}
IVsHierarchy hier;
uint cookie;
uint itemid;
IntPtr docData = IntPtr.Zero;
try
{
ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)(_VSRDTFLAGS.RDT_NoLock), filePath, out hier, out itemid, out docData, out cookie));
}
catch (Exception)
{
if (docData != IntPtr.Zero) Marshal.Release(docData);
throw;
}
if (docData != IntPtr.Zero)
{
Marshal.Release(docData);
IVsTextStream srpStream;
string inputFileContents = this.GetBufferContents(filePath, out srpStream);
if (srpStream != null)
{
int oldLen = 0;
int hr = srpStream.GetSize(out oldLen);
if (ErrorHandler.Succeeded(hr))
{
IntPtr dest = IntPtr.Zero;
try
{
dest = Marshal.AllocCoTaskMem(data.Length);
Marshal.Copy(data, 0, dest, data.Length);
ErrorHandler.ThrowOnFailure(srpStream.ReplaceStream(0, oldLen, dest, size / 2));
}
finally
{
if (dest != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(dest);
}
}
}
}
}
else
{
using (FileStream generatedFileStream = File.Open(filePath, FileMode.OpenOrCreate))
{
generatedFileStream.Write(data, 0, size);
}
EnvDTE.ProjectItem projectItem = fileNode.GetAutomationObject() as EnvDTE.ProjectItem;
if (projectItem != null && (this.projectMgr.FindChild(fileNode.FileName) == null))
{
projectItem.ProjectItems.AddFromFile(filePath);
}
}
return filePath;
}