public void TestContains() { //This is hackish, need to test that List.Contains will work as expected for FileElements Assert.AreEqual(0, lst.Count); lst.Add(fe); Assert.AreEqual(1, lst.Count); lst.Add(fe); //should be able to add again Assert.AreEqual(2, lst.Count); Assert.IsTrue(lst.Contains(fe)); FileElement feOther = new FileElement() { Name = "Other.txt", Path = @"C:\NWD-SNDBX\Other.txt" }; Assert.IsFalse(lst.Contains(feOther)); if (!lst.Contains(feOther)) { lst.Add(feOther); } Assert.AreEqual(3, lst.Count); if (!lst.Contains(feOther)) { lst.Add(feOther); } Assert.AreEqual(3, lst.Count); //should still be 3 }
public void PerformAction(FileElement fe) { FileNameTagExtractor te = new FileNameTagExtractor(); //string timeStamp = null; string fName = System.IO.Path.GetFileNameWithoutExtension(fe.Name); List<string> extractions = te.ExtractFromString(fName); List<string> currentTags = tgrGrid.GetTagsForCurrentSelection(); List<string> nonDuplicates = new List<string>(); foreach (string tag in extractions) { if (!currentTags.Contains(tag)) { nonDuplicates.Add(tag); } } if (nonDuplicates.Count > 0) { if (MessageBox.Show("Would you like to add tags:[" + TagString.Parse(nonDuplicates) + "]?", "Add Tags?", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { tgrGrid.AppendTagsToCurrentTagStringAndUpdate(extractions); } } }
private string CopyToVoiceMemoStaging(FileElement fe) { string vmStagingFolderPath = Configuration.VoiceMemoStagingFolder; //ensure directory exists Directory.CreateDirectory(vmStagingFolderPath); //create destination file path string fName = System.IO.Path.GetFileName(fe.Path); string destFilePath = System.IO.Path.Combine(vmStagingFolderPath, fName); //store hash for source file string hash = Hashes.Sha1ForFilePath(fe.Path); db.StoreHashForPath(hash, fe.Path); //copy if !exists, else message if (!File.Exists(destFilePath)) { File.Copy(fe.Path, destFilePath); return "copied to: " + destFilePath; } else { return "file exists: " + destFilePath; } }
public void PerformAction(FileElement fe) { if (fe != null && File.Exists(fe.Path)) { player = new SoundPlayer(fe.Path); player.Play(); } }
public void PerformAction(FileElement fe) { if (fe != null && chkPlayIfChecked.IsChecked) { SoundPlayer player = new SoundPlayer(fe.Path); player.Play(); } }
/// <summary> /// will return a file element with tag string, /// path, and name populated from supplied /// TagMatrix /// </summary> /// <param name="path"></param> /// <param name="matrix"></param> /// <returns></returns> public static FileElement FromPath(string path, TagMatrix matrix) { //return new FileElement //{ // Path = path, // Name = System.IO.Path.GetFileName(path), // TagString = matrix.GetTagString(path) //}; FileElement fe = new FileElement(path); fe.TagString = matrix.GetTagString(path); return fe; }
public void PerformAction(FileElement fe) { if (enabled != null && enabled.IsCheckable && enabled.IsChecked && !masterTagMatrix.FileElementHasMetaTag(fe, "timestamp")) { TimeStampExtractor tse = new TimeStampExtractor(); string timeStamp = null; List<string> extractions = tse.ExtractFromString(fe.Name); if (extractions.Count > 0) { if (extractions.Count == 1) { timeStamp = extractions.First(); } else { MessageBox.Show("ambiguous timestamp matches, unable to auto extract"); } } else { //TODO:extract from file attributes if none exists - github issue #7 string fromFile = tse.ExtractFromFileAttributes(fe.Path); if (fromFile != null) { //we try for file name first, but if not found, use file attributes timeStamp = fromFile; } } if (timeStamp != null) { if (MessageBox.Show("Would you like to add metaTag timestamp:[" + timeStamp + "]?", "Add TimeStamp?", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { tgrGrid.AppendTagToCurrentTagStringAndUpdate("timestamp: " + timeStamp); } } } }
public void PerformAction(FileElement fe) { if (fe != null) { //fileElement = fe; //BitmapImage image = new BitmapImage(); //image.BeginInit(); //image.UriSource = new Uri(fe.Path); //image.EndInit(); //imageControl.Source = image; fileElement = fe; BitmapImage image = new BitmapImage(); if (File.Exists(fe.Path)) { try { using (FileStream stream = File.OpenRead(fe.Path)) { image.BeginInit(); image.StreamSource = stream; image.CacheOption = BitmapCacheOption.OnLoad; image.EndInit(); } imageControl.Source = image; } catch (Exception ex) { imageControl.Source = null; Display.Message("error opening file path [" + fe.Path + "]:" + ex.Message); } } else { imageControl.Source = null; Display.Message("file not found"); } } }
public void TestInitialize() { fe = new FileElement() { Name = "Test.txt", Path = @"C:\NWD-SNDBX\Test.txt" }; lst = new List<FileElement>(); }
public bool FileElementHasMetaTag(FileElement fe, string metaTagName) { return !string.IsNullOrWhiteSpace(GetMetaTagForFileElement(fe, metaTagName)); }
public void UpdateTagString(FileElement fe, string tagString) { if (fe != null) { //remove all references to file element in tag map tagFilesMap.PurgeValue(fe.Path); //clear current tags in file map fileTagsMap.Clear(fe.Path); //add all tags for file SetTags(fe.Path, tagString); //prune unused tags PruneTagList(); //update file element fe.TagString = tagString; } }
public string GetMetaTagForFileElement(FileElement fe, string metaTagName) { string metaTag = null; //go through all tags for file element, return first for name, or return null if not found foreach (string tag in fileTagsMap[fe.Path]) { if (TagString.IsMetaTag(tag) && metaTagName.Equals(TagString.ExtractTagNameFromMetaTag(tag))) { metaTag = tag; } } return metaTag; }