src/Misc/EFTools/DesignXmlCore/Common/RdtManager.cs
/// <summary>
///     Get IVsTextLines from a file.  If that file is in RDT, get text buffer from it.
///     If the file is not in RDT, open that file in invisible editor and get text buffer
///     from it.
///     If failed to get text buffer, it will return null.
/// </summary>
/// <remarks>
///     This method created for refactoring usage, refactoring will work on all kinds of
///     docdata, not only SqlEditorDocData.  If change this method, please get let LiangZ
///     know.
/// </remarks>
/// <param name="fullPathFileName">File name with full path.</param>
/// <returns>Text buffer for that file.</returns>
Get IVsTextLines from a file.  If that file is in RDT, get text buffer from it.
If the file is not in RDT, open that file in invisible editor and get text buffer
from it.
If failed to get text buffer, it will return null.
Get IVsTextLines from a file . If that file is in RDT get text buffer from it . If the file is not in RDT open that file in invisible editor and get text buffer from it . If failed to get text buffer it will return null .
public VsTextMgr.IVsTextLines GetTextLines(string fullPathFileName)
        {
            VsTextMgr.IVsTextLines textLines = null;
            var rdt = Instance.GetRunningDocumentTable();
            if (rdt != null)
            {
                VsShell.IVsHierarchy ppHier;
                uint pitemid, pdwCookie;
                var ppunkDocData = IntPtr.Zero;
                try
                {
                    NativeMethods.ThrowOnFailure(
                        FindAndLockDocument(
                            (uint)(VsShell._VSRDTFLAGS.RDT_NoLock),
                            fullPathFileName,
                            out ppHier,
                            out pitemid,
                            out ppunkDocData,
                            out pdwCookie));
                    if (pdwCookie != 0)
                    {
                        if (ppunkDocData != IntPtr.Zero)
                        {
                            try
                            {
                                textLines = Marshal.GetObjectForIUnknown(ppunkDocData) as VsTextMgr.IVsTextLines;
                            }
                            catch (ArgumentException)
                            {
                            }
                        }
                    }
                    else
                    {
                        VsShell.IVsInvisibleEditor invisibleEditor = null;
                        try
                        {
                            TryGetTextLinesAndInvisibleEditor(fullPathFileName, out invisibleEditor, out textLines);
                        }
                        finally
                        {
                            if (invisibleEditor != null)
                            {
                                Marshal.ReleaseComObject(invisibleEditor);
                            }
                        }
                    }
                }
                finally
                {
                    if (ppunkDocData != IntPtr.Zero)
                    {
                        Marshal.Release(ppunkDocData);
                    }
                }
            }
            return textLines;
        }
public VsTextMgr . IVsTextLines GetTextLines ( string fullPathFileName ) { VsTextMgr . IVsTextLines textLines = null ; var rdt = Instance . GetRunningDocumentTable ( ) ; if ( rdt != null ) { VsShell . IVsHierarchy ppHier ; uint pitemid , pdwCookie ; var ppunkDocData = IntPtr . Zero ; try { NativeMethods . ThrowOnFailure ( FindAndLockDocument ( ( uint ) ( VsShell . _VSRDTFLAGS . RDT_NoLock ) , fullPathFileName , out ppHier , out pitemid , out ppunkDocData , out pdwCookie ) ) ; if ( pdwCookie != 0 ) { if ( ppunkDocData != IntPtr . Zero ) { try { textLines = Marshal . GetObjectForIUnknown ( ppunkDocData ) as VsTextMgr . IVsTextLines ; } catch ( ArgumentException ) { } } } else { VsShell . IVsInvisibleEditor invisibleEditor = null ; try { TryGetTextLinesAndInvisibleEditor ( fullPathFileName , out invisibleEditor , out textLines ) ; } finally { if ( invisibleEditor != null ) { Marshal . ReleaseComObject ( invisibleEditor ) ; } } } } finally { if ( ppunkDocData != IntPtr . Zero ) { Marshal . Release ( ppunkDocData ) ; } } } return textLines ; }
Get IVsTextLines from a file.
Get IVsTextLines from a file .
// Get text lines from the doc data // Do nothing here, it will return null stream at the end. // The file is not in RDT, open it in invisible editor and get the text lines from it.
Text buffer for that file.
Text buffer for that file .
fullPathFileName
string
File name with full path.
File name with full path .
remarks
This method created for refactoring usage, refactoring will work on all kinds of
docdata, not only SqlEditorDocData.  If change this method, please get let LiangZ
know.
This method created for refactoring usage refactoring will work on all kinds of docdata not only SqlEditorDocData . If change this method please get let LiangZ know .