protected override IBirthdayEvent OnExecute()
        {
            this.Trace.TraceDebug((long)this.GetHashCode(), "Updating birthday for contact");
            this.Result = new BirthdayEventCommandResult();
            IBirthdayEventInternal birthdayEventInternal = this.BirthdayEvent as IBirthdayEventInternal;

            if (birthdayEventInternal == null)
            {
                throw new ArgumentException("Was not expecting a null internal birthday event");
            }
            IBirthdayContactInternal birthdayContactInternal = this.BirthdayContact as IBirthdayContactInternal;

            if (birthdayContactInternal == null)
            {
                throw new ArgumentException("Was not expecting a null internal birthday contact");
            }
            if (UpdateBirthdayEventForContact.ShouldEventBeUpdated(birthdayEventInternal, birthdayContactInternal))
            {
                this.Scope.BirthdayEventDataProvider.Delete(birthdayEventInternal.StoreId, DeleteItemFlags.HardDelete);
                this.Result.DeletedEvents.Add(this.BirthdayEvent);
                this.Result.MergeWith(this.Scope.CreateBirthdayEventForContact(this.BirthdayContact));
            }
            PersonId personId = birthdayEventInternal.PersonId;

            if (personId != null && !personId.Equals(birthdayContactInternal.PersonId))
            {
                IEnumerable <IBirthdayContact> linkedContacts = this.Scope.ParentScope.ParentScope.Contacts.GetLinkedContacts(personId);
                this.Result.MergeWith(this.Scope.UpdateBirthdaysForLinkedContacts(linkedContacts));
            }
            return(this.Result.CreatedEvents.FirstOrDefault <IBirthdayEvent>());
        }
Beispiel #2
0
        internal BirthdayEventCommandResult OnContactModified(IBirthdayContact birthdayContact, IBirthdaysContainer birthdaysContainer)
        {
            IBirthdayContactInternal birthdayContactInternal = birthdayContact as IBirthdayContactInternal;

            if (birthdayContactInternal == null)
            {
                throw new ArgumentException("Argument must implement IBirthdayContactInternal", "birthdayContact");
            }
            IEnumerable <IBirthdayContact> linkedContacts = birthdaysContainer.Contacts.GetLinkedContacts(birthdayContactInternal.PersonId);

            return(birthdaysContainer.Events.UpdateBirthdaysForLinkedContacts(linkedContacts));
        }
        internal DeleteBirthdayEventForContact(IBirthdayContact contact, IBirthdayEvents scope)
        {
            this.Trace.TraceDebug((long)this.GetHashCode(), "DeleteBirthdayEventForContact:Constructor/contact");
            IBirthdayContactInternal birthdayContactInternal = contact as IBirthdayContactInternal;

            if (birthdayContactInternal == null)
            {
                throw new ArgumentException("Contact has to implement IBirthdayContactInternal", "contact");
            }
            this.ContactStoreObjectId = StoreId.GetStoreObjectId(birthdayContactInternal.StoreId);
            this.Scope = scope;
        }
        private BirthdayEvent CreateNewBirthdayEventForContact(IBirthdayContact contact)
        {
            if (contact == null || contact.Birthday == null)
            {
                this.Trace.TraceDebug <IBirthdayContact>((long)this.GetHashCode(), "CreateBirthdayEventForContact::CreateNewBirthdayEvent: don't need to create a birthday for contact {0}", this.Contact);
                return(null);
            }
            ExDateTime value = contact.Birthday.Value;

            this.Trace.TraceDebug <ExDateTime, TimeSpan>((long)this.GetHashCode(), "CreateBirthdayEventForContact::CreateNewBirthdayEvent: birthday value is {0}, time zone bias is {1}", value, value.Bias);
            BirthdayEvent birthdayEvent = new BirthdayEvent
            {
                Birthday    = value,
                Subject     = contact.DisplayName,
                Attribution = contact.Attribution,
                IsWritable  = contact.IsWritable
            };
            IBirthdayEventInternal   birthdayEventInternal   = birthdayEvent;
            IBirthdayContactInternal birthdayContactInternal = (IBirthdayContactInternal)this.Contact;

            birthdayEventInternal.PersonId  = birthdayContactInternal.PersonId;
            birthdayEventInternal.ContactId = StoreId.GetStoreObjectId(birthdayContactInternal.StoreId);
            return(this.Scope.BirthdayEventDataProvider.CreateBirthday(birthdayEvent));
        }
        private static bool ShouldEventBeUpdated(IBirthdayEventInternal birthdayEvent, IBirthdayContactInternal birthdayContact)
        {
            if (birthdayEvent == null)
            {
                throw new ArgumentNullException("birthdayEvent");
            }
            if (birthdayContact == null)
            {
                throw new ArgumentNullException("birthdayContact");
            }
            if (!birthdayEvent.ContactId.Equals(StoreId.GetStoreObjectId(birthdayContact.StoreId)))
            {
                throw new ArgumentException("Birthday event and birthday contact should have the same contact IDs", "birthdayEvent");
            }
            bool flag  = birthdayEvent.Subject != birthdayContact.DisplayName;
            bool flag2 = birthdayEvent.Birthday != birthdayContact.Birthday;
            bool flag3 = !birthdayEvent.PersonId.Equals(birthdayContact.PersonId);
            bool flag4 = birthdayEvent.Attribution != birthdayContact.Attribution;

            UpdateBirthdayEventForContact.UpdateBirthdayEventsForContactTracer.TraceDebug(0L, "Differences: subject - {0}, birthday - {1}, person ID - {2}, attribution - {3}", new object[]
            {
                flag,
                flag2,
                flag3,
                flag4
            });
            return(flag || flag2 || flag3 || flag4);
        }