コード例 #1
0
        /// <summary>
        /// Get the CRM id for this item, if known, else the empty string.
        /// </summary>
        /// <param name="olItem">The Outlook item under consideration.</param>
        /// <returns>the CRM id for this item, if known, else the empty string.</returns>
        public static CrmId GetCrmId(this Outlook.ContactItem olItem)
        {
            Outlook.UserProperty property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName];
            CrmId result = property != null?CrmId.Get(property.Value) : CrmId.Empty;

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Create a new instance of ProtoAppointment, taking values from this Outlook item.
        /// </summary>
        /// <param name="olItem">The Outlook item to take values from.</param>
        public ProtoAppointment(Outlook.AppointmentItem olItem) : base(olItem.MeetingStatus)
        {
            this.olItem     = olItem;
            this.body       = olItem.Body;
            this.CrmEntryId = olItem.GetCrmId();
            this.duration   = olItem.Duration;
            this.end        = olItem.End;
            this.location   = olItem.Location;
            this.start      = olItem.Start;
            this.subject    = olItem.Subject;
            this.globalId   = olItem.GlobalAppointmentID;

            var organiserProperty = olItem.UserProperties[AppointmentsSynchroniser <SyncStateType> .OrganiserPropertyName];

            if (organiserProperty == null || string.IsNullOrWhiteSpace(organiserProperty.Value))
            {
                if (olItem.Organizer == Globals.ThisAddIn.Application.GetCurrentUsername())
                {
                    this.organiser = CrmId.Get(RestAPIWrapper.GetUserId());
                }
                else
                {
                    this.organiser = TryResolveOrganiser(olItem);
                }
            }
            else
            {
                this.organiser = CrmId.Get(organiserProperty.Value.ToString());
            }

            foreach (Outlook.Recipient recipient in olItem.Recipients)
            {
                this.recipientAddresses.Add(recipient.GetSmtpAddress());
            }
        }
コード例 #3
0
        private void ProcessNewMeetingItem(Outlook.MeetingItem meetingItem)
        {
            string vCalId = meetingItem.GetVCalId();

            if (CrmId.IsValid(vCalId) && RestAPIWrapper.GetEntry(MeetingsSynchroniser.DefaultCrmModule, vCalId, new string[] { "id" }) != null)
            {
                meetingItem.GetAssociatedAppointment(false).SetCrmId(CrmId.Get(vCalId));
            }
        }
コード例 #4
0
        /// <summary>
        /// AsNameValues is used in transmission to CRM as well as for comparison, so it should NOT
        /// access our cache of recipient addresses.
        /// </summary>
        /// <returns>A set of name/value pairs suitable for transmitting to CRM.</returns>
        public override NameValueCollection AsNameValues()
        {
            string statusString;
            string name;

            switch (this.Status)
            {
            case Outlook.OlMeetingStatus.olMeetingCanceled:
                statusString = "Not Held";
                name         = this.subject.StartsWith(CancelledPrefix) ? this.subject : $"{CancelledPrefix}: {this.subject}";
                break;

            default:
                statusString = this.start < DateTime.Now ? "Held" : "Planned";
                name         = this.subject;
                break;
            }

            NameValueCollection data = new NameValueCollection
            {
                RestAPIWrapper.SetNameValuePair("name", name),
                RestAPIWrapper.SetNameValuePair("description", this.body),
                RestAPIWrapper.SetNameValuePair("location", this.location),
                RestAPIWrapper.SetNameValuePair("date_start",
                                                string.Format("{0:yyyy-MM-dd HH:mm:ss}", this.start.ToUniversalTime())),
                RestAPIWrapper.SetNameValuePair("date_end",
                                                string.Format("{0:yyyy-MM-dd HH:mm:ss}", this.end.ToUniversalTime())),
                RestAPIWrapper.SetNameValuePair("duration_minutes", (this.duration % 60).ToString()),
                RestAPIWrapper.SetNameValuePair("duration_hours", (this.duration / 60).ToString()),
                RestAPIWrapper.SetNameValuePair("outlook_id", this.globalId),
                RestAPIWrapper.SetNameValuePair("status", statusString)
            };

            if (CrmId.IsValid(this.organiser))
            {
                data.Add(RestAPIWrapper.SetNameValuePair("assigned_user_id", this.organiser.ToString()));
            }

            if (CrmId.IsInvalid(CrmEntryId))
            {
                /* A Guid can be constructed from a 32 digit hex string. The globalId is a
                 * 112 digit hex string. It appears from inspection that the least significant
                 * bytes are those that vary between examples, with the most significant bytes
                 * being invariant in the samples we have to hand. */
                CrmEntryId = CrmId.Get(new Guid(this.globalId.Substring(this.globalId.Length - 32)));
                data.Add(RestAPIWrapper.SetNameValuePair("new_with_id", true));
            }

            data.Add(RestAPIWrapper.SetNameValuePair("id", CrmEntryId.ToString()));

            return(data);
        }
コード例 #5
0
        /// <summary>
        /// Get the CRM id for this item, if known, else the empty string.
        /// </summary>
        /// <param name="olItem">The Outlook item under consideration.</param>
        /// <returns>the CRM id for this item, if known, else the empty string.</returns>
        public static CrmId GetCrmId(this Outlook.TaskItem olItem)
        {
            Outlook.UserProperty property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName];

            if (property == null)
            {
                /* #6661: fail over to legacy property name if current property
                 * name not found */
                property = olItem.UserProperties[SyncStateManager.LegacyCrmIdPropertyName];
            }

            CrmId result = property != null?CrmId.Get(property.Value) : CrmId.Empty;

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Get the CRM id for this item, if known, else the empty string.
        /// </summary>
        /// <param name="olItem">The Outlook item under consideration.</param>
        /// <returns>the CRM id for this item, if known, else the empty string.</returns>
        public static CrmId GetCrmId(this Outlook.AppointmentItem olItem)
        {
            string result;

            Outlook.UserProperty property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName];
            if (property != null && !string.IsNullOrEmpty(property.Value))
            {
                result = property.Value;
            }
            else
            {
                result = olItem.GetVCalId();
            }

            return(CrmId.Get(result));
        }
コード例 #7
0
        /// <summary>
        /// Get the CRM id for this item, if known, else the empty string.
        /// </summary>
        /// <param name="olItem">The Outlook item under consideration.</param>
        /// <returns>the CRM id for this item, if known, else the empty string.</returns>
        public static CrmId GetCrmId(this Outlook.TaskItem olItem)
        {
            string result;

            Outlook.UserProperty property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName];
            if (property != null)
            {
                result = property.Value;
            }
            else
            {
                result = string.Empty;
            }

            return(CrmId.Get(result));
        }
        /// <summary>
        /// Get the CRM id for this item, if known, else the empty string.
        /// </summary>
        /// <param name="olItem">The Outlook item under consideration.</param>
        /// <returns>the CRM id for this item, if known, else null.</returns>
        public static CrmId GetCrmId(this Outlook.AppointmentItem olItem)
        {
            string result;

            if (olItem.IsValid())
            {
                try
                {
                    Outlook.UserProperty property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName];

                    if (property == null)
                    {
                        /* #6661: fail over to legacy property name if current property
                         * name not found */
                        property = olItem.UserProperties[SyncStateManager.LegacyCrmIdPropertyName];
                    }

                    if (property != null && !string.IsNullOrEmpty(property.Value))
                    {
                        result = property.Value;
                    }
                    else
                    {
                        result = olItem.GetVCalId();
                    }
                }
                catch (COMException)
                {
                    /* this is bad! It shouldn't be possible to get here, but
                     * it is. */
                    try
                    {
                        result = olItem.GetVCalId();
                    }
                    catch (COMException)
                    {
                        result = null;
                    }
                }
            }
            else
            {
                result = null;
            }

            return(CrmId.Get(result));
        }
コード例 #9
0
        /// <summary>
        /// Try to resolve the organiser of this Outlook Item against the users of the CRM.
        /// </summary>
        /// <param name="olItem">The Outlook item representing a meeting.</param>
        /// <returns>The id of the related user if any, else the empty string.</returns>
        public static CrmId TryResolveOrganiser(Outlook.AppointmentItem olItem)
        {
            CrmId  result    = CrmId.Empty;
            string organiser = olItem.Organizer;

            try
            {
                if (organiser.IndexOf('@') > -1)
                {
                    foreach (string pattern in new string[] { @".*<(.+@.+)>", @".+@.+" })
                    {
                        Match match = Regex.Match(organiser, pattern, RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            string address = match.Groups[0].Value;

                            try
                            {
                                result = CrmId.Get(RestAPIWrapper.GetUserId(new MailAddress(address)));
                            }
                            catch (FormatException)
                            {
                                // not a valid email address - no matter.
                            }
                        }
                    }
                }
                else
                {
                    result = CrmId.Get(RestAPIWrapper.GetUserId(organiser));
                }
            }
            catch (Exception any)
            {
                ErrorHandler.Handle($"Failed to resolve organiser `{olItem.Organizer}` of meeting `{olItem.Subject}`", any);
            }

            return(result);
        }