private void UpdateStats() { try { var totalQueueSizeInBytes = Queue.ToList().Sum((q) => q.File == null ? 0d : q.File.SizeInBytes); var totalToTransferInBytes = Workers.ToList().Sum((w) => w.SizeInBytes); var speedSample = new List <Worker>(Workers.Where((w) => w.SpeedInBytes > 0)); speedSample.AddRange(WorkersHistory.Skip(WorkersHistory.Count - 10).Where((w) => w.SpeedInBytes > 0)); var currentSpeed = speedSample.Count == 0 ? 0d : speedSample.Average((w) => w.SpeedInBytes); _SpeedHistory.Add(currentSpeed); while (_SpeedHistory.Count > 120) { _SpeedHistory.RemoveAt(0); } var averageSpeed = _SpeedHistory.Average((s) => s); if (Workers.Count == 0) { averageSpeed = 0; } AverageSpeed = SizeUtil.Format(averageSpeed, "/s"); TotalQueueSize = SizeUtil.Format(totalQueueSizeInBytes); TotalToTransfer = SizeUtil.Format(totalToTransferInBytes); TotalTransfered = SizeUtil.Format(Workers.ToList().Sum((w) => w.TransferedInBytes)); RemainingTime = Workers.Count == 0 ? TimeSpan.FromSeconds(0) : Workers.ToList().Max((w) => w.TimeRemaining); QueueCount = Queue.Count; WorkersCount = Workers.Count; QueueRemainingTime = TimeSpan.FromSeconds(averageSpeed == 0 ? 0 : Convert.ToInt32((totalQueueSizeInBytes + totalToTransferInBytes) / averageSpeed)); } catch { } }
private void HandleUploadProgress(object o, UploadProgressEventArgs args) { if (approx_size == 0) { progress_dialog.ProgressText = System.String.Format("{0} Sent", SizeUtil.ToHumanReadable(args.BytesSent)); } else { progress_dialog.ProgressText = System.String.Format("{0} of approx. {1}", SizeUtil.ToHumanReadable(sent_bytes + args.BytesSent), SizeUtil.ToHumanReadable(approx_size)); } progress_dialog.Fraction = ((photo_index - 1) / (double)items.Length) + (args.BytesSent / (args.BytesTotal * (double)items.Length)); }
/// <summary> /// Handles what happens when <see cref="IMainView.ResetClicked"/> occurs. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event.</param> private void View_ResetClicked(object sender, EventArgs e) { _statisticsTimer.Stop(); Settings.Default.Downloaded = "0"; Settings.Default.Uploaded = "0"; Settings.Default.Save(); _totalDownloaded = 0; _totalUploaded = 0; _view.UpdateTotalDownloaded(SizeUtil.SizeSuffix(0, 2)); _view.UpdateTotalUploaded(SizeUtil.SizeSuffix(0, 2)); _statisticsTimer.Start(); }
protected override void ShowProgress(string title, long bytes_sent) { progress_dialog.Message = title; progress_dialog.ProgressText = String.Format( Catalog.GetString( "{0} of approx. {1}"), SizeUtil.ToHumanReadable(bytes_sent), SizeUtil.ToHumanReadable( (long)TotalFileSize)); progress_dialog.Fraction = (double)bytes_sent / TotalFileSize; }
private void UpdateEstimatedSize() { int new_size_index; long new_approx_total_size; string approxresult; new_size_index = GetScaleIndex(); if (new_size_index == 0) { new_approx_total_size = Orig_Photo_Size; } else { new_approx_total_size = System.Convert.ToInt64(Orig_Photo_Size * avg_scale [new_size_index]); } approxresult = SizeUtil.ToHumanReadable(new_approx_total_size); ApproxNewSize.Text = approxresult; }
public void Run(IBrowsableCollection selection) { xml = new Glade.XML(null, "CDExport.glade", dialog_name, "f-spot"); xml.Autoconnect(this); this.selection = selection; // Calculate the total size long total_size = 0; string path; System.IO.FileInfo file_info; foreach (IBrowsableItem item in selection.Items) { path = item.DefaultVersionUri.LocalPath; if (System.IO.File.Exists(path)) { file_info = new System.IO.FileInfo(path); total_size += file_info.Length; } } IconView view = new IconView(selection); view.DisplayDates = false; view.DisplayTags = false; Dialog.Modal = false; Dialog.TransientFor = null; size_label.Text = SizeUtil.ToHumanReadable(total_size); thumb_scrolledwindow.Add(view); Dialog.ShowAll(); previous_frame.Visible = IsEmpty(dest); //LoadHistory (); Dialog.Response += HandleResponse; }
/// <summary> /// Handles what happens when the main form loads. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event.</param> private void View_Load(object sender, EventArgs e) { _modem = new HuaweiModem(); try { LookForDevices(); LoadProfiles(); _totalDownloaded = long.Parse(Settings.Default.Downloaded); _totalUploaded = long.Parse(Settings.Default.Uploaded); _view.UpdateSessionDownload(SizeUtil.SizeSuffix(0, 2)); _view.UpdateSessionUpload(SizeUtil.SizeSuffix(0, 2)); _view.UpdateTotalDownloaded(SizeUtil.SizeSuffix(_totalDownloaded, 2)); _view.UpdateTotalUploaded(SizeUtil.SizeSuffix(_totalUploaded, 2)); } catch (Exception ex) { _view.UpdateToolStripStatus(ex.Message); } }
public void Run(IBrowsableCollection selection) { this.selection = selection; // Calculate the total size long total_size = 0; string path; System.IO.FileInfo file_info; foreach (IBrowsableItem item in selection.Items) { path = item.DefaultVersionUri.LocalPath; if (System.IO.File.Exists(path)) { file_info = new System.IO.FileInfo(path); total_size += file_info.Length; } } IconView view = new IconView(selection); view.DisplayDates = false; view.DisplayTags = false; Dialog.Modal = false; Dialog.TransientFor = null; size_label.Text = SizeUtil.ToHumanReadable(total_size); thumb_scrolledwindow.Add(view); Dialog.ShowAll(); //LoadHistory (); Dialog.Response += HandleResponse; }
private void Connect(GoogleAccount selected, string token, string text) { try { if (accounts.Count != 0 && connect) { if (selected == null) { account = (GoogleAccount)accounts [gallery_optionmenu.History]; } else { account = selected; } if (!account.Connected) { account.Connect(); } PopulateAlbumOptionMenu(account.Picasa); long qu = account.Picasa.QuotaUsed; long ql = account.Picasa.QuotaLimit; StringBuilder sb = new StringBuilder("<small>"); sb.Append(Catalog.GetString("Available space :")); sb.Append(SizeUtil.ToHumanReadable(ql - qu)); sb.Append(" ("); sb.Append(100 * qu / ql); sb.Append("% used out of "); sb.Append(SizeUtil.ToHumanReadable(ql)); sb.Append(")"); sb.Append("</small>"); status_label.Text = sb.ToString(); status_label.UseMarkup = true; album_button.Sensitive = true; } } catch (CaptchaException exc) { System.Console.WriteLine("Your google account is locked"); if (selected != null) { account = selected; } PopulateAlbumOptionMenu(account.Picasa); album_button.Sensitive = false; new GoogleAccountDialog(this.Dialog, account, false, exc); System.Console.WriteLine("Your google account is locked, you can unlock it by visiting: {0}", CaptchaException.UnlockCaptchaURL); } catch (System.Exception) { System.Console.WriteLine("Can not connect to Picasa. Bad username ? password ? network connection ?"); //System.Console.WriteLine ("{0}",ex); if (selected != null) { account = selected; } PopulateAlbumOptionMenu(account.Picasa); status_label.Text = String.Empty; album_button.Sensitive = false; new GoogleAccountDialog(this.Dialog, account, true, null); } }
public SendEmail(IBrowsableCollection selection) : base("mail_dialog") { this.selection = selection; for (int i = 0; i < selection.Count; i++) { Photo p = selection[i] as Photo; if (Gnome.Vfs.MimeType.GetMimeTypeForUri(p.DefaultVersionUri.ToString()) != "image/jpeg") { force_original = true; } } if (force_original) { original_size.Active = true; tiny_size.Sensitive = false; small_size.Sensitive = false; medium_size.Sensitive = false; large_size.Sensitive = false; x_large_size.Sensitive = false; } else { switch (Preferences.Get <int> (Preferences.EXPORT_EMAIL_SIZE)) { case 0: original_size.Active = true; break; case 1: tiny_size.Active = true; break; case 2: small_size.Active = true; break; case 3: medium_size.Active = true; break; case 4: large_size.Active = true; break; case 5: x_large_size.Active = true; break; default: break; } } rotate_check.Active = Preferences.Get <bool> (Preferences.EXPORT_EMAIL_ROTATE); rotate_check.Sensitive = original_size.Active && tiny_size.Sensitive; tray_scrolled.Add(new TrayView(selection)); Dialog.Modal = false; // Calculate total original filesize for (int i = 0; i < selection.Count; i++) { Photo photo = selection[i] as Photo; try { Orig_Photo_Size += (new Gnome.Vfs.FileInfo(photo.DefaultVersionUri.ToString())).Size; } catch { } } for (int k = 0; k < avg_scale_ref.Length; k++) { avg_scale[k] = avg_scale_ref[k]; } // Calculate approximate size shrinking, use first photo, and shrink to medium size as base. Photo scalephoto = selection [0] as Photo; if (scalephoto != null && !force_original) { // Get first photos file size long orig_size = (new Gnome.Vfs.FileInfo(scalephoto.DefaultVersionUri.ToString())).Size; FilterSet filters = new FilterSet(); filters.Add(new ResizeFilter((uint)(sizes [3]))); long new_size; using (FilterRequest request = new FilterRequest(scalephoto.DefaultVersionUri)) { filters.Convert(request); new_size = (new Gnome.Vfs.FileInfo(request.Current.ToString())).Size; } if (orig_size > 0) { // Get the factor (scale) between original and resized medium size. scale_percentage = 1 - ((float)(orig_size - new_size) / orig_size); // What is the relation between the estimated medium scale factor, and reality? double scale_scale = scale_percentage / avg_scale_ref[3]; //System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}", // scale_percentage, avg_scale_ref[3], scale_scale ); // Re-Calculate the proper relation per size for (int k = 0; k < avg_scale_ref.Length; k++) { avg_scale[k] = avg_scale_ref[k] * scale_scale; // System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})", // k, avg_scale[k], avg_scale_ref[k] ); } } } NumberOfPictures.Text = selection.Count.ToString(); TotalOriginalSize.Text = SizeUtil.ToHumanReadable(Orig_Photo_Size); UpdateEstimatedSize(); Dialog.ShowAll(); //LoadHistory (); Dialog.Response += HandleResponse; }
private void MeasureFontRelatedSizes() { // Find largest digit int widestDigitWidth = int.MinValue; char widestDigitChar = new char(); for (int i = 0; i <= 9; i++) { char digitChar = (char)('0' + i); Size digitSize = TextRenderer.MeasureText(new string(digitChar, 1), this.Font); int digitWidth = digitSize.Width; if (widestDigitWidth < digitWidth) { widestDigitWidth = digitWidth; widestDigitChar = digitChar; } } // Find widest year/month width string sampleYearMonthText = DateTime.Now.ToString(this.DateTimeFormat.YearMonthPattern); var sbYearMonthText = new StringBuilder(sampleYearMonthText.Length); foreach (var ch in sampleYearMonthText) // Replace digits with largest digit { if (char.IsDigit(ch)) { sbYearMonthText.Append(widestDigitChar); } else { sbYearMonthText.Append(ch); } } sampleYearMonthText = sbYearMonthText.ToString(); int widestYearMonthNameWidth = TextRenderer.MeasureText(sampleYearMonthText, this.Font).Width; // Find widest day in month (MM) format string sampleDayInMonthText = new string(widestDigitChar, 2); int widestDayInMonthWidth = TextRenderer.MeasureText(sampleDayInMonthText, this.Font).Width; // Find widest short date width string sampleShortDateText = DateTime.Now.ToString(this.DateTimeFormat.ShortDatePattern); var sbShortDateText = new StringBuilder(sampleShortDateText.Length); foreach (var ch in sampleShortDateText) // Replace digits with largest digit { if (char.IsDigit(ch)) { sbShortDateText.Append(widestDigitChar); } else { sbShortDateText.Append(ch); } } sampleShortDateText = sbShortDateText.ToString(); this.widestShortDateWidth = TextRenderer.MeasureText(sampleShortDateText, this.Font).Width; // Find widest week day name int widestWeekDayNameWidth = int.MinValue; for (int i = 0; i < DaysInWeek; i++) { string weekDayName = this.DateTimeFormat.GetAbbreviatedDayName((DayOfWeek)i); Size weekDayNameSize = TextRenderer.MeasureText(weekDayName, this.Font); if (weekDayNameSize.Width > widestWeekDayNameWidth) { widestWeekDayNameWidth = weekDayNameSize.Width; } } // Measure body padding in pixels this.bodyPadding = SizeUtil.DLUToPixels(BodyPaddingDLU); // Measure title padding in pixels this.titlePadding = SizeUtil.DLUToPixels(TitlePaddingDLU); // Measure title text margin in pixels this.titleTextMargin = SizeUtil.DLUToPixels(TitleTextMarginDLU); // Measure week day padding this.weekDayPadding = SizeUtil.DLUToPixels(WeekDayPaddingDLU); // Measure column width this.dayTextPadding = SizeUtil.DLUToPixels(DayTextPaddingDLU); this.columnWidth = Math.Max(widestDayInMonthWidth + this.dayTextPadding.Horizontal, widestWeekDayNameWidth + weekDayPadding.Horizontal); // Measure days part padding this.monthPadding = SizeUtil.DLUToPixels(MonthPaddingDLU); // Measure row hegiht this.rowHeight = this.Font.Height + this.dayTextPadding.Vertical; // Measure footer padding this.footerPadding = SizeUtil.DLUToPixels(FooterPaddingDLU); }
public SendEmail(IBrowsableCollection selection) : base("mail_dialog") { this.selection = selection; // Set default values in dialog. Fetch from Preferences. switch ((int)Preferences.Get(Preferences.EXPORT_EMAIL_SIZE)) { case 0: original_size.Active = true; break; case 1: tiny_size.Active = true; break; case 2: small_size.Active = true; break; case 3: medium_size.Active = true; break; case 4: large_size.Active = true; break; case 5: x_large_size.Active = true; break; default: break; } rotate_check.Active = (bool)Preferences.Get(Preferences.EXPORT_EMAIL_ROTATE); rotate_check.Sensitive = original_size.Active; tray_scrolled.Add(new TrayView(selection)); Dialog.Modal = false; string path; System.IO.FileInfo file_info; // Calculate total original filesize foreach (Photo photo in selection.Items) { if (photo != null) { path = photo.GetVersionPath(photo.DefaultVersionId); if (System.IO.File.Exists(path)) { file_info = new System.IO.FileInfo(path); Orig_Photo_Size += file_info.Length; } // if file exists } // if photo != null } // foreach for (int k = 0; k < avg_scale_ref.Length; k++) { avg_scale[k] = avg_scale_ref[k]; } // Calculate approximate size shrinking, use first photo, and shrink to medium size as base. Photo scalephoto = selection.Items [0] as Photo; if (scalephoto != null) { // Get first photos file size file_info = new System.IO.FileInfo(scalephoto.GetVersionPath(scalephoto.DefaultVersionId)); long orig_size = file_info.Length; // Get filesize of first photo after resizing it to medium size path = PixbufUtils.Resize(scalephoto.GetVersionPath(scalephoto.DefaultVersionId), sizes[3], true); file_info = new System.IO.FileInfo(path); long new_size = file_info.Length; // Delete the just created temporary resized photo System.IO.File.Delete(path); if (orig_size > 0) { // Get the factor (scale) between original and resized medium size. scale_percentage = 1 - ((float)(orig_size - new_size) / orig_size); // What is the relation between the estimated medium scale factor, and reality? double scale_scale = scale_percentage / avg_scale_ref[3]; //System.Console.WriteLine ("scale_percentage {0}, ref {1}, relative {2}", // scale_percentage, avg_scale_ref[3], scale_scale ); // Re-Calculate the proper relation per size for (int k = 0; k < avg_scale_ref.Length; k++) { avg_scale[k] = avg_scale_ref[k] * scale_scale; // System.Console.WriteLine ("avg_scale[{0}]={1} (was {2})", // k, avg_scale[k], avg_scale_ref[k] ); } } } NumberOfPictures.Text = selection.Count.ToString(); TotalOriginalSize.Text = SizeUtil.ToHumanReadable(Orig_Photo_Size); UpdateEstimatedSize(); Dialog.ShowAll(); //LoadHistory (); Dialog.Response += HandleResponse; }
/// <summary> /// Handles timer for stats updates. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event.</param> private void StatisticsTimer_Elapsed(object sender, ElapsedEventArgs e) { if (!_rasConnected) { return; } try { if (_currentConnection == null) { return; } // Retrieve stats from the current connection RasLinkStatistics statistics = _currentConnection.GetConnectionStatistics(); // Compare new values to old ones and get the current // data size been downloaded or uploaded var received = statistics.BytesReceived - _oldReceivedStat; var sent = statistics.BytesTransmitted - _oldSentStat; // Add new data amount to the total _totalDownloaded += received; _totalUploaded += sent; // Format the total stat. Adds units at the end of the string // 1.01 -> 1.01 KB/MB/GB/etc var totalDownloadedFormatted = SizeUtil.SizeSuffix(_totalDownloaded, 2); var totalUploadedFormatted = SizeUtil.SizeSuffix(_totalUploaded, 2); // Format session stats var sessionDownloadedFormatted = SizeUtil.SizeSuffix(statistics.BytesReceived); var sessionUploadedFormatted = SizeUtil.SizeSuffix(statistics.BytesTransmitted); // Calculate speed var downSpeed = Math.Round(received / 1024d, 2); var upSpeed = Math.Round(sent / 1024d, 2); // Now the new data becomes the old data _oldReceivedStat = statistics.BytesReceived; _oldSentStat = statistics.BytesTransmitted; // Format the duration of the connection var connDuration = $"{statistics.ConnectionDuration:hh\\:mm\\:ss}"; // Update the UI _view.UpdateDownloadSpeed($"{downSpeed}"); _view.UpdateUploadSpeed($"{upSpeed}"); _view.UpdateSessionDownload($"{sessionDownloadedFormatted}"); _view.UpdateSessionUpload($"{sessionUploadedFormatted}"); _view.UpdateTotalDownloaded($"{totalDownloadedFormatted}"); _view.UpdateTotalUploaded($"{totalUploadedFormatted}"); _view.UpdateChart(downSpeed, upSpeed); _view.UpdateConnDuration(connDuration); } catch (Exception ex) { _view.UpdateToolStripStatus(ex.Message); } }
/// <summary> /// Handles what happens when <see cref="IMainView.ResetSessionClicked"/> occurs. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event.</param> private void View_ResetSessionClicked(object sender, EventArgs e) { _view.UpdateSessionDownload(SizeUtil.SizeSuffix(0, 2)); _view.UpdateSessionUpload(SizeUtil.SizeSuffix(0, 2)); }