/// <summary> /// Synchronise items in the specified folder with the specified SuiteCRM module. /// </summary> /// <remarks> /// TODO: candidate for refactoring upwards, in concert with ContactSyncing.SyncFolder. /// </remarks> /// <param name="folder">The folder.</param> /// <param name="crmModule">The module.</param> protected override void SyncFolder(Outlook.MAPIFolder folder, string crmModule) { Log.Info(String.Format("AppointmentSyncing.SyncFolder: '{0}'", crmModule)); try { /* this.ItemsSyncState already contains items to be synced. */ var untouched = new HashSet <SyncState <Outlook.AppointmentItem> >(this.ItemsSyncState); MergeRecordsFromCrm(folder, crmModule, untouched); EntryValue[] invited = RestAPIWrapper.GetRelationships("Users", RestAPIWrapper.GetUserId(), crmModule.ToLower(), RestAPIWrapper.GetSugarFields(crmModule)); if (invited != null) { AddOrUpdateItemsFromCrmToOutlook(invited, folder, untouched, crmModule); } try { this.ResolveUnmatchedItems(untouched, crmModule); } catch (Exception ex) { Log.Error("AppointmentSyncing.SyncFolder: Exception", ex); } } catch (Exception ex) { Log.Error("AppointmentSyncing.SyncFolder: Exception", ex); } }
private void SetRecipients(Outlook.AppointmentItem olItem, string sMeetingID, string sModule) { this.LogItemAction(olItem, "SetRecipients"); try { olItem.MeetingStatus = Outlook.OlMeetingStatus.olMeeting; int iCount = olItem.Recipients.Count; for (int iItr = 1; iItr <= iCount; iItr++) { olItem.Recipients.Remove(1); } string[] invitee_categories = { "users", ContactSyncing.CrmModule, "leads" }; foreach (string invitee_category in invitee_categories) { EntryValue[] relationships = RestAPIWrapper.GetRelationships(sModule, sMeetingID, invitee_category, new string[] { "id", "email1", "phone_work" }); if (relationships != null) { foreach (var relationship in relationships) { string phone_work = relationship.GetValueAsString("phone_work"); string email1 = relationship.GetValueAsString("email1"); string identifier = (sModule == AppointmentSyncing.CrmModule) || string.IsNullOrWhiteSpace(phone_work) ? email1 : $"{email1} : {phone_work}"; if (!String.IsNullOrWhiteSpace(identifier)) { olItem.Recipients.Add(identifier); } } } } } finally { this.SaveItem(olItem); } }