Пример #1
0
        public async Task LoadsCalendarFromUrl()
        {
            Calendar calendar = await service.Read(new Uri(Registry.AppSettings["iCalUrl"]));

            Assert.IsNotNull(calendar);
            Assert.AreNotEqual(0, calendar.Events.Count);
        }
Пример #2
0
        public async Task ExecutesEventSyncOperations()
        {
            Uri iCalUrl = new Uri(Registry.AppSettings["iCalUrl"]);
            var iCal    = await iCalService.Read(iCalUrl);

            string gCalID = await gCalEventSyncer.GetOrCreateGCalID(iCalUrl);

            var operations = await gCalEventSyncer.GetEventSyncOperations(gCalID, iCal);

            foreach (var operation in operations.Take(10))
            {
                await operation.Execute(gCalService);
            }
        }
Пример #3
0
        public async Task Execute(Calendar calendar, int eventLimit = 100)
        {
            await CreateGCalIfNotExists(calendar);

            logger("Reading iCal data...");
            var iCal = await iCalService.Read(new Uri(calendar.iCalendarUrl));

            calendar.iCalendarEventCount = iCal.Events.Count;

            logger("Determining events to sync...");
            var events = await gCalEventSyncer.GetEventSyncOperations(calendar.GoogleCalendarID, iCal);

            using (var countTracker = calendar.BeginSyncCountTracking(
                       remainingCreateCount: events.OfType <ImportGCalEventOperation>().Count(),
                       remainingUpdateCount: events.OfType <UpdateGCalEventOperation>().Count(),
                       remainingDeleteCount: events.OfType <DeleteGCalEventOperation>().Count()))
            {
                if (events.Any())
                {
                    var eventsToSync = events.Take(eventLimit).ToArray();
                    logger($"Syncing {eventsToSync.Count()} events...");

                    foreach (var @event in eventsToSync)
                    {
                        await @event.Execute(gCalService);

                        countTracker.CreateCount += @event is ImportGCalEventOperation ? 1 : 0;
                        countTracker.UpdateCount += @event is UpdateGCalEventOperation ? 1 : 0;
                        countTracker.DeleteCount += @event is DeleteGCalEventOperation ? 1 : 0;
                    }
                }
                else
                {
                    logger("No events to sync.");
                }
            }
        }