Beispiel #1
0
 private async void Imprimir(ReportDocument rpt, string reportName)
 {
     await Task.Run(() => {
         bool impreso = false;
         var Modal    = new ModalLoading("Imprimiendo");
         Modal.Show();
         try
         {
             DiskFileDestinationOptions diskOptions = new DiskFileDestinationOptions();
             rpt.Refresh();
             diskOptions.DiskFileName                   = ConfigurationManager.AppSettings.Get(reportName) + reportName + "_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".pdf";
             rpt.ExportOptions.ExportFormatType         = ExportFormatType.PortableDocFormat;
             rpt.ExportOptions.ExportDestinationType    = ExportDestinationType.DiskFile;
             rpt.ExportOptions.ExportDestinationOptions = diskOptions;
             rpt.Export();
             impreso = true;
             Modal.Close();
         }
         catch (Exception e)
         {
             Modal.Close();
             MessageBox.Show("Error", "Descripcion: " + e, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         return(impreso);
     });
 }
Beispiel #2
0
        private void search()
        {
            modalLoading.Show(null, null, true, null);
            Task.Run(() =>
            {
#pragma warning disable CA1416 // 验证平台兼容性
                Processes = Process.GetProcesses()
                            .Where(t => string.IsNullOrEmpty(searchKeywords) || t.Id.ToString() == searchKeywords || t.ProcessName.Contains(searchKeywords))
                            .Select(t => new ProcessInfo()
                {
                    Id         = t.Id,
                    Name       = t.ProcessName,
                    MemoryInfo = getProcessMemInfo(t),
                    Threads    = t.Threads.Count,
                    StartTime  = getProcessStartTime(t)
                }).ToArray();
#pragma warning restore CA1416 // 验证平台兼容性
                modalLoading.Close();
                InvokeAsync(StateHasChanged);
            });
        }
Beispiel #3
0
        private async void btnDownload_Click()
        {
            var file = SelectedItem as FileInfo;

            if (file == null)
            {
                return;
            }

            if (DownloadFileAction != null)
            {
                DownloadFileAction.Invoke(JSRuntime, file.FullName);
                return;
            }

            System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource();
            loading.Show(TextDownload, file.Name, false, cts.Cancel);
            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();
            DateTime lastDisplayTime = DateTime.MinValue;

            byte[] buffer         = new byte[24 * 1024];
            var    fileSize       = file.Length;
            long   readTotalCount = 0;

            try
            {
                using (var fs = file.OpenRead())
                {
                    while (!cts.IsCancellationRequested)
                    {
                        var ret = fs.Read(buffer, 0, buffer.Length);
                        if (ret <= 0)
                        {
                            break;
                        }
                        readTotalCount += ret;

                        if ((DateTime.Now - lastDisplayTime).TotalSeconds > 0.5 && stopwatch.ElapsedMilliseconds > 0)
                        {
                            StringBuilder sb    = new StringBuilder();
                            var           speed = Convert.ToDouble(readTotalCount / stopwatch.ElapsedMilliseconds);
                            sb.Append(TextTransferSpeed + ": " + storageUSC.GetString(Convert.ToDecimal(speed * 1000), 1, true) + "B/s");
                            var remainingTime = TimeSpan.FromMilliseconds((fileSize - readTotalCount) / speed);
                            sb.Append("," + TextRemainingTime + ": " + remainingTime.ToString(@"hh\:mm\:ss"));
                            loading.UpdateProgress(Convert.ToInt32(readTotalCount * 100 / fileSize), sb.ToString());
                            await InvokeAsync(StateHasChanged);

                            lastDisplayTime = DateTime.Now;
                        }
                        await BlazorDownloadFileService.AddBuffer(new ArraySegment <byte>(buffer, 0, ret), cts.Token);
                    }
                }
                if (cts.IsCancellationRequested)
                {
                    alert.Show(TextUpload, TextCanceled);
                    return;
                }
                var result = await BlazorDownloadFileService.DownloadBinaryBuffers(file.Name, cts.Token);

                if (!result.Succeeded)
                {
                    alert.Show(TextDownload, TextFailed + Environment.NewLine + result.ErrorName + Environment.NewLine + result.ErrorMessage);
                }
            }
            catch (TaskCanceledException)
            {
                alert.Show(TextUpload, TextCanceled);
            }
            catch (Exception ex)
            {
                alert.Show(TextUpload, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex));
            }
            finally
            {
                await BlazorDownloadFileService.ClearBuffers();

                stopwatch.Stop();
                loading.Close();
            }
        }