public void UpdateStatus(string item, bool completed, bool archived) { Parser.Parser p = new Parser.Parser(); string itemValue = p.Extract("item", item); if (string.IsNullOrWhiteSpace(itemValue)) { itemValue = item; } ToDoItem tdi = new ToDoItem() { Description = itemValue, Completed = completed, Archived = archived }; //tdi.Add(new Fragment(item)); AddWithMerge(tdi); }
private static string GetTagsFromKeyValFile(SyncProfile sp, string sha1Hash) { //load by using profile to get sync root //which gives us NWD/config string fileHashIndexPath = Configuration.SyncRootConfigFile(sp.Name, "FileHashIndex"); string tagIndexPath = Configuration.SyncRootConfigFile(sp.Name, "TagIndex"); string tags = ""; if (File.Exists(fileHashIndexPath) && File.Exists(tagIndexPath)) { Parser.Parser p = new Parser.Parser(); List<string> paths = new List<string>(); //get all paths matching hash (may be multiple files, if copied in multiple places) foreach (string lineItem in File.ReadLines(fileHashIndexPath)) { string path = p.Extract("path", lineItem); string hash = p.Extract("sha1Hash", lineItem); if (!string.IsNullOrWhiteSpace(path) && !string.IsNullOrWhiteSpace(hash)) { if (hash.Equals(sha1Hash, StringComparison.CurrentCultureIgnoreCase)) { paths.Add(path); } } } List<string> tagStrings = new List<string>(); //since we may have multiple files for a given hash, need to get all tags for those paths foreach (string lineItem in File.ReadLines(tagIndexPath)) { string path = p.Extract("path", lineItem); string tagString = p.Extract("tags", lineItem); if (paths.Contains(path)) { tagStrings.Add(tagString); } } //remove any duplicates HashSet<string> uniqueTags = new HashSet<string>(); foreach (string tagString in tagStrings) { var theseTags = StringToList(tagString); foreach (string tag in theseTags) { if (!uniqueTags.Contains(tag)) { uniqueTags.Add(tag); } } } tags = string.Join(", ", uniqueTags); } return tags; }
private IEnumerable<NwdUriProcessEntry> GetDeviceHashedMedia(NwdPortableDevice device) { string uri = "NWD/config/FileHashIndex.txt"; NwdPortableDeviceFile hashedMediaIndex = GetFirstFileByUri(uri); if (hashedMediaIndex == null) { Display.Message("[" + uri + "] not found"); return new List<NwdUriProcessEntry>(); //empty list } else { Display.Message("found [" + uri + "]"); //copy to local file system string localFilePath = Configuration.NwdUriToLocalPath(uri); //Display.Message(localFilePath); string localDestinationFolder = Path.GetDirectoryName(localFilePath); //Display.Message(localDestinationFolder); device.DownloadFile(hashedMediaIndex, localDestinationFolder); Display.Message("copied file to [" + localFilePath + "]"); List<string> lineItems = File.ReadAllLines(localFilePath).ToList(); Display.Message("found " + lineItems.Count + " lineItems"); Parser.Parser p = new Parser.Parser(); List<NwdUri> lst = new List<NwdUri>(); List<string> invalidPaths = new List<string>(); foreach (string li in lineItems) { string path = p.Extract("path", li); string hash = p.Extract("sha1Hash", li); List<string> whitelistedFolders = new List<string>(); whitelistedFolders.Add("Pictures"); whitelistedFolders.Add("DCIM"); //NwdUri newUri = Configuration.NwdPathToNwdUri(path); NwdUri newUri = Configuration.NwdPathToNwdUri(path, whitelistedFolders); if (newUri != null) { newUri.Hash = hash; newUri.Path = path; lst.Add(newUri); } else { invalidPaths.Add(path); } } var pathList = (from li in invalidPaths select new { Path = li }).ToList(); if (pathList.Count > 0) { Display.Grid(invalidPaths.Count + " invalid paths skipped", lst, pathList); } else { Display.Grid("0 invalid paths skipped", lst); } var processEntries = (from nwdUri in lst select new NwdUriProcessEntry(nwdUri)).ToList(); return processEntries; } }
public static Dictionary<string, string> LoadFromHashToTagsIndex(SyncProfile sp) { Dictionary<string, string> hashToTagString = new Dictionary<string, string>(); Parser.Parser p = new Parser.Parser(); //use syncprofile to load an existing one if it is there string exportedTagsIndexPath = HashToTagsIndexPath(sp, false); if (File.Exists(exportedTagsIndexPath)) { foreach (string lineItem in File.ReadLines(exportedTagsIndexPath)) { string hash = p.Extract("sha1Hash", lineItem); string tagString = p.Extract("tags", lineItem); hashToTagString[hash] = tagString; } } return hashToTagString; }
private void ParseIntoDictionary(Dictionary<string, string> keyVals, string fragmentVal) { Parser.Parser p = new Parser.Parser(); while (fragmentVal.Length > 0 && p.Validate(fragmentVal) && p.IsAtomic(fragmentVal)) { string firstKey = p.GetFirstKey(fragmentVal); keyVals[firstKey] = p.Extract(firstKey, fragmentVal); fragmentVal = p.TrimKeyVal(firstKey, fragmentVal); } }