/// <summary> /// Load from an existing Task... /// </summary> public static Task Load(string read_file, TaskManager manager) { TaskData data = TaskArchiver.Read(read_file, UrlFromPath(read_file)); Task task = CreateExistingTask(data, read_file, manager); return(task); }
public void Save() { // Do nothing if we don't need to save. Avoids unneccessary saves // e.g on forced quit when we call save for every task. if (!save_needed) { return; } Logger.Log("Saving task '{0}'...", data.Summary); TaskArchiver.Write(filepath, data); if (Saved != null) { Saved(this); } }
public virtual TaskData ReadFile(string read_file, string uri) { TaskData data = new TaskData(uri); string version = string.Empty; StreamReader reader = new StreamReader(read_file, System.Text.Encoding.UTF8); XmlTextReader xml = new XmlTextReader(reader); xml.Namespaces = false; while (xml.Read()) { switch (xml.NodeType) { case XmlNodeType.Element: switch (xml.Name) { case "task": version = xml.GetAttribute("version"); break; case "summary": data.Summary = xml.ReadString(); break; case "details": data.Details = xml.ReadInnerXml(); break; case "create-date": data.CreateDate = XmlConvert.ToDateTime(xml.ReadString(), DATE_TIME_FORMAT); break; case "last-change-date": data.LastChangeDate = XmlConvert.ToDateTime(xml.ReadString(), DATE_TIME_FORMAT); break; case "due-date": data.DueDate = XmlConvert.ToDateTime(xml.ReadString(), DATE_TIME_FORMAT); break; case "completion-date": data.CompletionDate = XmlConvert.ToDateTime(xml.ReadString(), DATE_TIME_FORMAT); break; case "priority": string priority_str = xml.ReadString(); if (priority_str == null || priority_str.Length == 0) { data.Priority = TaskPriority.Normal; } else { switch (priority_str.ToLower()) { case "low": data.Priority = TaskPriority.Low; break; case "normal": data.Priority = TaskPriority.Normal; break; case "high": data.Priority = TaskPriority.High; break; default: data.Priority = TaskPriority.Undefined; break; } } break; case "origin-note-uri": data.OriginNoteUri = xml.ReadString(); break; } break; } } xml.Close(); if (version != TaskArchiver.CURRENT_VERSION) { // Task has old format, so rewrite it. No need // to reread, since we are not adding anything. Logger.Log("Updating task XML to newest format..."); TaskArchiver.Write(read_file, data); } return(data); }