I'm doing the synchronization between the two lists.
IList<Event> GoogleEvents
and Table<myEvent> DB.Events;
On google side i'm using this
String Summary,
String Description,
EventDateTime Start,
EventDateTime End,
Event.RemindersData Reminders;
On db side like this
my code is like this
foreach (myEvent item in DB.Events)
{
if (item.GoogleID == "" || item.GoogleID == null)// i add event my db
{
//Add dbEvent to google and save id to googleid column
}
}
foreach (Event item in myGoogleCalendar.Items)
{
if (DB.Events.Where(o => o.GoogleID == item.Id).Count() == 0)// i add event google
{
//Add googleEvent to dbEvent
}
else
{
//This event also existing in two server
myEvent dbEvent = DB.Olaylar.Where(o => o.GoogleID == item.Id).First();
if(item.Updated.Value == dbEvent.UpdateTime) continue;//Same
if (item.Updated.Value > dbEvent.UpdateTime)
{
//Google event is new
}
else
{
//dbEvent is new
}
}
}
There is one big problem : I forgot deletion
Where should I add deleting events part and how ?
The problem is not to implement a delete synchronization, but to recognize, whether the event has been deleted in one list or added to the other list.
I recommend not to delete events from the DB.Events list, but to mark them as deleted.
Therefore, you need a flag
in your type
myEvent
.In Google list (I assume you use https://developers.google.com/google-apps/calendar/v3/reference/events) you don't have such a flag. So your algorithm needs to be a bit tricky.
So you need the first synchronize from the Google list
Then your synchronize from your DB.Events list
This works in the scenarios
I created a Gist: https://gist.github.com/ricjac/947991ba96488c640bfe