public void SyncCollectionTest()
        {
            DataMigrationHelper.AddUsersFast(100, DbAccess);

            DbCollection <Users_Col> dbCollection = null;

            Assert.That(() => dbCollection = DbAccess.CreateDbCollection <Users_Col>(), Throws.Nothing);
            Assert.That(dbCollection, Is.Not.Empty);
            Assert.That(dbCollection.Count, Is.EqualTo(100));

            Assert.That(() => dbCollection.Add(new Users_Col()), Throws.Nothing);
            Assert.That(dbCollection.Count, Is.EqualTo(101));

            Assert.That(() => dbCollection.SaveChanges(DbAccess), Throws.Nothing);
            Assert.That(() => DbAccess.Select <Users_Col>().Length, Is.EqualTo(101));

            Assert.That(() => dbCollection.Remove(dbCollection.First()), Throws.Nothing);
            Assert.That(dbCollection.Count, Is.EqualTo(100));

            Assert.That(() => dbCollection.SaveChanges(DbAccess), Throws.Nothing);
            Assert.That(() => DbAccess.Select <Users_Col>().Length, Is.EqualTo(100));

            var user25 = dbCollection[25];

            user25.UserName = Guid.NewGuid().ToString();

            Assert.That(() => dbCollection.GetEntryState(user25), Is.EqualTo(CollectionStates.Changed));
            Assert.That(() => dbCollection.SaveChanges(DbAccess), Throws.Nothing);
            Assert.That(() => dbCollection.GetEntryState(user25), Is.EqualTo(CollectionStates.Unchanged));

            Assert.That(() => DbAccess.SelectSingle <Users_Col>(user25.User_ID), Is.Not.Null.And
                        .Property("User_ID").EqualTo(user25.User_ID)
                        .And
                        .Property("UserName").EqualTo(user25.UserName));
        }
        private async Task <IList <GenericEvent> > PullEvents()
        {
            Log.Info("Pulling events");
            var myEvts = new DbCollection <GenericEvent>();

            try
            {
                var evts = await Service.Events.List(_settings.CalendarId).ExecuteAsync();

                foreach (var evt in evts.Items)
                {
                    var iCalUid = StringHelper.GetString(StringHelper.GoogleBase32.FromBaseString(evt.Id));
                    var myEvt   = new GenericEvent(id: iCalUid,
                                                   summary: evt.Summary,
                                                   description: evt.Description,
                                                   location: new GenericLocation {
                        Name = evt.Location
                    });
                    // Organizer
                    if (evt.Organizer != null)
                    {
                        myEvt.Organizer = new GenericPerson
                        {
                            Email = evt.Organizer.Email,
                            Name  = evt.Organizer.DisplayName
                        };
                    }
                    // Creator
                    if (evt.Creator != null)
                    {
                        myEvt.Creator = new GenericPerson
                        {
                            Email = evt.Creator.Email,
                            Name  = evt.Creator.DisplayName
                        };
                    }
                    // Start
                    if (evt.Start != null)
                    {
                        myEvt.Start = evt.Start.DateTime;
                    }
                    // End
                    if (evt.End != null)
                    {
                        myEvt.End = evt.End.DateTime;
                    }
                    // Creation date
                    if (evt.Created.HasValue)
                    {
                        myEvt.Created = evt.Created;
                    }
                    // Recurrence
                    if (evt.Recurrence != null)
                    {
                        myEvt.Recurrence = new GoogleRecurrence();
                        ((GoogleRecurrence)myEvt.Recurrence).Parse(evt.Recurrence[0]);
                        //warning: this only parses one line inside Recurrence...
                    }
                    // Attendees
                    if (evt.Attendees != null)
                    {
                        myEvt.Attendees = new List <GenericAttendee>();
                        foreach (var attendee in evt.Attendees)
                        {
                            ResponseStatus r;
                            switch (attendee.ResponseStatus)
                            {
                            case "accepted":
                                r = ResponseStatus.Accepted;
                                break;

                            case "tentative":
                                r = ResponseStatus.Tentative;
                                break;

                            case "needsAction":
                                r = ResponseStatus.NotResponded;
                                break;

                            case "declined":
                                r = ResponseStatus.Declined;
                                break;

                            default:
                                r = ResponseStatus.None;
                                break;
                            }
                            myEvt.Attendees.Add(
                                new GenericAttendee
                            {
                                Email    = attendee.Email,
                                Name     = attendee.DisplayName,
                                Response = r
                            }
                                );
                        }
                    }
                    myEvts.Add(myEvt);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception", ex);
            }
            return(myEvts);
        }
 private async Task<IList<GenericEvent>> PullEvents()
 {
     Log.Info("Pulling events");
     var myEvts = new DbCollection<GenericEvent>();
     try
     {
         var evts = await Service.Events.List(_settings.CalendarId).ExecuteAsync();
         foreach (var evt in evts.Items)
         {
             var iCalUid = StringHelper.GetString(StringHelper.GoogleBase32.FromBaseString(evt.Id));
             var myEvt = new GenericEvent(   id: iCalUid,
                                             summary: evt.Summary,
                                             description: evt.Description,
                                             location: new GenericLocation {Name = evt.Location});
             // Organizer
             if (evt.Organizer != null)
             {
                 myEvt.Organizer = new GenericPerson
                 {
                     Email = evt.Organizer.Email,
                     Name = evt.Organizer.DisplayName
                 };
             }
             // Creator
             if (evt.Creator != null)
             {
                 myEvt.Creator = new GenericPerson
                 {
                     Email = evt.Creator.Email,
                     Name = evt.Creator.DisplayName
                 };
             }
             // Start
             if (evt.Start != null)
             {
                 myEvt.Start = evt.Start.DateTime;
             }
             // End
             if (evt.End != null)
             {
                 myEvt.End = evt.End.DateTime;
             }
             // Creation date
             if (evt.Created.HasValue)
             {
                 myEvt.Created = evt.Created;
             }
             // Recurrence
             if (evt.Recurrence != null)
             {
                 myEvt.Recurrence = new GoogleRecurrence();
                 ((GoogleRecurrence) myEvt.Recurrence).Parse(evt.Recurrence[0]);
                     //warning: this only parses one line inside Recurrence...
             }
             // Attendees
             if (evt.Attendees != null)
             {
                 myEvt.Attendees = new List<GenericAttendee>();
                 foreach (var attendee in evt.Attendees)
                 {
                     ResponseStatus r;
                     switch (attendee.ResponseStatus)
                     {
                         case "accepted":
                             r = ResponseStatus.Accepted;
                             break;
                         case "tentative":
                             r = ResponseStatus.Tentative;
                             break;
                         case "needsAction":
                             r = ResponseStatus.NotResponded;
                             break;
                         case "declined":
                             r = ResponseStatus.Declined;
                             break;
                         default:
                             r = ResponseStatus.None;
                             break;
                     }
                     myEvt.Attendees.Add(
                         new GenericAttendee
                         {
                             Email = attendee.Email,
                             Name = attendee.DisplayName,
                             Response = r
                         }
                         );
                 }
             }
             myEvts.Add(myEvt);
         }
     }
     catch (Exception ex)
     {
         Log.Error("Exception", ex);
     }
     return myEvts;
 }