public async Task <TasksWrapper> DeleteReminderTasks(List <ReminderTask> reminderTasks, IDictionary <string, object> taskListSpecificData) { var deletedTasks = new TasksWrapper(); if (!reminderTasks.Any()) { deletedTasks.IsSuccess = true; return(deletedTasks); } CheckTaskListSpecificData(taskListSpecificData); var errorList = new Dictionary <int, ReminderTask>(); //Get Calendar Service var calendarService = GetTasksService(AccountName); if (reminderTasks == null || string.IsNullOrEmpty(TaskListId)) { deletedTasks.IsSuccess = false; return(deletedTasks); } try { if (reminderTasks.Any()) { //Create a Batch Request var batchRequest = new BatchRequest(calendarService); //Split the list of calendarAppointments by 1000 per list //Iterate over each appointment to create a event and batch it for (var i = 0; i < reminderTasks.Count; i++) { if (i != 0 && i % 999 == 0) { await batchRequest.ExecuteAsync(); batchRequest = new BatchRequest(calendarService); } var appointment = reminderTasks[i]; var deleteRequest = calendarService.Tasks.Delete(TaskListId, appointment.TaskId); batchRequest.Queue <Task>(deleteRequest, (content, error, index, message) => CallbackEventErrorMessage(content, error, index, message, reminderTasks, "Error in deleting events", errorList, deletedTasks)); } await batchRequest.ExecuteAsync(); } } catch (Exception exception) { Logger.Error(exception); deletedTasks.IsSuccess = false; return(deletedTasks); } deletedTasks.IsSuccess = true; return(deletedTasks); }
/// <summary> /// /// </summary> /// <param name="addedTasks"></param> /// <param name="existingTasks"></param> /// <returns></returns> private List <Appointment> UpdateWithChildId(TasksWrapper addedTasks, TasksWrapper existingTasks) { //Add appointments to update var updateList = new List <Appointment>(); foreach (var appointment in addedTasks) { //var presentAppointment = existingTasks.FirstOrDefault(t => t.CompareSourceId(appointment)); //if (presentAppointment != null) //{ // var childKey = appointment.GetChildEntryKey(); // if (!presentAppointment.ExtendedProperties.ContainsKey(childKey)) // { // presentAppointment.ExtendedProperties.Add(childKey, appointment.AppointmentId); // } // else // { // presentAppointment.ExtendedProperties[childKey] = appointment.AppointmentId; // } // updateList.Add(presentAppointment); //} } return(updateList); }
public bool GetDestEntriesToDelete(TaskSyncProfile syncProfile, TasksWrapper sourceList, TasksWrapper destinationList) { EvaluateTasksToDelete(syncProfile, sourceList, destinationList, DestTasksToDelete, DestTasksToUpdate, SourceTasksToUpdate, DestOrphanEntries); return(true); }
public async Task <TasksWrapper> GetReminderTasksInRangeAsync(IDictionary <string, object> taskListSpecificData) { CheckTaskListSpecificData(taskListSpecificData); var finalTaskList = new TasksWrapper(); //Get Calendar Service var tasksService = GetTasksService(AccountName); var taskListRequest = tasksService.Tasks.List(TaskListId); taskListRequest.MaxResults = 1000; try { var result = taskListRequest.Execute(); if (result != null) { while (result.Items != null) { // Add events to list, Split recurring appointments foreach (var eventItem in result.Items) { var reminderTask = CreateReminderTask(eventItem); finalTaskList.Add(reminderTask); } //If all pages are over break if (result.NextPageToken == null) { break; } //Set the next page to pull from request taskListRequest.PageToken = result.NextPageToken; result = await taskListRequest.ExecuteAsync(); } } else { return(null); } } catch (Exception exception) { Logger.Error(exception); } return(finalTaskList); }
private bool UpdateTasks(List <ReminderTask> reminderTasks, TasksWrapper tasksWrapper) { var wrapper = UpdateTasksToOutlook(reminderTasks, tasksWrapper); if (!wrapper.WaitForApplicationQuit) { return(wrapper.Success); } while (Process.GetProcessesByName("OUTLOOK").Any()) { ThreadingTask.Delay(5000); } return(wrapper.Success); }
public async Task<TasksWrapper> GetReminderTasksInRangeAsync(IDictionary<string, object> taskListSpecificData) { CheckTaskListSpecificData(taskListSpecificData); var finalTaskList = new TasksWrapper(); //Get Calendar Service var tasksService = GetTasksService(AccountName); var taskListRequest = tasksService.Tasks.List(TaskListId); taskListRequest.MaxResults = 1000; try { var result = taskListRequest.Execute(); if (result != null) { while (result.Items != null) { // Add events to list, Split recurring appointments foreach (var eventItem in result.Items) { var reminderTask = CreateReminderTask(eventItem); finalTaskList.Add(reminderTask); } //If all pages are over break if (result.NextPageToken == null) { break; } //Set the next page to pull from request taskListRequest.PageToken = result.NextPageToken; result = await taskListRequest.ExecuteAsync(); } } else { return null; } } catch (Exception exception) { Logger.Error(exception); } return finalTaskList; }
public async Task <TasksWrapper> AddReminderTasks(List <ReminderTask> reminderTasks, IDictionary <string, object> taskListSpecificData) { var tasksWrapper = new TasksWrapper(); if (!reminderTasks.Any()) { tasksWrapper.IsSuccess = true; return(tasksWrapper); } CheckTaskListSpecificData(taskListSpecificData); var result = await Task <bool> .Factory.StartNew(() => AddTasks(reminderTasks, tasksWrapper)); tasksWrapper.IsSuccess = result; return(tasksWrapper); }
public async Task <TasksWrapper> GetReminderTasksInRangeAsync(IDictionary <string, object> taskListSpecificData) { CheckTaskListSpecificData(taskListSpecificData); var taskWrapper = new TasksWrapper(); var appointmentList = await Task <List <ReminderTask> > .Factory.StartNew( GetTasks); if (appointmentList == null) { return(null); } taskWrapper.AddRange(appointmentList); return(taskWrapper); }
/// <summary> /// </summary> /// <param name="syncProfile"></param> /// <param name="sourceList"></param> /// <param name="destinationList"></param> /// <param name="destTasksToDelete"></param> /// <param name="destTasksToUpdate"></param> /// <param name="sourceTasksToUpdate"></param> /// <param name="destOrphanEntries"></param> /// <returns> /// </returns> private void EvaluateTasksToDelete(TaskSyncProfile syncProfile, TasksWrapper sourceList, TasksWrapper destinationList, List <ReminderTask> destTasksToDelete, List <ReminderTask> destTasksToUpdate, List <ReminderTask> sourceTasksToUpdate, List <ReminderTask> destOrphanEntries) { if (!destinationList.Any()) { return; } foreach (var destTask in destinationList) { var sourceTask = sourceList.FirstOrDefault(t => t.Equals(destTask)); if (sourceTask == null) { destTasksToDelete.Add(destTask); } else if (destTask.IsCompleted != sourceTask.IsCompleted) { if (destTask.Due.HasValue && sourceTask.Due.HasValue && !destTask.Due.Value.Equals(sourceTask.Due.Value)) { if (destTask.Due.Value.Year < 4500 || destTask.Due.Value.Year < 4500) { if (destTask.UpdatedOn.GetValueOrDefault() .CompareTo(sourceTask.UpdatedOn.GetValueOrDefault()) < 0) { destTask.CopyDetail(sourceTask); destTasksToUpdate.Add(destTask); } else { sourceTasksToUpdate.Add(sourceTask); } } } } } }
public async Task <TasksWrapper> AddReminderTasks(List <ReminderTask> tasks, IDictionary <string, object> taskListSpecificData) { var addedTasks = new TasksWrapper(); if (!tasks.Any()) { addedTasks.IsSuccess = true; return(addedTasks); } CheckTaskListSpecificData(taskListSpecificData); var errorList = new Dictionary <int, ReminderTask>(); //Get Calendar Service var calendarService = GetTasksService(AccountName); if (tasks == null || string.IsNullOrEmpty(TaskListId)) { addedTasks.IsSuccess = false; return(addedTasks); } try { if (tasks.Any()) { //Split the list of calendarAppointments by 1000 per list var appts = await AddTasksInternal(tasks, calendarService, errorList); addedTasks.AddRange(appts); } } catch (Exception exception) { Logger.Error(exception); addedTasks.IsSuccess = false; return(addedTasks); } addedTasks.IsSuccess = addedTasks.Count == tasks.Count; return(addedTasks); }
public async Task<TasksWrapper> UpdateReminderTasks(List<ReminderTask> reminderTasks, IDictionary<string, object> taskListSpecificData) { var updatedAppointments = new TasksWrapper(); if (!reminderTasks.Any()) { updatedAppointments.IsSuccess = true; return updatedAppointments; } CheckTaskListSpecificData(taskListSpecificData); var errorList = new Dictionary<int, ReminderTask>(); //Get Calendar Service var calendarService = GetTasksService(AccountName); if (reminderTasks == null || string.IsNullOrEmpty(TaskListId)) { updatedAppointments.IsSuccess = false; return updatedAppointments; } try { if (reminderTasks.Any()) { //Create a Batch Request var batchRequest = new BatchRequest(calendarService); //Split the list of calendarAppointments by 1000 per list //Iterate over each appointment to create a event and batch it for (var i = 0; i < reminderTasks.Count; i++) { if (i != 0 && i % 999 == 0) { await batchRequest.ExecuteAsync(); batchRequest = new BatchRequest(calendarService); } var appointment = reminderTasks[i]; var task = CreateUpdatedGoogleTask(appointment); var updateRequest = calendarService.Tasks.Update(task, TaskListId, task.Id); batchRequest.Queue<Task>(updateRequest, (content, error, index, message) => CallbackEventErrorMessage(content, error, index, message, reminderTasks, "Error in updating event", errorList, updatedAppointments)); } await batchRequest.ExecuteAsync(); } } catch (Exception exception) { Logger.Error(exception); updatedAppointments.IsSuccess = false; return updatedAppointments; } updatedAppointments.IsSuccess = reminderTasks.Count == updatedAppointments.Count; return updatedAppointments; }
private bool UpdateTasks(List<ReminderTask> reminderTasks, TasksWrapper tasksWrapper) { OutlookTasksWrapper wrapper = UpdateTasksToOutlook(reminderTasks, tasksWrapper); if (!wrapper.WaitForApplicationQuit) { return wrapper.Success; } while (Process.GetProcessesByName("OUTLOOK").Any()) { ThreadingTask.Delay(5000); } return wrapper.Success; }
private OutlookTasksWrapper UpdateTasksToOutlook(List <ReminderTask> reminderTasks, TasksWrapper tasksWrapper) { var disposeOutlookInstances = false; Application application = null; NameSpace nameSpace = null; MAPIFolder defaultOutlookCalendar = null; Items outlookItems = null; try { // Get Application and Namespace GetOutlookApplication(out disposeOutlookInstances, out application, out nameSpace, ProfileName); // Get Default Calendar defaultOutlookCalendar = OutlookTaskList != null ? nameSpace.GetFolderFromID(OutlookTaskList.EntryId, OutlookTaskList.StoreId) : nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); outlookItems = defaultOutlookCalendar.Items; foreach (var reminderTask in reminderTasks) { try { TaskItem appItem = null; appItem = nameSpace.GetItemFromID(reminderTask.TaskId) as TaskItem; var success = UpdateTask(appItem, reminderTask); if (success) { tasksWrapper.Add(reminderTask); } } catch (Exception exception) { Logger.Error(exception); } } } catch (Exception exception) { Logger.Error(exception); return(new OutlookTasksWrapper { WaitForApplicationQuit = disposeOutlookInstances, Success = false }); } finally { //Close and Shutdown if (disposeOutlookInstances) { nameSpace.Logoff(); } //Unassign all instances if (outlookItems != null) { Marshal.FinalReleaseComObject(outlookItems); outlookItems = null; } Marshal.FinalReleaseComObject(defaultOutlookCalendar); defaultOutlookCalendar = null; Marshal.FinalReleaseComObject(nameSpace); nameSpace = null; if (disposeOutlookInstances) { // Casting Removes a warninig for Ambigous Call application.Quit(); Marshal.FinalReleaseComObject(application); } application = null; GC.Collect(); GC.WaitForPendingFinalizers(); } return(new OutlookTasksWrapper { WaitForApplicationQuit = disposeOutlookInstances, Success = true }); }
/// <summary> /// /// </summary> /// <param name="addedTasks"></param> /// <param name="existingTasks"></param> /// <returns></returns> private List<Appointment> UpdateWithChildId(TasksWrapper addedTasks, TasksWrapper existingTasks) { //Add appointments to update var updateList = new List<Appointment>(); foreach (var appointment in addedTasks) { //var presentAppointment = existingTasks.FirstOrDefault(t => t.CompareSourceId(appointment)); //if (presentAppointment != null) //{ // var childKey = appointment.GetChildEntryKey(); // if (!presentAppointment.ExtendedProperties.ContainsKey(childKey)) // { // presentAppointment.ExtendedProperties.Add(childKey, appointment.AppointmentId); // } // else // { // presentAppointment.ExtendedProperties[childKey] = appointment.AppointmentId; // } // updateList.Add(presentAppointment); //} } return updateList; }
public async Task<TasksWrapper> GetReminderTasksInRangeAsync(IDictionary<string, object> taskListSpecificData) { CheckTaskListSpecificData(taskListSpecificData); var taskWrapper = new TasksWrapper(); var appointmentList = await Task<List<ReminderTask>>.Factory.StartNew( GetTasks); if (appointmentList == null) { return null; } taskWrapper.AddRange(appointmentList); return taskWrapper; }
public async Task<TasksWrapper> UpdateReminderTasks(List<ReminderTask> reminderTasks, IDictionary<string, object> taskListSpecificData) { var tasksWrapper = new TasksWrapper(); if (!reminderTasks.Any()) { tasksWrapper.IsSuccess = true; return tasksWrapper; } CheckTaskListSpecificData(taskListSpecificData); var result = await Task<bool>.Factory.StartNew(() => UpdateTasks(reminderTasks, tasksWrapper)); tasksWrapper.IsSuccess = result; return tasksWrapper; }
public bool GetDestEntriesToAdd(TaskSyncProfile syncProfile, TasksWrapper sourceList, TasksWrapper destinationList) { EvaluateTasksToAdd(syncProfile, sourceList, destinationList, DestTasksToAdd); return(true); }
private OutlookTasksWrapper UpdateTasksToOutlook(List<ReminderTask> reminderTasks, TasksWrapper tasksWrapper) { var disposeOutlookInstances = false; Application application = null; NameSpace nameSpace = null; MAPIFolder defaultOutlookCalendar = null; Items outlookItems = null; try { // Get Application and Namespace GetOutlookApplication(out disposeOutlookInstances, out application, out nameSpace, ProfileName); // Get Default Calendar defaultOutlookCalendar = OutlookTaskList != null ? nameSpace.GetFolderFromID(OutlookTaskList.EntryId, OutlookTaskList.StoreId) : nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); outlookItems = defaultOutlookCalendar.Items; foreach (var reminderTask in reminderTasks) { try { TaskItem appItem = null; appItem = nameSpace.GetItemFromID(reminderTask.TaskId) as TaskItem; var success = UpdateTask(appItem, reminderTask); if (success) { tasksWrapper.Add(reminderTask); } } catch (Exception exception) { Logger.Error(exception); } } } catch (Exception exception) { Logger.Error(exception); return new OutlookTasksWrapper { WaitForApplicationQuit = disposeOutlookInstances, Success = false }; } finally { //Close and Shutdown if (disposeOutlookInstances) { nameSpace.Logoff(); } //Unassign all instances if (outlookItems != null) { Marshal.FinalReleaseComObject(outlookItems); outlookItems = null; } Marshal.FinalReleaseComObject(defaultOutlookCalendar); defaultOutlookCalendar = null; Marshal.FinalReleaseComObject(nameSpace); nameSpace = null; if (disposeOutlookInstances) { // Casting Removes a warninig for Ambigous Call application.Quit(); Marshal.FinalReleaseComObject(application); } application = null; GC.Collect(); GC.WaitForPendingFinalizers(); } return new OutlookTasksWrapper() { WaitForApplicationQuit = disposeOutlookInstances, Success = true }; }
public async Task<TasksWrapper> AddReminderTasks(List<ReminderTask> tasks, IDictionary<string, object> taskListSpecificData) { var addedTasks = new TasksWrapper(); if (!tasks.Any()) { addedTasks.IsSuccess = true; return addedTasks; } CheckTaskListSpecificData(taskListSpecificData); var errorList = new Dictionary<int, ReminderTask>(); //Get Calendar Service var calendarService = GetTasksService(AccountName); if (tasks == null || string.IsNullOrEmpty(TaskListId)) { addedTasks.IsSuccess = false; return addedTasks; } try { if (tasks.Any()) { //Split the list of calendarAppointments by 1000 per list var appts = await AddTasksInternal(tasks, calendarService, errorList); addedTasks.AddRange(appts); } } catch (Exception exception) { Logger.Error(exception); addedTasks.IsSuccess = false; return addedTasks; } addedTasks.IsSuccess = addedTasks.Count == tasks.Count; return addedTasks; }