Skip to content

Commit

Permalink
Catch failure to logon to Exchange on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
phw198 committed Sep 18, 2021
1 parent 9921169 commit 46d8f25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs

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

9 changes: 7 additions & 2 deletions src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ public void Connect() {
explorerWatcher = new ExplorerWatcher(oApp);

} catch (System.Runtime.InteropServices.COMException ex) {
if (OGCSexception.GetErrorCode(ex) == "0x84120009") { //Cannot complete the operation. You are not connected. [Issue #514, occurs on GetNamespace("mapi")]
String errCode = OGCSexception.GetErrorCode(ex);
if (errCode == "0x84120009") { //Cannot complete the operation. You are not connected. [Issue #514, occurs on GetNamespace("mapi")]
log.Warn(ex.Message);
throw new ApplicationException("A problem was encountered with your Office install.\r\n" +
"Please perform an Office Repair or reinstall Outlook and then try running OGCS again.");
} else if (errCode == "0x8004011D") { //The attempt to log on to Microsoft Exchange has failed. [Eg VPN connectivity down]
throw new ApplicationException(ex.Message);
} else throw;

} finally {
Expand All @@ -121,7 +124,7 @@ public void Disconnect(Boolean onlyWhenNoGUI = false) {
calendarFolders.Remove(calendarFolders.ElementAt(fld).Key);
}
calendarFolders = new Dictionary<string, MAPIFolder>();
Calendar.Categories.Dispose();
Calendar.Categories?.Dispose();
explorerWatcher = (ExplorerWatcher)Calendar.ReleaseObject(explorerWatcher);
} catch (System.Exception ex) {
log.Debug(ex.Message);
Expand Down Expand Up @@ -435,6 +438,8 @@ private void getDefaultCalendar(NameSpace oNS, ref MAPIFolder defaultCalendar) {

Forms.Main.Instance.lOutlookCalendar.BackColor = System.Drawing.Color.White;
Forms.Main.Instance.SetControlPropertyThreadSafe(Forms.Main.Instance.lOutlookCalendar, "Text", "Select calendar");
} catch (System.Runtime.InteropServices.COMException) {
throw;
} catch (System.Exception ex) {
OGCSexception.Analyse(ex, true);
throw;
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static void Main(string[] args) {
((Settings.Instance.StartupDelay == 0) ? "setting a" : "increasing the") + " delay for OGCS on startup.",
"Set a delay on startup", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} else
} else if (!string.IsNullOrEmpty(aex.Message))
MessageBox.Show(aex.Message, "Application terminated", MessageBoxButtons.OK, MessageBoxIcon.Error);
log.Warn("OGCS has crashed out.");

Expand Down Expand Up @@ -493,7 +493,7 @@ private static void isNewVersion(Boolean isSquirrelInstall) {
private static Boolean isCLIstartup() {
try {
if (File.Exists(logSettingsFile)) return false;
else if (File.Exists(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), logSettingsFile))) return true;
else if (File.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), logSettingsFile))) return true;
else return false;
} catch (System.Exception ex) {
log.Error("Failed to determine if OGCS was started by CLI.");
Expand Down

0 comments on commit 46d8f25

Please sign in to comment.