private void ChangeTags() { var fileName = Path.GetFileNameWithoutExtension(File.FullName); if (!_maskParser.ValidateFileName(fileName)) { throw new InvalidDataException("Mask doesn't match the file name."); } var tagPatternsInMask = _maskParser.GetTags(); var splitsInMask = _maskParser.GetSplits(); fileName = fileName.Remove(0, splitsInMask[0].Length); // Remove first split for (var i = 0; i < splitsInMask.Count - 1; i++) { var indexOfSplit = splitsInMask[i + 1] != String.Empty ? fileName.IndexOf(splitsInMask[i + 1], StringComparison.Ordinal) : fileName.Length; var tagValueInFileName = fileName.Substring(0, indexOfSplit); ChangeTag(tagPatternsInMask[i], tagValueInFileName); fileName = fileName.Remove(0, indexOfSplit + splitsInMask[i + 1].Length); } }
private string Analyse(IMp3File mp3File) { var fileName = Path.GetFileNameWithoutExtension(mp3File.FullName); if (!_maskParser.ValidateFileName(fileName)) { throw new InvalidDataException("Mask doesn't match the file name."); } var resultMessage = new StringBuilder(); var tagPatternsInMask = _maskParser.GetTags(); var splitsInMask = _maskParser.GetSplits(); fileName = fileName.Remove(0, splitsInMask[0].Length); for (var i = 0; i < splitsInMask.Count - 1; i++) { var indexOfSplit = splitsInMask[i + 1] != String.Empty ? fileName.IndexOf(splitsInMask[i + 1], StringComparison.Ordinal) : fileName.Length; var tagValueInFileName = fileName.Substring(0, indexOfSplit); var tagValueInTags = GetTagValueByTagPattern(mp3File, tagPatternsInMask[i]); if (tagValueInFileName != tagValueInTags) { resultMessage.Append(_maskParser.GetTags()[i] + " in file name: " + tagValueInFileName + "; "); resultMessage.Append(_maskParser.GetTags()[i] + " in tags: " + tagValueInTags + "\n"); } fileName = fileName.Remove(0, indexOfSplit + splitsInMask[i + 1].Length); } // Add file name to message if (resultMessage.Length > 0) { resultMessage.Insert(0, "File: " + mp3File.FullName + "\n"); resultMessage.Append("\n"); } return(resultMessage.ToString()); }
public void MaskParser_SplitInBegin_Successful() { var parser = new MaskParser("a{artist}"); Assert.IsTrue(parser.ValidateFileName("aTestArtist")); }
public void MaskParser_WithoutSplits_Exception() { var parser = new MaskParser("{artist}{track}"); parser.ValidateFileName("TestArtist1"); }
public void MaskParser_SplitInBeginAndEnd_Successful() { var parser = new MaskParser("-{artist}.{track}-"); Assert.IsTrue(parser.ValidateFileName("-TestArtist.1-")); }
public void MaskParser_SameSplits_Successful() { var parser = new MaskParser("{artist} - {title} - {track}"); Assert.IsTrue(parser.ValidateFileName("TestArtist - TestTitle - 1")); }
public void MaskParser_ManySplits_Exception() { var parser = new MaskParser("{artist}-{track}"); parser.ValidateFileName("Test-Artist-1"); }
public void MaskParser_LetterInCenter_Successful() { var parser = new MaskParser("{artist}Q{track}"); Assert.IsTrue(parser.ValidateFileName("TestArtistQ1")); }
public void MaskParser_Common_Successful() { var parser = new MaskParser("{artist} - {title}"); Assert.IsTrue(parser.ValidateFileName("TestArtist - TestTitle")); }