Skip to content

Commit

Permalink
Improved message following exhausted quota.
Browse files Browse the repository at this point in the history
Fix scrollbar showing unnecessarily.
#1120
  • Loading branch information
phw198 committed Jan 10, 2021
1 parent 82ff5fc commit 0c1bbec
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/OutlookGoogleCalendarSync/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,25 +599,44 @@ public void Sync_Click(object sender, EventArgs e) {

public enum SyncNotes {
QuotaExhaustedInfo,
QuotaExhaustedPreviously,
RecentSubscription,
SubscriptionPendingExpire,
SubscriptionExpired,
NotLogFile
}
public void SyncNote(SyncNotes syncNote, Object extraData, Boolean show = true) {
if (!this.tbSyncNote.Visible && !show) return; //Already hidden
if (this.Visible && !this.tbSyncNote.Visible && !show) return; //Already hidden

String note = "";
String url = "";
String urlStub = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E595EQ7SNDBHA&item_name=";
String cr = "\r\n";

if (syncNote == SyncNotes.QuotaExhaustedInfo && !show && this.tbSyncNote.Text.Contains("quota is exhausted")) {
syncNote = SyncNotes.QuotaExhaustedPreviously;
show = true;
}

switch (syncNote) {
case SyncNotes.QuotaExhaustedInfo:
note = " Google's daily free calendar quota is exhausted!" + cr +
" Either wait for new quota at 08:00GMT or " + cr +
" get yourself guaranteed quota for just £1/month.";
url = urlStub + "OGCS Premium for " + Settings.Instance.GaccountEmail;
break;
case SyncNotes.QuotaExhaustedPreviously:
DateTime utcNow = DateTime.UtcNow;
DateTime quotaReset = utcNow.Date.AddHours(8).AddMinutes(utcNow.Minute);
if ((quotaReset - utcNow).Ticks < 0) quotaReset = quotaReset.AddDays(1);
int delayHours = (int)(quotaReset - DateTime.Now).TotalHours + 1;
note = "Google's daily free calendar quota was exhausted!" + cr +
" Syncs were delayed "+ delayHours +" hours until 08:00GMT " + cr +
" Get yourself guaranteed quota for just £1/month.";
url = urlStub + "OGCS Premium for " + Settings.Instance.GaccountEmail;
System.Threading.Thread hide = new System.Threading.Thread(() => { System.Threading.Thread.Sleep((delayHours + 3) * 60 * 60 * 1000); SyncNote(SyncNotes.QuotaExhaustedPreviously, null, false); });
hide.Start();
break;
case SyncNotes.RecentSubscription:
note = " " + cr +
" Thank you for your subscription and support! " + cr +
Expand Down Expand Up @@ -771,10 +790,12 @@ private void Main_Load(object sender, EventArgs e) {
}

public void MainFormShow() {
this.tbSyncNote.ScrollBars = RichTextBoxScrollBars.None; //Reset scrollbar
this.Show(); //Show minimised back in taskbar
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
this.TopMost = true;
this.tbSyncNote.ScrollBars = RichTextBoxScrollBars.Vertical; //Show scrollbar if necessary
this.Show(); //Now restore
this.TopMost = false;
this.Refresh();
Expand Down

0 comments on commit 0c1bbec

Please sign in to comment.