Skip to content

Commit

Permalink
Squashed commit and merge of the 'release' branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
phw198 committed Dec 29, 2020
1 parent 8832dde commit 2711020
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/OutlookGoogleCalendarSync/Console/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public void Update(String moreOutput, Markup? markupPrefix = null, bool newLine
if (logit) {
//Log the output sans HTML tags
String tagsStripped = Regex.Replace(htmlOutput, "(</p>|<br/?>)", "\r\n");
tagsStripped = Regex.Replace(tagsStripped, "<span class='em em-repeat'></span>", "(R)");
tagsStripped = Regex.Replace(tagsStripped, "<.*?>", String.Empty);
String[] logLines = tagsStripped.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (markupPrefix == Markup.warning)
Expand Down Expand Up @@ -351,7 +352,7 @@ private String parseEmoji(String output, Markup? markupPrefix = null) {

output = output.Replace(":calendar:", "<span class='em em-date' style='margin-top:5px'></span>");
output = output.Replace("(R)", "<span class='em em-repeat'></span>");
output = output.Replace("=>", "");
output = output.Replace("=> ", "");

} catch (System.Exception ex) {
log.Error("Failed parsing for emoji.");
Expand Down
35 changes: 32 additions & 3 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ private void updateGUIsettings() {
ToolTips.SetToolTip(cbCloakEmail,
"Google has been known to send meeting updates to attendees without your consent.\n" +
"This option safeguards against that by appending '"+ GoogleOgcs.EventAttendee.EmailCloak +"' to their email address.");
ToolTips.SetToolTip(cbSingleCategoryOnly,
"Only allow a single Outlook category - ie 1:1 sync with Google.\n" +
"Otherwise, for multiple categories and only one synced with OGCS, manually prefix the category name(s) with \"OGCS \".");
ToolTips.SetToolTip(cbReminderDND,
"Do Not Disturb: Don't sync reminders to Google if they will trigger between these times.");

Expand Down Expand Up @@ -284,6 +287,7 @@ private void updateGUIsettings() {
tbClientSecret.ReadOnly = false;
}

cbExcludeDeclinedInvites.Checked = Settings.Instance.ExcludeDeclinedInvites;
cbExcludeGoals.Checked = Settings.Instance.ExcludeGoals;
cbExcludeGoals.Enabled = GoogleOgcs.Calendar.IsDefaultCalendar() ?? true;

Expand Down Expand Up @@ -398,6 +402,8 @@ private void updateGUIsettings() {
dtDNDend.Value = Settings.Instance.ReminderDNDend;
cbAddColours.Checked = Settings.Instance.AddColours;
btColourMap.Enabled = Settings.Instance.AddColours;
cbSingleCategoryOnly.Checked = Settings.Instance.SingleCategoryOnly;
cbSingleCategoryOnly.Enabled = Settings.Instance.AddColours && Settings.Instance.SyncDirection.Id != Sync.Direction.OutlookToGoogle.Id;
this.gbSyncOptions_What.ResumeLayout();
#endregion
#endregion
Expand Down Expand Up @@ -1157,6 +1163,9 @@ private void btResetGCal_Click(object sender, EventArgs e) {
}
}

private void cbExcludeDeclinedInvites_CheckedChanged(object sender, EventArgs e) {
Settings.Instance.ExcludeDeclinedInvites = cbExcludeDeclinedInvites.Checked;
}
private void cbExcludeGoals_CheckedChanged(object sender, EventArgs e) {
Settings.Instance.ExcludeGoals = cbExcludeGoals.Checked;
}
Expand Down Expand Up @@ -1261,6 +1270,7 @@ private void syncDirection_SelectedIndexChanged(object sender, EventArgs e) {
tbTargetCalendar.Items.Remove("target calendar");
tbTargetCalendar.SelectedIndex = 0;
tbTargetCalendar.Enabled = true;
cbSingleCategoryOnly.Visible = true;
} else {
cbObfuscateDirection.Enabled = false;
cbObfuscateDirection.SelectedIndex = Settings.Instance.SyncDirection.Id - 1;
Expand All @@ -1284,6 +1294,7 @@ private void syncDirection_SelectedIndexChanged(object sender, EventArgs e) {
this.lDNDand.Visible = false;
this.ddGoogleColour.Visible = false;
this.ddOutlookColour.Visible = true;
this.cbSingleCategoryOnly.Visible = true;
}
if (Settings.Instance.SyncDirection == Sync.Direction.OutlookToGoogle) {
Sync.Engine.Instance.RegisterForPushSync();
Expand All @@ -1294,6 +1305,7 @@ private void syncDirection_SelectedIndexChanged(object sender, EventArgs e) {
this.lDNDand.Visible = true;
this.ddGoogleColour.Visible = true;
this.ddOutlookColour.Visible = false;
this.cbSingleCategoryOnly.Visible = false;
}
cbAddAttendees_CheckedChanged(null, null);
cbAddReminders_CheckedChanged(null, null);
Expand Down Expand Up @@ -1620,6 +1632,7 @@ private void cbCloakEmail_CheckedChanged(object sender, EventArgs e) {
private void cbAddColours_CheckedChanged(object sender, EventArgs e) {
Settings.Instance.AddColours = cbAddColours.Checked;
btColourMap.Enabled = Settings.Instance.AddColours;
cbSingleCategoryOnly.Enabled = Settings.Instance.AddColours;
}
private void btColourMap_Click(object sender, EventArgs e) {
if (Settings.Instance.UseGoogleCalendar == null || string.IsNullOrEmpty(Settings.Instance.UseGoogleCalendar.Id)) {
Expand All @@ -1628,6 +1641,9 @@ private void btColourMap_Click(object sender, EventArgs e) {
}
new Forms.ColourMap().ShowDialog(this);
}
private void cbSingleCategoryOnly_CheckedChanged(object sender, EventArgs e) {
Settings.Instance.SingleCategoryOnly = cbSingleCategoryOnly.Checked;
}
#endregion
#endregion
#region Application settings
Expand Down Expand Up @@ -1737,6 +1753,8 @@ private void cbCloudLogging_CheckStateChanged(object sender, EventArgs e) {
}

private void cbTelemetryDisabled_CheckedChanged(object sender, EventArgs e) {
if (!this.Visible) return;

if (!cbTelemetryDisabled.Checked) {
Settings.Instance.TelemetryDisabled = cbTelemetryDisabled.Checked;
return;
Expand Down
9 changes: 7 additions & 2 deletions src/OutlookGoogleCalendarSync/GoogleOgcs/EventColour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ public List<Palette> ActivePalette {
get {
List<Palette> activePalette = new List<Palette>();
if (Settings.Instance.UseGoogleCalendar == null) return activePalette;


if (Settings.Instance.UseGoogleCalendar.ColourId == null) {
List<GoogleCalendarListEntry> gCals = GoogleOgcs.Calendar.Instance.GetCalendars();
Settings.Instance.UseGoogleCalendar.ColourId = gCals.Find(c => c.Id == Settings.Instance.UseGoogleCalendar.Id).ColourId;
}

//Palette currentCal = calendarPalette.Find(p => p.Id == Settings.Instance.UseGoogleCalendar.ColourId);
Palette currentCal = null;
foreach (Palette cal in calendarPalette) {
Expand Down Expand Up @@ -225,7 +230,7 @@ public void Get() {
/// <param name="colourId">Google ID</param>
public Palette GetColour(String colourId) {
Palette gColour = this.ActivePalette.Where(x => x.Id == colourId).FirstOrDefault();
if (gColour != null)
if (colourId != "0" && gColour != null)
return gColour;
else
return Palette.NullPalette;
Expand Down
22 changes: 19 additions & 3 deletions src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ public List<Event> GetCalendarEntriesInRange(DateTime from, DateTime to) {
result = result.Except(cancelled).ToList();
}

if (Settings.Instance.ExcludeDeclinedInvites) {
List<Event> declined = result.Where(ev => string.IsNullOrEmpty(ev.RecurringEventId) && ev.Attendees != null && ev.Attendees.Count(a => a.Self == true && a.ResponseStatus == "declined") == 1).ToList();
if (declined.Count > 0) {
log.Debug(declined.Count + " Google Event invites have been declined and will be excluded.");
result = result.Except(declined).ToList();
}
}

if ((IsDefaultCalendar() ?? true) && Settings.Instance.ExcludeGoals) {
List<Event> goals = result.Where(ev =>
!string.IsNullOrEmpty(ev.Description) && ev.Description.Contains("This event was added from Goals in Google Calendar.") &&
Expand Down Expand Up @@ -486,6 +494,7 @@ private Event createCalendarEntry_save(Event ev, AppointmentItem ai) {
if (Settings.Instance.SyncDirection == Sync.Direction.Bidirectional || OutlookOgcs.CustomProperty.ExistsAny(ai)) {
log.Debug("Storing the Google event IDs in Outlook appointment.");
OutlookOgcs.CustomProperty.AddGoogleIDs(ref ai, createdEvent);
OutlookOgcs.CustomProperty.SetOGCSlastModified(ref ai);
ai.Save();
}
//DOS ourself by triggering API limit
Expand Down Expand Up @@ -896,6 +905,13 @@ public void DeleteCalendarEntries(List<Event> events) {
if (doDelete) deleteCalendarEntry_save(ev);
else events.Remove(ev);
} catch (System.Exception ex) {
if (ex is Google.GoogleApiException) {
Google.GoogleApiException gex = ex as Google.GoogleApiException;
if (gex.Error != null && gex.Error.Code == 410) { //Resource has been deleted
log.Fail("This event is already deleted! Ignoring failed request to delete.");
continue;
}
}
Forms.Main.Instance.Console.UpdateWithError(GoogleOgcs.Calendar.GetEventSummary(ev, true) + "Deleted event failed to remove.", ex);
OGCSexception.Analyse(ex, true);
if (OgcsMessageBox.Show("Deleted Google event failed to remove. Continue with synchronisation?", "Sync item failed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
Expand Down Expand Up @@ -1348,7 +1364,7 @@ public void GetSettings() {
this.UTCoffset = TimezoneDB.GetUtcOffset(setting.Value);
} catch (System.Exception ex) {
OGCSexception.Analyse("Not able to retrieve Google calendar's global timezone", ex);
throw new System.ApplicationException("Unable to retrieve Google calendar's global timezone.", ex);
throw;
}
getCalendarSettings();
}
Expand All @@ -1362,8 +1378,8 @@ private void getCalendarSettings() {
else
this.MinDefaultReminder = cal.DefaultReminders.Where(x => x.Method.Equals("popup")).OrderBy(x => x.Minutes.Value).First().Minutes.Value;
} catch (System.Exception ex) {
OGCSexception.Analyse("Failed to get calendar settings.", ex);
throw new System.ApplicationException("Unable to retrieve Google calendar's reminder settings.", ex);
OGCSexception.Analyse("Failed to get calendar's reminder settings.", ex);
throw;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,12 @@ public Boolean UpdateCalendarEntry(ref AppointmentItem ai, Event ev, ref int ite
}
String gCategoryName = getColour(ev.ColorId, oCategoryName ?? "");
if (Sync.Engine.CompareAttribute("Category/Colour", Sync.Direction.GoogleToOutlook, gCategoryName, oCategoryName, sb, ref itemModified)) {
if (Settings.Instance.SingleCategoryOnly)
aiCategories = new List<string>();
else {
//Only allow one OGCS category at a time (Google Events can only have one colour)
aiCategories.RemoveAll(x => x.StartsWith("OGCS ") || x == gCategoryName);
}
aiCategories.Insert(0, gCategoryName);
ai.Categories = String.Join(Categories.Delimiter, aiCategories.ToArray());
}
Expand Down Expand Up @@ -1352,7 +1356,7 @@ public static void IdentifyEventDifferences(
//Don't delete any items that aren't yet in Google or just created in Google during this sync
for (int o = outlook.Count - 1; o >= 0; o--) {
if (!CustomProperty.Exists(outlook[o], CustomProperty.MetadataId.gEventID) ||
outlook[o].LastModificationTime > Sync.Engine.Instance.SyncStarted)
CustomProperty.GetOGCSlastModified(outlook[o]) > Sync.Engine.Instance.SyncStarted)
outlook.Remove(outlook[o]);
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,14 @@ public String GetRecipientEmail(Recipient recipient) {
ExchangeUser eu = null;
try {
eu = addressEntry.GetExchangeUser();
if (eu != null && eu.PrimarySmtpAddress != null)
retEmail = eu.PrimarySmtpAddress;
else {
if (eu != null) {
try {
retEmail = eu.PrimarySmtpAddress;
} catch (System.Exception ex) {
OGCSexception.Analyse("Could not access Exchange users's primary SMTP.", OGCSexception.LogAsFail(ex));
}
}
if (eu == null || string.IsNullOrEmpty(retEmail)) {
log.Warn("Exchange does not have an email for recipient: " + recipient.Name);
Microsoft.Office.Interop.Outlook.PropertyAccessor pa = null;
try {
Expand Down Expand Up @@ -800,7 +805,7 @@ private TimeZoneInfo getWindowsTimezoneFromDescription(String tzDescription) {
if (tzi != null) return tzi;

//Finally, fuzzy logic
log.Warn("Could not find timezone ID based on given description. Attempting some fuzzy logic...");
log.Warn("Could not find timezone ID based on given description, '" + tzDescription + "'. Attempting some fuzzy logic...");
if (tzDescription.StartsWith("(GMT")) {
log.Fine("Replace GMT with UTC");
String modTzDescription = tzDescription.Replace("(GMT", "(UTC");
Expand Down
Loading

0 comments on commit 2711020

Please sign in to comment.