protected virtual void LockRdtEntry()
{
// Define flags for the nested project document
_VSRDTFLAGS flags = _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_ProjSlnDocument; ;
// Request the RDT service
IVsRunningDocumentTable rdt = this.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;
IntPtr docData = IntPtr.Zero;
IVsHierarchy ivsHierarchy;
uint docCookie;
IntPtr projectPtr = IntPtr.Zero;
try
{
ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)flags, this.ProjectPath, out ivsHierarchy, out itemid, out docData, out docCookie));
flags |= _VSRDTFLAGS.RDT_EditLock;
if (ivsHierarchy != null && docCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL)
{
if (docCookie != this.DocCookie)
{
this.DocCookie = docCookie;
}
}
else
{
// get inptr for hierarchy
projectPtr = Marshal.GetIUnknownForObject(this.nestedHierarchy);
Debug.Assert(projectPtr != IntPtr.Zero, " Project pointer for the nested hierarchy has not been initialized");
ErrorHandler.ThrowOnFailure(rdt.RegisterAndLockDocument((uint)flags, this.ProjectPath, this.ProjectManager.InteropSafeIVsHierarchy, this.Id, projectPtr, out docCookie));
this.DocCookie = docCookie;
Debug.Assert(this.DocCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL, "Invalid cookie when registering document in the running document table.");
//we must also set the doc cookie on the nested hier
this.SetDocCookieOnNestedHier(this.DocCookie);
}
}
finally
{
// Release all IntPtr's that were given as out pointers
if (docData != IntPtr.Zero)
{
Marshal.Release(docData);
}
if (projectPtr != IntPtr.Zero)
{
Marshal.Release(projectPtr);
}
}
}