Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        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);
        }
Beispiel #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);
        }