Esempio n. 1
0
        private Synchronizer <Identifier, int, string, Identifier, int, string, int> CreateSynchronizer(
            IInitialSyncStateCreationStrategy <Identifier, int, string, Identifier, int, string> strategy,
            List <IEntityRelationData <Identifier, int, Identifier, int> > matchingEntities = null)
        {
            var initialEntityMatcherStub = MockRepository.GenerateStub <IInitialEntityMatcher <string, Identifier, int, string, Identifier, int> >();

            initialEntityMatcherStub
            .Stub(_ => _.FindMatchingEntities(
                      Arg <IEntityRelationDataFactory <Identifier, int, Identifier, int> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, string> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, string> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, int> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, int> > .Is.NotNull))
            .Return(matchingEntities ?? new List <IEntityRelationData <Identifier, int, Identifier, int> >());

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(_localRepository);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(_serverRepository);

            return(new Synchronizer <Identifier, int, string, Identifier, int, string, int> (
                       _localRepository,
                       _serverRepository,
                       atypeWriteRepository,
                       btypeWriteRepository,
                       strategy,
                       _entityRelationDataAccess,
                       _entityRelationDataFactory,
                       initialEntityMatcherStub,
                       IdentifierEqualityComparer.Instance,
                       IdentifierEqualityComparer.Instance,
                       NullTotalProgressFactory.Instance,
                       MockRepository.GenerateMock <IExceptionLogger>(),
                       NullSynchronizationContextFactory.Instance,
                       EqualityComparer <int> .Default,
                       EqualityComparer <int> .Default));
        }
Esempio n. 2
0
 public Synchronizer <string, string, string, string, string, string, int, string, string, int, int> Build()
 {
     return(new Synchronizer <string, string, string, string, string, string, int, string, string, int, int>(
                AtypeRepository,
                BtypeRepository,
                BatchEntityRepositoryAdapter.Create(AtypeRepository, ExceptionHandlingStrategy),
                BatchEntityRepositoryAdapter.Create(BtypeRepository, ExceptionHandlingStrategy),
                InitialSyncStateCreationStrategy,
                EntityRelationDataAccess,
                EntityRelationDataFactory,
                InitialEntityMatcher,
                AtypeIdComparer,
                BtypeIdComparer,
                new NullTotalProgressFactory(),
                EqualityComparer <string> .Default,
                EqualityComparer <string> .Default,
                MockRepository.GenerateMock <IEntitySyncStateFactory <string, string, string, string, string, string, int> >(),
                ExceptionHandlingStrategy,
                IdentityMatchDataFactory <string> .Instance,
                IdentityMatchDataFactory <string> .Instance,
                null,
                NullChunkedExecutor.Instance,
                NullFullEntitySynchronizationLoggerFactory <string, string, string, string> .Instance,
                new VersionAwareToStateAwareEntityRepositoryAdapter <string, string, int, int>(AtypeRepository, AtypeIdComparer, EqualityComparer <string> .Default),
                new VersionAwareToStateAwareEntityRepositoryAdapter <string, string, int, int>(BtypeRepository, BtypeIdComparer, EqualityComparer <string> .Default),
                NullStateTokensDataAccess <int, int> .Instance));
 }
        private IOutlookSynchronizer CreateGoogleContactSynchronizer(Options options, AvailableSynchronizerComponents componentsToFill)
        {
            var atypeRepository = new OutlookContactRepository <GoogleContactContext> (
                _outlookSession,
                options.OutlookFolderEntryId,
                options.OutlookFolderStoreId,
                _daslFilterProvider);

            IWebProxy proxy = options.ProxyOptions != null?CreateProxy(options.ProxyOptions) : null;

            var googleApiExecutor = new GoogleApiOperationExecutor(
                System.Threading.Tasks.Task.Run(() => OAuth.Google.GoogleHttpClientFactory.LoginToContactsService(options.UserName, proxy).Result).Result);

            var mappingParameters = GetMappingParameters <ContactMappingConfiguration> (options);

            var atypeIdEqulityComparer  = EqualityComparer <string> .Default;
            var btypeIdEqualityComparer = EqualityComparer <string> .Default;

            var btypeRepository = new GoogleContactRepository(googleApiExecutor, options.UserName, mappingParameters, btypeIdEqualityComparer);

            var entityMapper = new GoogleContactEntityMapper(mappingParameters);

            var entityRelationDataFactory = new GoogleContactRelationDataFactory();

            var syncStateFactory = new EntitySyncStateFactory <string, DateTime, ContactItemWrapper, string, GoogleContactVersion, GoogleContactWrapper> (
                entityMapper,
                entityRelationDataFactory,
                ExceptionHandler.Instance);

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var storageDataAccess = new EntityRelationDataAccess <string, DateTime, GoogleContactRelationData, string, GoogleContactVersion> (storageDataDirectory);

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create <ContactItemWrapper, string, DateTime, GoogleContactContext> (atypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, ContactItemWrapper, string, GoogleContactVersion, GoogleContactWrapper, GoogleContactContext> (
                atypeRepository,
                btypeRepository,
                atypeWriteRepository,
                btypeRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, ContactItemWrapper, string, GoogleContactVersion, GoogleContactWrapper> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new GoogleContactConflictInitialSyncStateCreationStrategyAutomatic(e)),
                storageDataAccess,
                entityRelationDataFactory,
                new InitialGoogleContactEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqulityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance,
                new GoogleContactContextFactory(googleApiExecutor, btypeIdEqualityComparer, options.UserName),
                EqualityComparer <DateTime> .Default,
                new GoogleContactVersionComparer());

            return(new OutlookSynchronizer <string, GoogleContactVersion> (synchronizer));
        }
Esempio n. 4
0
        private ISynchronizer <DistributionListSychronizationContext> CreateDistListSynchronizer(
            Options options,
            GeneralOptions generalOptions,
            CardDavEntityRepository <DistributionList, int, DistributionListSychronizationContext> btypeRepository)
        {
            var atypeRepository = new OutlookDistListRepository <DistributionListSychronizationContext> (
                _outlookSession,
                options.OutlookFolderEntryId,
                options.OutlookFolderStoreId,
                _daslFilterProvider,
                _queryFolderStrategy);

            var entityMapper = new DistListEntityMapper();

            var entityRelationDataFactory = new DistListRelationDataFactory();

            var syncStateFactory = new EntitySyncStateFactory <string, DateTime, GenericComObjectWrapper <DistListItem>, WebResourceName, string, DistributionList, DistributionListSychronizationContext> (
                entityMapper,
                entityRelationDataFactory,
                ExceptionHandler.Instance);

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqulityComparer  = EqualityComparer <string> .Default;

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var storageDataAccess = new EntityRelationDataAccess <string, DateTime, DistListRelationData, WebResourceName, string> (storageDataDirectory, "distList");

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, GenericComObjectWrapper <DistListItem>, WebResourceName, string, DistributionList, DistributionListSychronizationContext> (
                atypeRepository,
                btypeRepository,
                atypeWriteRepository,
                btypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, GenericComObjectWrapper <DistListItem>, WebResourceName, string, DistributionList, DistributionListSychronizationContext> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new DistListConflictInitialSyncStateCreationStrategyAutomatic(e)),
                storageDataAccess,
                entityRelationDataFactory,
                new InitialDistListEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqulityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default,
                syncStateFactory);

            return(synchronizer);
        }
Esempio n. 5
0
 public Synchronizer <string, string, string, string, string, string, int> Build()
 {
     return(new Synchronizer <string, string, string, string, string, string, int> (
                AtypeRepository,
                BtypeRepository,
                BatchEntityRepositoryAdapter.Create(AtypeRepository),
                BatchEntityRepositoryAdapter.Create(BtypeRepository),
                InitialSyncStateCreationStrategy,
                EntityRelationDataAccess,
                EntityRelationDataFactory,
                InitialEntityMatcher,
                AtypeIdComparer,
                BtypeIdComparer,
                new NullTotalProgressFactory(),
                EqualityComparer <string> .Default,
                EqualityComparer <string> .Default,
                MockRepository.GenerateMock <IEntitySyncStateFactory <string, string, string, string, string, string, int> > ()));
 }
        private Synchronizer <Identifier, int, string, Identifier, int, string, int, string, string, int, int> CreateSynchronizer(
            IInitialSyncStateCreationStrategy <Identifier, int, string, Identifier, int, string, int> strategy,
            List <IEntityRelationData <Identifier, int, Identifier, int> > matchingEntities = null)
        {
            var initialEntityMatcherStub = MockRepository.GenerateStub <IInitialEntityMatcher <Identifier, int, string, Identifier, int, string> >();

            initialEntityMatcherStub
            .Stub(_ => _.FindMatchingEntities(
                      Arg <IEntityRelationDataFactory <Identifier, int, Identifier, int> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, string> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, string> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, int> > .Is.NotNull,
                      Arg <IReadOnlyDictionary <Identifier, int> > .Is.NotNull))
            .Return(matchingEntities ?? new List <IEntityRelationData <Identifier, int, Identifier, int> >());

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(_localRepository, TestExceptionHandlingStrategy.Instance);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(_serverRepository, TestExceptionHandlingStrategy.Instance);

            return(new Synchronizer <Identifier, int, string, Identifier, int, string, int, string, string, int, int>(
                       _localRepository,
                       _serverRepository,
                       atypeWriteRepository,
                       btypeWriteRepository,
                       strategy,
                       _entityRelationDataAccess,
                       _entityRelationDataFactory,
                       initialEntityMatcherStub,
                       IdentifierEqualityComparer.Instance,
                       IdentifierEqualityComparer.Instance,
                       NullTotalProgressFactory.Instance,
                       EqualityComparer <int> .Default,
                       EqualityComparer <int> .Default,
                       MockRepository.GenerateMock <IEntitySyncStateFactory <Identifier, int, string, Identifier, int, string, int> >(),
                       TestExceptionHandlingStrategy.Instance,
                       IdentityMatchDataFactory <string> .Instance,
                       IdentityMatchDataFactory <string> .Instance,
                       null,
                       NullChunkedExecutor.Instance,
                       NullFullEntitySynchronizationLoggerFactory <Identifier, string, Identifier, string> .Instance,
                       new VersionAwareToStateAwareEntityRepositoryAdapter <Identifier, int, int, int>(_localRepository, IdentifierEqualityComparer.Instance, EqualityComparer <int> .Default),
                       new VersionAwareToStateAwareEntityRepositoryAdapter <Identifier, int, int, int>(_serverRepository, IdentifierEqualityComparer.Instance, EqualityComparer <int> .Default),
                       NullStateTokensDataAccess <int, int> .Instance));
        }
        private IOutlookSynchronizer CreateContactSynchronizer(Options options, GeneralOptions generalOptions, AvailableSynchronizerComponents componentsToFill)
        {
            var atypeRepository = new OutlookContactRepository <int> (
                _outlookSession,
                options.OutlookFolderEntryId,
                options.OutlookFolderStoreId,
                _daslFilterProvider);

            var cardDavDataAccess = new CardDavDataAccess(
                new Uri(options.CalenderUrl),
                CreateWebDavClient(
                    options.UserName,
                    options.GetEffectivePassword(_outlookAccountPasswordProvider),
                    options.CalenderUrl,
                    _calDavConnectTimeout,
                    options.ServerAdapterType,
                    options.CloseAfterEachRequest,
                    options.PreemptiveAuthentication,
                    options.ForceBasicAuthentication,
                    options.ProxyOptions,
                    generalOptions.AcceptInvalidCharsInServerResponse));

            componentsToFill.CardDavDataAccess = cardDavDataAccess;

            IEntityRepository <vCard, WebResourceName, string, int> btypeRepository = new CardDavRepository(
                cardDavDataAccess);

            var mappingParameters = GetMappingParameters <ContactMappingConfiguration> (options);

            var entityMapper = new ContactEntityMapper(mappingParameters);

            var entityRelationDataFactory = new OutlookContactRelationDataFactory();

            var syncStateFactory = new EntitySyncStateFactory <string, DateTime, ContactItemWrapper, WebResourceName, string, vCard> (
                entityMapper,
                entityRelationDataFactory,
                ExceptionHandler.Instance);

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqulityComparer  = EqualityComparer <string> .Default;

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var storageDataAccess = new EntityRelationDataAccess <string, DateTime, OutlookContactRelationData, WebResourceName, string> (storageDataDirectory);

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, ContactItemWrapper, WebResourceName, string, vCard, int> (
                atypeRepository,
                btypeRepository,
                atypeWriteRepository,
                btypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, ContactItemWrapper, WebResourceName, string, vCard> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new ContactConflictInitialSyncStateCreationStrategyAutomatic(e)),
                storageDataAccess,
                entityRelationDataFactory,
                new InitialContactEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqulityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance,
                NullSynchronizationContextFactory.Instance,
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default);

            return(new OutlookSynchronizer <WebResourceName, string> (synchronizer));
        }
        private IOutlookSynchronizer CreateGoogleTaskSynchronizer(Options options)
        {
            var atypeRepository = new OutlookTaskRepository(_outlookSession, options.OutlookFolderEntryId, options.OutlookFolderStoreId, _daslFilterProvider);

            IWebProxy proxy = options.ProxyOptions != null?CreateProxy(options.ProxyOptions) : null;

            var tasksService = System.Threading.Tasks.Task.Run(() => OAuth.Google.GoogleHttpClientFactory.LoginToGoogleTasksService(options.UserName, proxy).Result).Result;

            TaskList taskList;

            try
            {
                taskList = tasksService.Tasklists.Get(options.CalenderUrl).Execute();
            }
            catch (Google.GoogleApiException)
            {
                s_logger.ErrorFormat($"Profile '{options.Name}' (Id: '{options.Id}'): task list '{options.CalenderUrl}' not found.");
                throw;
            }

            var btypeRepository = new GoogleTaskRepository(tasksService, taskList);


            var relationDataFactory = new GoogleTaskRelationDataFactory();
            var syncStateFactory    = new EntitySyncStateFactory <string, DateTime, TaskItemWrapper, string, string, Task> (
                new GoogleTaskMapper(),
                relationDataFactory,
                ExceptionHandler.Instance);

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var btypeIdEqualityComparer = EqualityComparer <string> .Default;
            var atypeIdEqualityComparer = EqualityComparer <string> .Default;

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, TaskItemWrapper, string, string, Task, int> (
                atypeRepository,
                btypeRepository,
                atypeWriteRepository,
                btypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, TaskItemWrapper, string, string, Task> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new GoogleTaskConflictInitialSyncStateCreationStrategyAutomatic(e)),
                new EntityRelationDataAccess <string, DateTime, GoogleTaskRelationData, string, string> (storageDataDirectory),
                relationDataFactory,
                new InitialGoogleTastEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqualityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance,
                NullSynchronizationContextFactory.Instance,
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default);

            return(new OutlookSynchronizer <string, string> (synchronizer));
        }
        /// <remarks>
        /// Public because it is being used by integration tests
        /// </remarks>
        public IOutlookSynchronizer CreateEventSynchronizer(
            Options options,
            ICalDavDataAccess calDavDataAccess,
            IEntityRelationDataAccess <string, DateTime, WebResourceName, string> entityRelationDataAccess)
        {
            var dateTimeRangeProvider =
                options.IgnoreSynchronizationTimeRange ?
                NullDateTimeRangeProvider.Instance :
                new DateTimeRangeProvider(options.DaysToSynchronizeInThePast, options.DaysToSynchronizeInTheFuture);

            var mappingParameters = GetMappingParameters <EventMappingConfiguration> (options);

            var atypeRepository = new OutlookEventRepository(
                _outlookSession,
                options.OutlookFolderEntryId,
                options.OutlookFolderStoreId,
                dateTimeRangeProvider,
                mappingParameters,
                _daslFilterProvider);

            IEntityRepository <IICalendar, WebResourceName, string, int> btypeRepository = new CalDavRepository(
                calDavDataAccess,
                new iCalendarSerializer(),
                CalDavRepository.EntityType.Event,
                dateTimeRangeProvider,
                options.ServerAdapterType == ServerAdapterType.WebDavHttpClientBasedWithGoogleOAuth);

            var entityMapper = new EventEntityMapper(
                _outlookEmailAddress, new Uri("mailto:" + options.EmailAddress),
                _outlookSession.Application.TimeZones.CurrentTimeZone.ID,
                _outlookSession.Application.Version,
                mappingParameters);

            var outlookEventRelationDataFactory = new OutlookEventRelationDataFactory();

            var syncStateFactory = new EntitySyncStateFactory <string, DateTime, AppointmentItemWrapper, WebResourceName, string, IICalendar> (
                entityMapper,
                outlookEventRelationDataFactory,
                ExceptionHandler.Instance
                );

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqualityComparer = EqualityComparer <string> .Default;

            var aTypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var bTypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, AppointmentItemWrapper, WebResourceName, string, IICalendar, int> (
                atypeRepository,
                btypeRepository,
                aTypeWriteRepository,
                bTypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, AppointmentItemWrapper, WebResourceName, string, IICalendar> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new EventConflictInitialSyncStateCreationStrategyAutomatic(e)),
                entityRelationDataAccess,
                outlookEventRelationDataFactory,
                new InitialEventEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqualityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance,
                NullSynchronizationContextFactory.Instance,
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default);

            return(new OutlookSynchronizer <WebResourceName, string> (synchronizer));
        }
        private IOutlookSynchronizer CreateTaskSynchronizer(Options options, GeneralOptions generalOptions, AvailableSynchronizerComponents componentsToFill)
        {
            var mappingParameters = GetMappingParameters <TaskMappingConfiguration> (options);

            var atypeRepository = new OutlookTaskRepository(_outlookSession, options.OutlookFolderEntryId, options.OutlookFolderStoreId, _daslFilterProvider, mappingParameters);



            ICalDavDataAccess calDavDataAccess;
            var calendarUrl = new Uri(options.CalenderUrl);

            if (calendarUrl.Scheme == Uri.UriSchemeFile)
            {
                calDavDataAccess = new FileSystemDavDataAccess(calendarUrl);
            }
            else
            {
                calDavDataAccess = new CalDavDataAccess(
                    calendarUrl,
                    CreateWebDavClient(
                        options.UserName,
                        options.GetEffectivePassword(_outlookAccountPasswordProvider),
                        options.CalenderUrl,
                        generalOptions.CalDavConnectTimeout,
                        options.ServerAdapterType,
                        options.CloseAfterEachRequest,
                        options.PreemptiveAuthentication,
                        options.ForceBasicAuthentication,
                        options.ProxyOptions,
                        generalOptions.EnableClientCertificate,
                        generalOptions.AcceptInvalidCharsInServerResponse));
            }

            componentsToFill.CalDavDataAccess = calDavDataAccess;

            var btypeRepository = new CalDavRepository <int> (
                calDavDataAccess,
                new iCalendarSerializer(),
                CalDavRepository.EntityType.Todo,
                NullDateTimeRangeProvider.Instance,
                false,
                options.IsChunkedSynchronizationEnabled ? new ChunkedExecutor(options.ChunkSize) : NullChunkedExecutor.Instance);

            var relationDataFactory = new TaskRelationDataFactory();
            var syncStateFactory    = new EntitySyncStateFactory <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar> (
                new TaskMapper(_outlookSession.Application.TimeZones.CurrentTimeZone.ID, mappingParameters),
                relationDataFactory,
                ExceptionHandler.Instance);

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqualityComparer = EqualityComparer <string> .Default;

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar, int> (
                atypeRepository,
                btypeRepository,
                atypeWriteRepository,
                btypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new TaskConflictInitialSyncStateCreationStrategyAutomatic(e)),
                new EntityRelationDataAccess <string, DateTime, TaskRelationData, WebResourceName, string> (storageDataDirectory),
                relationDataFactory,
                new InitialTaskEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqualityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance,
                NullSynchronizationContextFactory.Instance,
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default,
                syncStateFactory);

            return(new OutlookSynchronizer <WebResourceName, string> (synchronizer));
        }
        /// <remarks>
        /// Public because it is being used by integration tests
        /// </remarks>
        public async Task <IOutlookSynchronizer> CreateEventSynchronizer(
            Options options,
            ICalDavDataAccess calDavDataAccess,
            IEntityRelationDataAccess <AppointmentId, DateTime, WebResourceName, string> entityRelationDataAccess)
        {
            var dateTimeRangeProvider =
                options.IgnoreSynchronizationTimeRange ?
                NullDateTimeRangeProvider.Instance :
                new DateTimeRangeProvider(options.DaysToSynchronizeInThePast, options.DaysToSynchronizeInTheFuture);

            var mappingParameters = GetMappingParameters <EventMappingConfiguration> (options);

            var atypeRepository = new OutlookEventRepository(
                _outlookSession,
                options.OutlookFolderEntryId,
                options.OutlookFolderStoreId,
                dateTimeRangeProvider,
                mappingParameters,
                _daslFilterProvider);

            IEntityRepository <WebResourceName, string, IICalendar, IEventSynchronizationContext> btypeRepository = new CalDavRepository <IEventSynchronizationContext> (
                calDavDataAccess,
                new iCalendarSerializer(),
                CalDavRepository.EntityType.Event,
                dateTimeRangeProvider,
                options.ServerAdapterType == ServerAdapterType.WebDavHttpClientBasedWithGoogleOAuth,
                options.IsChunkedSynchronizationEnabled ? new ChunkedExecutor(options.ChunkSize) : NullChunkedExecutor.Instance);

            var timeZoneCache = new TimeZoneCache(CreateHttpClient(options.ProxyOptions), mappingParameters.IncludeHistoricalData, _globalTimeZoneCache);

            ITimeZone configuredEventTimeZoneOrNull;

            if (mappingParameters.UseIanaTz)
            {
                configuredEventTimeZoneOrNull = await timeZoneCache.GetByTzIdOrNull(mappingParameters.EventTz);
            }
            else
            {
                configuredEventTimeZoneOrNull = null;
            }

            var entityMapper = new EventEntityMapper(
                _outlookEmailAddress, new Uri("mailto:" + options.EmailAddress),
                _outlookSession.Application.TimeZones.CurrentTimeZone.ID,
                _outlookSession.Application.Version,
                timeZoneCache,
                mappingParameters,
                configuredEventTimeZoneOrNull);

            var outlookEventRelationDataFactory = new OutlookEventRelationDataFactory();

            var syncStateFactory = new EntitySyncStateFactory <AppointmentId, DateTime, AppointmentItemWrapper, WebResourceName, string, IICalendar> (
                entityMapper,
                outlookEventRelationDataFactory,
                ExceptionHandler.Instance
                );

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqualityComparer = AppointmentId.Comparer;

            var aTypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var bTypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <AppointmentId, DateTime, AppointmentItemWrapper, WebResourceName, string, IICalendar, IEventSynchronizationContext> (
                atypeRepository,
                btypeRepository,
                aTypeWriteRepository,
                bTypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <AppointmentId, DateTime, AppointmentItemWrapper, WebResourceName, string, IICalendar> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new EventConflictInitialSyncStateCreationStrategyAutomatic(e)),
                entityRelationDataAccess,
                outlookEventRelationDataFactory,
                new InitialEventEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqualityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance,
                new EventSynchronizationContextFactory(atypeRepository, btypeRepository, entityRelationDataAccess, mappingParameters.CleanupDuplicateEvents, atypeIdEqualityComparer),
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default,
                syncStateFactory,
                new EventSynchronizationInterceptorFactory());

            return(new OutlookEventSynchronizer <WebResourceName, string> (synchronizer));
        }
Esempio n. 12
0
        private IOutlookSynchronizer CreateContactSynchronizer(Options options, GeneralOptions generalOptions, AvailableSynchronizerComponents componentsToFill)
        {
            var atypeRepository = new OutlookContactRepository <ICardDavRepositoryLogger> (
                _outlookSession,
                options.OutlookFolderEntryId,
                options.OutlookFolderStoreId,
                _daslFilterProvider,
                _queryFolderStrategy);

            ICardDavDataAccess cardDavDataAccess;
            var serverUrl = new Uri(options.CalenderUrl);

            IWebDavClient webDavClientOrNullIfFileAccess = null;

            if (serverUrl.Scheme == Uri.UriSchemeFile)
            {
                cardDavDataAccess = new FileSystemDavDataAccess(serverUrl);
            }
            else
            {
                webDavClientOrNullIfFileAccess = CreateWebDavClient(
                    options.UserName,
                    options.GetEffectivePassword(_outlookAccountPasswordProvider),
                    options.CalenderUrl,
                    generalOptions.CalDavConnectTimeout,
                    options.ServerAdapterType,
                    options.CloseAfterEachRequest,
                    options.PreemptiveAuthentication,
                    options.ForceBasicAuthentication,
                    options.ProxyOptions,
                    generalOptions.EnableClientCertificate,
                    generalOptions.AcceptInvalidCharsInServerResponse);

                cardDavDataAccess = new CardDavDataAccess(
                    serverUrl,
                    webDavClientOrNullIfFileAccess,
                    contentType => contentType != "text/x-vlist");
            }
            componentsToFill.CardDavDataAccess = cardDavDataAccess;

            var chunkedExecutor = options.IsChunkedSynchronizationEnabled ? new ChunkedExecutor(options.ChunkSize) : NullChunkedExecutor.Instance;

            var cardDavRepository = new CardDavRepository(
                cardDavDataAccess,
                chunkedExecutor);
            var btypeRepository =
                new LoggingCardDavRepositoryDecorator(
                    cardDavRepository);

            componentsToFill.CardDavEntityRepository = cardDavRepository;

            var mappingParameters = GetMappingParameters <ContactMappingConfiguration> (options);

            var entityMapper = new ContactEntityMapper(mappingParameters);

            var entityRelationDataFactory = new OutlookContactRelationDataFactory();

            var syncStateFactory = new EntitySyncStateFactory <string, DateTime, ContactItemWrapper, WebResourceName, string, vCard, ICardDavRepositoryLogger> (
                entityMapper,
                entityRelationDataFactory,
                ExceptionHandler.Instance);

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqulityComparer  = EqualityComparer <string> .Default;

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var storageDataAccess = new EntityRelationDataAccess <string, DateTime, OutlookContactRelationData, WebResourceName, string> (storageDataDirectory);

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, ContactItemWrapper, WebResourceName, string, vCard, ICardDavRepositoryLogger> (
                atypeRepository,
                btypeRepository,
                atypeWriteRepository,
                btypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, ContactItemWrapper, WebResourceName, string, vCard, ICardDavRepositoryLogger> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new ContactConflictInitialSyncStateCreationStrategyAutomatic(e)),
                storageDataAccess,
                entityRelationDataFactory,
                new InitialContactEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqulityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default,
                syncStateFactory);

            if (mappingParameters.MapDistributionLists)
            {
                CardDavEntityRepository <DistributionList, int, DistributionListSychronizationContext> bDistListRepository;

                // TODO: muss auch für das file funktionieren
                ICardDavDataAccess distListDataAccess = new CardDavDataAccess(
                    serverUrl,
                    webDavClientOrNullIfFileAccess,
                    contentType => contentType == "text/x-vlist");

                componentsToFill.DistListDataAccess = distListDataAccess;

                switch (mappingParameters.DistributionListType)
                {
                case DistributionListType.Sogo:
                    bDistListRepository = new SogoDistributionListRepository(distListDataAccess, chunkedExecutor);
                    break;

                default:
                    throw new NotImplementedException($"{nameof(DistributionListType)} '{mappingParameters.DistributionListType}' not implemented.");
                }

                var distributionListSynchronizer = CreateDistListSynchronizer(options, generalOptions, bDistListRepository);

                return(new OutlookSynchronizer <WebResourceName, string>(
                           new ContactAndDistListSynchronizer(
                               synchronizer,
                               distributionListSynchronizer,
                               new EmailAddressCacheDataAccess(Path.Combine(storageDataDirectory, "emailAddressCache.xml")),
                               btypeRepository,
                               storageDataAccess,
                               atypeRepository,
                               _outlookSession)));
            }
            else
            {
                return(new OutlookSynchronizer <WebResourceName, string>(
                           new ContextCreatingSynchronizerDecorator <string, DateTime, ContactItemWrapper, WebResourceName, string, vCard, ICardDavRepositoryLogger>(
                               synchronizer,
                               new SynchronizationContextFactory <ICardDavRepositoryLogger>(() => NullCardDavRepositoryLogger.Instance))));
            }
        }