public static IOutlookSynchronizer CreateEventSynchronizer (
        SynchronizationMode mode,
        ICalDavDataAccess calDavDataAccess,
        IEntityRelationDataAccess<string, DateTime, Uri, string> entityRelationDataAccess = null,
        Action<Options> optionsModifier = null)
    {
      var options = new Options()
                    {
                        ConflictResolution = ConflictResolution.Automatic,
                        EmailAddress = "[email protected]",
                        IgnoreSynchronizationTimeRange = true,
                        OutlookFolderEntryId = s_outlookFolderEntryId,
                        OutlookFolderStoreId = s_outlookFolderStoreId,
                        SynchronizationMode = mode,
                        CalenderUrl = "http://invalidurl.net"
                    };

      if (optionsModifier != null)
        optionsModifier (options);

      return s_synchronizerFactory.CreateEventSynchronizer (
          options,
          calDavDataAccess,
          entityRelationDataAccess ?? MockRepository.GenerateStub<IEntityRelationDataAccess<string, DateTime, Uri, string>>());
    }
    public void Initialize ()
    {
      var applicationDataDirectory = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), "CalDavSynchronizer");

      var optionsDataAccess = new OptionsDataAccess (
          Path.Combine (
              applicationDataDirectory,
              ComponentContainer.GetOrCreateConfigFileName (applicationDataDirectory, "Outlook")
              ));

      var options = optionsDataAccess.LoadOptions().Single (o => o.Name == ProfileName);

      if (ServerAdapterTypeOverride.HasValue)
        options.ServerAdapterType = ServerAdapterTypeOverride.Value;

      _calDavDataAccess = new CalDavDataAccess (
          new Uri (options.CalenderUrl),
          SynchronizerFactory.CreateWebDavClient (options, TimeSpan.FromSeconds (30)));
    }
    public void Initialize ()
    {
      var applicationDataDirectory = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), "CalDavSynchronizer");

      var optionsDataAccess = new OptionsDataAccess (
          Path.Combine (
              applicationDataDirectory,
              ComponentContainer.GetOrCreateConfigFileName (applicationDataDirectory, "Outlook")
              ));

      var options = optionsDataAccess.LoadOptions().Single (o => o.Name == ProfileName);

      _calDavDataAccess = SynchronizerFactory.CreateCalDavDataAccess (
          options.CalenderUrl,
          options.UserName,
          options.Password,
          TimeSpan.FromSeconds (30),
          options.ServerAdapterType);
    }
    /// <remarks>
    /// Public because it is being used by integration tests
    /// </remarks>
    public OutlookSynchronizer CreateEventSynchronizer (
        Options options,
        ICalDavDataAccess calDavDataAccess,
        IEntityRelationDataAccess<string, DateTime, Uri, string> entityRelationDataAccess)
    {
      var dateTimeRangeProvider =
          options.IgnoreSynchronizationTimeRange ?
              NullDateTimeRangeProvider.Instance :
              new DateTimeRangeProvider (options.DaysToSynchronizeInThePast, options.DaysToSynchronizeInTheFuture);

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

      IEntityRepository<IICalendar, Uri, string> btypeRepository = new CalDavRepository (
          calDavDataAccess,
          new iCalendarSerializer(),
          CalDavRepository.EntityType.Event,
          dateTimeRangeProvider);

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

      var outlookEventRelationDataFactory = new OutlookEventRelationDataFactory();

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

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

      var synchronizer = new Synchronizer<string, DateTime, AppointmentItemWrapper, Uri, string, IICalendar> (
          atypeRepository,
          btypeRepository,
          InitialEventSyncStateCreationStrategyFactory.Create (
              syncStateFactory,
              syncStateFactory.Environment,
              options.SynchronizationMode,
              options.ConflictResolution),
          entityRelationDataAccess,
          outlookEventRelationDataFactory,
          new InitialEventEntityMatcher (btypeIdEqualityComparer),
          atypeIdEqualityComparer,
          btypeIdEqualityComparer,
          _totalProgressFactory,
          ExceptionHandler.Instance);

      return new OutlookSynchronizer (synchronizer, atypeRepository);
    }