private bool TryAddRecipientInModule(string moduleName, string meetingId, Outlook.Recipient recipient) { bool result; string id = SetCrmRelationshipFromOutlook(meetingId, recipient, moduleName); if (!string.IsNullOrWhiteSpace(id)) { string smtpAddress = recipient.GetSmtpAddress(); this.meetingRecipientsCache[recipient.GetSmtpAddress()] = new AddressResolutionData(moduleName, id, smtpAddress); string accountId = RestAPIWrapper.GetRelationship(ContactSyncing.CrmModule, id, "accounts"); if (!string.IsNullOrWhiteSpace(accountId) && SetCrmRelationshipFromOutlook(meetingId, "Accounts", accountId)) { this.meetingRecipientsCache[smtpAddress] = new AddressResolutionData("Accounts", accountId, smtpAddress); } result = true; } else { result = false; } return(result); }
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> /// Find all CRM records related to this recipient of this meeting, and produce address /// resolution data from them. /// </summary> /// <param name="olItem">An appointment, assumed to be a meeting.</param> /// <param name="recipient">A recipient of that meeting request.</param> /// <returns>A list of address resolution objects.</returns> private List <AddressResolutionData> ResolveRecipient(Outlook.AppointmentItem olItem, Outlook.Recipient recipient) { List <AddressResolutionData> result = new List <AddressResolutionData>(); var smtpAddress = recipient.GetSmtpAddress(); Log.Info($"recepientName= {recipient.Name}, recepient= {smtpAddress}"); if (this.meetingRecipientsCache.ContainsKey(smtpAddress)) { result.AddRange(meetingRecipientsCache[smtpAddress]); } else { CrmId meetingId = olItem.GetCrmId(); Dictionary <string, CrmId> moduleIds = new Dictionary <string, CrmId>(); if (CrmId.IsValid(meetingId)) { foreach (string moduleName in new string[] { "Leads", "Users", ContactSynchroniser.CrmModule }) { CrmId moduleId = this.GetInviteeIdBySmtpAddress(smtpAddress, moduleName); if (CrmId.IsValid(moduleId)) { moduleIds[moduleName] = moduleId; AddressResolutionData data = new AddressResolutionData(moduleName, moduleId, smtpAddress); this.CacheAddressResolutionData(data); result.Add(data); } } if (moduleIds.ContainsKey(ContactSynchroniser.CrmModule)) { CrmId accountId = CrmId.Get(RestAPIWrapper.GetRelationship( ContactSynchroniser.CrmModule, moduleIds[ContactSynchroniser.CrmModule].ToString(), "accounts")); if (CrmId.IsValid(accountId) && SetCrmRelationshipFromOutlook(this, meetingId, "Accounts", accountId)) { var data = new AddressResolutionData("Accounts", accountId, smtpAddress); this.CacheAddressResolutionData(data); result.Add(data); } } } } return(result); }
private void AddMeetingRecipientsFromOutlookToCrm(Outlook.AppointmentItem olItem, string meetingId) { LogItemAction(olItem, "AppointmentSyncing.AddMeetingRecipientsFromOutlookToCrm"); foreach (Outlook.Recipient recipient in olItem.Recipients) { Log.Info($"objRecepientName= {recipient.Name}, objRecepient= {recipient.Address}"); string address = recipient.Address; if (!TryAddRecipientInModule(ContactSyncing.CrmModule, meetingId, recipient) || TryAddRecipientInModule("Users", meetingId, recipient) || TryAddRecipientInModule("Leads", meetingId, recipient)) { string AccountID = RestAPIWrapper.GetRelationship(ContactSyncing.CrmModule, string.Empty, "accounts"); if (SetCrmRelationshipFromOutlook(meetingId, "Accounts", AccountID)) { this.meetingRecipientsCache[address] = new AddressResolutionData("Accounts", AccountID, recipient.Address); } } } }