public void CreateAppointment(ExchangeService exchangeService, MailboxSession session, CalendarItemType remoteItem, LocalFolder localFolder)
        {
            AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator, string>((long)this.GetHashCode(), "{0}: Creating appointment {1}", this, remoteItem.ItemId.Id);
            CalendarItem calendarItem = CalendarItem.Create(session, localFolder.Id);
            bool         flag         = false;

            try
            {
                this.UpdateAppointment(exchangeService, session, remoteItem, calendarItem);
                flag = true;
            }
            catch (LastOccurrenceDeletionException arg)
            {
                AppointmentTranslator.Tracer.TraceDebug <AppointmentTranslator, string, LastOccurrenceDeletionException>((long)this.GetHashCode(), "{0}: All occurrences in the series were deleted - {1}, Error - {2}, We will delete the local item because there are no instances.", this, remoteItem.ItemId.Id, arg);
                localFolder.SelectItemToDelete(calendarItem.Id.ObjectId);
                flag = true;
            }
            finally
            {
                if (!flag && calendarItem.Id != null)
                {
                    localFolder.SelectItemToDelete(calendarItem.Id.ObjectId);
                }
                calendarItem.Dispose();
            }
        }
Example #2
0
        private bool BatchSync(MailboxSession mailboxSession, LocalFolder localFolder, ItemSynchronizer itemSynchronizer)
        {
            List <ItemIdType> list = new List <ItemIdType>();

            if (string.IsNullOrEmpty(this.SyncState))
            {
                this.SyncState = localFolder.LoadSyncState();
            }
            Changes changes = this.ExchangeService.GetChanges(128, this.SyncState);

            if (changes == null)
            {
                SharingEngine.Tracer.TraceDebug <LocalFolder>((long)this.GetHashCode(), "{0}: Unable to retrieve changes", localFolder);
                return(false);
            }
            SharingEngine.Tracer.TraceDebug <SharingEngine, int>((long)this.GetHashCode(), "{0}: Called SyncFolderItems. Got {1} changes", this, changes.Items.Length);
            foreach (ItemChange itemChange in changes.Items)
            {
                switch (itemChange.ChangeType)
                {
                case ItemChangeType.Create:
                case ItemChangeType.Update:
                    list.Add(itemChange.Id);
                    break;

                case ItemChangeType.Delete:
                {
                    StoreId localIdFromRemoteId = localFolder.GetLocalIdFromRemoteId(itemChange.Id.Id);
                    if (localIdFromRemoteId != null)
                    {
                        localFolder.SelectItemToDelete(localIdFromRemoteId);
                    }
                    break;
                }
                }
            }
            if (list.Count > 0)
            {
                SharingEngine.Tracer.TraceDebug <SharingEngine, int>((long)this.GetHashCode(), "{0}: Processing {1} creates/updates", this, list.Count);
                IEnumerable <ItemType> item = this.ExchangeService.GetItem(list.ToArray(), localFolder.Type);
                if (item != null)
                {
                    int num = 0;
                    foreach (ItemType remoteItem in item)
                    {
                        if (this.Deadline.IsOver)
                        {
                            SharingEngine.Tracer.TraceError <SharingEngine>((long)this.GetHashCode(), "{0}: run out of time for completing the sync", this);
                            return(true);
                        }
                        if (!this.TrySyncOneItem(mailboxSession, itemSynchronizer, remoteItem))
                        {
                            num++;
                            SharingEngine.Tracer.TraceError <SharingEngine, int>((long)this.GetHashCode(), "{0}: Item failed to sync. Total number of failures during this batch: {1}.", this, num);
                            if (num == 30)
                            {
                                SharingEngine.Tracer.TraceError <SharingEngine>((long)this.GetHashCode(), "{0}: Too many items have failed. Ending batch loop.", this);
                                break;
                            }
                        }
                    }
                    SharingLog.LogEntry(mailboxSession, string.Format("Synchronized {0} out of {1} items during this batch.", list.Count - num, list.Count));
                    if (num == list.Count || num == 30)
                    {
                        SharingEngine.Tracer.TraceError <SharingEngine>((long)this.GetHashCode(), "{0}: Excessive errors while processing batch. Sync state will not be saved.", this);
                        throw new BatchSynchronizationFailedException();
                    }
                }
            }
            localFolder.SaveSyncState(changes.SyncState);
            this.SyncState = changes.SyncState;
            return(changes.MoreChangesAvailable);
        }