internal string HandleHttpFileDownloadRequest()

in src/Sarif.Viewer.VisualStudio.Core/CodeAnalysisResultManager.cs [371:424]


        internal string HandleHttpFileDownloadRequest(Uri uri, string workingDirectory, string localRelativePath = null)
        {
            if (!SarifViewerPackage.IsUnitTesting)
            {
#pragma warning disable VSTHRD108 // Assert thread affinity unconditionally
                ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD108
            }

            bool allow = this._allowedDownloadHosts.Contains(uri.Host);

            // File needs to be downloaded, prompt for confirmation if host is not already allowed
            if (!allow)
            {
                MessageDialogCommand result = MessageDialog.Show(Resources.ConfirmDownloadDialog_Title,
                                                                 string.Format(Resources.ConfirmDownloadDialog_Message, uri),
                                                                 MessageDialogCommandSet.YesNo,
                                                                 string.Format(Resources.ConfirmDownloadDialog_CheckboxLabel, uri.Host),
                                                                 out bool alwaysAllow);

                if (result != MessageDialogCommand.No)
                {
                    allow = true;

                    if (alwaysAllow)
                    {
                        this.AddAllowedDownloadHost(uri.Host);
                    }
                }
            }

            if (allow)
            {
                try
                {
                    workingDirectory = string.IsNullOrWhiteSpace(workingDirectory) ?
                                       Path.Combine(Path.GetTempPath(), this.CurrentRunIndex.ToString()) :
                                       workingDirectory;
                    return this.DownloadFile(workingDirectory, uri.ToString(), localRelativePath);
                }
                catch (Exception ex)
                {
                    VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider,
                               Resources.DownloadFail_DialogMessage + Environment.NewLine + ex.Message,
                               null, // title
                               OLEMSGICON.OLEMSGICON_CRITICAL,
                               OLEMSGBUTTON.OLEMSGBUTTON_OK,
                               OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    Trace.WriteLine($"DownloadFile {uri.ToString()} threw exception: {ex.Message}");
                }
            }

            return null;
        }