Esempio n. 1
0
        private void ErrorListInlineLink_Click(object sender, RoutedEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Hyperlink hyperLink = sender as Hyperlink;

            if (hyperLink != null)
            {
                Tuple <int, object> data = hyperLink.Tag as Tuple <int, object>;
                // data.Item1 = index of SarifErrorListItem
                // data.Item2 = id of related location to link, or absolute URL string

                SarifErrorListItem sarifResult = _errors[Convert.ToInt32(data.Item1)];

                if (data.Item2 is int id)
                {
                    // The user clicked an inline link with an integer target. Look for a Location object
                    // whose Id property matches that integer. The spec says that might be _any_ Location
                    // object under the current result. At present, we only support Location objects that
                    // occur in Result.Locations or Result.RelatedLocations. So, for example, we don't
                    // look in Result.CodeFlows or Result.Stacks.
                    LocationModel location = sarifResult.RelatedLocations.Where(l => l.Id == id).FirstOrDefault();
                    if (location == null)
                    {
                        location = sarifResult.Locations.Where(l => l.Id == id).FirstOrDefault();
                    }

                    if (location != null)
                    {
                        // Set the current sarif error in the manager so we track code locations.
                        CodeAnalysisResultManager.Instance.CurrentSarifResult = sarifResult;

                        SarifViewerPackage.SarifToolWindow.Control.DataContext = null;

                        if (sarifResult.HasDetails)
                        {
                            // Setting the DataContext to null (above) forces the TabControl to select the appropriate tab.
                            SarifViewerPackage.SarifToolWindow.Control.DataContext = sarifResult;
                        }

                        location.NavigateTo(false);
                        location.ApplyDefaultSourceFileHighlighting();
                    }
                }
                else if (data.Item2 is string)
                {
                    System.Diagnostics.Process.Start(data.Item2.ToString());
                }
            }
        }