예제 #1
0
        public Task <IEnumerable <EntityVersion <AppointmentId, DateTime> > > GetVersions(IEnumerable <IdWithAwarenessLevel <AppointmentId> > idsOfEntitiesToQuery, IEventSynchronizationContext context)
        {
            var result = new List <EntityVersion <AppointmentId, DateTime> >();

            foreach (var id in idsOfEntitiesToQuery)
            {
                var appointment = _session.GetAppointmentItemOrNull(id.Id.EntryId, _folderId, _folderStoreId);
                if (appointment != null)
                {
                    try
                    {
                        if (_configuration.IsCategoryFilterSticky && id.IsKnown || DoesMatchCategoryCriterion(appointment))
                        {
                            result.Add(EntityVersion.Create(id.Id, appointment.LastModificationTime));
                            context.AnnounceAppointment(AppointmentSlim.FromAppointmentItem(appointment));
                        }
                    }
                    finally
                    {
                        Marshal.FinalReleaseComObject(appointment);
                    }
                }
            }

            return(Task.FromResult <IEnumerable <EntityVersion <AppointmentId, DateTime> > > (result));
        }
        public async Task <EntityVersion <AppointmentId, DateTime> > Create(Func <IAppointmentItemWrapper, Task <IAppointmentItemWrapper> > entityInitializer, IEventSynchronizationContext context)
        {
            IAppointmentItemWrapper newAppointmentItemWrapper;

            using (var folderWrapper = CreateFolderWrapper())
            {
                newAppointmentItemWrapper = _comWrapperFactory.Create(
                    _useDefaultFolderItemType
                        ? (AppointmentItem)folderWrapper.Inner.Items.Add()
                        : (AppointmentItem)folderWrapper.Inner.Items.Add(OlItemType.olAppointmentItem),
                    entryId => _session.GetAppointmentItem(entryId, _folderStoreId));
            }

            using (newAppointmentItemWrapper)
            {
                try
                {
                    var initializedWrapper = await entityInitializer(newAppointmentItemWrapper);

                    using (initializedWrapper)
                    {
                        initializedWrapper.SaveAndReload();
                        context.DuplicateEventCleaner.AnnounceAppointment(AppointmentSlim.FromAppointmentItem(initializedWrapper.Inner));
                        var result = new EntityVersion <AppointmentId, DateTime>(
                            new AppointmentId(initializedWrapper.Inner.EntryID, initializedWrapper.Inner.GlobalAppointmentID),
                            initializedWrapper.Inner.LastModificationTime.ToUniversalTime());
                        return(result);
                    }
                }
                catch
                {
                    try
                    {
                        newAppointmentItemWrapper.Inner.Delete();
                    }
                    catch (System.Exception x)
                    {
                        s_logger.Error("Error while deleting leftover entity", x);
                    }

                    throw;
                }
            }
        }
예제 #3
0
        public async Task <EntityVersion <AppointmentId, DateTime> > TryUpdate(
            AppointmentId entityId,
            DateTime entityVersion,
            IAppointmentItemWrapper entityToUpdate,
            Func <IAppointmentItemWrapper, Task <IAppointmentItemWrapper> > entityModifier,
            IEventSynchronizationContext context)
        {
            entityToUpdate = await entityModifier(entityToUpdate);

            entityToUpdate.Inner.Save();
            context.AnnounceAppointment(AppointmentSlim.FromAppointmentItem(entityToUpdate.Inner));

            var newAppointmentId = new AppointmentId(entityToUpdate.Inner.EntryID, entityToUpdate.Inner.GlobalAppointmentID);

            if (!entityId.Equals(newAppointmentId))
            {
                context.AnnounceAppointmentDeleted(entityId);
            }

            return(new EntityVersion <AppointmentId, DateTime> (
                       newAppointmentId,
                       entityToUpdate.Inner.LastModificationTime));
        }
예제 #4
0
        public async Task <EntityVersion <AppointmentId, DateTime> > Create(Func <IAppointmentItemWrapper, Task <IAppointmentItemWrapper> > entityInitializer, IEventSynchronizationContext context)
        {
            IAppointmentItemWrapper newAppointmentItemWrapper;

            using (var folderWrapper = CreateFolderWrapper())
            {
                newAppointmentItemWrapper = _comWrapperFactory.Create(
                    (AppointmentItem)folderWrapper.Inner.Items.Add(OlItemType.olAppointmentItem),
                    entryId => _session.GetAppointmentItem(entryId, _folderStoreId));
            }

            using (newAppointmentItemWrapper)
            {
                using (var initializedWrapper = await entityInitializer(newAppointmentItemWrapper))
                {
                    initializedWrapper.SaveAndReload();
                    context.AnnounceAppointment(AppointmentSlim.FromAppointmentItem(initializedWrapper.Inner));
                    var result = new EntityVersion <AppointmentId, DateTime>(
                        new AppointmentId(initializedWrapper.Inner.EntryID, initializedWrapper.Inner.GlobalAppointmentID),
                        initializedWrapper.Inner.LastModificationTime);
                    return(result);
                }
            }
        }