Exemple #1
0
        /// <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())
            {
                SyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
                //Update status for reading entries to update
                SyncStatus = 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;
                SyncStatus =
                    StatusHelper.GetMessage(isSuccess
                        ? SyncStateEnum.UpdateEntriesSuccess
                        : SyncStateEnum.UpdateEntriesFailed);
                SyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
                syncMetric.SourceMetric.UpdateCount       = CalendarSyncEngine.SourceAppointmentsToUpdate.Count;
                syncMetric.SourceMetric.UpdateFailedCount =
                    CalendarSyncEngine.SourceAppointmentsToUpdate.Count - updatedAppointments.Count;
            }

            if (CalendarSyncEngine.DestAppointmentsToUpdate.Any())
            {
                SyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
                //Update status for reading entries to update
                SyncStatus = 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;
                SyncStatus =
                    StatusHelper.GetMessage(isSuccess
                        ? SyncStateEnum.UpdateEntriesSuccess
                        : SyncStateEnum.UpdateEntriesFailed);
                SyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
                syncMetric.DestMetric.UpdateCount       = CalendarSyncEngine.DestAppointmentsToUpdate.Count;
                syncMetric.DestMetric.UpdateFailedCount =
                    CalendarSyncEngine.DestAppointmentsToUpdate.Count - updatedAppointments.Count;
            }

            return(isSuccess);
        }
Exemple #2
0
        /// <summary>
        ///     Add appointments to destination
        /// </summary>
        /// <param name="syncProfile"></param>
        /// <param name="syncMetric"></param>
        /// <param name="destinationCalendarSpecificData"></param>
        /// <returns>
        /// </returns>
        private bool AddDestinationAppointments(CalendarSyncProfile syncProfile, SyncMetric syncMetric,
                                                IDictionary <string, object> destinationCalendarSpecificData)
        {
            //Update status for reading entries to add
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.ReadingEntriesToAdd,
                                                         DestinationCalendarService.CalendarServiceName);
            //Get entries to add
            CalendarSyncEngine.GetDestEntriesToAdd(syncProfile, SourceAppointments,
                                                   DestinationAppointments);
            var appointmentsToAdd = CalendarSyncEngine.DestAppointmentsToAdd;

            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.EntriesToAdd, appointmentsToAdd.Count);
            if (appointmentsToAdd.Count == 0)
            {
                CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
                return(true);
            }
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.AddingEntries,
                                                         DestinationCalendarService.CalendarServiceName);
            //Add entries to destination calendar
            var addedAppointments = DestinationCalendarService.AddCalendarEvents(appointmentsToAdd,
                                                                                 syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description),
                                                                                 syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders),
                                                                                 syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees),
                                                                                 syncProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription),
                                                                                 destinationCalendarSpecificData)
                                    .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.DestMetric.AddCount = appointmentsToAdd.Count;
                LoadSourceId(addedAppointments, SourceAppointments.CalendarId);
                DestinationAppointments.AddRange(addedAppointments);
                if (syncProfile.SyncMode == SyncModeEnum.TwoWay)
                {
                    //Add appointments to update
                    var updateSourceList = UpdateWithChildId(addedAppointments, SourceAppointments);
                    CalendarSyncEngine.SourceAppointmentsToUpdate.AddRangeCompareForUpdate(updateSourceList);
                }
            }
            return(isSuccess);
        }
Exemple #3
0
        /// <summary>
        /// </summary>
        /// <param name="endDate"></param>
        /// <param name="skipPrivateEntries"></param>
        /// <param name="sourceCalendarSpecificData"></param>
        /// <param name="destinationCalendarSpecificData"></param>
        /// <param name="startDate"></param>
        /// <returns>
        /// </returns>
        private bool LoadAppointments(DateTime startDate, DateTime endDate, bool skipPrivateEntries,
                                      IDictionary <string, object> sourceCalendarSpecificData,
                                      IDictionary <string, object> destinationCalendarSpecificData)
        {
            //Update status
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.SourceReading,
                                                         SourceCalendarService.CalendarServiceName);

            //Get source calendar
            SourceAppointments =
                SourceCalendarService.GetCalendarEventsInRangeAsync(startDate, endDate, skipPrivateEntries,
                                                                    sourceCalendarSpecificData)
                .Result;
            if (SourceAppointments == null)
            {
                CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.SourceReadFailed);
                CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
                return(false);
            }
            //Update status
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.SourceRead,
                                                         SourceCalendarService.CalendarServiceName, SourceAppointments.Count);
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DestReading,
                                                         DestinationCalendarService.CalendarServiceName);

            //Get destination calendar
            DestinationAppointments =
                DestinationCalendarService.GetCalendarEventsInRangeAsync(startDate, endDate, skipPrivateEntries,
                                                                         destinationCalendarSpecificData).Result;
            if (DestinationAppointments == null)
            {
                CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DestReadFailed);
                CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);
                return(false);
            }
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.DestRead,
                                                         DestinationCalendarService.CalendarServiceName, DestinationAppointments.Count);
            CalendarSyncStatus = StatusHelper.GetMessage(SyncStateEnum.Line);

            return(true);
        }
Exemple #4
0
        /// <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);
        }