private static void Assd_ProgressChanged(ExtractProgressModel obj) { lock (locker) { int index = _files.FindIndex(f => f.File.Name == obj.File.Name); Console.SetCursorPosition(0, index * 17); Console.WriteLine(); Console.WriteLine($"Current file: {obj.File.Name}"); Console.WriteLine( $"Progress: {Math.Round(((double) obj.TotalHandled / (double) obj.TotalEntries) * 100.0, 1)}%"); Console.WriteLine(); Console.WriteLine("---------------------------------------------------------------------------"); Console.WriteLine($"Estimate: {new DateTime(obj.Estimate.Ticks):T}"); Console.WriteLine($"Elapsed: {new DateTime(obj.Elapsed.Ticks):T}"); Console.WriteLine($"TotalEntries/TotalHandled: {obj.TotalEntries}/{obj.TotalHandled}"); Console.WriteLine( $"TotalMessages/SuccessMessages: {obj.TotalMessages}/{obj.SuccessMessages}"); Console.WriteLine( $"TotalAttachments/SuccessAttachments: {obj.TotalAttachments}/{obj.SuccessAttachments}"); Console.WriteLine( $"Success/Failed: {obj.SuccessMessages + obj.SuccessAttachments}/{obj.Failed}"); Console.WriteLine( $"Failed ratio: {Math.Round(((double) obj.Failed / ((double) obj.SuccessMessages + obj.SuccessAttachments)) * 100.0, 1)}%"); Console.WriteLine(); Console.WriteLine($"Jpg: {obj.TotalJpg}"); Console.WriteLine($"Png: {obj.TotalPng}"); Console.WriteLine($"Doc: {obj.TotalDoc}"); Console.WriteLine(); } }
private static void Assd_Completed(ExtractProgressModel obj) { if (obj == null) { return; } if (!Directory.Exists(obj.GeneratedPath)) { Directory.CreateDirectory(obj.GeneratedPath); } FileInfo log = new FileInfo(Path.Combine(obj.GeneratedPath, "log.txt")); using (StreamWriter sw = log.CreateText()) { sw.WriteLine($"Current file: {obj.File.Name}"); sw.WriteLine($"Progress: {Math.Round(((double)obj.TotalHandled / (double)obj.TotalEntries) * 100.0, 1)}%"); sw.WriteLine(); sw.WriteLine("---------------------------------------------------------------------------"); sw.WriteLine($"Estimate: {new DateTime(obj.Estimate.Ticks):T}"); sw.WriteLine($"Elapsed: {new DateTime(obj.Elapsed.Ticks):T}"); sw.WriteLine($"TotalEntries/TotalHandled: {obj.TotalEntries}/{obj.TotalHandled}"); sw.WriteLine($"TotalMessages/SuccessMessages: {obj.TotalMessages}/{obj.SuccessMessages}"); sw.WriteLine($"TotalAttachments/SuccessAttachments: {obj.TotalAttachments}/{obj.SuccessAttachments}"); sw.WriteLine($"Success/Failed: {obj.SuccessMessages + obj.SuccessAttachments}/{obj.Failed}"); sw.WriteLine($"Failed ratio: {Math.Round(((double)obj.Failed / ((double)obj.SuccessMessages + obj.SuccessAttachments)) * 100.0, 1)}%"); sw.WriteLine(); sw.WriteLine($"Jpg: {obj.TotalJpg}"); sw.WriteLine($"Png: {obj.TotalPng}"); sw.WriteLine($"Doc: {obj.TotalDoc}"); } }
private void _backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { CurrentProgressState = e.UserState as ExtractProgressModel; ProgressChanged?.Invoke(CurrentProgressState); }
protected override void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { ExtractProgressModel progress = new ExtractProgressModel(); DateTime started = DateTime.Now; Stopwatch etaWatch = new Stopwatch(); var extractEnties = ParseExtractableFile(File.FullName); progress.TotalAttachments = extractEnties.Sum(entry => entry.Value.Count); progress.TotalMessages = extractEnties.Count; progress.File = File; progress.GeneratedPath = Path.Combine(_targetFolder, File.Name); using (WebClient client = new WebClient()) { client.Proxy = new WebProxy("54.39.144.247:3128"); extractEnties.ForEach(entry => { etaWatch.Start(); entry.Value.ForEach(url => { try { string type = url.AbsoluteUri.Contains("jpg") ? "jpg" : url.AbsoluteUri.Contains("png") ? "png" : "doc"; switch (type) { case "jpg": progress.TotalJpg++; break; case "png": progress.TotalPng++; break; case "doc": progress.TotalDoc++; break; } string path = Path.Combine(_targetFolder, File.Name, type); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var filePath = Path.Combine(path, entry.Key.ToString("dd-MM-yyyy-hh-mm-ss") + url.AbsoluteUri.Split('/').Last()); client.DownloadFile(url, filePath); progress.SuccessAttachments++; } catch (Exception ee) { progress.Failed++; } progress.Elapsed = DateTime.Now - started; progress.Estimate = etaWatch.GetEta(progress.TotalHandled, progress.TotalEntries); CurrentProgressState = progress; BackgroundWorker.ReportProgress(Math.Sign(progress.TotalHandled / (double)progress.TotalEntries * 100.0), progress); }); progress.SuccessMessages++; //BackgroundWorker.ReportProgress(Math.Sign(progress.TotalHandled / (double)progress.TotalEntries * 100.0), progress); }); } CurrentProgressState = progress; }