private async void Init() { try { var result = await new LogManager().GetLocalLog(); if (result.IsSuccess) { _fileLogs = result.Data.ToList(); FileLogs = new ObservableCollection <FileLog>(); foreach (var fileLog in result.Data) { FileLogs.Add(fileLog.TransReflection()); } } else { MessageBox.Show("提示", result.Message, MessageBoxButton.OK); } } catch (Exception ex) { MessageBox.Show("提示", ex.Message, MessageBoxButton.OK); } IsLoading = false; }
private async void Refresh() { IsLoading = true; var result = await new LogManager().GetLocalLog(); if (result.IsSuccess) { _fileLogs = result.Data.ToList(); FileLogs = new ObservableCollection <FileLog>(); var folder = GetCurrentPath(result.Data); var fileLogs = folder == null ? result.Data : folder.Files; foreach (var fileLog in fileLogs) { FileLogs.Add(fileLog.TransReflection()); } LogPages = new ObservableCollection <PageModel> { new PageModel { Index = 1, IsSelected = true } }; } else { MessageBox.Show("提示", result.Message, MessageBoxButton.OK); } IsLoading = false; }
private async void Init() { try { if (Common.Instance.LogType == "LocalLog") { var bytes = File.ReadAllBytes(Common.Instance.Parameter + ""); Value += Encoding.Default.GetString(bytes); return; } var url = BaseApi.GetDomain() + SysApi.Download + Common.Instance.Parameter; using (var httpClient = HttpClientUtil.CreateHttpClient()) { var response = await httpClient.GetAsync(url); var contentType = response.Content.Headers.ContentType; if (string.IsNullOrEmpty(contentType.CharSet)) { contentType.CharSet = "utf-8"; } long contentLength = -1; if (response.Content.Headers.ContentLength != null) { contentLength = response.Content.Headers.ContentLength.Value; } using (var stream = await response.Content.ReadAsStreamAsync()) { var readLength = 10 * 1024; if (readLength != -1 && contentLength < readLength) { readLength = (int)contentLength; } var bytes = new byte[readLength]; while (((stream.Read(bytes, 0, readLength))) > 0) { Value += Encoding.Default.GetString(bytes); contentLength -= readLength; if (contentLength <= 0) { break; } readLength = Math.Min((int)contentLength, readLength); bytes = new byte[readLength]; } } } } catch (Exception ex) { MessageBox.Show("错误", ex.Message, MessageBoxButton.OK); Utility.Logger.LogHelper.Error("下载文件出错", ex); } }
public void AddDownload(DownloadInfo info) { string msg; if (!DownloadManager.CanDownload(info, out msg)) { MessageBox.Show("重复下载", msg); return; } var vm = new UcDownloadInfoViewModel(info); vm.CancelAction = o => { DownList.Remove(vm); }; DownList.Add(vm); }