/// <summary> /// Get a string representing the values of the distinct fields of this crmItem, /// as a final fallback for identifying an otherwise unidentifiable object. /// </summary> /// <param name="crmItem">An item received from CRM.</param> /// <returns>An identifying string.</returns> /// <see cref="SyncState{ItemType}.IdentifyingFields"/> private string GetDistinctFields(EntryValue crmItem) { string result; switch (crmItem.module_name) { case CallsSynchroniser.CrmModule: result = CallSyncState.GetDistinctFields(crmItem); break; case ContactSynchroniser.CrmModule: result = ContactSyncState.GetDistinctFields(crmItem); break; case MeetingsSynchroniser.CrmModule: result = MeetingSyncState.GetDistinctFields(crmItem); break; case TaskSynchroniser.CrmModule: result = TaskSyncState.GetDistinctFields(crmItem); break; default: this.log.Warn($"Unexpected CRM module name '{crmItem.module_name}'"); result = string.Empty; break; } return(result); }
/// <summary> /// Add an item existing in CRM but not found in Outlook to Outlook. /// </summary> /// <param name="appointmentsFolder">The Outlook folder in which the item should be stored.</param> /// <param name="crmItem">The CRM item from which values are to be taken.</param> /// <returns>A sync state object for the new item.</returns> private SyncState <Outlook.ContactItem> AddNewItemFromCrmToOutlook(Outlook.MAPIFolder contactFolder, eEntryValue crmItem) { Log.Info( (string)string.Format( "ContactSyncing.AddNewItemFromCrmToOutlook, entry id is '{0}', creating in Outlook.", crmItem.GetValueAsString("id"))); Outlook.ContactItem olItem = contactFolder.Items.Add(Outlook.OlItemType.olContactItem); this.SetOutlookItemPropertiesFromCrmItem(crmItem, olItem); var newState = new ContactSyncState { OutlookItem = olItem, OModifiedDate = DateTime.ParseExact(crmItem.GetValueAsString("date_modified"), "yyyy-MM-dd HH:mm:ss", null), CrmEntryId = crmItem.GetValueAsString("id"), }; ItemsSyncState.Add(newState); olItem.Save(); LogItemAction(newState.OutlookItem, "AppointmentSyncing.AddNewItemFromCrmToOutlook, saved item"); return(newState); }
private SyncState <Outlook.ContactItem> AddOrGetSyncState(Outlook.ContactItem oItem) { var entryId = oItem.EntryID; var existingState = ItemsSyncState.FirstOrDefault(a => a.OutlookItem.EntryID == entryId); if (existingState != null) { existingState.OutlookItem = oItem; return(existingState); } else { var newState = new ContactSyncState { OutlookItem = oItem, CrmEntryId = oItem.UserProperties["SEntryID"]?.Value.ToString(), OModifiedDate = ParseDateTimeFromUserProperty(oItem.UserProperties["SOModifiedDate"]?.Value.ToString()), }; ItemsSyncState.Add(newState); return(newState); } }
/// <summary> /// Add an item existing in CRM but not found in Outlook to Outlook. /// </summary> /// <param name="appointmentsFolder">The Outlook folder in which the item should be stored.</param> /// <param name="crmItem">The CRM item from which values are to be taken.</param> /// <returns>A sync state object for the new item.</returns> private SyncState <Outlook.ContactItem> AddNewItemFromCrmToOutlook(Outlook.MAPIFolder contactFolder, dynamic crmItem) { Log.Info( (string)string.Format( "ContactSyncing.AddNewItemFromCrmToOutlook, entry id is '{0}', creating in Outlook.", crmItem.id.value.ToString())); Outlook.ContactItem olItem = ConstructOutlookItemFromCrmItem(contactFolder, crmItem); var newState = new ContactSyncState { OutlookItem = olItem, OModifiedDate = DateTime.ParseExact(crmItem.date_modified.value.ToString(), "yyyy-MM-dd HH:mm:ss", null), CrmEntryId = crmItem.id.value.ToString(), }; ItemsSyncState.Add(newState); olItem.Save(); LogItemAction(newState.OutlookItem, "AppointmentSyncing.AddNewItemFromCrmToOutlook, saved item"); return(newState); }