-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
3,574 additions
and
686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
* | ||
* @author SalesAgility <[email protected]> | ||
*/ | ||
|
||
using System.Threading; | ||
using SuiteCRMAddIn.Exceptions; | ||
|
||
namespace SuiteCRMAddIn.BusinessLogic | ||
{ | ||
using System; | ||
|
@@ -36,18 +40,41 @@ namespace SuiteCRMAddIn.BusinessLogic | |
/// </summary> | ||
public class ContactSyncState: SyncState<Outlook.ContactItem> | ||
{ | ||
private ILogger Log = Globals.ThisAddIn.Log; | ||
public ContactSyncState(Outlook.ContactItem oItem, CrmId crmId, DateTime modified) : base(oItem, crmId, modified) | ||
{ | ||
} | ||
|
||
public override Outlook.OlDefaultFolders DefaultFolder | ||
public override Outlook.Folder DefaultFolder => (Outlook.Folder)MapiNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); | ||
|
||
protected override bool VerifyItem() | ||
{ | ||
get | ||
bool result; | ||
try | ||
{ | ||
return Outlook.OlDefaultFolders.olFolderContacts; | ||
result = !string.IsNullOrEmpty(this.Item?.EntryID); | ||
} | ||
catch (Exception ex) when (ex is InvalidComObjectException || ex is COMException) | ||
{ | ||
result = false; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// If transmission was successful, clear the manual override if set. | ||
/// </summary> | ||
internal override void SetTransmitted() | ||
{ | ||
base.SetTransmitted(); | ||
this.OutlookItem.ClearManualOverride(); | ||
} | ||
|
||
/// <summary> | ||
/// True if the Outlook item wrapped by this state may be synchronised even when synchronisation is set to none. | ||
/// </summary> | ||
public override bool IsManualOverride => this.OutlookItem.IsManualOverride(); | ||
|
||
public override string CrmType => ContactSynchroniser.CrmModule; | ||
|
||
|
@@ -119,5 +146,10 @@ internal override void SaveItem() | |
{ | ||
this.OutlookItem?.Save(); | ||
} | ||
|
||
protected override void CacheOulookItemId(Outlook.ContactItem olItem) | ||
{ | ||
this.outlookItemId = olItem.EntryID; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
* | ||
* @author SalesAgility <[email protected]> | ||
*/ | ||
|
||
using SuiteCRMAddIn.Daemon; | ||
using SuiteCRMAddIn.Exceptions; | ||
|
||
namespace SuiteCRMAddIn.BusinessLogic | ||
{ | ||
using SuiteCRMClient.Logging; | ||
|
@@ -45,24 +49,75 @@ public static void Handle(Exception error) | |
/// <param name="badCredentials"></param> | ||
public static void Handle(BadCredentialsException badCredentials) | ||
{ | ||
if (Globals.ThisAddIn.ShowReconfigureOrDisable("Login failed; have your credentials changed?")) | ||
if (Globals.ThisAddIn.ShowReconfigureOrDisable("Login failed; have your credentials changed?") == DialogResult.Cancel) | ||
{ | ||
Globals.ThisAddIn.Disable(); | ||
} | ||
} | ||
|
||
public static void Handle(string message) | ||
{ | ||
Handle(message, null); | ||
Handle(message, (Exception)null); | ||
} | ||
|
||
public static void Handle(OutOfMemoryException error) | ||
{ | ||
Handle( "SuiteSRM AddIn recovered from an out of memory error; no work was lost, but some tasks may not have been completed", error); | ||
} | ||
|
||
public static void Handle(string contextMessage, OutOfMemoryException error, bool notify = false) | ||
{ | ||
Globals.ThisAddIn.Log.Error(contextMessage, error); | ||
MessageBox.Show(ComposeErrorDescription(contextMessage, error), "SuiteCRM AddIn ran out of memory", MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
} | ||
|
||
public static void Handle(string contextMessage, Exception error) | ||
public static void Handle(string contextMessage, NeverShowUserException error, bool notify = false) | ||
{ | ||
Globals.ThisAddIn.Log.Error(contextMessage, error); | ||
var errorClassName = error?.GetType().Name ?? string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Handle this error in the context described in this contextMessage. | ||
/// </summary> | ||
/// <param name="contextMessage">A message describing what was being attempted when the error occurred.</param> | ||
/// <param name="error">The error.</param> | ||
/// <param name="notify">If true, notify the user anyway, overriding the ShowExceptions setting.</param> | ||
public static void Handle(string contextMessage, Exception error, bool notify = false) | ||
{ | ||
Globals.ThisAddIn.Log.Error(contextMessage, error); | ||
|
||
if (notify) | ||
{ | ||
MessageBox.Show(ComposeErrorDescription(contextMessage, error), "SuiteCRM Addin Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
} | ||
else | ||
{ | ||
switch (Properties.Settings.Default.ShowExceptions) | ||
{ | ||
case PopupWhen.Never: | ||
break; | ||
case PopupWhen.FirstTime: | ||
var errorClassName = error?.GetType().Name ?? string.Empty; | ||
|
||
if (!SeenExceptions.Contains(errorClassName)) | ||
{ | ||
SeenExceptions.Add(errorClassName); | ||
MessageBox.Show(ComposeErrorDescription(contextMessage, error), "SuiteCRM Addin Error", | ||
MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
} | ||
break; | ||
default: | ||
MessageBox.Show(ComposeErrorDescription(contextMessage, error), "SuiteCRM Addin Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private static string ComposeErrorDescription(string contextMessage, Exception error) | ||
{ | ||
StringBuilder bob = new StringBuilder(contextMessage); | ||
|
||
for (Exception e = error; e != null; e = e.GetBaseException()) | ||
for (Exception e = error; e != null; e = e.InnerException) | ||
{ | ||
if (e != error) | ||
{ | ||
|
@@ -71,24 +126,32 @@ public static void Handle(string contextMessage, Exception error) | |
bob.Append(e.GetType().Name).Append(e.Message); | ||
} | ||
string text = bob.ToString(); | ||
return text; | ||
} | ||
|
||
switch (Properties.Settings.Default.ShowExceptions) | ||
/// <summary> | ||
/// Do this action and, if an error occurs, invoke the error handler on it with this message. | ||
/// </summary> | ||
/// <remarks> | ||
/// \todo this method is duplicated in Robustness, but the copy in ErrorHandler is preferred; | ||
/// in the next release it is intended to remove the Robustness class and move its functionality | ||
/// to ErrorHandler. | ||
/// </remarks> | ||
/// <param name="action">The action to perform</param> | ||
/// <param name="message">A string describing what the action was intended to achieve.</param> | ||
public static void DoOrHandleError(Action action, string message) | ||
{ | ||
try | ||
{ | ||
action(); | ||
} | ||
catch (Exception problem) | ||
{ | ||
case PopupWhen.Never: | ||
break; | ||
case PopupWhen.FirstTime: | ||
if (!SeenExceptions.Contains(errorClassName)) | ||
{ | ||
SeenExceptions.Add(errorClassName); | ||
MessageBox.Show(text, "SuiteCRM Addin Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
} | ||
break; | ||
default: | ||
MessageBox.Show(text, "SuiteCRM Addin Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
break; | ||
ErrorHandler.Handle(message, problem); | ||
} | ||
} | ||
|
||
|
||
public enum PopupWhen | ||
{ | ||
Never, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.