/// <summary> /// Appends a task to the task file. /// </summary> /// <param name="taskToAdd">The task to append.</param> /// <returns>True if operation was successful; False if not.</returns> internal bool AddTaskToFile(Task taskToAdd) { try { XDocument doc = XDocument.Load(taskStorageFile); XElement newTaskElem = taskToAdd.ToXElement(); doc.Root.Add(newTaskElem); doc.Save(taskStorageFile); } catch (Exception e) { Logger.Error(e, "AddTaskToFile::Storage"); AlertBox.Show("A problem was encoutered saving the new task to file."); return false; } return true; }
/// <summary> /// Updates a task in the task file. /// </summary> /// <param name="taskToUpdate">The task to update.</param> /// <returns>True if operation was successful; False if not.</returns> internal bool UpdateTask(Task taskToUpdate) { XDocument doc = XDocument.Load(taskStorageFile); var task = from node in doc.Descendants("Task") let attr = node.Attribute("id") where attr != null && attr.Value == taskToUpdate.ID.ToString() select node; if (task == null) return false; try { XElement taskNode = task.First(); taskNode.ReplaceWith(taskToUpdate.ToXElement()); } catch (Exception e) { Logger.Error(e, "UpdateTask::Storage"); return false; } doc.Save(taskStorageFile); return true; }