/// <summary>
        ///
        private string GetDocumentName(uint docCookie, IVsWindowFrame pFrame)
        {
            string documentName = null;
            IVsRunningDocumentTable runningDocTable = SdkUiUtilities.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>(ServiceProvider);

            if (runningDocTable != null)
            {
                uint         grfRDTFlags;
                uint         dwReadLocks;
                uint         dwEditLocks;
                IVsHierarchy pHier;
                uint         itemId;
                IntPtr       docData = IntPtr.Zero;
                try
                {
                    int hr = runningDocTable.GetDocumentInfo(docCookie,
                                                             out grfRDTFlags,
                                                             out dwReadLocks,
                                                             out dwEditLocks,
                                                             out documentName,
                                                             out pHier,
                                                             out itemId,
                                                             out docData);
                }
                finally
                {
                    if (docData != IntPtr.Zero)
                    {
                        Marshal.Release(docData);
                    }
                }
            }
            return(documentName);
        }
Ejemplo n.º 2
0
        internal IVsWindowFrame NavigateTo(bool usePreviewPane)
        {
            // Fall back to the file and line number

            if (!File.Exists(this.FullFilePath))
            {
                if (!CodeAnalysisResultManager.Instance.TryRebaselineAllSarifErrors(this.UriBaseId, this.FullFilePath))
                {
                    return null;
                }
            }

            IVsWindowFrame windowFrame = SdkUiUtilities.OpenDocument(SarifViewerPackage.ServiceProvider, this.FullFilePath, usePreviewPane);
            if (windowFrame != null)
            {
                IVsTextView textView = GetTextViewFromFrame(windowFrame);
                if (textView == null)
                {
                    return null;
                }

                var sourceLocation = this.GetSourceLocation();

                // Navigate the caret to the desired location. Text span uses 0-based indexes
                TextSpan ts;
                ts.iEndLine = ts.iStartLine = sourceLocation.StartLine - 1;
                ts.iEndIndex = ts.iStartIndex = Math.Max(sourceLocation.StartColumn - 1, 0);

                textView.EnsureSpanVisible(ts);
                textView.SetSelection(ts.iStartLine, ts.iStartIndex, ts.iEndLine, ts.iEndIndex);
            }
            return windowFrame;
        }
Ejemplo n.º 3
0
        internal IVsWindowFrame NavigateTo(bool highlightLine, string highlightColor, bool usePreviewPane)
        {
            // Fall back to the file and line number
            IVsWindowFrame windowFrame = SdkUiUtilities.OpenDocument(SarifViewerPackage.ServiceProvider, this.FullFilePath, usePreviewPane);

            if (windowFrame != null)
            {
                IVsTextView textView = GetTextViewFromFrame(windowFrame);
                if (textView == null)
                {
                    return(null);
                }

                var sourceLocation = this.GetSourceLocation();

                // Navigate the caret to the desired location. Text span uses 0-based indexes
                TextSpan ts;
                ts.iEndLine  = ts.iStartLine = sourceLocation.StartLine - 1;
                ts.iEndIndex = ts.iStartIndex = Math.Max(sourceLocation.StartColumn - 1, 0);

                textView.EnsureSpanVisible(ts);
                textView.SetSelection(ts.iStartLine, ts.iStartIndex, ts.iEndLine, ts.iEndIndex);

                if (highlightLine)
                {
                    this.AddSelectionMarker(highlightColor);
                }
            }
            return(windowFrame);
        }
        // This ctor is internal rather than private for unit test purposes.
        internal CodeAnalysisResultManager(
            IFileSystem fileSystem,
            PromptForResolvedPathDelegate promptForResolvedPathDelegate = null)
        {
            _fileSystem = fileSystem;
            _promptForResolvedPathDelegate = promptForResolvedPathDelegate ?? PromptForResolvedPath;

            this.SarifErrors       = new List <SarifErrorListItem>();
            _remappedUriBasePaths  = new Dictionary <string, Uri>();
            _remappedPathPrefixes  = new List <Tuple <string, string> >();
            _fileToNewLineIndexMap = new Dictionary <string, NewLineIndex>();
            _allowedDownloadHosts  = SdkUiUtilities.GetStoredObject <List <string> >(AllowedDownloadHostsFileName) ?? new List <string>();

            // Get temporary path for embedded files.
            TemporaryFilePath = Path.GetTempPath();
            TemporaryFilePath = Path.Combine(TemporaryFilePath, TemporaryFileDirectoryName);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Open the file using the current document state scope
        /// </summary>
        private static IVsWindowFrame OpenDocumentInCurrentScope(IServiceProvider provider, string file)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsUIShellOpenDocument  openDoc         = SdkUiUtilities.GetService <SVsUIShellOpenDocument, IVsUIShellOpenDocument>(provider);
            IVsRunningDocumentTable runningDocTable = SdkUiUtilities.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>(provider);

            if (openDoc == null || runningDocTable == null)
            {
                throw Marshal.GetExceptionForHR(VSConstants.E_FAIL);
            }

            uint cookieDocLock = FindDocument(runningDocTable, file);

            IVsWindowFrame windowFrame;
            Guid           textViewGuid = VSConstants.LOGVIEWID_TextView;
            // Unused variables
            IVsUIHierarchy uiHierarchy;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider;
            uint itemId;
            int  hr = openDoc.OpenDocumentViaProject(file, ref textViewGuid, out serviceProvider, out uiHierarchy, out itemId, out windowFrame);

            if (ErrorHandler.Failed(hr))
            {
                throw Marshal.GetExceptionForHR(hr);
            }

            if (cookieDocLock == 0) // Document was not open earlier, and should be open now.
            {
                cookieDocLock = FindDocument(runningDocTable, file);
            }

            if (windowFrame != null)
            {
                // This will make the document visible to the user and switch focus to it. ShowNoActivate doesn't help because for tabbed documents they
                // are not brought to the front if they are already opened.
                windowFrame.Show();
            }
            return(windowFrame);
        }
 internal void AddAllowedDownloadHost(string host)
 {
     _allowedDownloadHosts.Add(host);
     SdkUiUtilities.StoreObject <List <string> >(_allowedDownloadHosts, AllowedDownloadHostsFileName);
 }