private void SwitchCategories(ChangedOptions[] changedOptions) { foreach (var changedOption in changedOptions) { var oldEventCategory = GetMappingRefPropertyOrNull <EventMappingConfiguration, string> (changedOption.Old.MappingConfiguration, o => o.EventCategory); var newEventCategory = GetMappingRefPropertyOrNull <EventMappingConfiguration, string> (changedOption.New.MappingConfiguration, o => o.EventCategory); var negateEventCategoryFilter = GetMappingPropertyOrNull <EventMappingConfiguration, bool> (changedOption.New.MappingConfiguration, o => o.InvertEventCategoryFilter); if (oldEventCategory != newEventCategory && !String.IsNullOrEmpty(oldEventCategory) && !negateEventCategoryFilter.Value) { try { SwitchEventCategories(changedOption, oldEventCategory, newEventCategory); } catch (Exception x) { s_logger.Error(null, x); } } if (!String.IsNullOrEmpty(newEventCategory)) { var mappingConfiguration = (EventMappingConfiguration)changedOption.New.MappingConfiguration; if (mappingConfiguration.UseEventCategoryColorAndMapFromCalendarColor || mappingConfiguration.CategoryShortcutKey != OlCategoryShortcutKey.olCategoryShortcutKeyNone) { try { using (var categoriesWrapper = GenericComObjectWrapper.Create(_session.Categories)) { foreach (var existingCategory in categoriesWrapper.Inner.ToSafeEnumerable <Category>()) { if (existingCategory.ShortcutKey == mappingConfiguration.CategoryShortcutKey) { existingCategory.ShortcutKey = OlCategoryShortcutKey.olCategoryShortcutKeyNone; } } using (var categoryWrapper = GenericComObjectWrapper.Create(categoriesWrapper.Inner[newEventCategory])) { if (categoryWrapper.Inner == null) { categoriesWrapper.Inner.Add(newEventCategory, mappingConfiguration.EventCategoryColor, mappingConfiguration.CategoryShortcutKey); } else { categoryWrapper.Inner.Color = mappingConfiguration.EventCategoryColor; categoryWrapper.Inner.ShortcutKey = mappingConfiguration.CategoryShortcutKey; } } } } catch (Exception x) { s_logger.Error(null, x); } } } var oldTaskCategory = GetMappingRefPropertyOrNull <TaskMappingConfiguration, string> (changedOption.Old.MappingConfiguration, o => o.TaskCategory); var newTaskCategory = GetMappingRefPropertyOrNull <TaskMappingConfiguration, string> (changedOption.New.MappingConfiguration, o => o.TaskCategory); var negateTaskCategoryFilter = GetMappingPropertyOrNull <TaskMappingConfiguration, bool> (changedOption.New.MappingConfiguration, o => o.InvertTaskCategoryFilter); if (oldTaskCategory != newTaskCategory && !String.IsNullOrEmpty(oldTaskCategory) && !negateTaskCategoryFilter.Value) { try { SwitchTaskCategories(changedOption, oldTaskCategory, newTaskCategory); } catch (Exception x) { s_logger.Error(null, x); } } } }
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(); }
private void MapRecurrance2To1(ITodo source, TaskItemWrapper targetWrapper, IEntityMappingLogger logger) { if (source.RecurrenceRules.Count > 0) { using (var targetRecurrencePatternWrapper = GenericComObjectWrapper.Create(targetWrapper.Inner.GetRecurrencePattern())) { var targetRecurrencePattern = targetRecurrencePatternWrapper.Inner; if (source.RecurrenceRules.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one recurrence rule. Since outlook supports only one rule, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one recurrence rule. Since outlook supports only one rule, all except the first one will be ignored."); } var sourceRecurrencePattern = source.RecurrenceRules[0]; switch (sourceRecurrencePattern.Frequency) { case FrequencyType.Daily: targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursDaily; break; case FrequencyType.Weekly: if (sourceRecurrencePattern.ByDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursWeekly; targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursWeekly; } break; case FrequencyType.Monthly: if (sourceRecurrencePattern.ByDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursMonthNth; if (sourceRecurrencePattern.ByWeekNo.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one week in a monthly recurrence rule. Since outlook supports only one week, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one week in a monthly recurrence rule. Since outlook supports only one week, all except the first one will be ignored."); } else if (sourceRecurrencePattern.ByWeekNo.Count > 0) { targetRecurrencePattern.Instance = sourceRecurrencePattern.ByWeekNo[0]; } else { targetRecurrencePattern.Instance = (sourceRecurrencePattern.ByDay[0].Offset >= 0) ? sourceRecurrencePattern.ByDay[0].Offset : 5; } if (sourceRecurrencePattern.BySetPosition.Count > 0) { targetRecurrencePattern.Instance = (sourceRecurrencePattern.BySetPosition[0] >= 0) ? sourceRecurrencePattern.BySetPosition[0] : 5; } targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.ByMonthDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursMonthly; if (sourceRecurrencePattern.ByMonthDay.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored."); } try { targetRecurrencePattern.DayOfMonth = sourceRecurrencePattern.ByMonthDay[0]; } catch (COMException ex) { s_logger.Warn($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); logger.LogMappingWarning($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); } } else { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursMonthly; } break; case FrequencyType.Yearly: if (sourceRecurrencePattern.ByMonth.Count > 0 && sourceRecurrencePattern.ByWeekNo.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearNth; if (sourceRecurrencePattern.ByMonth.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored."); } targetRecurrencePattern.MonthOfYear = sourceRecurrencePattern.ByMonth[0]; if (sourceRecurrencePattern.ByWeekNo.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one week in a yearly recurrence rule. Since outlook supports only one week, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one week in a yearly recurrence rule. Since outlook supports only one week, all except the first one will be ignored."); } targetRecurrencePattern.Instance = sourceRecurrencePattern.ByWeekNo[0]; targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.ByMonth.Count > 0 && sourceRecurrencePattern.ByMonthDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearly; if (sourceRecurrencePattern.ByMonth.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored."); } if (sourceRecurrencePattern.ByMonth[0] != targetRecurrencePattern.MonthOfYear) { targetRecurrencePattern.MonthOfYear = sourceRecurrencePattern.ByMonth[0]; } if (sourceRecurrencePattern.ByMonthDay.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one days in a monthly recurrence rule. Since outlook supports only one day, all except the first one will be ignored."); } if (sourceRecurrencePattern.ByMonthDay[0] != targetRecurrencePattern.DayOfMonth) { try { targetRecurrencePattern.DayOfMonth = sourceRecurrencePattern.ByMonthDay[0]; } catch (COMException ex) { s_logger.Warn($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); logger.LogMappingWarning($"Recurring task '{source.UID}' contains invalid BYMONTHDAY '{sourceRecurrencePattern.ByMonthDay[0]}', which will be ignored.", ex); } } } else if (sourceRecurrencePattern.ByMonth.Count > 0 && sourceRecurrencePattern.ByDay.Count > 0) { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearNth; if (sourceRecurrencePattern.ByMonth.Count > 1) { s_logger.WarnFormat("Task '{0}' contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored.", source.UID); logger.LogMappingWarning("Task contains more than one months in a yearly recurrence rule. Since outlook supports only one month, all except the first one will be ignored."); } targetRecurrencePattern.MonthOfYear = sourceRecurrencePattern.ByMonth[0]; targetRecurrencePattern.Instance = (sourceRecurrencePattern.ByDay[0].Offset >= 0) ? sourceRecurrencePattern.ByDay[0].Offset : 5; if (sourceRecurrencePattern.BySetPosition.Count > 0) { targetRecurrencePattern.Instance = (sourceRecurrencePattern.BySetPosition[0] >= 0) ? sourceRecurrencePattern.BySetPosition[0] : 5; } targetRecurrencePattern.DayOfWeekMask = CommonEntityMapper.MapDayOfWeek2To1(sourceRecurrencePattern.ByDay); } else { targetRecurrencePattern.RecurrenceType = OlRecurrenceType.olRecursYearly; } break; default: s_logger.WarnFormat("Recurring task '{0}' contains the Frequency '{1}', which is not supported by outlook. Ignoring recurrence rule.", source.UID, sourceRecurrencePattern.Frequency); logger.LogMappingWarning($"Recurring task contains the Frequency '{sourceRecurrencePattern.Frequency}', which is not supported by outlook. Ignoring recurrence rule."); targetWrapper.Inner.ClearRecurrencePattern(); break; } try { targetRecurrencePattern.Interval = (targetRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly || targetRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval * 12 : sourceRecurrencePattern.Interval; } catch (COMException ex) { s_logger.Warn(string.Format("Recurring task '{0}' contains the Interval '{1}', which is not supported by outlook. Ignoring interval.", source.UID, sourceRecurrencePattern.Interval), ex); logger.LogMappingWarning($"Recurring task contains the Interval '{sourceRecurrencePattern.Interval}', which is not supported by outlook. Ignoring interval.", ex); } if (sourceRecurrencePattern.Count >= 0) { targetRecurrencePattern.Occurrences = sourceRecurrencePattern.Count; } if (sourceRecurrencePattern.Until != default(DateTime)) { if (sourceRecurrencePattern.Until.Date >= targetRecurrencePattern.PatternStartDate) { targetRecurrencePattern.PatternEndDate = sourceRecurrencePattern.Until.Date; } else { targetRecurrencePattern.PatternEndDate = targetRecurrencePattern.PatternStartDate; } } } targetWrapper.SaveAndReload(); } }
public async Task Synchronizer_ServerMasterEventIsMissing_IsReconstructed(string category) { var options = _testComponentContainer.TestOptionsFactory.CreateLocalFolderEvents(); var synchronizer = await CreateSynchronizer(options); await synchronizer.ClearEventRepositoriesAndCache(); await synchronizer.CreateEventInOutlook( "Meeting", DateTime.Now.AddDays(10), DateTime.Now.AddDays(10).AddHours(1), false, e => { if (category != null) { e.Inner.Categories = "cat1"; } using (var recurrencePatternWrapper = GenericComObjectWrapper.Create(e.Inner.GetRecurrencePattern())) { var recurrencePattern = recurrencePatternWrapper.Inner; recurrencePattern.RecurrenceType = Microsoft.Office.Interop.Outlook.OlRecurrenceType.olRecursDaily; recurrencePattern.Occurrences = 10; } e.SaveAndReload(); using (var recurrencePatternWrapper = GenericComObjectWrapper.Create(e.Inner.GetRecurrencePattern())) { var recurrencePattern = recurrencePatternWrapper.Inner; foreach (var exDay in new[] { 2, 4, 6 }) { using (var wrapper = GenericComObjectWrapper.Create(recurrencePattern.GetOccurrence(e.Inner.Start.AddDays(exDay)))) { wrapper.Inner.Subject = $"Long Meeting on day {exDay}"; wrapper.Inner.End = wrapper.Inner.End.AddHours(1); wrapper.Inner.Save(); } } } }); await synchronizer.SynchronizeAndAssertNoErrors(); synchronizer.ClearCache(); await synchronizer.Outlook.DeleteAllEntities(); var entityVersion = (await synchronizer.Components.CalDavDataAccess.GetEventVersions(null)).Single(); var entity = (await synchronizer.Components.CalDavRepository.Get(new[] { entityVersion.Id }, NullLoadEntityLogger.Instance, NullEventSynchronizationContext.Instance)).Single(); await synchronizer.Components.CalDavRepository.TryUpdate( entityVersion.Id, entityVersion.Version, entity.Entity, c => { var master = c.Events.Single(e => e.Summary == "Meeting"); c.Events.Remove(master); return(Task.FromResult(c)); }, NullEventSynchronizationContext.Instance); // Now a server event was set up without an master event var report = await synchronizer.Synchronize(); Assert.That(report.HasErrors, Is.False); Assert.That( report.EntitySynchronizationReports.SingleOrDefault()?.MappingWarnings.FirstOrDefault(w => w == "CalDav Ressources contains only exceptions. Reconstructing master event."), Is.Not.Null); using (var outlookEvent = (await synchronizer.Outlook.GetAllEntities()).Single().Entity) { // the name of the recostructed master event has been taken from the first exception Assert.That(outlookEvent.Inner.Subject, Is.EqualTo("Long Meeting on day 2")); Assert.That(outlookEvent.Inner.Categories, Is.EqualTo(category)); } }
public async Task <Tuple <IOutlookSynchronizer, AvailableSynchronizerComponents> > CreateSynchronizerWithComponents(Options options, GeneralOptions generalOptions) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (generalOptions == null) { throw new ArgumentNullException(nameof(generalOptions)); } var synchronizerComponents = new AvailableSynchronizerComponents(); OlItemType defaultItemType; string folderName; using (var outlookFolderWrapper = GenericComObjectWrapper.Create((Folder)_outlookSession.GetFolderFromID(options.OutlookFolderEntryId, options.OutlookFolderStoreId))) { defaultItemType = outlookFolderWrapper.Inner.DefaultItemType; folderName = outlookFolderWrapper.Inner.Name; } IOutlookSynchronizer synchronizer; switch (defaultItemType) { case OlItemType.olAppointmentItem: synchronizer = await CreateEventSynchronizer(options, generalOptions, synchronizerComponents); break; case OlItemType.olTaskItem: if (options.ServerAdapterType == ServerAdapterType.GoogleTaskApi) { synchronizer = await CreateGoogleTaskSynchronizer(options); } else { synchronizer = CreateTaskSynchronizer(options, generalOptions, synchronizerComponents); } break; case OlItemType.olContactItem: if (options.ServerAdapterType == ServerAdapterType.GoogleContactApi) { synchronizer = await CreateGoogleContactSynchronizer(options, synchronizerComponents); } else { synchronizer = CreateContactSynchronizer(options, generalOptions, synchronizerComponents); } break; default: throw new NotSupportedException( string.Format( "The folder '{0}' contains an item type ('{1}'), whis is not supported for synchronization", folderName, defaultItemType)); } return(Tuple.Create(synchronizer, synchronizerComponents)); }
private void MapRecurrance1To2(TaskItem source, ITodo target, iCalTimeZone localIcalTimeZone) { if (source.IsRecurring) { using (var sourceRecurrencePatternWrapper = GenericComObjectWrapper.Create(source.GetRecurrencePattern())) { var sourceRecurrencePattern = sourceRecurrencePatternWrapper.Inner; IRecurrencePattern targetRecurrencePattern = new RecurrencePattern(); if (!sourceRecurrencePattern.NoEndDate) { targetRecurrencePattern.Count = sourceRecurrencePattern.Occurrences; //Until must not be set if count is set, since outlook always sets Occurrences //but sogo wants it as utc end time of the last event not only the enddate at 0000 //targetRecurrencePattern.Until = sourceRecurrencePattern.PatternEndDate.Add(sourceRecurrencePattern.EndTime.TimeOfDay).ToUniversalTime(); } targetRecurrencePattern.Interval = (sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly || sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval / 12 : sourceRecurrencePattern.Interval; switch (sourceRecurrencePattern.RecurrenceType) { case OlRecurrenceType.olRecursDaily: targetRecurrencePattern.Frequency = FrequencyType.Daily; break; case OlRecurrenceType.olRecursWeekly: targetRecurrencePattern.Frequency = FrequencyType.Weekly; CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); break; case OlRecurrenceType.olRecursMonthly: targetRecurrencePattern.Frequency = FrequencyType.Monthly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); break; case OlRecurrenceType.olRecursMonthNth: targetRecurrencePattern.Frequency = FrequencyType.Monthly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } break; case OlRecurrenceType.olRecursYearly: targetRecurrencePattern.Frequency = FrequencyType.Yearly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; case OlRecurrenceType.olRecursYearNth: targetRecurrencePattern.Frequency = FrequencyType.Yearly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; } target.RecurrenceRules.Add(targetRecurrencePattern); } } }
private void MapRecurrance1To2(TaskItem source, ITodo target, iCalTimeZone localIcalTimeZone) { if (source.IsRecurring) { using (var sourceRecurrencePatternWrapper = GenericComObjectWrapper.Create(source.GetRecurrencePattern())) { var sourceRecurrencePattern = sourceRecurrencePatternWrapper.Inner; // Recurring task must have a DTSTART according to the RFC but Outlook may have no task start date set, use PatternStartDate in this case if (source.StartDate == OutlookUtility.OUTLOOK_DATE_NONE) { target.Start = new iCalDateTime(sourceRecurrencePattern.PatternStartDate.Year, sourceRecurrencePattern.PatternStartDate.Month, sourceRecurrencePattern.PatternStartDate.Day, true); if (!_configuration.MapStartAndDueAsFloating) { target.Start.SetTimeZone(localIcalTimeZone); } } IRecurrencePattern targetRecurrencePattern = new RecurrencePattern(); // Don't set Count if pattern has NoEndDate or invalid Occurences for some reason. if (!sourceRecurrencePattern.NoEndDate && sourceRecurrencePattern.Occurrences > 0) { targetRecurrencePattern.Count = sourceRecurrencePattern.Occurrences; //Until must not be set if count is set, since outlook always sets Occurrences //but sogo wants it as utc end time of the last event not only the enddate at 0000 //targetRecurrencePattern.Until = sourceRecurrencePattern.PatternEndDate.Add(sourceRecurrencePattern.EndTime.TimeOfDay).ToUniversalTime(); } targetRecurrencePattern.Interval = (sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearly || sourceRecurrencePattern.RecurrenceType == OlRecurrenceType.olRecursYearNth) ? sourceRecurrencePattern.Interval / 12 : sourceRecurrencePattern.Interval; switch (sourceRecurrencePattern.RecurrenceType) { case OlRecurrenceType.olRecursDaily: targetRecurrencePattern.Frequency = FrequencyType.Daily; break; case OlRecurrenceType.olRecursWeekly: targetRecurrencePattern.Frequency = FrequencyType.Weekly; CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); break; case OlRecurrenceType.olRecursMonthly: targetRecurrencePattern.Frequency = FrequencyType.Monthly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); break; case OlRecurrenceType.olRecursMonthNth: targetRecurrencePattern.Frequency = FrequencyType.Monthly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } break; case OlRecurrenceType.olRecursYearly: targetRecurrencePattern.Frequency = FrequencyType.Yearly; targetRecurrencePattern.ByMonthDay.Add(sourceRecurrencePattern.DayOfMonth); targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; case OlRecurrenceType.olRecursYearNth: targetRecurrencePattern.Frequency = FrequencyType.Yearly; if (sourceRecurrencePattern.Instance == 5) { targetRecurrencePattern.BySetPosition.Add(-1); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else if (sourceRecurrencePattern.Instance > 0) { targetRecurrencePattern.BySetPosition.Add(sourceRecurrencePattern.Instance); CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } else { CommonEntityMapper.MapDayOfWeek1To2(sourceRecurrencePattern.DayOfWeekMask, targetRecurrencePattern.ByDay); } targetRecurrencePattern.ByMonth.Add(sourceRecurrencePattern.MonthOfYear); break; } target.RecurrenceRules.Add(targetRecurrencePattern); } } }
private GenericComObjectWrapper <Folder> CreateFolderWrapper() { return(GenericComObjectWrapper.Create((Folder)_mapiNameSpace.GetFolderFromID(_folderId, _folderStoreId))); }
List <AppointmentSlim> IQueryOutlookAppointmentItemFolderStrategy.QueryAppointmentFolder(IOutlookSession session, Folder calendarFolder, string filter, IGetVersionsLogger logger) { var events = new List <AppointmentSlim>(); using (var tableWrapper = GenericComObjectWrapper.Create( calendarFolder.GetTable(filter))) { var table = tableWrapper.Inner; table.Columns.RemoveAll(); table.Columns.Add(PR_GLOBAL_OBJECT_ID); table.Columns.Add(PR_LONG_TERM_ENTRYID_FROM_TABLE); table.Columns.Add(PR_ENTRYID); table.Columns.Add(LastModificationTimeColumnId); table.Columns.Add(SubjectColumnId); table.Columns.Add(StartColumnId); table.Columns.Add(EndColumnId); while (!table.EndOfTable) { var row = table.GetNextRow(); string entryId; byte[] entryIdArray = row[PR_LONG_TERM_ENTRYID_FROM_TABLE] as byte[]; if (entryIdArray != null && entryIdArray.Length > 0) { entryId = row.BinaryToString(PR_LONG_TERM_ENTRYID_FROM_TABLE); } else { // Fall back to short-term ENTRYID if long-term ID not available entryId = row.BinaryToString(PR_ENTRYID); s_logger.Warn($"Could not access long-term ENTRYID of appointment '{entryId}', use short-term ENTRYID as fallback."); } string globalAppointmentId = null; try { byte[] globalIdArray = row[PR_GLOBAL_OBJECT_ID] as byte[]; if (globalIdArray != null && globalIdArray.Length > 0) { globalAppointmentId = row.BinaryToString(PR_GLOBAL_OBJECT_ID); } } catch (Exception ex) { s_logger.Warn($"Could not access GlobalAppointmentID of appointment '{entryId}'.", ex); } var subject = (string)row[SubjectColumnId]; var appointmentId = new AppointmentId(entryId, globalAppointmentId); var lastModificationTimeObject = row[LastModificationTimeColumnId]; DateTime lastModificationTime; if (lastModificationTimeObject != null) { lastModificationTime = ((DateTime)lastModificationTimeObject).ToUniversalTime(); } else { s_logger.Warn($"Column '{nameof(LastModificationTimeColumnId)}' of event '{entryId}' is NULL."); logger.LogWarning(entryId, $"Column '{nameof(LastModificationTimeColumnId)}' is NULL."); lastModificationTime = OutlookUtility.OUTLOOK_DATE_NONE; } var startObject = row[StartColumnId]; DateTime?start; if (startObject != null) { start = (DateTime)startObject; } else { s_logger.Warn($"Column '{nameof(StartColumnId)}' of event '{entryId}' is NULL."); logger.LogWarning(entryId, $"Column '{nameof(StartColumnId)}' is NULL."); start = null; } var endObject = row[EndColumnId]; DateTime?end; if (endObject != null) { end = (DateTime)endObject; } else { s_logger.Warn($"Column '{nameof(EndColumnId)}' of event '{entryId}' is NULL."); logger.LogWarning(entryId, $"Column '{nameof(EndColumnId)}' is NULL."); end = null; } events.Add(new AppointmentSlim(EntityVersion.Create(appointmentId, lastModificationTime.ToUniversalTime()), start, end, subject)); } } return(events); }
public Task <GenericComObjectWrapper <DistListItem> > Map2To1(DistributionList source, GenericComObjectWrapper <DistListItem> target, IEntityMappingLogger logger, DistributionListSychronizationContext context) { var outlookMembersByAddress = new Dictionary <string, GenericComObjectWrapper <Recipient> >(StringComparer.InvariantCultureIgnoreCase); target.Inner.DLName = source.Name; if (!string.IsNullOrEmpty(source.Description)) { target.Inner.Body = source.Description; } try { using (var userPropertiesWrapper = GenericComObjectWrapper.Create(target.Inner.UserProperties)) { using (var userProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Find("NICKNAME"))) { if (userProperty.Inner != null) { userProperty.Inner.Value = source.Nickname; } else if (!string.IsNullOrEmpty(source.Nickname)) { using (var newUserProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Add("NICKNAME", OlUserPropertyType.olText, true))) { newUserProperty.Inner.Value = source.Nickname; } } } } } catch (COMException ex) { s_logger.Warn("Can't access UserProperty of Distribution List!", ex); logger.LogMappingWarning("Can't access UserProperty of Distribution List!", ex); } try { for (int i = 1; i <= target.Inner.MemberCount; i++) { var recipientWrapper = GenericComObjectWrapper.Create(target.Inner.GetMember(i)); if (!string.IsNullOrEmpty(recipientWrapper.Inner?.Address) && !outlookMembersByAddress.ContainsKey(recipientWrapper.Inner.Address)) { outlookMembersByAddress.Add(recipientWrapper.Inner.Address, recipientWrapper); } else { recipientWrapper.Dispose(); } } foreach (var sourceMember in source.Members.Concat(source.NonAddressBookMembers)) { GenericComObjectWrapper <Recipient> existingRecipient; if (!string.IsNullOrEmpty(sourceMember.EmailAddress) && outlookMembersByAddress.TryGetValue(sourceMember.EmailAddress, out existingRecipient)) { outlookMembersByAddress.Remove(sourceMember.EmailAddress); existingRecipient.Dispose(); } else { string recipientString = sourceMember.DisplayName ?? sourceMember.EmailAddress; if (!string.IsNullOrEmpty(recipientString)) { using (var recipientWrapper = GenericComObjectWrapper.Create(context.OutlookSession.CreateRecipient(recipientString))) { recipientWrapper.Inner.Resolve(); target.Inner.AddMember(recipientWrapper.Inner); } } } } foreach (var existingRecipient in outlookMembersByAddress.ToArray()) { target.Inner.RemoveMember(existingRecipient.Value.Inner); outlookMembersByAddress.Remove(existingRecipient.Key); } } catch (COMException ex) { s_logger.Warn("Can't access member of Distribution List!", ex); logger.LogMappingWarning("Can't access member of Distribution List!", ex); } finally { foreach (var existingRecipient in outlookMembersByAddress.Values) { existingRecipient.Dispose(); } } return(Task.FromResult(target)); }
public static void MapDistListMembers2To1( IEnumerable <DistributionListMember> sourceMembers, IDistListItemWrapper target, IEntitySynchronizationLogger logger, DistributionListSychronizationContext context) { var outlookMembersByAddress = new Dictionary <string, GenericComObjectWrapper <Recipient> >(StringComparer.InvariantCultureIgnoreCase); try { for (int i = 1; i <= target.Inner.MemberCount; i++) { var recipientWrapper = GenericComObjectWrapper.Create(target.Inner.GetMember(i)); if (!string.IsNullOrEmpty(recipientWrapper.Inner?.Address) && !outlookMembersByAddress.ContainsKey(recipientWrapper.Inner.Address)) { outlookMembersByAddress.Add(recipientWrapper.Inner.Address, recipientWrapper); } else { recipientWrapper.Dispose(); } } foreach (var sourceMember in sourceMembers) { GenericComObjectWrapper <Recipient> existingRecipient; if (!string.IsNullOrEmpty(sourceMember.EmailAddress) && outlookMembersByAddress.TryGetValue(sourceMember.EmailAddress, out existingRecipient)) { outlookMembersByAddress.Remove(sourceMember.EmailAddress); existingRecipient.Dispose(); } else { var recipientString = !string.IsNullOrEmpty(sourceMember.DisplayName) ? sourceMember.DisplayName : sourceMember.EmailAddress; if (!string.IsNullOrEmpty(recipientString)) { using (var recipientWrapper = GenericComObjectWrapper.Create(context.OutlookSession.CreateRecipient(recipientString))) { if (recipientWrapper.Inner.Resolve()) { target.Inner.AddMember(recipientWrapper.Inner); } else { // Add a member which is not in the Addressbook var builder = new StringBuilder(); if (!string.IsNullOrEmpty(sourceMember.DisplayName)) { builder.Append(sourceMember.DisplayName); builder.Append(" <"); builder.Append(sourceMember.EmailAddress); builder.Append(">"); } else { builder.Append(sourceMember.EmailAddress); } using (var tempRecipientMember = GenericComObjectWrapper.Create(context.OutlookSession.CreateRecipient(builder.ToString()))) { tempRecipientMember.Inner.Resolve(); target.Inner.AddMember(tempRecipientMember.Inner); } } } } } } foreach (var existingRecipient in outlookMembersByAddress.ToArray()) { target.Inner.RemoveMember(existingRecipient.Value.Inner); outlookMembersByAddress.Remove(existingRecipient.Key); } } catch (COMException ex) { s_logger.Warn("Can't access member of Distribution List!", ex); logger.LogWarning("Can't access member of Distribution List!", ex); } finally { foreach (var existingRecipient in outlookMembersByAddress.Values) { existingRecipient.Dispose(); } } }
public static void MapCustomProperties2To1(ICalendarPropertyList sourceList, GenericComObjectWrapper <UserProperties> userPropertiesWrapper, bool mapAllCustomProperties, PropertyMapping[] mappings, IEntitySynchronizationLogger logger, ILog s_logger) { var alreadyMappedOutlookProperties = new HashSet <string>(); foreach (var mapping in mappings) { var prop = sourceList.FirstOrDefault(p => p.Name == mapping.DavProperty); if (prop != null) { try { alreadyMappedOutlookProperties.Add(mapping.OutlookProperty); using (var userProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Find(mapping.OutlookProperty))) { if (userProperty.Inner != null) { userProperty.Inner.Value = prop.Value; } else { using (var newUserProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Add(mapping.OutlookProperty, OlUserPropertyType.olText, true))) { newUserProperty.Inner.Value = prop.Value; } } } } catch (COMException ex) { s_logger.Warn("Can't set UserProperty of Item!", ex); logger.LogWarning("Can't set UserProperty of Item!", ex); } } } if (mapAllCustomProperties) { foreach (var prop in sourceList.Where(p => p.Name.StartsWith("X-CALDAVSYNCHRONIZER-"))) { var outlookProperty = prop.Name.Replace("X-CALDAVSYNCHRONIZER-", ""); if (!alreadyMappedOutlookProperties.Contains(outlookProperty)) { try { using (var userProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Find(outlookProperty))) { if (userProperty.Inner != null) { userProperty.Inner.Value = prop.Value; } else { using (var newUserProperty = GenericComObjectWrapper.Create(userPropertiesWrapper.Inner.Add(outlookProperty, OlUserPropertyType.olText, true))) { newUserProperty.Inner.Value = prop.Value; } } } } catch (COMException ex) { s_logger.Warn("Can't set UserProperty of Item!", ex); logger.LogWarning("Can't set UserProperty of Item!", ex); } } } } }
private static GenericComObjectWrapper <Folder> CreateFolderWrapper() { return(GenericComObjectWrapper.Create((Folder)s_mapiNameSpace.GetFolderFromID(s_outlookFolderEntryId, s_outlookFolderStoreId))); }
private GenericComObjectWrapper <Folder> CreateFolderWrapper() { return(GenericComObjectWrapper.Create((Folder)_session.GetFolderFromId(_folderId, _folderStoreId))); }
public ITaskItemWrapper Map2To1(ITodo source, ITaskItemWrapper target, IEntitySynchronizationLogger logger) { target.Inner.Subject = source.Summary; target.Inner.Body = _configuration.MapBody ? source.Description : string.Empty; DateTimeZone localZone = DateTimeZoneProviders.Bcl.GetSystemDefault(); if (source.Start != null) { if (source.Start.IsUniversalTime) { target.Inner.StartDate = Instant.FromDateTimeUtc(source.Start.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.StartDate = source.Start.Date; } } else { target.Inner.StartDate = OutlookUtility.OUTLOOK_DATE_NONE; } if (source.Due != null) { if (source.Start == null || source.Start.Value <= source.Due.Value) { if (source.Due.IsUniversalTime) { target.Inner.DueDate = Instant.FromDateTimeUtc(source.Due.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.DueDate = source.Due.Date; } } } else { target.Inner.DueDate = OutlookUtility.OUTLOOK_DATE_NONE; } if (source.Completed != null) { if (source.Completed.IsUniversalTime) { target.Inner.DateCompleted = Instant.FromDateTimeUtc(source.Completed.Value).InZone(localZone).ToDateTimeUnspecified().Date; } else { target.Inner.DateCompleted = source.Completed.Date; } target.Inner.Complete = true; } else { target.Inner.Complete = false; } target.Inner.Status = (target.Inner.Complete && target.Inner.PercentComplete == 100) ? OlTaskStatus.olTaskComplete : MapStatus2To1(source.Status); // Only set PercentComplete if source is actually set and status is not already completed to avoid overwriting the status again if (source.PercentComplete != 0 && target.Inner.Status != OlTaskStatus.olTaskComplete) { target.Inner.PercentComplete = source.PercentComplete; } if (_configuration.MapPriority) { target.Inner.Importance = CommonEntityMapper.MapPriority2To1(source.Priority); } target.Inner.Sensitivity = CommonEntityMapper.MapPrivacy2To1(source.Class, false, false); MapCategories2To1(source, target); MapReminder2To1(source, target, logger); if (_configuration.MapCustomProperties || _configuration.UserDefinedCustomPropertyMappings.Length > 0) { using (var userPropertiesWrapper = GenericComObjectWrapper.Create(target.Inner.UserProperties)) { CommonEntityMapper.MapCustomProperties2To1(source.Properties, userPropertiesWrapper, _configuration.MapCustomProperties, _configuration.UserDefinedCustomPropertyMappings, logger, s_logger); } } if (_configuration.MapRecurringTasks) { MapRecurrance2To1(source, target, logger); } return(target); }
public static string GetEmailAdressOrNull(AddressEntry addressEntry, IEntityMappingLogger logger, ILog generalLogger) { OlAddressEntryUserType type; if (addressEntry != null) { try { type = addressEntry.AddressEntryUserType; } catch (COMException ex) { generalLogger.Warn("Could not get type from AddressEntry", ex); logger.LogMappingWarning("Could not get type from AddressEntry", ex); return(null); } if (type == OlAddressEntryUserType.olExchangeUserAddressEntry || type == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry || type == OlAddressEntryUserType.olExchangeAgentAddressEntry || type == OlAddressEntryUserType.olExchangeOrganizationAddressEntry || type == OlAddressEntryUserType.olExchangePublicFolderAddressEntry) { try { using (var exchUser = GenericComObjectWrapper.Create(addressEntry.GetExchangeUser())) { if (exchUser.Inner != null) { return(exchUser.Inner.PrimarySmtpAddress); } } } catch (COMException ex) { generalLogger.Warn("Could not get email address from adressEntry.GetExchangeUser()", ex); logger.LogMappingWarning("Could not get email address from adressEntry.GetExchangeUser()", ex); } } else if (type == OlAddressEntryUserType.olExchangeDistributionListAddressEntry || type == OlAddressEntryUserType.olOutlookDistributionListAddressEntry) { try { using (var exchDL = GenericComObjectWrapper.Create(addressEntry.GetExchangeDistributionList())) { if (exchDL.Inner != null) { return(exchDL.Inner.PrimarySmtpAddress); } } } catch (COMException ex) { generalLogger.Warn("Could not get email address from adressEntry.GetExchangeDistributionList()", ex); logger.LogMappingWarning("Could not get email address from adressEntry.GetExchangeDistributionList()", ex); } } else if (type == OlAddressEntryUserType.olSmtpAddressEntry || type == OlAddressEntryUserType.olLdapAddressEntry) { return(addressEntry.Address); } else if (type == OlAddressEntryUserType.olOutlookContactAddressEntry) { if (addressEntry.Type == "EX") { try { using (var exchContact = GenericComObjectWrapper.Create(addressEntry.GetContact())) { if (exchContact.Inner != null) { if (exchContact.Inner.Email1AddressType == "EX") { return(exchContact.Inner.GetPropertySafe(PR_EMAIL1ADDRESS)); } else { return(exchContact.Inner.Email1Address); } } } } catch (COMException ex) { generalLogger.Warn("Could not get email address from adressEntry.GetContact()", ex); logger.LogMappingWarning("Could not get email address from adressEntry.GetContact()", ex); } } else { return(addressEntry.Address); } } else { try { return(addressEntry.GetPropertySafe(PR_SMTP_ADDRESS)); } catch (COMException ex) { generalLogger.Warn("Could not get property PR_SMTP_ADDRESS for adressEntry", ex); logger.LogMappingWarning("Could not get property PR_SMTP_ADDRESS for adressEntry", ex); } } } return(null); }
public void Map1To2(ITaskItemWrapper source, ITodo target, iCalTimeZone localIcalTimeZone, IEntitySynchronizationLogger logger) { target.Summary = CalendarDataPreprocessor.EscapeBackslash(source.Inner.Subject); if (_configuration.MapBody) { target.Description = CalendarDataPreprocessor.EscapeBackslash(source.Inner.Body); } if (source.Inner.StartDate != OutlookUtility.OUTLOOK_DATE_NONE) { target.Start = new iCalDateTime(source.Inner.StartDate.Year, source.Inner.StartDate.Month, source.Inner.StartDate.Day, true); if (!_configuration.MapStartAndDueAsFloating) { target.Start.SetTimeZone(localIcalTimeZone); } } if (source.Inner.Complete && source.Inner.DateCompleted != OutlookUtility.OUTLOOK_DATE_NONE) { target.Completed = new iCalDateTime(source.Inner.DateCompleted.ToUniversalTime()) { IsUniversalTime = true, HasTime = true }; } target.PercentComplete = source.Inner.PercentComplete; if (_configuration.MapRecurringTasks) { MapRecurrance1To2(source.Inner, target, localIcalTimeZone); } if (source.Inner.DueDate != OutlookUtility.OUTLOOK_DATE_NONE) { target.Due = new iCalDateTime(source.Inner.DueDate.Year, source.Inner.DueDate.Month, source.Inner.DueDate.Day, 23, 59, 59); if (!_configuration.MapStartAndDueAsFloating) { target.Due.SetTimeZone(localIcalTimeZone); } // Workaround for a bug in DDay.iCal, according to RFC5545 DUE must not occur together with DURATION target.Properties.Remove(new CalendarProperty("DURATION")); } target.Properties.Set("STATUS", MapStatus1To2(source.Inner.Status)); if (_configuration.MapPriority) { target.Priority = CommonEntityMapper.MapPriority1To2(source.Inner.Importance); } target.Class = CommonEntityMapper.MapPrivacy1To2(source.Inner.Sensitivity, false, false); MapReminder1To2(source, target); MapCategories1To2(source, target); if (_configuration.MapCustomProperties || _configuration.UserDefinedCustomPropertyMappings.Length > 0) { using (var userPropertiesWrapper = GenericComObjectWrapper.Create(source.Inner.UserProperties)) { CommonEntityMapper.MapCustomProperties1To2(userPropertiesWrapper, target.Properties, _configuration.MapCustomProperties, _configuration.UserDefinedCustomPropertyMappings, logger, s_logger); } } }
public ComponentContainer(Application application) { s_logger.Info("Startup..."); _generalOptionsDataAccess = new GeneralOptionsDataAccess(); _synchronizationStatus = new SynchronizationStatus(); 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); _globalTimeZoneCache = new GlobalTimeZoneCache(); 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, _daslFilterProvider, _outlookAccountPasswordProvider, _globalTimeZoneCache); _synchronizationReportRepository = CreateSynchronizationReportRepository(); UpdateGeneralOptionDependencies(generalOptions); _scheduler = new Scheduler( _synchronizerFactory, this, EnsureSynchronizationContext, new FolderChangeWatcherFactory( _session), _synchronizationStatus); var options = _optionsDataAccess.LoadOptions(); EnsureCacheCompatibility(options); _profileStatusesViewModel = new ProfileStatusesViewModel(this); _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; _uiService = new UiService(_profileStatusesViewModel); using (var syncObjects = GenericComObjectWrapper.Create(_session.SyncObjects)) { if (syncObjects.Inner != null && syncObjects.Inner.Count > 0) { _syncObject = syncObjects.Inner[1]; if (generalOptions.TriggerSyncAfterSendReceive) { _syncObject.SyncEnd += _sync_SyncEnd; } } } }
public ComponentContainer(Application application) { s_logger.Info("Startup..."); if (GeneralOptionsDataAccess.WpfRenderModeSoftwareOnly) { RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly; } _generalOptionsDataAccess = new 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(); 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) )); _profileStatusesViewModel = new ProfileStatusesViewModel(this); _uiService = new UiService(_profileStatusesViewModel); _queryFolderStrategyWrapper = new OutlookFolderStrategyWrapper(QueryOutlookFolderByRequestingItemStrategy.Instance); _totalProgressFactory = new TotalProgressFactory( _uiService, generalOptions.ShowProgressBar, generalOptions.ThresholdForProgressDisplay, ExceptionHandler.Instance); _synchronizerFactory = new SynchronizerFactory( GetProfileDataDirectory, _totalProgressFactory, _session, _daslFilterProvider, _outlookAccountPasswordProvider, _globalTimeZoneCache, _queryFolderStrategyWrapper); _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(_session, _daslFilterProvider, _queryFolderStrategyWrapper); }