public OptionsCollectionViewModel( bool expandAllSyncProfiles, Func <Guid, string> profileDataDirectoryFactory, IUiService uiService, IOptionTasks optionTasks, IProfileTypeRegistry profileTypeRegistry, Func <IOptionsViewModelParent, IProfileType, IProfileModelFactory> profileModelFactoryFactory, IViewOptions viewOptions) { _optionTasks = optionTasks; ViewOptions = viewOptions; _profileDataDirectoryFactory = profileDataDirectoryFactory; _uiService = uiService; if (profileDataDirectoryFactory == null) { throw new ArgumentNullException(nameof(profileDataDirectoryFactory)); } if (optionTasks == null) { throw new ArgumentNullException(nameof(optionTasks)); } if (viewOptions == null) { throw new ArgumentNullException(nameof(viewOptions)); } _expandAllSyncProfiles = expandAllSyncProfiles; _profileTypeRegistry = profileTypeRegistry; _profileModelFactoriesByType = profileTypeRegistry.AllTypes.ToDictionary(t => t, t => profileModelFactoryFactory(this, t)); RegisterPropertyChangeHandler(viewOptions, nameof(viewOptions.IsAdvancedViewEnabled), () => { if (!viewOptions.IsAdvancedViewEnabled) { OnAdvancedViewDisabled(); } }); AddCommand = new DelegateCommand(_ => Add()); AddMultipleCommand = new DelegateCommand(_ => AddMultiple()); CloseCommand = new DelegateCommand(shouldSaveNewOptions => Close((bool)shouldSaveNewOptions)); DeleteSelectedCommand = new DelegateCommandHandlingRequerySuggested(_ => DeleteSelected(), _ => CanDeleteSelected); ClearCacheOfSelectedCommand = new DelegateCommandHandlingRequerySuggested(_ => ClearCacheOfSelected(), _ => CanClearCacheOfSelected); CopySelectedCommand = new DelegateCommandHandlingRequerySuggested(_ => CopySelected(), _ => CanCopySelected); MoveSelectedUpCommand = new DelegateCommandHandlingRequerySuggested(_ => MoveSelectedUp(), _ => CanMoveSelectedUp); MoveSelectedDownCommand = new DelegateCommandHandlingRequerySuggested(_ => MoveSelectedDown(), _ => CanMoveSelectedDown); OpenProfileDataDirectoryCommand = new DelegateCommandHandlingRequerySuggested(_ => OpenProfileDataDirectory(), _ => CanOpenProfileDataDirectory); ExpandAllCommand = new DelegateCommandHandlingRequerySuggested(_ => ExpandAll(), _ => _options.Count > 0); CollapseAllCommand = new DelegateCommandHandlingRequerySuggested(_ => CollapseAll(), _ => _options.Count > 0); ExportAllCommand = new DelegateCommandHandlingRequerySuggested(_ => ExportAll(), _ => _options.Count > 0); ImportCommand = new DelegateCommandHandlingRequerySuggested(_ => Import(), _ => true); }
public ComponentContainer(Application application, IGeneralOptionsDataAccess generalOptionsDataAccess, IComWrapperFactory comWrapperFactory, IExceptionHandlingStrategy exceptionHandlingStrategy) { if (application == null) { throw new ArgumentNullException(nameof(application)); } if (generalOptionsDataAccess == null) { throw new ArgumentNullException(nameof(generalOptionsDataAccess)); } if (comWrapperFactory == null) { throw new ArgumentNullException(nameof(comWrapperFactory)); } s_logger.Info("Startup..."); s_logger.Info($"Version: {Assembly.GetExecutingAssembly().GetName().Version}"); s_logger.Info($"Operating system: {Environment.OSVersion}"); _profileTypeRegistry = ProfileTypeRegistry.Instance; 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(generalOptions.CultureName); ConfigureServicePointManager(generalOptions); ConfigureLogLevel(generalOptions.EnableDebugLog); _session = application.Session; _outlookAccountPasswordProvider = string.IsNullOrEmpty(_session.CurrentProfileName) ? NullOutlookAccountPasswordProvider.Instance : new OutlookAccountPasswordProvider(_session.CurrentProfileName, application.Version); _globalTimeZoneCache = new GlobalTimeZoneCache(); var applicationDataDirectoryBase = Path.Combine( Environment.GetFolderPath( generalOptions.StoreAppDataInRoamingFolder ? Environment.SpecialFolder.ApplicationData : Environment.SpecialFolder.LocalApplicationData), "CalDavSynchronizer"); string optionsFilePath; (_applicationDataDirectory, optionsFilePath) = GetOrCreateDataDirectory(applicationDataDirectoryBase, _session.CurrentProfileName); _optionsDataAccess = new OptionsDataAccess(optionsFilePath); _uiService = new UiService(); var options = _optionsDataAccess.Load(); _permanentStatusesViewModel = new PermanentStatusesViewModel(_uiService, this, options); _permanentStatusesViewModel.OptionsRequesting += PermanentStatusesViewModel_OptionsRequesting; _queryFolderStrategyWrapper = new OutlookFolderStrategyWrapper(QueryOutlookFolderByRequestingItemStrategy.Instance); _totalProgressFactory = new TotalProgressFactory( _uiService, generalOptions.ShowProgressBar, generalOptions.ThresholdForProgressDisplay, ExceptionHandler.Instance); _outlookSession = new OutlookSession(_session); _synchronizerFactory = new SynchronizerFactory( GetProfileDataDirectory, _totalProgressFactory, _outlookSession, _daslFilterProvider, _outlookAccountPasswordProvider, _globalTimeZoneCache, _queryFolderStrategyWrapper, exceptionHandlingStrategy, comWrapperFactory, _optionsDataAccess, _profileTypeRegistry); _synchronizationReportRepository = CreateSynchronizationReportRepository(); UpdateGeneralOptionDependencies(generalOptions); _scheduler = new Scheduler( _synchronizerFactory, this, EnsureSynchronizationContext, new FolderChangeWatcherFactory( _session), _synchronizationStatus); EnsureCacheCompatibility(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); } _oneTimeTaskRunner = new OneTimeTaskRunner(_outlookSession); DDayICalWorkaround.DDayICalCustomization.InitializeNoThrow(); }