/// <summary> /// Delete appointments from source /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceCalendarSpecificData"></param> /// <param name="syncCallback"></param> /// <returns> /// </returns> private bool DeleteSourceTasks(TaskSyncProfile syncProfile, SyncMetric syncMetric, IDictionary <string, object> sourceCalendarSpecificData, SyncCallback syncCallback) { //if (syncProfile.SyncSettings.DisableDelete) //{ // return true; //} //Updating entry isDeleteOperation status TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToDelete, SourceTaskService.TaskServiceName); //Getting appointments to isDeleteOperation TaskSyncEngine.GetSourceEntriesToDelete(syncProfile, SourceTasks, DestinationTasks); var appointmentsToDelete = TaskSyncEngine.SourceTasksToDelete; //Updating Get entry isDeleteOperation status TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToDelete, appointmentsToDelete.Count); if (appointmentsToDelete.Count == 0) { TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return(true); } //Updating isDeleteOperation status TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DeletingEntries, SourceTaskService.TaskServiceName); //Deleting entries var deletedTasks = SourceTaskService.DeleteReminderTasks(appointmentsToDelete, sourceCalendarSpecificData).Result; var isSuccess = deletedTasks.IsSuccess; //Update status if entries were successfully deleted TaskSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.DeletingEntriesComplete : SyncStateEnum.DeletingEntriesFailed); TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.SourceMetric.DeleteCount = appointmentsToDelete.Count; syncMetric.SourceMetric.DeleteFailedCount = appointmentsToDelete.Count - deletedTasks.Count; for (var index = 0; index < appointmentsToDelete.Count; index++) { SourceTasks.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 AddSourceTasks(TaskSyncProfile syncProfile, SyncMetric syncMetric, IDictionary <string, object> sourceCalendarSpecificData) { //Update status for reading entries to add TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToAdd, SourceTaskService.TaskServiceName); //Get entries to add TaskSyncEngine.GetSourceEntriesToAdd(syncProfile, SourceTasks, DestinationTasks); var appointmentsToAdd = TaskSyncEngine.SourceTasksToAdd; TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToAdd, appointmentsToAdd.Count); if (appointmentsToAdd.Count == 0) { TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return(true); } TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.AddingEntries, SourceTaskService.TaskServiceName); //Add entries to calendar var addedTasks = SourceTaskService.AddReminderTasks(appointmentsToAdd, sourceCalendarSpecificData) .Result; var isSuccess = addedTasks.IsSuccess; //Update status if entries were successfully added TaskSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.AddEntriesComplete : SyncStateEnum.AddEntriesFailed); TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.SourceMetric.AddCount = appointmentsToAdd.Count; //LoadSourceId(addedTasks, DestinationTasks.TaskListId); SourceTasks.AddRange(addedTasks); if (syncProfile.SyncMode == SyncModeEnum.TwoWay) { //var updateDestList = UpdateWithChildId(addedTasks, DestinationTasks); //TaskSyncEngine.DestTasksToUpdate.AddRangeCompareForUpdate(updateDestList); } } return(isSuccess); }
public bool SyncTask(TaskSyncProfile syncProfile, SyncMetric syncMetric, SyncCallback syncCallback) { InitiatePreSyncSetup(syncProfile); var isSuccess = false; if (syncProfile != null) { TaskSyncEngine.Clear(); //Add log for sync mode TaskSyncStatus = string.Format("Calendar Sync : {0} {2} {1}", SourceTaskService.TaskServiceName, DestinationTaskService.TaskServiceName, syncProfile.SyncMode == SyncModeEnum.TwoWay ? "<===>" : "===>"); TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); DateTime startDate, endDate; GetDateRange(syncProfile, out startDate, out endDate); //Add log for date range TaskSyncStatus = $"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 Tasks isSuccess = LoadTasks(sourceCalendarSpecificData, destinationCalendarSpecificData); if (isSuccess) { syncMetric.SourceMetric.OriginalCount = SourceTasks.Count; syncMetric.DestMetric.OriginalCount = DestinationTasks.Count; //LoadSourceId(DestinationTasks, SourceTasks.TaskListId); //LoadSourceId(SourceTasks, DestinationTasks.TaskListId); } if (isSuccess) { //Delete destination Tasks isSuccess = DeleteDestinationTasks(syncProfile, syncMetric, destinationCalendarSpecificData, syncCallback); } if (isSuccess) { //Add Tasks to destination isSuccess = AddDestinationTasks(syncProfile, syncMetric, destinationCalendarSpecificData); } if (isSuccess && syncProfile.SyncMode == SyncModeEnum.TwoWay) { //Delete destination appointments isSuccess = DeleteSourceTasks(syncProfile, syncMetric, sourceCalendarSpecificData, syncCallback); if (isSuccess) { //If sync mode is two way... add events to source isSuccess = AddSourceTasks(syncProfile, syncMetric, sourceCalendarSpecificData); } } if (isSuccess) { isSuccess = UpdateEntries(syncProfile, syncMetric, sourceCalendarSpecificData, destinationCalendarSpecificData); } } syncMetric.IsSuccess = isSuccess; SourceTasks = null; DestinationTasks = null; SourceTaskService = null; DestinationTaskService = null; return(isSuccess); }
/// <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 DeleteDestinationTasks(TaskSyncProfile syncProfile, SyncMetric syncMetric, IDictionary <string, object> destinationCalendarSpecificData, SyncCallback syncCallback) { //if (syncProfile.SyncSettings.DisableDelete) //{ // return true; //} //Updating entry isDeleteOperation status TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToDelete, DestinationTaskService.TaskServiceName); //Getting appointments to isDeleteOperation TaskSyncEngine.GetDestEntriesToDelete(syncProfile, SourceTasks, DestinationTasks); var appointmentsToDelete = TaskSyncEngine.DestTasksToDelete; if (syncProfile.SyncMode == SyncModeEnum.OneWay) { //if (syncProfile.SyncSettings.ConfirmOnDelete && syncCallback != null) //{ // var orphanEntries = Environment.NewLine + // string.Join(Environment.NewLine, TaskSyncEngine.DestOrphanEntries); // //Log Orphan Entries // Logger.Warn("Orphan entries to delete: " + orphanEntries); // var message = string.Format("Are you sure you want to delete {0} orphan entries from {1}?{2}", // appointmentsToDelete.Count, DestinationTaskService.TaskServiceName, // orphanEntries); // var e = new SyncEventArgs(message, UserActionEnum.ConfirmDelete); // var task = syncCallback(e); // if (task.Result) // { // appointmentsToDelete.AddRange(TaskSyncEngine.DestOrphanEntries); // } //} //else if (!syncProfile.SyncSettings.DisableDelete) //{ // appointmentsToDelete.AddRange(TaskSyncEngine.DestOrphanEntries); //} } //Updating Get entry isDeleteOperation status TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToDelete, appointmentsToDelete.Count); if (appointmentsToDelete.Count == 0) { TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); return(true); } //Updating isDeleteOperation status TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DeletingEntries, DestinationTaskService.TaskServiceName); //Deleting entries var deletedTasks = DestinationTaskService.DeleteReminderTasks(appointmentsToDelete, destinationCalendarSpecificData) .Result; var isSuccess = deletedTasks.IsSuccess; //Update status if entries were successfully deleted TaskSyncStatus = StatusHelper.GetMessage(isSuccess ? SyncStateEnum.DeletingEntriesComplete : SyncStateEnum.DeletingEntriesFailed); TaskSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line); if (isSuccess) { syncMetric.DestMetric.DeleteCount = appointmentsToDelete.Count; syncMetric.DestMetric.DeleteFailedCount = appointmentsToDelete.Count - deletedTasks.Count; for (var index = 0; index < appointmentsToDelete.Count; index++) { DestinationTasks.Remove(appointmentsToDelete[index]); } } return(isSuccess); }