private bool TryAddRecipientInModule(string moduleName, CrmId meetingId, Outlook.Recipient recipient) { bool result; CrmId id = SetCrmRelationshipFromOutlook(this, meetingId, recipient, moduleName); if (CrmId.IsValid(id)) { string smtpAddress = recipient.GetSmtpAddress(); this.CacheAddressResolutionData( new AddressResolutionData(moduleName, id, smtpAddress)); CrmId accountId = CrmId.Get(RestAPIWrapper.GetRelationship( ContactSynchroniser.CrmModule, id.ToString(), "accounts")); if (CrmId.IsValid(accountId) && SetCrmRelationshipFromOutlook(this, meetingId, "Accounts", accountId)) { this.CacheAddressResolutionData( new AddressResolutionData("Accounts", accountId, smtpAddress)); } result = true; } else { result = false; } return(result); }
/// <summary> /// If it was created in Outlook and doesn't exist in CRM, (in which case it won't yet have a /// magic SShouldSync property) then we need to guarantee changes made in CRM are copied back /// by setting the Sync to Outlook checkbox in CRM. /// </summary> /// <param name="contactIdInCRM">The identifier of the contact in the CRM system</param> /// <param name="syncProperty">If null, set the checkbox.</param> /// <param name="create">If provided and false, then remove rather than creating the relationship.</param> private static void EnsureSyncWithOutlookSetInCRM(CrmId contactIdInCRM, Outlook.UserProperty syncProperty, bool create = true) { if (syncProperty == null) { SetRelationshipParams info = new SetRelationshipParams { module1 = CrmModule, module1_id = contactIdInCRM.ToString(), module2 = "user_sync", module2_id = RestAPIWrapper.GetUserId(), delete = create ? 0 : 1 }; RestAPIWrapper.SetRelationshipUnsafe(info); } }
public void CreateEmailRelationshipOrFail(CrmId emailId, CrmEntity entity) { var success = RestAPIWrapper.TrySetRelationship( new SetRelationshipParams { module2 = "emails", module2_id = emailId.ToString(), module1 = entity.ModuleName, module1_id = entity.EntityId, }, Objective.Email); if (!success) { throw new CrmSaveDataException($"Cannot create email relationship with {entity.ModuleName} ('set_relationship' failed)"); } }
/// <summary> /// Return the global appointment id corresponding to this crm id. /// </summary> /// <remarks> /// Outlook items arriving from CRM have a global appointment id based on their CRM id. /// Arguably this should not go here. /// </remarks> /// <see cref="Outlook.AppointmentItem.GlobalAppointmentId"/> /// <see cref="AppointmentItemExtension.GetVCalId(Outlook.AppointmentItem)"/> /// <param name="crmId">The CRM id from which the global id should be reverse engineered.</param> /// <returns>The reverse-engineered global id.</returns> private static string SimulateGlobalId(CrmId crmId) { byte[] globalId = new byte[89]; byte[] header = new byte[40] { 0x04, // 1: EOT 0x00, 0x00, 0x00, 0x82, // 5: left parenthesis 0x00, 0xE0, // 7: shift out 0x00, 0x74, // 9: G 0xC5, // 10: right square bracket 0xB7, // 11: left brace 0x10, // 12: start of heading 0x1A, // 13: ? 0x82, // 14: left parenthesis 0xE0, // 15: shift out 0x08, // 16: ? 0x00, 0x00, 0x00, 0x00, // 20 0x00, 0x00, 0x00, 0x00, 0x00, // 25 0x00, 0x00, 0x00, 0x00, 0x00, // 30 0x00, 0x00, 0x00, 0x00, 0x00, // 35 0x00, 0x31, // 37: s 0x00, 0x00, 0x00 // 40 }; byte[] signature = Encoding.UTF8.GetBytes("vCal-Uid"); byte[] crmIdBytes = Encoding.UTF8.GetBytes(crmId.ToString()); Buffer.BlockCopy(header, 0, globalId, 0, 40); Buffer.BlockCopy(signature, 0, globalId, 40, signature.Length); int cursor = 40 + signature.Length; globalId[cursor++] = 0x01; globalId[cursor++] = 0; globalId[cursor++] = 0; Buffer.BlockCopy(crmIdBytes, 0, globalId, cursor, crmIdBytes.Length); string result = Encoding.UTF8.GetString(globalId, 0, globalId.Length); return(result); }