src/Misc/EFTools/DesignXmlCore/Refactoring/PreviewBuffer.cs
/// <summary>
///     Get the preview temp file for a file extension.
///     If the temp file already exists, use that one.  Otherwise, create a new one.
/// </summary>
/// <param name="fileExtension">The file extension.</param>
/// <returns>The preview temp file with file path, invisible editor and text buffer inforamtion.</returns>
Get the preview temp file for a file extension.
If the temp file already exists, use that one.  Otherwise, create a new one.
Get the preview temp file for a file extension . If the temp file already exists use that one . Otherwise create a new one .
private PreviewTempFile GetPreviewTempFile(string fileExtension)
        {
            ArgumentValidation.CheckForNullReference(fileExtension, "fileExtension");
            PreviewTempFile tempFile = null;
            if (!_tempFiles.TryGetValue(fileExtension, out tempFile))
            {
                var failed = false;
                var tempFilePath = CreatePreviewTempFile(fileExtension);
                if (!File.Exists(tempFilePath))
                {
                    failed = true;
                }
                else
                {
                    IVsInvisibleEditor invisibleEditor = null;
                    IVsTextLines textBuffer = null;
                    if (RdtManager.Instance.TryGetTextLinesAndInvisibleEditor(tempFilePath, out invisibleEditor, out textBuffer)
                        && invisibleEditor != null
                        && textBuffer != null)
                    {
                        tempFile = new PreviewTempFile(tempFilePath, invisibleEditor, textBuffer);
                        _tempFiles.Add(fileExtension, tempFile);
                    }
                    else
                    {
                        failed = true;
                    }
                }
                if (failed)
                {
                    throw new InvalidOperationException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.Exception_CannotGetTextBuffer,
                            tempFilePath));
                }
            }
            return tempFile;
        }
private PreviewTempFile GetPreviewTempFile ( string fileExtension ) { ArgumentValidation . CheckForNullReference ( fileExtension , " " ) ; PreviewTempFile tempFile = null ; if ( ! _tempFiles . TryGetValue ( fileExtension , out tempFile ) ) { var failed = false ; var tempFilePath = CreatePreviewTempFile ( fileExtension ) ; if ( ! File . Exists ( tempFilePath ) ) { failed = true ; } else { IVsInvisibleEditor invisibleEditor = null ; IVsTextLines textBuffer = null ; if ( RdtManager . Instance . TryGetTextLinesAndInvisibleEditor ( tempFilePath , out invisibleEditor , out textBuffer ) && invisibleEditor != null && textBuffer != null ) { tempFile = new PreviewTempFile ( tempFilePath , invisibleEditor , textBuffer ) ; _tempFiles . Add ( fileExtension , tempFile ) ; } else { failed = true ; } } if ( failed ) { throw new InvalidOperationException ( string . Format ( CultureInfo . CurrentCulture , Resources . Exception_CannotGetTextBuffer , tempFilePath ) ) ; } } return tempFile ; }
Get the preview temp file for a file extension.
Get the preview temp file for a file extension .
// If the temp file already exists, use that one. // Create a new preview temp file // Failed to create the temp file. // Open the file in invisible editor and get text buffer from it. // Temp file is opened in invisible editor, and we got the text buffer from it. // Failed to get InvisibleEditor or TextBuffer for that file, // throw exception.
The preview temp file with file path, invisible editor and text buffer inforamtion.
The preview temp file with file path invisible editor and text buffer inforamtion .
fileExtension
string
The file extension.
The file extension .