Beispiel #1
0
        /// <summary>
        /// Sync local GGItem to GG calendar
        /// </summary>
        /// <param name="addToLocal">List of GGItems to be added to local GGList</param>
        /// <param name="removeFromLocal">List of GGItems to be removed from local GGList</param>
        /// <param name="GGService">Google calendar service object</param>
        /// <param name="GGCalendar">GG calendar</param>
        /// <param name="GGEvents">Google event query results</param>
        /// <param name="server">List of bools to indicate if a Google event has a local version</param>
        /// <param name="ggItem">The local GGItem to be synced</param>
        private void SyncFromLocalToServer(List<GGItem> addToLocal, List<GGItem> removeFromLocal, CalendarService GGService, CalendarEntry GGCalendar, EventFeed GGEvents, List<bool> server, GGItem ggItem)
        {
            if (ggItem.GetEventAbsoluteUrl() == String.Empty)
            {   // Not synced : add to GG Calendar
                Log("Never synced");
                ggItem.SetEventAbsoluteUrl(AddGGEvent(GGService, GGCalendar, ggItem));
                Log("Add to server: " + ggItem.ToString());
            }
            else
            {   // Synced before
                Log("Synced before");
                string id = ggItem.GetEventAbsoluteUrl();

                // Find the coresponding Google event
                AtomEntry theEvent = FindGoogleEvent(GGEvents, server, id);

                if (theEvent == null)
                {   // Not found: deleted on GG calendar : remove from local list
                    Log("Event is deleted on server");
                    removeFromLocal.Add(ggItem);
                    Log("Removed in local list");
                }
                else
                {   // Found
                    SolveConflict(addToLocal, removeFromLocal, GGService, GGCalendar, ggItem, theEvent);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Solve conflict by comparing last modified time
 /// </summary>
 /// <param name="addToLocal">List of GGItems to be added to local GGList</param>
 /// <param name="removeFromLocal">List of GGItems to be removed from local GGList</param>
 /// <param name="GGService">Google calendar service object</param>
 /// <param name="GGCalendar">GG calendar</param>
 /// <param name="ggItem">The local GGItem to be compared</param>
 /// <param name="theEvent">The Google event to be compared</param>
 private void SolveConflict(List<GGItem> addToLocal, List<GGItem> removeFromLocal, CalendarService GGService, CalendarEntry GGCalendar, GGItem ggItem, AtomEntry theEvent)
 {
     if (theEvent.Updated.CompareTo(ggItem.GetLastModifiedTime()) < 0)
     {   // Local is the latest version : delete on server, then add the latest one
         Log("Local is the latest");
         theEvent.Delete();
         Log("Delete on server");
         ggItem.SetEventAbsoluteUrl(AddGGEvent(GGService, GGCalendar, ggItem));
         Log("Add to server: " + ggItem.ToString());
     }
     else
     {   // Server is the latest version : delete on local, then add the latest one
         Log("Server is the latest");
         EventEntry e = (EventEntry)theEvent;
         GGItem newGGItem = new GGItem(e.Title.Text, e.Times[0].EndTime, ExtractTagFromContents(e.Content.Content), DateTime.Parse(e.Updated.ToLongTimeString()), e.Id.AbsoluteUri, ExtractPathFromContents(e.Content.Content));
         removeFromLocal.Add(ggItem);
         addToLocal.Add(newGGItem);
         Log("Update to lsocal: " + newGGItem.ToString());
     }
 }