private async Task SetUpAsync() { string localFullName = $"{DownloadPath}setup.exe"; Uri uri = new Uri("http://Public.mujiannan.me/1Math/setup.exe"); Reportor.Report($"下载{uri.AbsolutePath}至{localFullName},请耐心等待..."); await DownloadAsync(uri, localFullName); System.Diagnostics.Process.Start(localFullName); }
private void Initialize() { if (_target == null) { throw new Exception("PleaseGiveMeAnExcelRange"); } if (_target.Areas.Count > 1) { throw new Exception("DiscontinuousExcelRange"); } _application = _target.Application; Reportor = new Reportor(this); }
public Installer() { this.Reportor = new Reportor(this); }
private async Task DownloadAsync(Uri uri, string localFullName) { HttpClientHandler httpClientHandler = new HttpClientHandler(); ProgressMessageHandler progressMessageHandler = new ProgressMessageHandler(httpClientHandler); HttpClient httpClient = new HttpClient(progressMessageHandler); progressMessageHandler.HttpReceiveProgress += (object sender, HttpProgressEventArgs e) => Reportor.Report(e.ProgressPercentage);//捕获下载进度,向外汇报 FileStream fileStream = File.Create(localFullName, 1024, FileOptions.Asynchronous); byte[] bytes = await httpClient.GetByteArrayAsync(uri); fileStream.Write(bytes, 0, bytes.Length); fileStream.Flush(); fileStream.Close(); }