/// <summary> /// Writes the items added, updated and deleted in Outlook back to the server. /// </summary> /// <param name="syncItems">A collection with all new, updated and deleted items on Outlook side.</param> /// <returns>The servers SyncIDs for items newly added in Outlook as dictionary.</returns> public Dictionary <string, string> DoUpdates(AppointmentSyncCollection syncItems) { Dictionary <string, string> newSyncIds = new Dictionary <string, string>(); //Delete items from server foreach (var deleteItem in syncItems.DeleteList) { if (_localStorage.FindUrl(deleteItem.SyncID) != null && !_localStorage.FindUrl(deleteItem.SyncID).Equals("")) { try { this.QueryCaldavServer("DELETE", new WebHeaderCollection(), "", null, _localStorage.FindUrl(deleteItem.SyncID)); } catch (WebException e) { Debug.WriteLine(e.Message); MessageBox.Show("The following error occurred: " + e.Message); } _localStorage.DeleteEntry(deleteItem.SyncID); } } //Update items on server foreach (var updateItem in syncItems.UpdateList) { if (_localStorage.FindUrl(updateItem.SyncID) != null && !_localStorage.FindUrl(updateItem.SyncID).Equals("")) { try { this.QueryCaldavServer("PUT", new WebHeaderCollection(), AppointmentItemXmlParser.Parse(updateItem), "text/calendar", _localStorage.FindUrl(updateItem.SyncID)); } catch (WebException e) { Debug.WriteLine(e.Message); MessageBox.Show("The following error occurred: " + e.Message); } _localStorage.EditETag(updateItem.SyncID, GetSingleItemFromServer(_localStorage.FindUrl(updateItem.SyncID)).ETag); } } //Add items to server foreach (var addItem in syncItems.AddList) { String guid = System.Guid.NewGuid().ToString(); addItem.SyncID = guid; newSyncIds.Add(addItem.GlobalAppointmentID, guid); String url = guid + ".ics"; try { this.QueryCaldavServer("PUT", new WebHeaderCollection(), AppointmentItemXmlParser.Parse(addItem), "text/calendar", url); string url_corrected = CheckSlashAtEnd(new Uri(calendarUrl).PathAndQuery) + url; CalDavElement newElement = GetSingleItemFromServer(url_corrected); _localStorage.WriteEntry(guid, newElement.ETag, newElement.Url); } catch (WebException e) { Debug.WriteLine(e.Message); MessageBox.Show("The following error occurred: " + e.Message); } } //Return the dictionary with the new SyncIDs return(newSyncIds); }