/// <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); }
private SyncState <Outlook.TaskItem> AddNewItemFromCrmToOutlook(Outlook.MAPIFolder tasksFolder, eEntryValue crmItem, DateTime?date_start, DateTime?date_due, string time_start, string time_due) { Outlook.TaskItem olItem = tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem); this.SetOutlookItemPropertiesFromCrmItem(crmItem, date_start, date_due, time_start, time_due, olItem); var newState = new TaskSyncState { 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(olItem, "AppointmentSyncing.AddNewItemFromCrmToOutlook"); return(newState); }
private SyncState <Outlook.TaskItem> AddNewItemFromCrmToOutlook(Outlook.MAPIFolder tasksFolder, EntryValue crmItem, DateTime?date_start, DateTime?date_due, string time_start, string time_due) { Outlook.TaskItem olItem = tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem); TaskSyncState newState = null; try { this.SetOutlookItemPropertiesFromCrmItem(crmItem, date_start, date_due, time_start, time_due, olItem); this.AddOrGetSyncState(olItem); } finally { this.SaveItem(olItem); } return(newState); }
private SyncState <Outlook.TaskItem> AddNewItemFromCrmToOutlook(Outlook.MAPIFolder tasksFolder, EntryValue crmItem, DateTime?date_start, DateTime?date_due, string time_start, string time_due) { Outlook.TaskItem olItem = tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem); TaskSyncState newState = null; try { this.SetOutlookItemPropertiesFromCrmItem(crmItem, date_start, date_due, time_start, time_due, olItem); newState = new TaskSyncState { OutlookItem = olItem, OModifiedDate = DateTime.ParseExact(crmItem.GetValueAsString("date_modified"), "yyyy-MM-dd HH:mm:ss", null), CrmEntryId = crmItem.GetValueAsString("id"), }; ItemsSyncState.Add(newState); } finally { this.SaveItem(olItem); } return(newState); }
private SyncState <Outlook.TaskItem> UpdateFromCrm(Outlook.MAPIFolder tasksFolder, eEntryValue oResult) { dynamic dResult = JsonConvert.DeserializeObject(oResult.name_value_object.ToString()); // if (clsSuiteCRMHelper.GetUserId() != dResult.assigned_user_id.value.ToString()) { return(null); } DateTime?date_start = null; DateTime?date_due = null; string time_start = "--:--", time_due = "--:--"; if (!string.IsNullOrWhiteSpace(dResult.date_start.value.ToString()) && !string.IsNullOrEmpty(dResult.date_start.value.ToString())) { Log.Warn("\tSET date_start = dResult.date_start"); date_start = DateTime.ParseExact(dResult.date_start.value.ToString(), "yyyy-MM-dd HH:mm:ss", null); date_start = date_start.Value.Add(new DateTimeOffset(DateTime.Now).Offset); time_start = TimeSpan.FromHours(date_start.Value.Hour) .Add(TimeSpan.FromMinutes(date_start.Value.Minute)) .ToString(@"hh\:mm"); } if (date_start != null && date_start < GetStartDate()) { Log.Warn("\tdate_start=" + date_start.ToString() + ", GetStartDate= " + GetStartDate().ToString()); return(null); } if (!string.IsNullOrWhiteSpace(dResult.date_due.value.ToString())) { date_due = DateTime.ParseExact(dResult.date_due.value.ToString(), "yyyy-MM-dd HH:mm:ss", null); date_due = date_due.Value.Add(new DateTimeOffset(DateTime.Now).Offset); time_due = TimeSpan.FromHours(date_due.Value.Hour).Add(TimeSpan.FromMinutes(date_due.Value.Minute)).ToString(@"hh\:mm"); ; } foreach (var lt in ItemsSyncState) { Log.Warn("\tTask= " + lt.CrmEntryId); } var oItem = ItemsSyncState.FirstOrDefault(a => a.CrmEntryId == dResult.id.value.ToString()); if (oItem == null) { Log.Warn("\tif default"); Outlook.TaskItem tItem = tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem); tItem.Subject = dResult.name.value.ToString(); if (!string.IsNullOrWhiteSpace(dResult.date_start.value.ToString())) { tItem.StartDate = date_start.Value; } if (!string.IsNullOrWhiteSpace(dResult.date_due.value.ToString())) { tItem.DueDate = date_due.Value; // DateTime.Parse(dResult.date_due.value.ToString()); } string body = dResult.description.value.ToString(); tItem.Body = string.Concat(body, "#<", time_start, "#", time_due); tItem.Status = GetStatus(dResult.status.value.ToString()); tItem.Importance = GetImportance(dResult.priority.value.ToString()); Outlook.UserProperty oProp = tItem.UserProperties.Add("SOModifiedDate", Outlook.OlUserPropertyType.olText); oProp.Value = dResult.date_modified.value.ToString(); Outlook.UserProperty oProp2 = tItem.UserProperties.Add("SEntryID", Outlook.OlUserPropertyType.olText); oProp2.Value = dResult.id.value.ToString(); var newState = new TaskSyncState { OutlookItem = tItem, OModifiedDate = DateTime.ParseExact(dResult.date_modified.value.ToString(), "yyyy-MM-dd HH:mm:ss", null), CrmEntryId = dResult.id.value.ToString(), }; ItemsSyncState.Add(newState); Log.Warn("\tsave 0"); tItem.Save(); return(newState); } else { Log.Warn("\telse not default"); Outlook.TaskItem tItem = oItem.OutlookItem; Outlook.UserProperty oProp = tItem.UserProperties["SOModifiedDate"]; Log.Warn( (string) ("\toProp.Value= " + oProp.Value + ", dResult.date_modified=" + dResult.date_modified.value.ToString())); if (oProp.Value != dResult.date_modified.value.ToString()) { tItem.Subject = dResult.name.value.ToString(); if (!string.IsNullOrWhiteSpace(dResult.date_start.value.ToString())) { Log.Warn("\ttItem.StartDate= " + tItem.StartDate + ", date_start=" + date_start); tItem.StartDate = date_start.Value; } if (!string.IsNullOrWhiteSpace(dResult.date_due.value.ToString())) { tItem.DueDate = date_due.Value; // DateTime.Parse(dResult.date_due.value.ToString()); } string body = dResult.description.value.ToString(); tItem.Body = string.Concat(body, "#<", time_start, "#", time_due); tItem.Status = GetStatus(dResult.status.value.ToString()); tItem.Importance = GetImportance(dResult.priority.value.ToString()); if (oProp == null) { oProp = tItem.UserProperties.Add("SOModifiedDate", Outlook.OlUserPropertyType.olText); } oProp.Value = dResult.date_modified.value.ToString(); Outlook.UserProperty oProp2 = tItem.UserProperties["SEntryID"]; if (oProp2 == null) { oProp2 = tItem.UserProperties.Add("SEntryID", Outlook.OlUserPropertyType.olText); } oProp2.Value = dResult.id.value.ToString(); Log.Warn("\tsave 1"); tItem.Save(); } oItem.OModifiedDate = DateTime.ParseExact(dResult.date_modified.value.ToString(), "yyyy-MM-dd HH:mm:ss", null); return(oItem); } }