public ComponentContainer(Application application) { s_logger.Info("Startup..."); _generalOptionsDataAccess = new GeneralOptionsDataAccess(); var generalOptions = _generalOptionsDataAccess.LoadOptions(); _daslFilterProvider = new DaslFilterProvider(generalOptions.IncludeCustomMessageClasses); FrameworkElement.LanguageProperty.OverrideMetadata( typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); ConfigureServicePointManager(generalOptions); ConfigureLogLevel(generalOptions.EnableDebugLog); _session = application.Session; _outlookAccountPasswordProvider = string.IsNullOrEmpty(_session.CurrentProfileName) ? NullOutlookAccountPasswordProvider.Instance : new OutlookAccountPasswordProvider(_session.CurrentProfileName, application.Version); EnsureSynchronizationContext(); _applicationDataDirectory = Path.Combine( Environment.GetFolderPath( generalOptions.StoreAppDataInRoamingFolder ? Environment.SpecialFolder.ApplicationData : Environment.SpecialFolder.LocalApplicationData), "CalDavSynchronizer"); _optionsDataAccess = new OptionsDataAccess( Path.Combine( _applicationDataDirectory, GetOrCreateConfigFileName(_applicationDataDirectory, _session.CurrentProfileName) )); _synchronizerFactory = new SynchronizerFactory( GetProfileDataDirectory, new TotalProgressFactory( new ProgressFormFactory(), int.Parse(ConfigurationManager.AppSettings["loadOperationThresholdForProgressDisplay"]), ExceptionHandler.Instance), _session, TimeSpan.Parse(ConfigurationManager.AppSettings["calDavConnectTimeout"]), _daslFilterProvider, _outlookAccountPasswordProvider); _synchronizationReportRepository = CreateSynchronizationReportRepository(); UpdateGeneralOptionDependencies(generalOptions); _scheduler = new Scheduler( _synchronizerFactory, this, EnsureSynchronizationContext, new FolderChangeWatcherFactory( _session)); var options = _optionsDataAccess.LoadOptions(); EnsureCacheCompatibility(options); _profileStatusesViewModel = new ProfileStatusesViewModel(this); _profileStatusesViewModel.EnsureProfilesDisplayed(options); _scheduler.SetOptions(options, generalOptions.CheckIfOnline); _availableVersionService = new AvailableVersionService(); _updateChecker = new UpdateChecker(_availableVersionService, () => _generalOptionsDataAccess.IgnoreUpdatesTilVersion); _updateChecker.NewerVersionFound += UpdateChecker_NewerVersionFound; _updateChecker.IsEnabled = generalOptions.ShouldCheckForNewerVersions; _reportGarbageCollection = new ReportGarbageCollection(_synchronizationReportRepository, TimeSpan.FromDays(generalOptions.MaxReportAgeInDays)); _trayNotifier = generalOptions.EnableTrayIcon ? new TrayNotifier(this) : NullTrayNotifer.Instance; _uiService = new UiService(_profileStatusesViewModel); }
public ComponentContainer(Application application, IUiServiceFactory uiServiceFactory, IGeneralOptionsDataAccess generalOptionsDataAccess, IComWrapperFactory comWrapperFactory, IExceptionHandlingStrategy exceptionHandlingStrategy) { if (application == null) { throw new ArgumentNullException(nameof(application)); } if (uiServiceFactory == null) { throw new ArgumentNullException(nameof(uiServiceFactory)); } if (generalOptionsDataAccess == null) { throw new ArgumentNullException(nameof(generalOptionsDataAccess)); } if (comWrapperFactory == null) { throw new ArgumentNullException(nameof(comWrapperFactory)); } s_logger.Info("Startup..."); if (GeneralOptionsDataAccess.WpfRenderModeSoftwareOnly) { RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly; } _generalOptionsDataAccess = generalOptionsDataAccess; _synchronizationStatus = new SynchronizationStatus(); var generalOptions = _generalOptionsDataAccess.LoadOptions(); _daslFilterProvider = new DaslFilterProvider(generalOptions.IncludeCustomMessageClasses); SetWpfLocale(); ConfigureServicePointManager(generalOptions); ConfigureLogLevel(generalOptions.EnableDebugLog); _session = application.Session; _outlookAccountPasswordProvider = string.IsNullOrEmpty(_session.CurrentProfileName) ? NullOutlookAccountPasswordProvider.Instance : new OutlookAccountPasswordProvider(_session.CurrentProfileName, application.Version); _globalTimeZoneCache = new GlobalTimeZoneCache(); _applicationDataDirectory = Path.Combine( Environment.GetFolderPath( generalOptions.StoreAppDataInRoamingFolder ? Environment.SpecialFolder.ApplicationData : Environment.SpecialFolder.LocalApplicationData), "CalDavSynchronizer"); _optionsDataAccess = new OptionsDataAccess( Path.Combine( _applicationDataDirectory, GetOrCreateConfigFileName(_applicationDataDirectory, _session.CurrentProfileName) )); _profileStatusesViewModel = new ProfileStatusesViewModel(this); _uiService = uiServiceFactory.Create(_profileStatusesViewModel); _queryFolderStrategyWrapper = new OutlookFolderStrategyWrapper(QueryOutlookFolderByRequestingItemStrategy.Instance); _totalProgressFactory = new TotalProgressFactory( _uiService, generalOptions.ShowProgressBar, generalOptions.ThresholdForProgressDisplay, ExceptionHandler.Instance); _synchronizerFactory = new SynchronizerFactory( GetProfileDataDirectory, _totalProgressFactory, new OutlookSession(_session), _daslFilterProvider, _outlookAccountPasswordProvider, _globalTimeZoneCache, _queryFolderStrategyWrapper, exceptionHandlingStrategy, comWrapperFactory); _synchronizationReportRepository = CreateSynchronizationReportRepository(); UpdateGeneralOptionDependencies(generalOptions); _scheduler = new Scheduler( _synchronizerFactory, this, EnsureSynchronizationContext, new FolderChangeWatcherFactory( _session), _synchronizationStatus); var options = _optionsDataAccess.Load(); EnsureCacheCompatibility(options); _profileStatusesViewModel.EnsureProfilesDisplayed(options); _availableVersionService = new AvailableVersionService(); _updateChecker = new UpdateChecker(_availableVersionService, () => _generalOptionsDataAccess.IgnoreUpdatesTilVersion); _updateChecker.NewerVersionFound += UpdateChecker_NewerVersionFound; _updateChecker.IsEnabled = generalOptions.ShouldCheckForNewerVersions; _reportGarbageCollection = new ReportGarbageCollection(_synchronizationReportRepository, TimeSpan.FromDays(generalOptions.MaxReportAgeInDays)); _trayNotifier = generalOptions.EnableTrayIcon ? new TrayNotifier(this) : NullTrayNotifer.Instance; try { using (var syncObjects = GenericComObjectWrapper.Create(_session.SyncObjects)) { if (syncObjects.Inner != null && syncObjects.Inner.Count > 0) { _syncObject = syncObjects.Inner[1]; if (generalOptions.TriggerSyncAfterSendReceive) { _syncObject.SyncEnd += SyncObject_SyncEnd; } } } } catch (COMException ex) { s_logger.Error("Can't access SyncObjects", ex); } _categorySwitcher = new CategorySwitcher(new OutlookSession(_session), _daslFilterProvider, _queryFolderStrategyWrapper); }