public SynergyV5ListItemNode(string listName, string itemValue) : base("SynergyV5ListItem/" + Hashes.Sha1ForStringValue(listName + ": " + itemValue)) { Item = new SynergyV5ListItem(itemValue); List = new SynergyV5List(listName); }
public static XElement Export(SynergyV5List lst) { XElement synergyListEl = new XElement(TAG_SYNERGY_LIST); synergyListEl.Add(new XAttribute(ATTRIBUTE_LIST_NAME, lst.ListName)); string activatedAt = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(lst.ActivatedAt); string shelvedAt = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(lst.ShelvedAt); synergyListEl.Add( new XAttribute(ATTRIBUTE_ACTIVATED_AT, activatedAt)); synergyListEl.Add( new XAttribute(ATTRIBUTE_SHELVED_AT, shelvedAt)); for (int i = 0; i < lst.ListItems.Count; i++) { SynergyV5ListItem item = lst.ListItems[i]; XElement synergyItemEl = new XElement(TAG_SYNERGY_ITEM); synergyItemEl.Add(new XAttribute(ATTRIBUTE_POSITION, i)); XElement itemValueEl = new XElement(TAG_ITEM_VALUE); itemValueEl.SetValue(item.ItemValue); synergyItemEl.Add(itemValueEl); SynergyV5ToDo toDo = item.ToDo; if (toDo != null) { string toDoActivatedAt = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ActivatedAt); string toDoCompletedAt = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.CompletedAt); string toDoArchivedAt = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ArchivedAt); XElement toDoEl = new XElement(TAG_TO_DO, new XAttribute(ATTRIBUTE_ACTIVATED_AT, toDoActivatedAt), new XAttribute(ATTRIBUTE_COMPLETED_AT, toDoCompletedAt), new XAttribute(ATTRIBUTE_ARCHIVED_AT, toDoArchivedAt)); synergyItemEl.Add(toDoEl); } synergyListEl.Add(synergyItemEl); } return synergyListEl; }
private async void AsyncMenuItemExportSynergyV5ActiveLists_Click(object sender, RoutedEventArgs e) { //var activeLists = _dbV5.GetAllActiveLists(); await Task.Run(() => { string detail; List<SynergyV5List> activeLists = new List<SynergyV5List>(); var activeListNames = _dbV5.GetAllActiveListNames(); //mirrors Gauntlet foreach (string listName in activeListNames) { SynergyV5List lst = new SynergyV5List(listName); detail = "loading list: " + lst.ListName; StatusDetailUpdate(detail); //save() populates each list as part of its process _dbV5.Save(lst); activeLists.Add(lst); } //XDocument doc = // new XDocument(Xml.Xml.Export(activeLists)); XElement synergySubsetEl = new XElement(Xml.Xml.TAG_SYNERGY_SUBSET); detail = "exporting lists to XML"; StatusDetailUpdate(detail); foreach (SynergyV5List lst in activeLists) { synergySubsetEl.Add(Xml.Xml.Export(lst)); } XDocument doc = new XDocument( new XElement("nwd", synergySubsetEl)); //here, take doc and save to all sync locations string fileName = NwdUtils.GetTimeStamp_yyyyMMddHHmmss() + "-nwd-synergy-v5.xml"; var allFolders = Configuration.GetActiveSyncProfileIncomingXmlFolders(); foreach (string xmlIncomingFolderPath in allFolders) { string fullFilePath = System.IO.Path.Combine(xmlIncomingFolderPath, fileName); doc.Save(fullFilePath); } }); statusDetail.Text = "finished."; }
private void PopulateListItems(SynergyV5List synLst, SQLiteCommand cmd) { //mirrors synergyV5PopulateListItems() in Gauntlet //select list items by position for list cmd.Parameters.Clear(); cmd.CommandText = SYNERGY_V5_SELECT_LIST_ITEMS_AND_TODOS_BY_POSITION_FOR_LIST_ID_X; SQLiteParameter listIdParam = new SQLiteParameter(); listIdParam.Value = synLst.ListId; cmd.Parameters.Add(listIdParam); using (var rdr = cmd.ExecuteReader()) { int itemId, position, listItemId, toDoId; String itemValue, toDoActivatedAtString, toDoCompletedAtString, toDoArchivedAtString; while (rdr.Read()) { itemId = GetNullableInt32(rdr, 0); itemValue = GetNullableString(rdr, 1); position = GetNullableInt32(rdr, 2); listItemId = GetNullableInt32(rdr, 3); toDoId = GetNullableInt32(rdr, 4); toDoActivatedAtString = GetNullableString(rdr, 5); toDoCompletedAtString = GetNullableString(rdr, 6); toDoArchivedAtString = GetNullableString(rdr, 7); SynergyV5ListItem sli = new SynergyV5ListItem(itemValue); sli.ItemId = itemId; sli.ListItemId = listItemId; if(toDoId > 0) { //has toDo item SynergyV5ToDo toDo = new SynergyV5ToDo(); toDo.ToDoId = toDoId; DateTime? activated = TimeStamp.YYYY_MM_DD_HH_MM_SS_UTC_ToDateTime(toDoActivatedAtString); DateTime? completed = TimeStamp.YYYY_MM_DD_HH_MM_SS_UTC_ToDateTime(toDoCompletedAtString); DateTime? archived = TimeStamp.YYYY_MM_DD_HH_MM_SS_UTC_ToDateTime(toDoArchivedAtString); toDo.SetTimeStamps(activated, completed, archived); sli.ToDo = toDo; } synLst.Add(position, sli); } } }
private void PopulateIdAndTimeStamps(SynergyV5List synLst, SQLiteCommand cmd) { string listName = synLst.ListName; cmd.Parameters.Clear(); cmd.CommandText = SYNERGY_V5_SELECT_ID_ACTIVATED_AT_SHELVED_AT_FOR_LIST_NAME; SQLiteParameter listNameParam = new SQLiteParameter(); listNameParam.Value = listName; cmd.Parameters.Add(listNameParam); using (var rdr = cmd.ExecuteReader()) { if (rdr.Read()) { int listId = rdr.GetInt32(0); string activatedString = rdr.GetString(1); string shelvedString = rdr.GetString(2); DateTime? activated = TimeStamp.YYYY_MM_DD_HH_MM_SS_UTC_ToDateTime(activatedString); DateTime? shelved = TimeStamp.YYYY_MM_DD_HH_MM_SS_UTC_ToDateTime(shelvedString); synLst.ListId = listId; synLst.SetTimeStamps(activated, shelved); } } }
internal void Save(SynergyV5List synLst, SynergyV5ListItem sli, int position, SQLiteCommand cmd) { if(synLst.ListId < 1) { UI.Display.Message("unable to save list item, list id not set"); } else { //item id should be set, or ensured if not if(sli.ItemId < 1) { EnsureSynergyV5ItemValue(sli.ItemValue, cmd); sli.ItemId = GetIdForSynergyV5ItemValue(sli.ItemValue, cmd); } if(sli.ListItemId < 1) { EnsureListItemPosition(synLst.ListId, sli.ItemId, position, cmd); sli.ListItemId = GetListItemId(synLst.ListId, sli.ItemId, cmd); } UpdatePositionForListItemId(position, sli.ListItemId, cmd); SynergyV5ToDo toDo = sli.ToDo; if(toDo != null) { string activated = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ActivatedAt); string completed = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.CompletedAt); string archived = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ArchivedAt); EnsureToDoForListItemId(sli.ListItemId, activated, completed, archived, cmd); UpdateToDoForListItemId(activated, completed, archived, sli.ListItemId, cmd); } } }
internal void Save(SynergyV5List synLst) { // parallels gauntlet logic // (Android App: http://github.com/BBuchholz/Gauntlet) string listName = synLst.ListName; //populate list id if not set, creating list if !exists //this runs in its own transaction so the list will have written to db //before the later transaction needs to access its id if (synLst.ListId < 1) { EnsureSynergyV5ListName(listName); } using (var conn = new SQLiteConnection( @"Data Source=" + Configuration.GetSqliteDbPath(DbName))) { conn.Open(); using (var cmd = new SQLiteCommand(conn)) { using (var transaction = conn.BeginTransaction()) { //try { string activated = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(synLst.ActivatedAt); string shelved = TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(synLst.ShelvedAt); //ensure current timestamps UpdateTimeStampsForSynergyV5ListName(activated, shelved, listName, cmd); PopulateIdAndTimeStamps(synLst, cmd); PopulateListItems(synLst, cmd); // for each SynergyV5ListItem, // do the same (populate item id, ensure, etc.) for (int i = 0; i < synLst.ListItems.Count; i++) { SynergyV5ListItem sli = synLst.ListItems[i]; Save(synLst, sli, i, cmd); } transaction.Commit(); } //catch (Exception ex) //{ // //handle exception here // transaction.Rollback(); // throw ex; // //UI.Display.Exception(ex); //} } } conn.Close(); } }
public List<SynergyV5List> GetAllActiveLists() { List<SynergyV5List> activeLists = new List<SynergyV5List>(); var activeListNames = GetAllActiveListNames(); //mirrors Gauntlet foreach(string listName in activeListNames) { SynergyV5List lst = new SynergyV5List(listName); //save() populates each list as part of its process Save(lst); activeLists.Add(lst); } return activeLists; }
//public static XElement Export(List<SynergyV5List> synergyV5Lists) //{ // XElement synergySubsetEl = new XElement(TAG_SYNERGY_SUBSET); // foreach (SynergyV5List lst in synergyV5Lists) // { // XElement synergyListEl = // new XElement(TAG_SYNERGY_LIST); // synergyListEl.Add(new XAttribute(ATTRIBUTE_LIST_NAME, lst.ListName)); // string activatedAt = // TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(lst.ActivatedAt); // string shelvedAt = // TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(lst.ShelvedAt); // synergyListEl.Add( // new XAttribute(ATTRIBUTE_ACTIVATED_AT, activatedAt)); // synergyListEl.Add( // new XAttribute(ATTRIBUTE_SHELVED_AT, shelvedAt)); // for(int i = 0; i < lst.ListItems.Count; i++) // { // SynergyV5ListItem item = lst.ListItems[i]; // XElement synergyItemEl = // new XElement(TAG_SYNERGY_ITEM); // synergyItemEl.Add(new XAttribute(ATTRIBUTE_POSITION, i)); // XElement itemValueEl = // new XElement(TAG_ITEM_VALUE); // itemValueEl.SetValue(item.ItemValue); // synergyItemEl.Add(itemValueEl); // SynergyV5ToDo toDo = item.ToDo; // if(toDo != null) // { // string toDoActivatedAt = // TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ActivatedAt); // string toDoCompletedAt = // TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.CompletedAt); // string toDoArchivedAt = // TimeStamp.To_UTC_YYYY_MM_DD_HH_MM_SS(toDo.ArchivedAt); // XElement toDoEl = // new XElement(TAG_TO_DO, // new XAttribute(ATTRIBUTE_ACTIVATED_AT, toDoActivatedAt), // new XAttribute(ATTRIBUTE_COMPLETED_AT, toDoCompletedAt), // new XAttribute(ATTRIBUTE_ARCHIVED_AT, toDoArchivedAt)); // synergyItemEl.Add(toDoEl); // } // synergyListEl.Add(synergyItemEl); // } // synergySubsetEl.Add(synergyListEl); // } // return synergySubsetEl; //} public static List<SynergyV5List> RetrieveSynergyV5Lists(XDocument doc) { List<SynergyV5List> allLists = new List<SynergyV5List>(); foreach(XElement listEl in doc.Descendants(TAG_SYNERGY_LIST)) { string listName = listEl.Attribute(ATTRIBUTE_LIST_NAME).Value; string activatedAt = listEl.Attribute(ATTRIBUTE_ACTIVATED_AT).Value; string shelvedAt = listEl.Attribute(ATTRIBUTE_SHELVED_AT).Value; DateTime? activatedAtTime = ToTime(activatedAt); DateTime? shelvedAtTime = ToTime(shelvedAt); SynergyV5List lst = new SynergyV5List(listName); lst.SetTimeStamps(activatedAtTime, shelvedAtTime); foreach(XElement itemEl in listEl.Descendants(TAG_SYNERGY_ITEM)) { string position = itemEl.Attribute(ATTRIBUTE_POSITION).Value; string itemValue = itemEl.Descendants(TAG_ITEM_VALUE).First().Value; var toDos = itemEl.Descendants(TAG_TO_DO); if(toDos.Count() > 0) { XElement toDoEl = toDos.First(); string itemActivatedAt = toDoEl.Attribute(ATTRIBUTE_ACTIVATED_AT).Value; string completedAt = toDoEl.Attribute(ATTRIBUTE_COMPLETED_AT).Value; string archivedAt = toDoEl.Attribute(ATTRIBUTE_ARCHIVED_AT).Value; DateTime? itemActivatedAtTime = ToTime(itemActivatedAt); DateTime? completedAtTime = ToTime(completedAt); DateTime? archivedAtTime = ToTime(archivedAt); SynergyV5ListItem item = new SynergyV5ListItem(itemValue, itemActivatedAtTime, completedAtTime, archivedAtTime); lst.ListItems.Add(item); } else { lst.ListItems.Add(new SynergyV5ListItem(itemValue)); } } allLists.Add(lst); } return allLists; }