Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…CalendarSync into release
  • Loading branch information
phw198 committed Oct 25, 2020
2 parents 8baf3b6 + 30d0062 commit fbd410e
Show file tree
Hide file tree
Showing 15 changed files with 438 additions and 203 deletions.
2 changes: 1 addition & 1 deletion nuget-build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ REM src\packages\squirrel.windows.1.9.0\tools\signtool.exe sign /n "Open Source
REM Build ZIP
PAUSE
cd src\OutlookGoogleCalendarSync\bin\Release
"c:\Program Files\7-Zip\7z.exe" u Portable_OGCS_v2.8.3.zip -u- -up0q0r2x2y2z1w2!Portable_OGCS_v2.8.4.zip *.dll *.ps1 ErrorReportingTemplate.json logger.xml tzdb.nzd OutlookGoogleCalendarSync.exe OutlookGoogleCalendarSync.exe.config Console\*
"c:\Program Files\7-Zip\7z.exe" u Portable_OGCS_v2.8.3.zip -u- -up0q0r2x2y2z1w2!Portable_OGCS_v2.8.4.zip *.dll *.ps1 ErrorReportingTemplate.json logger.xml tzdb.nzd OutlookGoogleCalendarSync.exe OutlookGoogleCalendarSync.exe.config OutlookGoogleCalendarSync.pdb Console\*

"c:\Program Files\7-Zip\7z.exe" e Portable_OGCS_v2.8.3.zip Microsoft.Office.Interop.Outlook.DLL
"c:\Program Files\7-Zip\7z.exe" e Portable_OGCS_v2.8.3.zip stdole.dll
Expand Down
42 changes: 36 additions & 6 deletions src/OutlookGoogleCalendarSync/Extensions/Exception.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using log4net;
using System;
using System.ComponentModel;
using System.Linq;

namespace OutlookGoogleCalendarSync {
class UserCancelledSyncException : System.Exception {
Expand All @@ -24,8 +25,18 @@ public static void Analyse(System.Exception ex, Boolean includeStackTrace = fals
}

log.ErrorOrFail(ex.GetType().FullName + ": " + ex.Message, logLevel);
String errorLocation = "; Location: ";
try {
errorLocation += ex.TargetSite.Name + "() in ";
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(ex, true);
String[] frameBits = st.GetFrame(0).ToString().Split('\\');
if (frameBits.Count() == 1) throw new Exception();
errorLocation += frameBits.LastOrDefault().Trim();
} catch {
errorLocation += "<Unknown File>";
}
int errorCode = getErrorCode(ex);
log.ErrorOrFail("Code: 0x" + errorCode.ToString("X8") + ";" + errorCode.ToString(), logLevel);
log.ErrorOrFail("Code: 0x" + errorCode.ToString("X8") + "," + errorCode.ToString() + errorLocation, logLevel);

if (ex.InnerException != null) {
log.ErrorOrFail("InnerException:-", logLevel);
Expand Down Expand Up @@ -76,16 +87,19 @@ public static void AnalyseTokenResponse(Google.Apis.Auth.OAuth2.Responses.TokenR
String instructions = "On the Settings > Google tab, please disconnect and re-authenticate your account.";

log.Warn("Token response error: " + ex.Message);
if (ex.Error.Error == "access_denied")
if (ex.Error.Error == "access_denied") {
Forms.Main.Instance.Console.Update("Failed to obtain Calendar access from Google - it's possible your access has been revoked.<br/>" + instructions, Console.Markup.fail, notifyBubble: true);
LogAsFail(ref ex);

else if ("invalid_client;unauthorized_client".Contains(ex.Error.Error))
} else if ("invalid_client;unauthorized_client".Contains(ex.Error.Error)) {
Forms.Main.Instance.Console.Update("Invalid authentication token. Account requires reauthorising.\r\n" + instructions, Console.Markup.fail, notifyBubble: true);
LogAsFail(ref ex);

else if (ex.Error.Error == "invalid_grant")
} else if (ex.Error.Error == "invalid_grant") {
Forms.Main.Instance.Console.Update("Google has revoked your authentication token. Account requires reauthorising.<br/>" + instructions, Console.Markup.fail, notifyBubble: true);
LogAsFail(ref ex);

else {
} else {
log.Warn("Unknown web exception.");
Forms.Main.Instance.Console.UpdateWithError("Unable to communicate with Google. The following error occurred:", ex, notifyBubble: true);
}
Expand Down Expand Up @@ -169,7 +183,23 @@ public static void LogAsFail(ref System.NullReferenceException ex) {
else
ex.Data.Add(LogAs, OGCSexception.LogLevel.FAIL);
}


/// <summary>Capture this exception as log4net FAIL (not ERROR) when logged</summary>
public static void LogAsFail(ref Google.Apis.Auth.OAuth2.Responses.TokenResponseException ex) {
if (ex.Data.Contains(LogAs))
ex.Data[LogAs] = OGCSexception.LogLevel.FAIL;
else
ex.Data.Add(LogAs, OGCSexception.LogLevel.FAIL);
}

/// <summary>Capture this exception as log4net FAIL (not ERROR) when logged</summary>
public static void LogAsFail(ref Google.GoogleApiException ex) {
if (ex.Data.Contains(LogAs))
ex.Data[LogAs] = OGCSexception.LogLevel.FAIL;
else
ex.Data.Add(LogAs, OGCSexception.LogLevel.FAIL);
}

/// <summary>
/// Check if this exception has been set to log as log4net FAIL (not ERROR)
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/Extensions/ILogExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ protected override void Append(LoggingEvent loggingEvent) {
else configSetting = XMLManager.ImportElement("CloudLogging", Settings.ConfigFile);

if (!string.IsNullOrEmpty(configSetting)) {
if (configSetting == "true" && GoogleOgcs.ErrorReporting.GetThreshold().ToString().ToUpper() != "ALL") {
if (Convert.ToBoolean(configSetting) && GoogleOgcs.ErrorReporting.GetThreshold().ToString().ToUpper() != "ALL") {
GoogleOgcs.ErrorReporting.SetThreshold(true);
replayLogs();
} else if (configSetting == "false" && GoogleOgcs.ErrorReporting.GetThreshold().ToString().ToUpper() != "OFF") {
} else if (!Convert.ToBoolean(configSetting) && GoogleOgcs.ErrorReporting.GetThreshold().ToString().ToUpper() != "OFF") {
GoogleOgcs.ErrorReporting.SetThreshold(false);
}
return;
Expand Down
87 changes: 78 additions & 9 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs

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

Loading

0 comments on commit fbd410e

Please sign in to comment.