/// <summary> /// Parse a GGItem to CSV string /// </summary> /// <param name="ggItem"></param> /// <returns></returns> private string ToCSVString(GGItem ggItem) { string description = ggItem.GetDescription().Replace(Environment.NewLine, "[newline]"); description = description.Replace(",", "[comma]"); string tag = ggItem.GetTag().Replace(Environment.NewLine, "[newline]"); tag = tag.Replace(",", "[comma]"); CultureInfo usCulture = CultureInfo.CreateSpecificCulture("en-US"); return description + "," + ggItem.GetEndDate().ToString(usCulture) + "," + tag + "," + ggItem.GetLastModifiedTime().ToString() + "," + ggItem.GetEventAbsoluteUrl() + "," + ggItem.GetPath(); }
/// <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()); } }