Skip to content

Commit

Permalink
Merge O365 code refactor changes.
Browse files Browse the repository at this point in the history
Branch 'feature-wip/release-code-refactor-google' into release
  • Loading branch information
phw198 committed May 19, 2024
2 parents 79f5925 + 80e84d6 commit 2d7aae3
Show file tree
Hide file tree
Showing 51 changed files with 1,393 additions and 1,354 deletions.
17 changes: 9 additions & 8 deletions src/OutlookGoogleCalendarSync/Console/Console.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using log4net;
using Ogcs = OutlookGoogleCalendarSync;
using log4net;
using Microsoft.Win32;
using System;
using System.Linq;
Expand Down Expand Up @@ -309,7 +310,7 @@ public void Update(String moreOutput, Markup? markupPrefix = null, bool newLine
} else
this.wb.DocumentText = content;
} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
Ogcs.Exception.Analyse(ex);
}

while (navigationStatus != NavigationStatus.completed) {
Expand All @@ -327,9 +328,9 @@ public void Update(String moreOutput, Markup? markupPrefix = null, bool newLine

public void UpdateWithError(String moreOutput, System.Exception ex, bool notifyBubble = false, String logEntry = null) {
Markup emoji = Markup.error;
if (OGCSexception.LoggingAsFail(ex))
if (ex.LoggingAsFail())
emoji = Markup.fail;
Update(moreOutput + (!string.IsNullOrEmpty(moreOutput) ? "<br/>" : "") + OGCSexception.FriendlyMessage(ex), logEntry, emoji, notifyBubble: notifyBubble);
Update(moreOutput + (!string.IsNullOrEmpty(moreOutput) ? "<br/>" : "") + Ogcs.Exception.FriendlyMessage(ex), logEntry, emoji, notifyBubble: notifyBubble);
}

/// <summary>Log the output sans HTML tags.</summary>
Expand Down Expand Up @@ -388,7 +389,7 @@ private String parseEmoji(String output, Markup? markupPrefix = null) {

} catch (System.Exception ex) {
log.Error("Failed parsing for emoji.");
OGCSexception.Analyse(ex);
Ogcs.Exception.Analyse(ex);
}
return output;
}
Expand All @@ -412,7 +413,7 @@ public void FormatEventChanges(StringBuilder sb, String anonymised) {
if (Settings.Instance.AnonymiseLogs) {
MatchCollection matches = Regex.Matches(anonymised, @"^Subject:\s(.*?)\s=>\s(.*?)$", RegexOptions.Multiline);
if (matches.Count > 0) {
anonymised = anonymised.Replace(matches[0].Value, "Subject: " + GoogleOgcs.Authenticator.GetMd5(matches[0].Groups[1].Value) + " => " + GoogleOgcs.Authenticator.GetMd5(matches[0].Groups[2].Value.TrimEnd("\r".ToCharArray())));
anonymised = anonymised.Replace(matches[0].Value, "Subject: " + Ogcs.Google.Authenticator.GetMd5(matches[0].Groups[1].Value) + " => " + Ogcs.Google.Authenticator.GetMd5(matches[0].Groups[2].Value.TrimEnd("\r".ToCharArray())));
}
}
Update(lines[0] + "<br/>" + table.ToString(), anonymised, verbose: true, newLine: false);
Expand Down Expand Up @@ -470,7 +471,7 @@ public static void MuteClicks(Boolean mute) {
log.Warn("Could not find default navigation sound registry key.");
}
} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
Ogcs.Exception.Analyse(ex);
}
}
#endregion
Expand All @@ -485,7 +486,7 @@ public void CallGappScript() {
System.Threading.Thread.Sleep(100);
}
} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
Ogcs.Exception.Analyse(ex);
}
log.Debug("Done");
*/
Expand Down
5 changes: 3 additions & 2 deletions src/OutlookGoogleCalendarSync/EmailAddress.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Ogcs = OutlookGoogleCalendarSync;
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using log4net;
Expand Down Expand Up @@ -75,7 +76,7 @@ public static String MaskAddressWithinText(String sourceContainingEmailAddress)
return sourceContainingEmailAddress.Replace(emailAddress, masked);
}
} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
Ogcs.Exception.Analyse(ex);
}
return sourceContainingEmailAddress;
}
Expand Down
79 changes: 40 additions & 39 deletions src/OutlookGoogleCalendarSync/Extensions/ColourPicker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Office.Interop.Outlook;
using Ogcs = OutlookGoogleCalendarSync;
using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -26,18 +27,18 @@ public void AddColourItems() {
/// Add all the available Outlook colours
/// </summary>
public void AddStandardColours() {
foreach (KeyValuePair<OlCategoryColor, Color> colour in OutlookOgcs.Categories.Map.Colours) {
Items.Add(new OutlookOgcs.Categories.ColourInfo(colour.Key, colour.Value));
foreach (KeyValuePair<OlCategoryColor, Color> colour in Outlook.Categories.Map.Colours) {
Items.Add(new Outlook.Categories.ColourInfo(colour.Key, colour.Value));
}
}

/// <summary>
/// Add just the colours associated with categories
/// </summary>
public void AddCategoryColours() {
if (OutlookOgcs.Factory.OutlookVersionName == OutlookOgcs.Factory.OutlookVersionNames.Outlook2003) return;
if (Outlook.Factory.OutlookVersionName == Outlook.Factory.OutlookVersionNames.Outlook2003) return;

Items.AddRange(OutlookOgcs.Calendar.Categories.DropdownItems().ToArray());
Items.AddRange(Outlook.Calendar.Categories.DropdownItems().ToArray());
}

public void ColourPicker_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) {
Expand All @@ -46,12 +47,12 @@ public void ColourPicker_DrawItem(object sender, System.Windows.Forms.DrawItemEv
return;

// Get the colour
OutlookOgcs.Categories.ColourInfo colour = (OutlookOgcs.Categories.ColourInfo)Items[e.Index];
Outlook.Categories.ColourInfo colour = (Outlook.Categories.ColourInfo)Items[e.Index];
ColourCombobox.DrawComboboxItemColour(cbColour, new SolidBrush(colour.Colour), colour.Text, e);
}

public new OutlookOgcs.Categories.ColourInfo SelectedItem {
get { return (OutlookOgcs.Categories.ColourInfo)base.SelectedItem; }
public new Outlook.Categories.ColourInfo SelectedItem {
get { return (Outlook.Categories.ColourInfo)base.SelectedItem; }
set { base.SelectedItem = value; }
}
}
Expand All @@ -66,9 +67,9 @@ public GoogleColourPicker() {
/// Add all the available Google colours
/// </summary>
public void AddPaletteColours(Boolean connectToGoogle = false) {
if (GoogleOgcs.Calendar.IsInstanceNull && !connectToGoogle) return;
if (Ogcs.Google.Calendar.IsInstanceNull && !connectToGoogle) return;

foreach (GoogleOgcs.EventColour.Palette palette in GoogleOgcs.Calendar.Instance.ColourPalette.ActivePalette) {
foreach (Ogcs.Google.EventColour.Palette palette in Ogcs.Google.Calendar.Instance.ColourPalette.ActivePalette) {
Items.Add(palette);
}
}
Expand All @@ -79,50 +80,50 @@ public void ColourPicker_DrawItem(object sender, System.Windows.Forms.DrawItemEv
return;

// Get the colour
GoogleOgcs.EventColour.Palette colour = (GoogleOgcs.EventColour.Palette)Items[e.Index];
Ogcs.Google.EventColour.Palette colour = (Ogcs.Google.EventColour.Palette)Items[e.Index];
ColourCombobox.DrawComboboxItemColour(cbColour, new SolidBrush(colour.RgbValue), colour.Name, e);
}

public new GoogleOgcs.EventColour.Palette SelectedItem {
get { return (GoogleOgcs.EventColour.Palette)base.SelectedItem; }
public new Ogcs.Google.EventColour.Palette SelectedItem {
get { return (Ogcs.Google.EventColour.Palette)base.SelectedItem; }
set { base.SelectedItem = value; }
}

private void ColourPicker_Enter(object sender, EventArgs e) {
if (Forms.Main.Instance.ActiveCalendarProfile.UseGoogleCalendar == null || string.IsNullOrEmpty(Forms.Main.Instance.ActiveCalendarProfile.UseGoogleCalendar.Id)) {
OgcsMessageBox.Show("You need to select a Google Calendar first on the 'Settings' tab.", "Configuration Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
Ogcs.Extensions.MessageBox.Show("You need to select a Google Calendar first on the 'Settings' tab.", "Configuration Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}

ToolTip loading = new ToolTip();
try {
GoogleOgcs.EventColour.Palette currentSelection = null;
Ogcs.Google.EventColour.Palette currentSelection = null;

if (GoogleOgcs.Calendar.IsInstanceNull || !GoogleOgcs.Calendar.Instance.ColourPalette.IsCached()) {
if (Ogcs.Google.Calendar.IsInstanceNull || !Ogcs.Google.Calendar.Instance.ColourPalette.IsCached()) {
loading.SetToolTip(this, "Retrieving colours from Google...");
loading.ShowAlways = true;
loading.InitialDelay = 0;
loading.Show("Retrieving colours from Google...", this, this.FindForm().PointToClient(this.Parent.PointToScreen(this.Location)));

GoogleOgcs.Calendar.Instance.ColourPalette.Get();
currentSelection = (GoogleOgcs.EventColour.Palette)SelectedItem;
Ogcs.Google.Calendar.Instance.ColourPalette.Get();
currentSelection = (Ogcs.Google.EventColour.Palette)SelectedItem;

loading.Hide(this);
}
if (Items.Count != GoogleOgcs.Calendar.Instance.ColourPalette.ActivePalette.Count) {
if (Items.Count != Ogcs.Google.Calendar.Instance.ColourPalette.ActivePalette.Count) {
while (Items.Count > 0)
Items.RemoveAt(0);
AddPaletteColours(true);
}

foreach (GoogleOgcs.EventColour.Palette pInfo in Items) {
foreach (Ogcs.Google.EventColour.Palette pInfo in Items) {
if (pInfo.Id == currentSelection?.Id) {
SelectedItem = pInfo;
break;
}
}
} catch (System.Exception ex) {
OGCSexception.Analyse("ColourPicker_Enter()", ex);
ex.Analyse("ColourPicker_Enter()");
} finally {
loading.Hide(this);
loading.RemoveAll();
Expand Down Expand Up @@ -187,8 +188,8 @@ public override void InitializeEditingControl(int rowIndex, object initialFormat
if (ctl.Items.Count == 0)
ctl.PopulateDropdownItems();
if (!string.IsNullOrEmpty(currentText)) this.Value = currentText;
foreach (OutlookOgcs.Categories.ColourInfo ci in Forms.ColourMap.OutlookComboBox.Items) {

foreach (Outlook.Categories.ColourInfo ci in Forms.ColourMap.OutlookComboBox.Items) {
if (ci.Text == (String)this.Value) {
ctl.SelectedValue = ci;
break;
Expand All @@ -206,7 +207,7 @@ public override Type EditType {

public override Type ValueType {
get {
return typeof(OutlookOgcs.Categories.ColourInfo);
return typeof(Outlook.Categories.ColourInfo);
}
}

Expand All @@ -224,7 +225,7 @@ protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.R
if (rowIndex < 0)
return;

foreach (OutlookOgcs.Categories.ColourInfo ci in Forms.ColourMap.OutlookComboBox.Items) {
foreach (Outlook.Categories.ColourInfo ci in Forms.ColourMap.OutlookComboBox.Items) {
if (ci.Text == this.Value.ToString()) {
Brush boxBrush = new SolidBrush(ci.Colour);
Brush textBrush = SystemBrushes.WindowText;
Expand All @@ -233,7 +234,7 @@ protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.R
}
}
} catch (System.Exception ex) {
OGCSexception.Analyse("OutlookColourComboboxCell.Paint()", ex);
ex.Analyse("OutlookColourComboboxCell.Paint()");
}
}
}
Expand All @@ -253,7 +254,7 @@ public override void InitializeEditingControl(int rowIndex, object initialFormat
ctl.PopulateDropdownItems();
if (!string.IsNullOrEmpty(currentText)) this.Value = currentText;

foreach (GoogleOgcs.EventColour.Palette p in Forms.ColourMap.GoogleComboBox.Items) {
foreach (Ogcs.Google.EventColour.Palette p in Forms.ColourMap.GoogleComboBox.Items) {
if (p.Name == (String)this.Value) {
ctl.SelectedValue = p;
break;
Expand All @@ -271,7 +272,7 @@ public override Type EditType {

public override Type ValueType {
get {
return typeof(GoogleOgcs.EventColour.Palette);
return typeof(Ogcs.Google.EventColour.Palette);
}
}

Expand All @@ -289,7 +290,7 @@ protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.R
if (rowIndex < 0)
return;

foreach (GoogleOgcs.EventColour.Palette ci in Forms.ColourMap.GoogleComboBox.Items) {
foreach (Ogcs.Google.EventColour.Palette ci in Forms.ColourMap.GoogleComboBox.Items) {
if (ci.Name == this.Value?.ToString()) {
Brush boxBrush = new SolidBrush(ci.RgbValue);
Brush textBrush = SystemBrushes.WindowText;
Expand All @@ -298,7 +299,7 @@ protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.R
}
}
} catch (System.Exception ex) {
OGCSexception.Analyse("GoogleColourComboboxCell.Paint()", ex);
ex.Analyse("GoogleColourComboboxCell.Paint()");
}
}
}
Expand Down Expand Up @@ -424,7 +425,7 @@ public static void DrawComboboxItemColour(ComboBox cbColour, Brush boxColour, St
if ((e.State & DrawItemState.NoFocusRect) == DrawItemState.None)
e.DrawFocusRectangle();
} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
Ogcs.Exception.Analyse(ex);
}
}

Expand All @@ -447,7 +448,7 @@ public static void DrawComboboxItemColour(Boolean comboEnabled, Brush boxColour,
cellBounds.Y + ((cellBounds.Height - Control.DefaultFont.Height) / 2));

} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
Ogcs.Exception.Analyse(ex);
}
}
}
Expand All @@ -464,8 +465,8 @@ public OutlookColourCombobox() {
}

public void PopulateDropdownItems() {
Dictionary<OutlookOgcs.Categories.ColourInfo, String> cbItems = new Dictionary<OutlookOgcs.Categories.ColourInfo, String>();
foreach (OutlookOgcs.Categories.ColourInfo ci in Forms.ColourMap.OutlookComboBox.Items) {
Dictionary<Outlook.Categories.ColourInfo, String> cbItems = new Dictionary<Outlook.Categories.ColourInfo, String>();
foreach (Outlook.Categories.ColourInfo ci in Forms.ColourMap.OutlookComboBox.Items) {
cbItems.Add(ci, ci.Text);
}
this.DataSource = new BindingSource(cbItems, null);
Expand All @@ -479,11 +480,11 @@ void ComboboxColor_DrawItem(object sender, DrawItemEventArgs e) {
if (indexItem < 0 || indexItem >= cbColour.Items.Count)
return;

KeyValuePair<OutlookOgcs.Categories.ColourInfo, String> kvp = (KeyValuePair< OutlookOgcs.Categories.ColourInfo, String>)cbColour.Items[indexItem];
KeyValuePair<Outlook.Categories.ColourInfo, String> kvp = (KeyValuePair<Outlook.Categories.ColourInfo, String>)cbColour.Items[indexItem];
if (kvp.Key != null) {
// Get the colour
OlCategoryColor olColour = kvp.Key.OutlookCategory;
Brush brush = new SolidBrush(OutlookOgcs.Categories.Map.RgbColour(olColour));
Brush brush = new SolidBrush(Outlook.Categories.Map.RgbColour(olColour));

DrawComboboxItemColour(cbColour, brush, kvp.Value, e);
}
Expand All @@ -502,8 +503,8 @@ public GoogleColourCombobox() {
}

public void PopulateDropdownItems() {
Dictionary <GoogleOgcs.EventColour.Palette, String> cbItems = new Dictionary<GoogleOgcs.EventColour.Palette, String>();
foreach (GoogleOgcs.EventColour.Palette ci in Forms.ColourMap.GoogleComboBox.Items) {
Dictionary<Ogcs.Google.EventColour.Palette, String> cbItems = new Dictionary<Ogcs.Google.EventColour.Palette, String>();
foreach (Ogcs.Google.EventColour.Palette ci in Forms.ColourMap.GoogleComboBox.Items) {
cbItems.Add(ci, ci.Name);
}
this.DataSource = new BindingSource(cbItems, null);
Expand All @@ -516,7 +517,7 @@ void ComboboxColor_DrawItem(object sender, DrawItemEventArgs e) {
if (e.Index < 0 || e.Index >= cbColour.Items.Count)
return;

KeyValuePair<GoogleOgcs.EventColour.Palette, String> kvp = (KeyValuePair<GoogleOgcs.EventColour.Palette, String>)cbColour.Items[e.Index];
KeyValuePair<Ogcs.Google.EventColour.Palette, String> kvp = (KeyValuePair<Ogcs.Google.EventColour.Palette, String>)cbColour.Items[e.Index];
if (kvp.Key != null) {
// Get the colour
Brush brush = new SolidBrush(kvp.Key.RgbValue);
Expand Down
10 changes: 5 additions & 5 deletions src/OutlookGoogleCalendarSync/Extensions/DateTime.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using Google.Apis.Calendar.v3.Data;
using System;

namespace OutlookGoogleCalendarSync {
public static class DateTimeExtensions {
namespace OutlookGoogleCalendarSync.Extensions {
public static class DateTime {
/// <summary>
/// Returns the DateTime with time and GMT offset.
/// This used to be the string format Google held date-times, eg "2012-08-20T00:00:00+02:00"
/// </summary>
/// <param name="dt">Date-time valule</param>
/// <returns>Formatted string</returns>
public static String ToPreciseString(this DateTime dt) {
public static String ToPreciseString(this System.DateTime dt) {
return dt.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", new System.Globalization.CultureInfo("en-US"));
}

/// <summary>
/// Returns the non-null Date or DateTime properties as a DateTime
/// </summary>
/// <returns>DateTime</returns>
public static DateTime SafeDateTime(this EventDateTime evDt) {
return evDt.DateTime ?? DateTime.Parse(evDt.Date);
public static System.DateTime SafeDateTime(this EventDateTime evDt) {
return evDt.DateTime ?? System.DateTime.Parse(evDt.Date);
}

/// <summary>
Expand Down
Loading

0 comments on commit 2d7aae3

Please sign in to comment.