private async Task <bool> DownloadIWYUWithProgressBar(string executablePath, IVsThreadedWaitDialogFactory dialogFactory)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsThreadedWaitDialog2 progressDialog;

            dialogFactory.CreateInstance(out progressDialog);
            if (progressDialog == null)
            {
                Output.Instance.WriteLine("Failed to get create wait dialog.");
                return(false);
            }

            progressDialog.StartWaitDialogWithPercentageProgress(
                szWaitCaption: "Include Toolbox - Downloading include-what-you-use",
                szWaitMessage: "", // comes in later.
                szProgressText: null,
                varStatusBmpAnim: null,
                szStatusBarText: "Downloading include-what-you-use",
                fIsCancelable: true,
                iDelayToShowDialog: 0,
                iTotalSteps: 100,
                iCurrentStep: 0);

            var cancellationToken = new System.Threading.CancellationTokenSource();

            try
            {
                await IWYUDownload.DownloadIWYU(executablePath, delegate(string section, string status, float percentage)
                {
                    ThreadHelper.ThrowIfNotOnUIThread();

                    bool canceled;
                    progressDialog.UpdateProgress(
                        szUpdatedWaitMessage: section,
                        szProgressText: status,
                        szStatusBarText: $"Downloading include-what-you-use - {section} - {status}",
                        iCurrentStep: (int)(percentage * 100),
                        iTotalSteps: 100,
                        fDisableCancel: true,
                        pfCanceled: out canceled);
                    if (canceled)
                    {
                        cancellationToken.Cancel();
                    }
                }, cancellationToken.Token);
            }
            catch (Exception e)
            {
                await Output.Instance.ErrorMsg("Failed to download include-what-you-use: {0}", e);

                return(false);
            }
            finally
            {
                progressDialog.EndWaitDialog();
            }

            return(true);
        }
        public async Task DownloadAsync()
        {
            var executableDir = GetCleanExecutableDir();

            Assert.AreEqual(false, File.Exists(executableDir));
            Assert.AreEqual(true, await IWYUDownload.IsNewerVersionAvailableOnline(executableDir)); // Nothing here practically means that there is a new version.

            await IWYUDownload.DownloadIWYU(executableDir, ReportProgress, new CancellationToken());

            Assert.AreEqual(false, await IWYUDownload.IsNewerVersionAvailableOnline(executableDir));
            Assert.AreEqual(true, File.Exists(executableDir));
        }
Example #3
0
        public void Download()
        {
            var executableDir = GetCleanExecutableDir();

            Assert.AreEqual(false, File.Exists(executableDir));
            Assert.AreEqual(true, IWYUDownload.IsNewerVersionAvailableOnline(executableDir).Result); // Nothing here practically means that there is a new version.

            var downloadTask = IWYUDownload.DownloadIWYU(executableDir, ReportProgress, new CancellationToken());

            downloadTask.Wait();

            Assert.AreEqual(false, IWYUDownload.IsNewerVersionAvailableOnline(executableDir).Result);
            Assert.AreEqual(true, File.Exists(executableDir));
        }