예제 #1
0
        private async Task <Statistics> SynchronizeInternalAsync(IAppointmentSource source, IAppointmentDestination destination, bool force)
        {
            var sourceAppointments = await source
                                     .LoadAllAppointments()
                                     .ToArrayAsync()
                                     .ConfigureAwait(false);

            var destAppointments = await destination
                                   .LoadAllAppointments()
                                   .ToArrayAsync()
                                   .ConfigureAwait(false);

            var newAppointments      = sourceAppointments.Except(destAppointments, LoadedAppointmentIdComparer.Default);
            var deletedAppointments  = destAppointments.Except(sourceAppointments, LoadedAppointmentIdComparer.Default);
            var modifiedAppointments = sourceAppointments.SmartZip(destAppointments, LoadedAppointmentIdComparer.Default,
                                                                   (src, dest) => new { Source = src, Destination = dest });

            if (!force)
            {
                modifiedAppointments = modifiedAppointments.Where(pair => pair.Source.LastModifiedDateTime > pair.Destination.LastModifiedDateTime);
            }

            int created = 0, deleted = 0, updated = 0;

            foreach (var appointment in newAppointments)
            {
                await destination
                .CreateAppointmentAsync(appointment.UniqueId, appointment)
                .ConfigureAwait(false);

                created++;
            }

            foreach (var appointment in deletedAppointments)
            {
                await destination
                .DeleteAppointmentAsync(appointment)
                .ConfigureAwait(false);

                deleted++;
            }

            foreach (var pair in modifiedAppointments)
            {
                await destination
                .UpdateAppointmentAsync(pair.Destination, pair.Source, force)
                .ConfigureAwait(false);

                updated++;
            }

            return(new Statistics(created, deleted, updated));
        }
예제 #2
0
파일: Form1.cs 프로젝트: Samarkin/SyncWhole
 private async void ButtonClick(object sender, EventArgs e)
 {
     _btnLoad.Enabled = false;
     try
     {
         listBox1.Items.Clear();
         if (!(_cmbCalendars.SelectedItem is IAppointmentSourceFactory factory))
         {
             return;
         }
         using (IAppointmentSource source = await factory.ConnectSourceAsync())
         {
             await source.LoadAllAppointments()
             .ForEachAsync(a => BeginInvoke((Action)(() => listBox1.Items.Add(a))));
         }
     }
     finally
     {
         _btnLoad.Enabled = true;
     }
 }