/// <summary> /// Checks the server for new, updated and deleted items and returns them. /// </summary> /// <returns>A collection with all new, updated and deleted items on serverside.</returns> public AppointmentSyncCollection GetUpdates() { AppointmentSyncCollection returnCollection = new AppointmentSyncCollection(); List <CalDavElement> responseListCalDav = GetAllItemsFromServer(); //Check for new and updated items foreach (var remoteitem in responseListCalDav) { String foundETag = _localStorage.FindEtag(remoteitem.Guid); if (foundETag == null) { returnCollection.AddList.Add(CalDavElementToAppointmentItemConverter.Convert(remoteitem)); _localStorage.WriteEntry(remoteitem.Guid, remoteitem.ETag, remoteitem.Url); } else if (foundETag != remoteitem.ETag) { returnCollection.UpdateList.Add(CalDavElementToAppointmentItemConverter.Convert(remoteitem)); _localStorage.EditETag(remoteitem.Guid, remoteitem.ETag); } } ; //Check for deleted items Boolean deleted; OutlookAppointment deletedAppointment = new OutlookAppointment(); List <String> guidsToDelete = new List <String>(); foreach (var localitem in _localStorage.GetAll()) { deleted = true; foreach (var remoteitem in responseListCalDav) { if (remoteitem.Guid.Equals(localitem.Key)) { deleted = false; } } if (deleted) { deletedAppointment.SyncID = localitem.Key; returnCollection.DeleteList.Add(deletedAppointment); guidsToDelete.Add(localitem.Key); } } foreach (var item in guidsToDelete) { _localStorage.DeleteEntry(item); } return(returnCollection); }
/// <summary> /// Drops an existing database, creates a new one, fetches all ics elements from server, /// writes their etags, uids and urls to the database, converts the ics to Outlook Appointments /// and returns them. /// </summary> /// <returns>A collection of all appointments on serverside.</returns> public AppointmentSyncCollection GetInitialSync() { _localStorage.RebuildDatabase(); AppointmentSyncCollection responseList = new AppointmentSyncCollection(); List <CalDavElement> responseListCalDav = GetAllItemsFromServer(); responseListCalDav.ForEach(delegate(CalDavElement element) { _localStorage.WriteEntry(element.Guid, element.ETag, element.Url); responseList.AddList.Add(CalDavElementToAppointmentItemConverter.Convert(element)); }); return(responseList); }