public bool GetSourceEntriesToDelete(CalendarSyncProfile syncProfile, CalendarAppointments sourceList, CalendarAppointments destinationList) { EvaluateAppointmentsToDelete(syncProfile, destinationList, sourceList, SourceAppointmentsToDelete, SourceAppointmentsToUpdate, DestAppointmentsToUpdate, SourceOrphanEntries); return(true); }
/// <summary> /// Gets appointments to add in the destination calendar /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceList"></param> /// <param name="destinationList"></param> /// <param name="appointmentsToAdd"></param> /// <returns> /// </returns> private void EvaluateAppointmentsToAdd(CalendarSyncProfile syncProfile, List <Appointment> sourceList, List <Appointment> destinationList, List <Appointment> appointmentsToAdd) { if (!destinationList.Any()) { appointmentsToAdd.AddRange(sourceList); //All entries need to be added return; } var checkChild = syncProfile.SyncMode == SyncModeEnum.TwoWay && syncProfile.SyncSettings.KeepLastModifiedVersion; foreach (var sourceAppointment in sourceList) { if (sourceAppointment.SourceId == null) { if (!checkChild || sourceAppointment.ChildId == null) { var destinationAppointment = destinationList.FirstOrDefault(t => t.Equals(sourceAppointment)); if (destinationAppointment == null) { appointmentsToAdd.Add(sourceAppointment); } } } } }
public string SyncNow(CalendarSyncProfile syncProfile, SyncMetric syncMetric, SyncCallback syncCallback) { try { if (syncProfile.GoogleAccount == null || syncProfile.GoogleAccount.GoogleCalendar == null || !syncProfile.ValidateOutlookSettings()) { _messageService.ShowMessageAsync( "Please configure Google and Outlook calendar in settings to continue."); return("Invalid Settings"); } ResetSyncData(); var isSyncComplete = _calendarUpdateService.SyncCalendar(syncProfile, syncMetric, syncCallback); return(isSyncComplete ? null : "Error Occurred"); } catch (AggregateException exception) { var flattenException = exception.Flatten(); _messageService.ShowMessageAsync(flattenException.Message); _applicationLogger.Error(exception); return(flattenException.Message); } catch (Exception exception) { _messageService.ShowMessageAsync(exception.Message); _applicationLogger.Error(exception); return(exception.Message); } }
public bool GetDestEntriesToDelete(CalendarSyncProfile syncProfile, AppointmentsWrapper sourceList, AppointmentsWrapper destinationList) { EvaluateAppointmentsToDelete(syncProfile, sourceList, destinationList, DestAppointmentsToDelete, DestAppointmentsToUpdate, SourceAppointmentsToUpdate, DestOrphanEntries); return true; }
public bool GetDestEntriesToDelete(CalendarSyncProfile syncProfile, AppointmentsWrapper sourceList, AppointmentsWrapper destinationList) { EvaluateAppointmentsToDelete(syncProfile, sourceList, destinationList, DestAppointmentsToDelete, DestAppointmentsToUpdate, SourceAppointmentsToUpdate, DestOrphanEntries); return(true); }
private async void CreateProfile() { if (SyncProfileList.Count > 4) { MessageService.ShowMessageAsync("You have reached the maximum number of profiles."); return; } var result = await MessageService.ShowInput("Please enter profile name."); if (!string.IsNullOrEmpty(result)) { if (SyncProfileList.Any(t => !string.IsNullOrEmpty(t.Name) && t.Name.Equals(result))) { MessageService.ShowMessageAsync( string.Format("A Profile with name '{0}' already exists. Please try again.", result)); return; } var syncProfile = CalendarSyncProfile.GetDefaultSyncProfile(); syncProfile.Name = result; syncProfile.IsDefault = false; var viewModel = new ProfileViewModel(syncProfile, GoogleCalendarService, OutlookCalendarService, MessageService, ExchangeWebCalendarService, ApplicationLogger, AccountAuthenticationService); PropertyChangedEventManager.AddHandler(viewModel, ProfilePropertyChangedHandler, "IsLoading"); viewModel.Initialize(null); SyncProfileList.Add(viewModel); } }
private void StartCalendarSyncTask(CalendarSyncProfile syncProfile) { lock (LockerObject) { if (IsSettingsLoading) { MessageService.ShowMessageAsync("Unable to do the operation as settings are loading."); return; } IsSyncInProgress = true; IsSettingsVisible = false; syncProfile.LastSync = DateTime.Now; ShowNotification(true); UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.SyncStarted, syncProfile.LastSync)); UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.Line)); UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.Profile, syncProfile.Name)); UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.Line)); var syncMetric = new SyncMetric { StartTime = syncProfile.LastSync.GetValueOrDefault(), ProfileName = syncProfile.Name, CalendarSyncDirection = syncProfile.SyncDirection.ToString() }; SyncSummary.SyncMetrics.Add(syncMetric); var result = SyncStartService.SyncNow(syncProfile, syncMetric, SyncCallback); OnSyncCompleted(syncProfile, syncMetric, result); } }
/// <summary> /// </summary> /// <param name="syncProfile"></param> /// <param name="syncMetric"></param> /// <param name="sourceCalendarSpecificData"></param> /// <param name="destinationCalendarSpecificData"></param> /// <returns></returns> private bool UpdateEntries(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary <string, object> sourceCalendarSpecificData, IDictionary <string, object> destinationCalendarSpecificData) { var isSuccess = true; if (CalendarSyncEngine.SourceAppointmentsToUpdate.Any()) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); //Update status for reading entries to update CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToUpdate, CalendarSyncEngine.SourceAppointmentsToUpdate.Count, SourceCalendarService.CalendarServiceName); var updatedAppointments = SourceCalendarService.UpdateCalendarEvents(CalendarSyncEngine.SourceAppointmentsToUpdate, syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription), sourceCalendarSpecificData).Result; isSuccess = updatedAppointments.IsSuccess; CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.UpdateEntriesSuccess : SyncStateEnum.UpdateEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); syncMetric.SourceMetric.UpdateCount = CalendarSyncEngine.SourceAppointmentsToUpdate.Count; syncMetric.SourceMetric.UpdateFailedCount = CalendarSyncEngine.SourceAppointmentsToUpdate.Count - updatedAppointments.Count; } if (CalendarSyncEngine.DestAppointmentsToUpdate.Any()) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); //Update status for reading entries to update CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToUpdate, CalendarSyncEngine.DestAppointmentsToUpdate.Count, DestinationCalendarService.CalendarServiceName); var updatedAppointments = DestinationCalendarService.UpdateCalendarEvents(CalendarSyncEngine.DestAppointmentsToUpdate, syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription), destinationCalendarSpecificData).Result; isSuccess = updatedAppointments.IsSuccess; CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.UpdateEntriesSuccess : SyncStateEnum.UpdateEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); syncMetric.DestMetric.UpdateCount = CalendarSyncEngine.DestAppointmentsToUpdate.Count; syncMetric.DestMetric.UpdateFailedCount = CalendarSyncEngine.DestAppointmentsToUpdate.Count - updatedAppointments.Count; } return(isSuccess); }
private void UploadAnalyticsData(CalendarSyncProfile syncProfile, bool isSuccess) { var syncMetric = new SyncMetric { IsSuccess = isSuccess }; //AnalyticsService.UploadSyncData(syncMetric, syncProfile.GoogleAccount.Name); }
public ProfileViewModel(CalendarSyncProfile syncProfile, IGoogleCalendarService googleCalendarService, IOutlookCalendarService outlookCalendarService, IMessageService messageService, IExchangeWebCalendarService exchangeWebCalendarService, ApplicationLogger applicationLogger, IAccountAuthenticationService accountAuthenticationService) { SyncProfile = syncProfile; ExchangeWebCalendarService = exchangeWebCalendarService; ApplicationLogger = applicationLogger.GetLogger(GetType()); AccountAuthenticationService = accountAuthenticationService; GoogleCalendarService = googleCalendarService; OutlookCalendarService = outlookCalendarService; MessageService = messageService; }
private IDictionary <string, object> GetCalendarSpecificData(ServiceType serviceType, CalendarSyncProfile syncProfile) { IDictionary <string, object> calendarSpecificData = null; switch (serviceType) { case ServiceType.Google: calendarSpecificData = new Dictionary <string, object> { { "CalendarId", syncProfile.GoogleSettings.GoogleCalendar.Id }, { "AccountName", syncProfile.GoogleSettings.GoogleAccount.Name } }; break; case ServiceType.OutlookDesktop: calendarSpecificData = new Dictionary <string, object> { { "ProfileName", !syncProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultProfile) ? syncProfile.OutlookSettings.OutlookProfileName : null }, { "OutlookCalendar", !syncProfile.OutlookSettings.OutlookOptions.HasFlag( OutlookOptionsEnum.DefaultMailBoxCalendar) ? syncProfile.OutlookSettings.OutlookFolder : null }, { "AddAsAppointments", syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AsAppointments) }, { "SetOrganizer", syncProfile.OutlookSettings.SetOrganizer } }; break; case ServiceType.EWS: return(null); } if (calendarSpecificData != null && syncProfile.SetCalendarCategory) { calendarSpecificData.Add("EventCategory", syncProfile.EventCategory); } return(calendarSpecificData); }
/// <summary> /// Delete appointments from source /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceCalendarSpecificData"></param> /// <param name="syncCallback"></param> /// <returns> /// </returns> private bool DeleteSourceAppointments(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary <string, object> sourceCalendarSpecificData, SyncCallback syncCallback) { if (syncProfile.SyncSettings.DisableDelete) { return(true); } //Updating entry isDeleteOperation status SyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); SyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToDelete, SourceCalendarService.CalendarServiceName); //Getting appointments to isDeleteOperation CalendarSyncEngine.GetSourceEntriesToDelete(syncProfile, SourceAppointments, DestinationAppointments); var appointmentsToDelete = CalendarSyncEngine.SourceAppointmentsToDelete; //Updating Get entry isDeleteOperation status SyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToDelete, appointmentsToDelete.Count); if (appointmentsToDelete.Count == 0) { SyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return(true); } //Updating isDeleteOperation status SyncStatus = StatusHelper.GetMessage(SyncStateEnum.DeletingEntries, SourceCalendarService.CalendarServiceName); //Deleting entries var deletedAppointments = SourceCalendarService.DeleteCalendarEvents(appointmentsToDelete, sourceCalendarSpecificData).Result; var isSuccess = deletedAppointments.IsSuccess; //Update status if entries were successfully deleted SyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.DeletingEntriesComplete : SyncStateEnum.DeletingEntriesFailed); SyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.SourceMetric.DeleteCount = appointmentsToDelete.Count; syncMetric.SourceMetric.DeleteFailedCount = appointmentsToDelete.Count - deletedAppointments.Count; for (var index = 0; index < appointmentsToDelete.Count; index++) { SourceAppointments.Remove(appointmentsToDelete[index]); } } return(isSuccess); }
private void GetDateRange(CalendarSyncProfile syncProfile, out DateTime startDate, out DateTime endDate) { startDate = syncProfile.SyncSettings.StartDate.Date; endDate = syncProfile.SyncSettings.EndDate.Date; if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncRangeInDays) { startDate = DateTime.Today.AddDays(-syncProfile.SyncSettings.DaysInPast); endDate = DateTime.Today.AddDays(syncProfile.SyncSettings.DaysInFuture + 1); } else if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncEntireCalendar) { startDate = DateTime.Parse("1990/01/01 12:00:00 AM"); endDate = DateTime.Today.AddYears(10); } }
/// <summary> /// Add appointments to source /// </summary> /// <param name="syncProfile"></param> /// <param name="syncMetric"></param> /// <param name="sourceCalendarSpecificData"></param> /// <returns> /// </returns> private bool AddSourceAppointments(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary <string, object> sourceCalendarSpecificData) { //Update status for reading entries to add CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToAdd, SourceCalendarService.CalendarServiceName); //Get entries to add CalendarSyncEngine.GetSourceEntriesToAdd(syncProfile, SourceAppointments, DestinationAppointments); var appointmentsToAdd = CalendarSyncEngine.SourceAppointmentsToAdd; CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToAdd, appointmentsToAdd.Count); if (appointmentsToAdd.Count == 0) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return(true); } CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.AddingEntries, SourceCalendarService.CalendarServiceName); //Add entries to calendar var addedAppointments = SourceCalendarService.AddCalendarEvents(appointmentsToAdd, syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription), sourceCalendarSpecificData) .Result; var isSuccess = addedAppointments.IsSuccess; //Update status if entries were successfully added CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.AddEntriesComplete : SyncStateEnum.AddEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.SourceMetric.AddCount = appointmentsToAdd.Count; LoadSourceId(addedAppointments, DestinationAppointments.CalendarId); SourceAppointments.AddRange(addedAppointments); if (syncProfile.SyncMode == SyncModeEnum.TwoWay) { var updateDestList = UpdateWithChildId(addedAppointments, DestinationAppointments); CalendarSyncEngine.DestAppointmentsToUpdate.AddRangeCompareForUpdate(updateDestList); } } return(isSuccess); }
private string GetCalendarName(CalendarSyncProfile syncProfile, CalendarServiceType calendarServiceType) { switch (calendarServiceType) { case CalendarServiceType.Google: return(string.Format("{0} - {1}", syncProfile.GoogleAccount.Name, syncProfile.GoogleAccount.GoogleCalendar.Name)); case CalendarServiceType.OutlookDesktop: return(syncProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultCalendar) ? "Default Calendar" : string.Format("{0} - {1}", syncProfile.OutlookSettings.OutlookMailBox.Name, syncProfile.OutlookSettings.OutlookCalendar.Name)); } return(string.Empty); }
public static bool ValidateOutlookSettings(this CalendarSyncProfile syncProfile) { if (!syncProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultProfile) && string.IsNullOrEmpty(syncProfile.OutlookSettings.OutlookProfileName)) { return(false); } if (!syncProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultCalendar) && (syncProfile.OutlookSettings.OutlookCalendar == null || syncProfile.OutlookSettings.OutlookMailBox == null)) { return(false); } return(true); }
private GoogleAccount GetGoogleAccount(CalendarSyncProfile syncProfile) { GoogleAccount googleAccount = null; if (syncProfile.GoogleAccount != null) { if (GoogleAccounts.Any()) { googleAccount = GoogleAccounts.FirstOrDefault( account => account.Name == syncProfile.GoogleAccount.Name); } } if (googleAccount != null) { googleAccount.GoogleCalendar = syncProfile.GoogleAccount.GoogleCalendar; } return(googleAccount); }
/// <summary> /// Gets appointments to add in the destination calendar /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceList"></param> /// <param name="destinationList"></param> /// <param name="appointmentsToAdd"></param> /// <returns> /// </returns> private void EvaluateAppointmentsToAdd(CalendarSyncProfile syncProfile, List <Appointment> sourceList, List <Appointment> destinationList, List <Appointment> appointmentsToAdd) { if (!destinationList.Any()) { appointmentsToAdd.AddRange(sourceList); //All entries need to be added return; } if (syncProfile.SyncSettings.SyncMode == SyncModeEnum.TwoWay && syncProfile.SyncSettings.KeepLastModifiedVersion) { foreach (var sourceAppointment in sourceList) { //Allow adding appointments which are original entries & do not have a child in this calendar if (sourceAppointment.SourceId == null && sourceAppointment.ChildId == null) { var destinationAppointment = destinationList.FirstOrDefault(t => t.Equals(sourceAppointment)); if (destinationAppointment == null) { appointmentsToAdd.Add(sourceAppointment); } } } } else { foreach (var sourceAppointment in sourceList) { if (sourceAppointment.SourceId == null) { var destinationAppointment = destinationList.FirstOrDefault(t => t.Equals(sourceAppointment)); if (destinationAppointment == null) { appointmentsToAdd.Add(sourceAppointment); } } } } }
/// <summary> /// /// </summary> private async void CreateProfile(object parameter) { if (parameter == null) { return; } if (parameter.ToString().Equals("Calendars")) { await AddNewProfile(CalendarSyncProfiles, CalendarSyncProfile.GetDefaultSyncProfile()); } else if (parameter.ToString().Equals("Tasks")) { await AddNewProfile(TaskSyncProfiles, TaskSyncProfile.GetDefaultSyncProfile()); } else if (parameter.ToString().Equals("Contacts")) { await AddNewProfile(ContactsSyncProfiles, ContactSyncProfile.GetDefaultSyncProfile()); } }
private void ValidateSettings(Settings result) { if (result.SyncProfiles == null) { result.SyncProfiles = new ObservableCollection <CalendarSyncProfile>(); } if (result.SyncProfiles.Count == 0) { result.SyncProfiles.Add(CalendarSyncProfile.GetDefaultSyncProfile()); } foreach (var syncProfile in result.SyncProfiles) { syncProfile.SetCalendarTypes(); if (syncProfile.SyncSettings == null || syncProfile.SyncSettings.SyncFrequency == null) { syncProfile.SyncSettings = SyncSettings.GetDefault(); } else if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncEntireCalendar) { syncProfile.SyncSettings.SyncRangeType = SyncRangeTypeEnum.SyncRangeInDays; syncProfile.SyncSettings.DaysInPast = 120; syncProfile.SyncSettings.DaysInFuture = 120; } } if (result.AppSettings == null) { result.AppSettings = new AppSettings(); } if (result.AppSettings.ProxySettings == null) { result.AppSettings.ProxySettings = new ProxySetting { ProxyType = ProxyType.Auto }; } }
public static void UpdateEntryOptions(this CalendarSyncProfile syncProfile, bool addDescription, bool addReminders, bool addAttendees, bool addAttendeesToDescription, bool addAttachments, bool asAppointments) { syncProfile.CalendarEntryOptions = CalendarEntryOptionsEnum.None; if (addDescription) { syncProfile.CalendarEntryOptions = syncProfile.CalendarEntryOptions | CalendarEntryOptionsEnum.Description; } if (addReminders) { syncProfile.CalendarEntryOptions = syncProfile.CalendarEntryOptions | CalendarEntryOptionsEnum.Reminders; } if (addAttendees) { syncProfile.CalendarEntryOptions = syncProfile.CalendarEntryOptions | CalendarEntryOptionsEnum.Attendees; if (addAttendeesToDescription) { syncProfile.CalendarEntryOptions = syncProfile.CalendarEntryOptions | CalendarEntryOptionsEnum.AttendeesToDescription; } } if (addAttachments) { syncProfile.CalendarEntryOptions = syncProfile.CalendarEntryOptions | CalendarEntryOptionsEnum.Attachments; } if (asAppointments) { syncProfile.CalendarEntryOptions = syncProfile.CalendarEntryOptions | CalendarEntryOptionsEnum.AsAppointments; } }
private void OnSyncCompleted(CalendarSyncProfile syncProfile, SyncMetric syncMetric, string result) { if (string.IsNullOrEmpty(result)) { UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.SyncSuccess, DateTime.Now)); } else { UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.SyncFailed, result)); } int totalSeconds = (int)DateTime.Now.Subtract(syncProfile.LastSync.GetValueOrDefault()).TotalSeconds; UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.Line)); UpdateStatus(string.Format("Time Elapsed : {0} s", totalSeconds)); UpdateStatus(StatusHelper.GetMessage(SyncStateEnum.LogSeparator)); syncMetric.ElapsedSeconds = totalSeconds; ShowNotification(false); syncProfile.NextSync = syncProfile.SyncSettings.SyncFrequency.GetNextSyncTime( DateTime.Now); IsSyncInProgress = false; CheckForUpdates(); }
private void GetDateRange(CalendarSyncProfile syncProfile, out DateTime startDate, out DateTime endDate) { startDate = syncProfile.SyncSettings.StartDate.Date; endDate = syncProfile.SyncSettings.EndDate.Date; if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncRangeInDays) { startDate = DateTime.Today.AddDays((-syncProfile.SyncSettings.DaysInPast)); endDate = DateTime.Today.AddDays((syncProfile.SyncSettings.DaysInFuture + 1)); } else if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncEntireCalendar) { startDate = DateTime.Parse("1990/01/01 12:00:00 AM"); endDate = DateTime.Today.AddYears(10); } }
private void UploadAnalyticsData(CalendarSyncProfile syncProfile, bool isSuccess) { var syncMetric = new SyncMetric { IsSuccess = isSuccess, }; //AnalyticsService.UploadSyncData(syncMetric, syncProfile.GoogleAccount.Name); }
public bool SyncCalendar(CalendarSyncProfile syncProfile, SyncMetric syncMetric, SyncCallback syncCallback) { InitiatePreSyncSetup(syncProfile); var isSuccess = false; if (syncProfile != null) { CalendarSyncEngine.Clear(); //Add log for sync mode CalendarSyncStatus = string.Format("Calendar Sync : {0} {2} {1}", SourceCalendarService.CalendarServiceName, DestinationCalendarService.CalendarServiceName, syncProfile.SyncMode == SyncModeEnum.TwoWay ? "<===>" : "===>"); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); DateTime startDate, endDate; GetDateRange(syncProfile, out startDate, out endDate); //Add log for date range CalendarSyncStatus = $"Date Range : {startDate.ToString("d")} - {endDate.ToString("d")}"; //Load calendar specific data var sourceCalendarSpecificData = GetCalendarSpecificData(syncProfile.Source, syncProfile); var destinationCalendarSpecificData = GetCalendarSpecificData(syncProfile.Destination, syncProfile); //Get source and destination appointments isSuccess = LoadAppointments(startDate, endDate, syncProfile.SyncSettings.SkipPrivateEntries, sourceCalendarSpecificData, destinationCalendarSpecificData); if (isSuccess) { syncMetric.SourceMetric.OriginalCount = SourceAppointments.Count; syncMetric.DestMetric.OriginalCount = DestinationAppointments.Count; LoadSourceId(DestinationAppointments, SourceAppointments.CalendarId); LoadSourceId(SourceAppointments, DestinationAppointments.CalendarId); } if (isSuccess) { //Delete destination appointments isSuccess = DeleteDestinationAppointments(syncProfile, syncMetric, destinationCalendarSpecificData, syncCallback); } if (isSuccess) { //Add appointments to destination isSuccess = AddDestinationAppointments(syncProfile, syncMetric, destinationCalendarSpecificData); } if (isSuccess && syncProfile.SyncMode == SyncModeEnum.TwoWay) { //Delete destination appointments isSuccess = DeleteSourceAppointments(syncProfile, syncMetric, sourceCalendarSpecificData, syncCallback); if (isSuccess) { //If sync mode is two way... add events to source isSuccess = AddSourceAppointments(syncProfile, syncMetric, sourceCalendarSpecificData); } } if (isSuccess) { isSuccess = UpdateEntries(syncProfile, syncMetric, sourceCalendarSpecificData, destinationCalendarSpecificData); } } syncMetric.IsSuccess = isSuccess; SourceAppointments = null; DestinationAppointments = null; SourceCalendarService = null; DestinationCalendarService = null; return isSuccess; }
/// <summary> /// Delete appointments from source /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceCalendarSpecificData"></param> /// <param name="syncCallback"></param> /// <returns> /// </returns> private bool DeleteSourceAppointments(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary<string, object> sourceCalendarSpecificData, SyncCallback syncCallback) { //Updating entry isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToDelete, SourceCalendarService.CalendarServiceName); //Getting appointments to isDeleteOperation CalendarSyncEngine.GetSourceEntriesToDelete(syncProfile, SourceAppointments, DestinationAppointments); var appointmentsToDelete = CalendarSyncEngine.SourceAppointmentsToDelete; //Updating Get entry isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToDelete, appointmentsToDelete.Count); if (appointmentsToDelete.Count == 0) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return true; } //Updating isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DeletingEntries, SourceCalendarService.CalendarServiceName); //Deleting entries var deletedAppointments = SourceCalendarService.DeleteCalendarEvents(appointmentsToDelete, sourceCalendarSpecificData).Result; var isSuccess = deletedAppointments.IsSuccess; //Update status if entries were successfully deleted CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.DeletingEntriesComplete : SyncStateEnum.DeletingEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.SourceMetric.DeleteCount = appointmentsToDelete.Count; syncMetric.SourceMetric.DeleteFailedCount = appointmentsToDelete.Count - deletedAppointments.Count; for (var index = 0; index < appointmentsToDelete.Count; index++) { SourceAppointments.Remove(appointmentsToDelete[index]); } } return isSuccess; }
public bool GetSourceEntriesToAdd(CalendarSyncProfile syncProfile, CalendarAppointments sourceList, CalendarAppointments destinationList) { EvaluateAppointmentsToAdd(syncProfile, destinationList, sourceList, SourceAppointmentsToAdd); return(true); }
public bool GetDestEntriesToAdd(CalendarSyncProfile syncProfile, AppointmentsWrapper sourceList, AppointmentsWrapper destinationList) { EvaluateAppointmentsToAdd(syncProfile, sourceList, destinationList, DestAppointmentsToAdd); return(true); }
public bool GetDestEntriesToAdd(CalendarSyncProfile syncProfile, AppointmentsWrapper sourceList, AppointmentsWrapper destinationList) { EvaluateAppointmentsToAdd(syncProfile, sourceList, destinationList, DestAppointmentsToAdd); return true; }
private void InitiatePreSyncSetup(CalendarSyncProfile syncProfile) { SourceCalendarService = CalendarServiceFactory.GetCalendarService(syncProfile.Source); DestinationCalendarService = CalendarServiceFactory.GetCalendarService(syncProfile.Destination); }
/// <summary> /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceList"></param> /// <param name="destinationList"></param> /// <param name="destAppointmentsToDelete"></param> /// <param name="destAppointmentsToUpdate"></param> /// <param name="sourceAppointmentsToUpdate"></param> /// <param name="destOrphanEntries"></param> /// <returns> /// </returns> private void EvaluateAppointmentsToDelete(CalendarSyncProfile syncProfile, AppointmentsWrapper sourceList, AppointmentsWrapper destinationList, List<Appointment> destAppointmentsToDelete, List<Appointment> destAppointmentsToUpdate, List<Appointment> sourceAppointmentsToUpdate, List<Appointment> destOrphanEntries) { var addDescription = syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description); var addReminders = syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders); var addAttendeesToDescription = syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription); if (!destinationList.Any()) { foreach (var appointment in sourceList) { if (appointment.ChildId != null) { var key = AppointmentHelper.GetChildEntryKey(sourceList.CalendarId); if (!appointment.ExtendedProperties.ContainsKey(key)) { appointment.ExtendedProperties.Remove(key); } sourceAppointmentsToUpdate.AddCompareForUpdate(appointment); } } return; } foreach (var destAppointment in destinationList) { //If SourceId is null, it is not a copy of any entry from the selected source calendar if (destAppointment.SourceId == null) { if (syncProfile.SyncMode == SyncModeEnum.OneWay) { //If mode is one way & user has disabled delete, do not remove this entry, as this is an original entry in the calendar //Else this entry is not a copy of any appointment in source calendar so delete it destOrphanEntries.Add(destAppointment); } else { if (destAppointment.ChildId == null) { var childAppointment = sourceList.FirstOrDefault(t => destAppointment.CompareSourceId(t)); if (childAppointment != null) { destAppointment.ChildId = childAppointment.AppointmentId; var key = childAppointment.GetChildEntryKey(); if (!destAppointment.ExtendedProperties.ContainsKey(key)) { destAppointment.ExtendedProperties.Add(key, childAppointment.AppointmentId); } else { destAppointment.ExtendedProperties[key] = childAppointment.AppointmentId; } destAppointmentsToUpdate.AddCompareForUpdate(destAppointment); } } else if (syncProfile.SyncSettings.KeepLastModifiedVersion) { var childAppointment = sourceList.FirstOrDefault(t => t.AppointmentId.Equals(destAppointment.ChildId)); if (childAppointment == null) { destAppointmentsToDelete.Add(destAppointment); } } } } else { //If the mode is two way, look for its parent copy in Source calendar Appointment sourceAppointment; if (syncProfile.SyncMode == SyncModeEnum.TwoWay && syncProfile.SyncSettings.KeepLastModifiedVersion) { //If no entry was found, it is original entry of the calendar, Ignore //If a child entry is found in source calendar, compare sourceAppointment = sourceList.FirstOrDefault(t => t.CompareSourceId(destAppointment)); if (sourceAppointment != null) { //If any entry is found in source appointment and its contents are not equal to source appointment, //If an entry is found and i same, ignore if (!CompareAppointments(destAppointment, sourceAppointment, addDescription, addReminders, addAttendeesToDescription)) { if (sourceAppointment.LastModified.HasValue && destAppointment.LastModified.HasValue) { if (destAppointment.LastModified.GetValueOrDefault() > sourceAppointment.LastModified.GetValueOrDefault()) { sourceAppointment.CopyDetail(destAppointment, syncProfile.CalendarEntryOptions); sourceAppointmentsToUpdate.AddCompareForUpdate(sourceAppointment); continue; } } //Destination Calendar Entry is not Matching its Source Calendar Entry, Update it destAppointment.CopyDetail(sourceAppointment, syncProfile.CalendarEntryOptions); destAppointmentsToUpdate.AddCompareForUpdate(destAppointment); continue; } } } //If source appointment is not null, means it is a copy of an existing entry in Source calendar sourceAppointment = sourceList.FirstOrDefault(t => t.CompareSourceId(destAppointment)); if (sourceAppointment != null) { //If any entry is found in source appointment and its contents are not equal to source appointment if (!CompareAppointments(destAppointment, sourceAppointment, addDescription, addReminders, addAttendeesToDescription)) { destAppointment.CopyDetail(sourceAppointment, syncProfile.CalendarEntryOptions); destAppointmentsToUpdate.AddCompareForUpdate(destAppointment); } } else { //No parent entry is found, delete it sourceAppointment = sourceList.FirstOrDefault(t => CompareAppointments(destAppointment, t, addDescription, addReminders, addAttendeesToDescription)); if (sourceAppointment == null) { //If parent entry isn't found destAppointmentsToDelete.Add(destAppointment); } } } } }
public bool SyncCalendar(CalendarSyncProfile syncProfile, SyncMetric syncMetric, SyncCallback syncCallback) { InitiatePreSyncSetup(syncProfile); var isSuccess = false; if (syncProfile != null) { CalendarSyncEngine.Clear(); //Add log for sync mode CalendarSyncStatus = string.Format("Calendar Sync : {0} {2} {1}", SourceCalendarService.CalendarServiceName, DestinationCalendarService.CalendarServiceName, syncProfile.SyncMode == SyncModeEnum.TwoWay ? "<===>" : "===>"); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); DateTime startDate, endDate; GetDateRange(syncProfile, out startDate, out endDate); //Add log for date range CalendarSyncStatus = $"Date Range : {startDate.ToString("d")} - {endDate.ToString("d")}"; //Load calendar specific data var sourceCalendarSpecificData = GetCalendarSpecificData(syncProfile.Source, syncProfile); var destinationCalendarSpecificData = GetCalendarSpecificData(syncProfile.Destination, syncProfile); //Get source and destination appointments isSuccess = LoadAppointments(startDate, endDate, syncProfile.SyncSettings.SkipPrivateEntries, sourceCalendarSpecificData, destinationCalendarSpecificData); if (isSuccess) { syncMetric.SourceMetric.OriginalCount = SourceAppointments.Count; syncMetric.DestMetric.OriginalCount = DestinationAppointments.Count; LoadSourceId(DestinationAppointments, SourceAppointments.CalendarId); LoadSourceId(SourceAppointments, DestinationAppointments.CalendarId); } if (isSuccess) { //Delete destination appointments isSuccess = DeleteDestinationAppointments(syncProfile, syncMetric, destinationCalendarSpecificData, syncCallback); } if (isSuccess) { //Add appointments to destination isSuccess = AddDestinationAppointments(syncProfile, syncMetric, destinationCalendarSpecificData); } if (isSuccess && syncProfile.SyncMode == SyncModeEnum.TwoWay) { //Delete destination appointments isSuccess = DeleteSourceAppointments(syncProfile, syncMetric, sourceCalendarSpecificData, syncCallback); if (isSuccess) { //If sync mode is two way... add events to source isSuccess = AddSourceAppointments(syncProfile, syncMetric, sourceCalendarSpecificData); } } if (isSuccess) { isSuccess = UpdateEntries(syncProfile, syncMetric, sourceCalendarSpecificData, destinationCalendarSpecificData); } } syncMetric.IsSuccess = isSuccess; SourceAppointments = null; DestinationAppointments = null; SourceCalendarService = null; DestinationCalendarService = null; return(isSuccess); }
private void ValidateSettings(Settings result) { if (result.GoogleAccounts == null) { result.GoogleAccounts = new ObservableCollection <GoogleAccount>(); } if (result.CalendarSyncProfiles == null || result.CalendarSyncProfiles.Count == 0) { result.CalendarSyncProfiles = new ObservableCollection <CalendarSyncProfile>() { CalendarSyncProfile.GetDefaultSyncProfile() }; } else { foreach (var syncProfile in result.CalendarSyncProfiles) { syncProfile.SetSourceDestTypes(); if (syncProfile.SyncSettings == null) { syncProfile.SyncSettings = CalendarSyncSettings.GetDefault(); } else if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncEntireCalendar) { syncProfile.SyncSettings.SyncRangeType = SyncRangeTypeEnum.SyncRangeInDays; syncProfile.SyncSettings.DaysInPast = 120; syncProfile.SyncSettings.DaysInFuture = 120; } if (syncProfile.SyncFrequency == null) { syncProfile.SyncFrequency = new IntervalSyncFrequency(); } } } if (result.TaskSyncProfiles == null || result.TaskSyncProfiles.Count == 0) { result.TaskSyncProfiles = new ObservableCollection <TaskSyncProfile>() { TaskSyncProfile.GetDefaultSyncProfile() }; } else { foreach (var syncProfile in result.TaskSyncProfiles) { syncProfile.SetSourceDestTypes(); if (syncProfile.SyncSettings == null) { syncProfile.SyncSettings = TaskSyncSettings.GetDefault(); } if (syncProfile.SyncFrequency == null) { syncProfile.SyncFrequency = new IntervalSyncFrequency(); } } } if (result.ContactSyncProfiles == null || result.ContactSyncProfiles.Count == 0) { result.ContactSyncProfiles = new ObservableCollection <ContactSyncProfile>() { ContactSyncProfile.GetDefaultSyncProfile() }; } if (result.AppSettings == null) { result.AppSettings = AppSettings.GetDefault(); } else if (result.AppSettings.ProxySettings == null) { result.AppSettings.ProxySettings = new ProxySetting { ProxyType = ProxyType.Auto }; } }
/// <summary> /// Delete appointments in destination /// </summary> /// <param name="syncProfile"></param> /// <param name="syncMetric"></param> /// <param name="destinationCalendarSpecificData"></param> /// <param name="syncCallback"></param> /// <returns> /// </returns> private bool DeleteDestinationAppointments(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary <string, object> destinationCalendarSpecificData, SyncCallback syncCallback) { //Updating entry isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToDelete, DestinationCalendarService.CalendarServiceName); //Getting appointments to isDeleteOperation CalendarSyncEngine.GetDestEntriesToDelete(syncProfile, SourceAppointments, DestinationAppointments); var appointmentsToDelete = CalendarSyncEngine.DestAppointmentsToDelete; if (syncProfile.SyncMode == SyncModeEnum.OneWay && CalendarSyncEngine.DestOrphanEntries.Any()) { if (syncProfile.SyncSettings.ConfirmOnDelete && syncCallback != null) { var orphanEntries = Environment.NewLine + string.Join(Environment.NewLine, CalendarSyncEngine.DestOrphanEntries); //Log Orphan Entries Logger.Warn("Orphan entries to delete: " + orphanEntries); var message = $"Are you sure you want to delete {appointmentsToDelete.Count} orphan entries from {DestinationCalendarService.CalendarServiceName}?{orphanEntries}"; var e = new SyncEventArgs(message, UserActionEnum.ConfirmDelete); var task = syncCallback(e); if (task.Result) { appointmentsToDelete.AddRange(CalendarSyncEngine.DestOrphanEntries); } } else { if (!syncProfile.SyncSettings.DisableDelete) { appointmentsToDelete.AddRange(CalendarSyncEngine.DestOrphanEntries); } else { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.SkipDelete); } } } //Updating Get entry isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToDelete, appointmentsToDelete.Count); if (appointmentsToDelete.Count == 0) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return(true); } //Updating isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DeletingEntries, DestinationCalendarService.CalendarServiceName); //Deleting entries var deletedAppointments = DestinationCalendarService.DeleteCalendarEvents(appointmentsToDelete, destinationCalendarSpecificData) .Result; var isSuccess = deletedAppointments.IsSuccess; //Update status if entries were successfully deleted CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.DeletingEntriesComplete : SyncStateEnum.DeletingEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.DestMetric.DeleteCount = appointmentsToDelete.Count; syncMetric.DestMetric.DeleteFailedCount = appointmentsToDelete.Count - deletedAppointments.Count; for (var index = 0; index < appointmentsToDelete.Count; index++) { DestinationAppointments.Remove(appointmentsToDelete[index]); } } return(isSuccess); }
private void GetDateRange(CalendarSyncProfile syncProfile, out DateTime startDate, out DateTime endDate) { startDate = syncProfile.SyncSettings.StartDate.Date; endDate = syncProfile.SyncSettings.EndDate.Date; //[CFL] remove "SyncEntireCalendar" and "SyncFixedDateRange" options //if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncRangeInDays) //{ startDate = DateTime.Today.AddDays((-syncProfile.SyncSettings.DaysInPast)); endDate = DateTime.Today.AddDays((syncProfile.SyncSettings.DaysInFuture + 1)); /*} else if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncEntireCalendar) { startDate = DateTime.Parse("1990/01/01 12:00:00 AM"); endDate = DateTime.Today.AddYears(10); }*/ }
private void InitiatePreSyncSetup(CalendarSyncProfile syncProfile) { SourceCalendarService = CalendarServiceFactory.GetCalendarService(syncProfile.Source); DestinationCalendarService = CalendarServiceFactory.GetCalendarService(syncProfile.Destination); }
/// <summary> /// /// </summary> /// <param name="syncProfile"></param> /// <param name="syncMetric"></param> /// <param name="sourceCalendarSpecificData"></param> /// <param name="destinationCalendarSpecificData"></param> /// <returns></returns> private bool UpdateEntries(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary<string, object> sourceCalendarSpecificData, IDictionary<string, object> destinationCalendarSpecificData) { var isSuccess = true; if (CalendarSyncEngine.SourceAppointmentsToUpdate.Any()) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); //Update status for reading entries to update CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToUpdate, CalendarSyncEngine.SourceAppointmentsToUpdate.Count, SourceCalendarService.CalendarServiceName); var updatedAppointments = SourceCalendarService.UpdateCalendarEvents(CalendarSyncEngine.SourceAppointmentsToUpdate, syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription), sourceCalendarSpecificData).Result; isSuccess = updatedAppointments.IsSuccess; CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.UpdateEntriesSuccess : SyncStateEnum.UpdateEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); syncMetric.SourceMetric.UpdateCount = CalendarSyncEngine.SourceAppointmentsToUpdate.Count; syncMetric.SourceMetric.UpdateFailedCount = CalendarSyncEngine.SourceAppointmentsToUpdate.Count - updatedAppointments.Count; } if (CalendarSyncEngine.DestAppointmentsToUpdate.Any()) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); //Update status for reading entries to update CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToUpdate, CalendarSyncEngine.DestAppointmentsToUpdate.Count, DestinationCalendarService.CalendarServiceName); var updatedAppointments = DestinationCalendarService.UpdateCalendarEvents(CalendarSyncEngine.DestAppointmentsToUpdate, syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription), destinationCalendarSpecificData).Result; isSuccess = updatedAppointments.IsSuccess; CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.UpdateEntriesSuccess : SyncStateEnum.UpdateEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); syncMetric.DestMetric.UpdateCount = CalendarSyncEngine.DestAppointmentsToUpdate.Count; syncMetric.DestMetric.UpdateFailedCount = CalendarSyncEngine.DestAppointmentsToUpdate.Count - updatedAppointments.Count; } return isSuccess; }
/// <summary> /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceList"></param> /// <param name="destinationList"></param> /// <param name="destAppointmentsToDelete"></param> /// <param name="destAppointmentsToUpdate"></param> /// <param name="sourceAppointmentsToUpdate"></param> /// <param name="destOrphanEntries"></param> /// <returns> /// </returns> private void EvaluateAppointmentsToDelete(CalendarSyncProfile syncProfile, AppointmentsWrapper sourceList, AppointmentsWrapper destinationList, List <Appointment> destAppointmentsToDelete, List <Appointment> destAppointmentsToUpdate, List <Appointment> sourceAppointmentsToUpdate, List <Appointment> destOrphanEntries) { var addDescription = syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description); var addReminders = syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders); var addAttendeesToDescription = syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription); if (!destinationList.Any()) { foreach (var appointment in sourceList) { if (appointment.ChildId != null) { var key = AppointmentHelper.GetChildEntryKey(sourceList.CalendarId); if (!appointment.ExtendedProperties.ContainsKey(key)) { appointment.ExtendedProperties.Remove(key); } sourceAppointmentsToUpdate.AddCompareForUpdate(appointment); } } return; } foreach (var destAppointment in destinationList) { //If SourceId is null, it is not a copy of any entry from the selected source calendar if (destAppointment.SourceId == null) { if (syncProfile.SyncMode == SyncModeEnum.OneWay) { //If mode is one way & user has disabled delete, do not remove this entry, as this is an original entry in the calendar //Else this entry is not a copy of any appointment in source calendar so delete it destOrphanEntries.Add(destAppointment); } else { if (destAppointment.ChildId == null) { var childAppointment = sourceList.FirstOrDefault(t => destAppointment.CompareSourceId(t)); if (childAppointment != null) { destAppointment.ChildId = childAppointment.AppointmentId; var key = childAppointment.GetChildEntryKey(); if (!destAppointment.ExtendedProperties.ContainsKey(key)) { destAppointment.ExtendedProperties.Add(key, childAppointment.AppointmentId); } else { destAppointment.ExtendedProperties[key] = childAppointment.AppointmentId; } destAppointmentsToUpdate.AddCompareForUpdate(destAppointment); } } else if (syncProfile.SyncSettings.KeepLastModifiedVersion) { var childAppointment = sourceList.FirstOrDefault(t => t.AppointmentId.Equals(destAppointment.ChildId)); if (childAppointment == null) { destAppointmentsToDelete.Add(destAppointment); } } } } else { //If the mode is two way, look for its parent copy in Source calendar Appointment sourceAppointment; if (syncProfile.SyncMode == SyncModeEnum.TwoWay && syncProfile.SyncSettings.KeepLastModifiedVersion) { //If no entry was found, it is original entry of the calendar, Ignore //If a child entry is found in source calendar, compare sourceAppointment = sourceList.FirstOrDefault(t => t.CompareSourceId(destAppointment)); if (sourceAppointment != null) { //If any entry is found in source appointment and its contents are not equal to source appointment, //If an entry is found and i same, ignore if (!CompareAppointments(destAppointment, sourceAppointment, addDescription, addReminders, addAttendeesToDescription)) { if (sourceAppointment.LastModified.HasValue && destAppointment.LastModified.HasValue) { if (destAppointment.LastModified.GetValueOrDefault() > sourceAppointment.LastModified.GetValueOrDefault()) { sourceAppointment.CopyDetail(destAppointment, syncProfile.CalendarEntryOptions); sourceAppointmentsToUpdate.AddCompareForUpdate(sourceAppointment); continue; } } //Destination Calendar Entry is not Matching its Source Calendar Entry, Update it destAppointment.CopyDetail(sourceAppointment, syncProfile.CalendarEntryOptions); destAppointmentsToUpdate.AddCompareForUpdate(destAppointment); continue; } } } //If source appointment is not null, means it is a copy of an existing entry in Source calendar sourceAppointment = sourceList.FirstOrDefault(t => t.CompareSourceId(destAppointment)); if (sourceAppointment != null) { //If any entry is found in source appointment and its contents are not equal to source appointment if (!CompareAppointments(destAppointment, sourceAppointment, addDescription, addReminders, addAttendeesToDescription)) { destAppointment.CopyDetail(sourceAppointment, syncProfile.CalendarEntryOptions); destAppointmentsToUpdate.AddCompareForUpdate(destAppointment); } } else { //No parent entry is found, delete it sourceAppointment = sourceList.FirstOrDefault(t => CompareAppointments(destAppointment, t, addDescription, addReminders, addAttendeesToDescription)); if (sourceAppointment == null) { //If parent entry isn't found destAppointmentsToDelete.Add(destAppointment); } } } } }
private IDictionary<string, object> GetCalendarSpecificData(ServiceType serviceType, CalendarSyncProfile syncProfile) { IDictionary<string, object> calendarSpecificData = null; switch (serviceType) { case ServiceType.Google: calendarSpecificData = new Dictionary<string, object> { {"CalendarId", syncProfile.GoogleSettings.GoogleCalendar.Id}, {"AccountName", syncProfile.GoogleSettings.GoogleAccount.Name} }; break; case ServiceType.OutlookDesktop: calendarSpecificData = new Dictionary<string, object> { { "ProfileName", !syncProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultProfile) ? syncProfile.OutlookSettings.OutlookProfileName : null }, { "OutlookCalendar", !syncProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultMailBoxCalendar) ? syncProfile.OutlookSettings.OutlookFolder : null }, { "AddAsAppointments", syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AsAppointments) }, { "SetOrganizer", syncProfile.OutlookSettings.SetOrganizer } }; break; case ServiceType.EWS: return null; } if (calendarSpecificData != null && syncProfile.SetCalendarCategory) { calendarSpecificData.Add("EventCategory", syncProfile.EventCategory); } return calendarSpecificData; }
/// <summary> /// Gets appointments to add in the destination calendar /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceList"></param> /// <param name="destinationList"></param> /// <param name="appointmentsToAdd"></param> /// <returns> /// </returns> private void EvaluateAppointmentsToAdd(CalendarSyncProfile syncProfile, List<Appointment> sourceList, List<Appointment> destinationList, List<Appointment> appointmentsToAdd) { if (!destinationList.Any()) { appointmentsToAdd.AddRange(sourceList); //All entries need to be added return; } bool checkChild = syncProfile.SyncMode == SyncModeEnum.TwoWay && syncProfile.SyncSettings.KeepLastModifiedVersion; foreach (var sourceAppointment in sourceList) { if (sourceAppointment.SourceId == null) { if (!checkChild || sourceAppointment.ChildId == null) { var destinationAppointment = destinationList.FirstOrDefault(t => t.Equals(sourceAppointment)); if (destinationAppointment == null) { appointmentsToAdd.Add(sourceAppointment); } } } } }
/// <summary> /// Delete appointments in destination /// </summary> /// <param name="syncProfile"></param> /// <param name="syncMetric"></param> /// <param name="destinationCalendarSpecificData"></param> /// <param name="syncCallback"></param> /// <returns> /// </returns> private bool DeleteDestinationAppointments(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary<string, object> destinationCalendarSpecificData, SyncCallback syncCallback) { //Updating entry isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToDelete, DestinationCalendarService.CalendarServiceName); //Getting appointments to isDeleteOperation CalendarSyncEngine.GetDestEntriesToDelete(syncProfile, SourceAppointments, DestinationAppointments); var appointmentsToDelete = CalendarSyncEngine.DestAppointmentsToDelete; if (syncProfile.SyncMode == SyncModeEnum.OneWay && CalendarSyncEngine.DestOrphanEntries.Any()) { if (syncProfile.SyncSettings.ConfirmOnDelete && syncCallback != null) { var orphanEntries = Environment.NewLine + string.Join(Environment.NewLine, CalendarSyncEngine.DestOrphanEntries); //Log Orphan Entries Logger.Warn("Orphan entries to delete: " + orphanEntries); var message = $"Are you sure you want to delete {appointmentsToDelete.Count} orphan entries from {DestinationCalendarService.CalendarServiceName}?{orphanEntries}"; var e = new SyncEventArgs(message, UserActionEnum.ConfirmDelete); var task = syncCallback(e); if (task.Result) { appointmentsToDelete.AddRange(CalendarSyncEngine.DestOrphanEntries); } } else { if (!syncProfile.SyncSettings.DisableDelete) { appointmentsToDelete.AddRange(CalendarSyncEngine.DestOrphanEntries); } else { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.SkipDelete); } } } //Updating Get entry isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToDelete, appointmentsToDelete.Count); if (appointmentsToDelete.Count == 0) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return true; } //Updating isDeleteOperation status CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DeletingEntries, DestinationCalendarService.CalendarServiceName); //Deleting entries var deletedAppointments = DestinationCalendarService.DeleteCalendarEvents(appointmentsToDelete, destinationCalendarSpecificData) .Result; var isSuccess = deletedAppointments.IsSuccess; //Update status if entries were successfully deleted CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.DeletingEntriesComplete : SyncStateEnum.DeletingEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.DestMetric.DeleteCount = appointmentsToDelete.Count; syncMetric.DestMetric.DeleteFailedCount = appointmentsToDelete.Count - deletedAppointments.Count; for (var index = 0; index < appointmentsToDelete.Count; index++) { DestinationAppointments.Remove(appointmentsToDelete[index]); } } return isSuccess; }
/// <summary> /// Add appointments to source /// </summary> /// <param name="syncProfile"></param> /// <param name="syncMetric"></param> /// <param name="sourceCalendarSpecificData"></param> /// <returns> /// </returns> private bool AddSourceAppointments(CalendarSyncProfile syncProfile, SyncMetric syncMetric, IDictionary<string, object> sourceCalendarSpecificData) { //Update status for reading entries to add CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToAdd, SourceCalendarService.CalendarServiceName); //Get entries to add CalendarSyncEngine.GetSourceEntriesToAdd(syncProfile, SourceAppointments, DestinationAppointments); var appointmentsToAdd = CalendarSyncEngine.SourceAppointmentsToAdd; CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToAdd, appointmentsToAdd.Count); if (appointmentsToAdd.Count == 0) { CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return true; } CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.AddingEntries, SourceCalendarService.CalendarServiceName); //Add entries to calendar var addedAppointments = SourceCalendarService.AddCalendarEvents(appointmentsToAdd, syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees), syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription), sourceCalendarSpecificData) .Result; var isSuccess = addedAppointments.IsSuccess; //Update status if entries were successfully added CalendarSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.AddEntriesComplete : SyncStateEnum.AddEntriesFailed); CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.SourceMetric.AddCount = appointmentsToAdd.Count; LoadSourceId(addedAppointments, DestinationAppointments.CalendarId); SourceAppointments.AddRange(addedAppointments); if (syncProfile.SyncMode == SyncModeEnum.TwoWay) { var updateDestList = UpdateWithChildId(addedAppointments, DestinationAppointments); CalendarSyncEngine.DestAppointmentsToUpdate.AddRangeCompareForUpdate(updateDestList); } } return isSuccess; }
private async Task StartCalendarSyncProfile(CalendarSyncProfile profile) { await Task.Run(() => StartCalendarSyncTask(profile)); }