Skip to content

Commit

Permalink
Merge branch 'release/3.0.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-brooke committed Feb 11, 2019
2 parents b9a9a14 + 84dbb1e commit 060744a
Show file tree
Hide file tree
Showing 71 changed files with 3,574 additions and 686 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "SuiteCRM Outlook Add-in"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 3.0.17.0
PROJECT_NUMBER = 3.0.18.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### What's in this repository

SuiteCRM Outlook Plug-In v 3.0.17.0
SuiteCRM Outlook Plug-In v 3.0.18.0

This repository has been created to allow community members to collaborate and contribute to the project.

Expand Down
29 changes: 21 additions & 8 deletions SuiteCRMAddIn/BusinessLogic/AppointmentSyncState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public abstract class AppointmentSyncState: SyncState<Outlook.AppointmentItem>
{
public AppointmentSyncState(Outlook.AppointmentItem item, CrmId crmId, DateTime modifiedDate) : base(item, crmId, modifiedDate)
{
this.outlookItemId = item.EntryID;
}

/// <summary>
Expand All @@ -47,13 +46,7 @@ public AppointmentSyncState(Outlook.AppointmentItem item, CrmId crmId, DateTime
private string crmType;


public override Outlook.OlDefaultFolders DefaultFolder
{
get
{
return Outlook.OlDefaultFolders.olFolderCalendar;
}
}
public override Outlook.Folder DefaultFolder => (Outlook.Folder)MapiNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);


/// <summary>
Expand Down Expand Up @@ -125,5 +118,25 @@ internal override void SaveItem()
{
this.OutlookItem?.Save();
}

protected override bool VerifyItem()
{
bool result;
try
{
result = !string.IsNullOrEmpty(this.Item?.EntryID);
}
catch (Exception ex) when (ex is InvalidComObjectException || ex is COMException)
{
result = false;
}

return result;
}

protected override void CacheOulookItemId(Outlook.AppointmentItem olItem)
{
this.outlookItemId = olItem.EntryID;
}
}
}
4 changes: 3 additions & 1 deletion SuiteCRMAddIn/BusinessLogic/AppointmentsSynchroniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected override void SaveItem(AppointmentItem olItem)
{
try
{
olItem.Save();
olItem?.Save();
try
{
LogItemAction(olItem, "AppointmentSyncing.SaveItem, saved item");
Expand Down Expand Up @@ -900,6 +900,8 @@ protected override void SyncFolder(MAPIFolder folder, string crmModule)

AddOrUpdateItemsFromCrmToOutlook(records, folder, untouched, crmModule);

/* You can add invitees to Appointments in Outlook, so this is not just for
* Meetings. */
var invited = RestAPIWrapper.GetRelationships("Users",
RestAPIWrapper.GetUserId(), crmModule.ToLower(),
RestAPIWrapper.GetSugarFields(crmModule));
Expand Down
38 changes: 35 additions & 3 deletions SuiteCRMAddIn/BusinessLogic/ContactSyncState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*
* @author SalesAgility <[email protected]>
*/

using System.Threading;
using SuiteCRMAddIn.Exceptions;

namespace SuiteCRMAddIn.BusinessLogic
{
using System;
Expand All @@ -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;

Expand Down Expand Up @@ -119,5 +146,10 @@ internal override void SaveItem()
{
this.OutlookItem?.Save();
}

protected override void CacheOulookItemId(Outlook.ContactItem olItem)
{
this.outlookItemId = olItem.EntryID;
}
}
}
12 changes: 11 additions & 1 deletion SuiteCRMAddIn/BusinessLogic/ContactSynchroniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ protected override void SaveItem(Outlook.ContactItem olItem)
{
try
{
olItem.Save();
olItem?.Save();
}
catch (System.Exception any)
{
ErrorHandler.Handle($"Error while saving contact {olItem?.Email1Address}", any);
}
}

/// <summary>
/// You can manually override the disablement of the contact synchroniser for particular items, but only for limited time.
/// </summary>
/// <param name="olItem">The Outlook item</param>
/// <returns>True if the item has had manual override set recently.</returns>
protected override bool IsManualOverride(Outlook.ContactItem olItem)
{
return olItem.IsManualOverride();
}

/// <summary>
/// Synchronise items in the specified folder with the specified SuiteCRM module.
/// </summary>
Expand Down
26 changes: 22 additions & 4 deletions SuiteCRMAddIn/BusinessLogic/CrmId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public override string ToString()
/// </returns>
public static bool IsValid(string id)
{
return !string.IsNullOrEmpty(id) && Validator.IsMatch(id);
bool result = !string.IsNullOrEmpty(id);
result = result && Validator.IsMatch(id);

return result;
}

/// <summary>
Expand Down Expand Up @@ -148,11 +151,26 @@ public override int GetHashCode()
/// Get the single CrmId instance for this value.
/// </summary>
/// <param name="value">The value to seek.</param>
/// <returns>A CrmId instance</returns>
/// <exception cref="TypeInitializationException"> if `value` does not appear to be a valid CRM id.</exception>
/// <returns>A CrmId instance, or Empty if the offered value is invalid.</returns>
public static CrmId Get(string value)
{
return string.IsNullOrEmpty(value) ? Empty : Issued.ContainsKey(value) ? Issued[value] : new CrmId(value);
CrmId result = Empty;

if (IsValid(value))
{
if (Issued.ContainsKey(value))
{
result = Issued[value];
}
else
{
result = new CrmId(value);
}
}
// This breaks, and I can't understand why:
// return IsValid(value) ? Empty : Issued.ContainsKey(value) ? Issued[value] : new CrmId(value);

return result;
}

/// <summary>
Expand Down
99 changes: 81 additions & 18 deletions SuiteCRMAddIn/BusinessLogic/ErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*
* @author SalesAgility <[email protected]>
*/

using SuiteCRMAddIn.Daemon;
using SuiteCRMAddIn.Exceptions;

namespace SuiteCRMAddIn.BusinessLogic
{
using SuiteCRMClient.Logging;
Expand All @@ -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)
{
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion SuiteCRMAddIn/BusinessLogic/LicenceValidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public bool Validate()
parameters["public_key"] = this.applicationKey;
parameters["key"] = this.licenceKey;

using (var response = this.service.CreateGetRequest(parameters).GetResponse() as HttpWebResponse)
using (var response =
this.service.CreateGetRequest(parameters).GetResponse() as HttpWebResponse)
{
result = InterpretStatusCode(response);
}
Expand Down
4 changes: 2 additions & 2 deletions SuiteCRMAddIn/BusinessLogic/SyncStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public void BruteForceSaveAll()
break;
}
}
catch (Exception)
catch (Exception ex)
{
// should log it but not critical.
Globals.ThisAddIn.Log.Warn("Exception during save all (probably not important)", ex);
}
}
}
Expand Down
Loading

0 comments on commit 060744a

Please sign in to comment.