public SynergyV5ListItemNode(string listName, string itemValue) : base("SynergyV5ListItem/" + Hashes.Sha1ForStringValue(listName + ": " + itemValue)) { Item = new SynergyV5ListItem(itemValue); List = new SynergyV5List(listName); }
public void Add(int index, SynergyV5ListItem sli) { if (IsNotDuplicate(sli)) { if(index > ListItems.Count) { index = ListItems.Count; } ListItems.Insert(index, sli); } }
private bool IsNotDuplicate(SynergyV5ListItem sli) { bool exists = false; foreach(SynergyV5ListItem existingListItem in ListItems) { string existingValue = existingListItem.ItemValue; if(existingValue.Equals(sli.ItemValue, StringComparison.CurrentCultureIgnoreCase)) { exists = true; } } return !exists; }
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); } } }
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); } } }
//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; }