private void CreateMp3Song(bool paramFileExists) { this.mp3File = new MockMp3File(InitTitle, InitArtist, InitAlbum); this.fileModifier = new MockFileModifier(paramFileExists); this.mp3Song = new Mp3Song(this.mp3File, this.fileModifier); }
//TODO: move to separate class {READY} public UserData GetInfoFromUser(TagType tag, Diff diff, IMp3File file, ICommunication communication) { communication.SendMessage($"File: {file.FilePath}"); communication.SendMessage($"There is a problem with tag \"{tag}\". "); communication.SendMessage( $"You can enter tag from: \n\t1) File name (Data: \"{diff.FileNameValue}\"), \n\t2) Mp3 Tags (Data: \"{diff.TagValue}\"), \n\t3) Manual"); while (true) { communication.SendMessage("Your choise (number): "); SyncActions inputData; var choiseCorrect = Enum.TryParse(communication.GetResponse(), out inputData); if (!choiseCorrect) { communication.SendMessage("Wrong input!"); communication.SendMessage("You sholud enter number with action!"); continue; } switch (inputData) { case SyncActions.FromFileName: return new UserData(inputData, diff.FileNameValue); case SyncActions.FromTags: return new UserData(inputData, diff.TagValue); case SyncActions.Manual: communication.SendMessage("Enter text for tag \"" + tag + "\""); return new UserData(inputData, communication.GetResponse()); } } }
//TODO: move to separate class {READY} public UserData GetInfoFromUser(TagType tag, Diff diff, IMp3File file, ICommunication communication) { communication.SendMessage($"File: {file.FilePath}"); communication.SendMessage($"There is a problem with tag \"{tag}\". "); communication.SendMessage( $"You can enter tag from: \n\t1) File name (Data: \"{diff.FileNameValue}\"), \n\t2) Mp3 Tags (Data: \"{diff.TagValue}\"), \n\t3) Manual"); while (true) { communication.SendMessage("Your choise (number): "); SyncActions inputData; var choiseCorrect = Enum.TryParse(communication.GetResponse(), out inputData); if (!choiseCorrect) { communication.SendMessage("Wrong input!"); communication.SendMessage("You sholud enter number with action!"); continue; } switch (inputData) { case SyncActions.FromFileName: return(new UserData(inputData, diff.FileNameValue)); case SyncActions.FromTags: return(new UserData(inputData, diff.TagValue)); case SyncActions.Manual: communication.SendMessage("Enter text for tag \"" + tag + "\""); return(new UserData(inputData, communication.GetResponse())); } } }
public ChangeTagsCommand(IMp3File mp3File, string mask) { File = mp3File; _maskParser = new MaskParser(mask); OldTags = new Mp3Tags(); File.Tags.CopyTo(OldTags); }
public Song(string mp3Path, int order, string title, TimeSpan start, TimeSpan end) { this.mp3File = new Mp3File(mp3Path); this.End = end == TimeSpan.Zero ? this.mp3File.TotalTime : end; this.Start = start; this.Title = $"{order} - {title}.mp3"; }
public FileBackuper(IMp3File sourceFile) { if (sourceFile == null) throw new InvalidOperationException(); _disposed = false; _sourceFile = sourceFile; _tempFile = MakeBackup(); }
public Mp3TagChanger(IMp3File mp3File, string mask, ISaver backuper) { Mp3 = mp3File; Backuper = backuper; _mask = mask; Mp3RealName = Path.GetFileNameWithoutExtension(mp3File.FilePath); _dataExtracter = new DataExtracter(_mask); }
public FileBackuper(IMp3File sourceFile) { if (sourceFile == null) { throw new InvalidOperationException(); } _disposed = false; _sourceFile = sourceFile; _tempFile = MakeBackup(); }
public static void PrintChanges(IMp3File file) { var mp3File = file as Mp3File; if (mp3File.NameChanged) { Console.WriteLine("_____________________________"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("{0}.mp3", mp3File.Name); Console.ResetColor(); Console.Write(" renamed to "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}.mp3 ", mp3File.NewName); Console.ResetColor(); Console.WriteLine("_____________________________"); } if (mp3File.TagChanged) { var tags = mp3File.GetTags(); Console.WriteLine("_____________________________"); Console.Write("Tags changed in "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}.mp3", mp3File.Name); Console.ResetColor(); if (tags.Album != mp3File.OldTags.Album) { Console.WriteLine("{0} [{1}]->[{2}]", Tags.Album, mp3File.OldTags.Album, tags.Album); } if (tags.Artist != mp3File.OldTags.Artist) { Console.WriteLine("{0} [{1}]->[{2}]", Tags.Artist, mp3File.OldTags.Artist, tags.Artist); } if (tags.Comment != mp3File.OldTags.Comment) { Console.WriteLine("{0} [{1}]->[{2}]", Tags.Comment, mp3File.OldTags.Comment, tags.Comment); } if (tags.Genre != mp3File.OldTags.Genre) { Console.WriteLine("{0} [{1}]->[{2}]", Tags.Genre, mp3File.OldTags.Genre, tags.Genre); } if (tags.Title != mp3File.OldTags.Title) { Console.WriteLine("{0} [{1}]->[{2}]", Tags.Title, mp3File.OldTags.Title, tags.Title); } if (tags.Track != mp3File.OldTags.Track) { Console.WriteLine("{0} [{1}]->[{2}]", Tags.Track, mp3File.OldTags.Track, tags.Track); } if (tags.Year != mp3File.OldTags.Year) { Console.WriteLine("{0} [{1}]->[{2}]", Tags.Year, mp3File.OldTags.Year, tags.Year); } Console.WriteLine("_____________________________"); } }
public Mp3FileNameChanger(IMp3File file, string mask, ISaver saver, bool fastChanges = false) { _mp3File = file; Id3Data = new Dictionary <TagType, string>(); _dataExtracter = new DataExtracter(mask); _fastChanges = fastChanges; _saver = saver; _mask = mask; }
public Mp3FileNameChanger(IMp3File file, string mask, ISaver saver, bool fastChanges = false) { _mp3File = file; Id3Data = new Dictionary<TagType, string>(); _dataExtracter = new DataExtracter(mask); _fastChanges = fastChanges; _saver = saver; _mask = mask; }
public static void PrintCurrentFile(IMp3File file) { if (file == null) { return; } Console.WriteLine("________________"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Current file:"); Console.ResetColor(); Console.WriteLine(file.Name + ".mp3"); Console.WriteLine("________________"); }
protected virtual void Dispose(bool disposing) { if (_disposed) return; if (disposing) { _tempFile.Delete(); _tempFile = null; _sourceFile = null; } _disposed = true; }
public void GetMp3FileWithDesiredTags() { // Arrange const string ExpectedArtist = "McCoffee"; const string ExpectedTitle = "Title value"; string ExpectedFilepath = MockMp3File.FolderPath + ExpectedArtist + " - " + ExpectedTitle + MockMp3File.Extension; // Act IMp3File mp3File = this.mockModelFactory.CreateMp3File(ExpectedFilepath); // Assert Assert.AreEqual(ExpectedArtist, mp3File.Artist); Assert.AreEqual(ExpectedTitle, mp3File.Title); }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _tempFile.Delete(); _tempFile = null; _sourceFile = null; } _disposed = true; }
Mp3Tags GetTagsFromFileName(IMp3File file) { if (file == null) throw new ArgumentException("File is not loaded"); Menu.PrintHelp(); var fileName = file.Name; var mask = new Mask(Menu.GetUserInput("mask:")); var tagValues = Select(mask.GetTagValuesFromString(fileName)); var result = new Mp3Tags(); foreach (var tagValue in tagValues) { result.SetTag(tagValue.Key, tagValue.Value); } return result; }
Mp3Tags GetTagsFromFileName(IMp3File file) { if (file == null) { throw new ArgumentException("File is not loaded"); } Menu.PrintHelp(); var fileName = file.Name; var mask = new Mask(Menu.GetUserInput("mask:")); var tagValues = Select(mask.GetTagValuesFromString(fileName)); var result = new Mp3Tags(); foreach (var tagValue in tagValues) { result.SetTag(tagValue.Key, tagValue.Value); } return(result); }
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 Command ChooseCommand(string commandName, IMp3File file, IWorker worker, string mask) { switch (commandName) { case CommandNames.Rename: return new RenameCommand(file, mask); case CommandNames.ChangeTags: return new ChangeTagsCommand(file, mask); case CommandNames.Analyse: return new AnalyseCommand(file, mask, worker); case CommandNames.Sync: return new SyncCommand(file, mask); default: throw new InvalidOperationException("Invalid operation: there is no such command!"); } }
public Command ChooseCommand(string commandName, IMp3File file, IWorker worker, string mask) { switch (commandName) { case CommandNames.Rename: return(new RenameCommand(file, mask)); case CommandNames.ChangeTags: return(new ChangeTagsCommand(file, mask)); case CommandNames.Analyse: return(new AnalyseCommand(file, mask, worker)); case CommandNames.Sync: return(new SyncCommand(file, mask)); default: throw new InvalidOperationException("Invalid operation: there is no such command!"); } }
public static void PrintChanges(IMp3File file) { var mp3File = file as Mp3File; if (mp3File.NameChanged) { Console.WriteLine("_____________________________"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("{0}.mp3", mp3File.Name); Console.ResetColor(); Console.Write(" renamed to "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}.mp3 ", mp3File.NewName); Console.ResetColor(); Console.WriteLine("_____________________________"); } if (mp3File.TagChanged) { var tags = mp3File.GetTags(); Console.WriteLine("_____________________________"); Console.Write("Tags changed in "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}.mp3", mp3File.Name); Console.ResetColor(); if (tags.Album != mp3File.OldTags.Album) Console.WriteLine("{0} [{1}]->[{2}]", Tags.Album, mp3File.OldTags.Album, tags.Album); if (tags.Artist != mp3File.OldTags.Artist) Console.WriteLine("{0} [{1}]->[{2}]", Tags.Artist, mp3File.OldTags.Artist, tags.Artist); if (tags.Comment != mp3File.OldTags.Comment) Console.WriteLine("{0} [{1}]->[{2}]", Tags.Comment, mp3File.OldTags.Comment, tags.Comment); if (tags.Genre != mp3File.OldTags.Genre) Console.WriteLine("{0} [{1}]->[{2}]", Tags.Genre, mp3File.OldTags.Genre, tags.Genre); if (tags.Title != mp3File.OldTags.Title) Console.WriteLine("{0} [{1}]->[{2}]", Tags.Title, mp3File.OldTags.Title, tags.Title); if (tags.Track != mp3File.OldTags.Track) Console.WriteLine("{0} [{1}]->[{2}]", Tags.Track, mp3File.OldTags.Track, tags.Track); if (tags.Year != mp3File.OldTags.Year) Console.WriteLine("{0} [{1}]->[{2}]", Tags.Year, mp3File.OldTags.Year, tags.Year); Console.WriteLine("_____________________________"); } }
public override bool Call(Mask mask, Tager tager, IMp3File file) { if (_isCanceled) { RestoreFile(); return true; } _file = file; try { _memento = _file.GetMemento(); tager.ChangeTags(tager.GetTagsFromName(mask)); return true; } catch { return false; } }
public override bool Call(Mask mask, Tager tager, IMp3File file) { if (_isCanceled) { RestoreFile(); return(true); } _file = file; try { _memento = _file.GetMemento(); tager.ChangeTags(tager.GetTagsFromName(mask)); return(true); } catch { return(false); } }
public void Sync(IMp3File file, Mask mask, ISyncRule rule) { var errorFlag = true; _tager.CurrentFile = file; foreach (var operation in rule.OperationsList) { if (operation.Call(mask, _tager, file)) { OperationList.Add(operation); ModifiedFiles.Add(_tager.CurrentFile); errorFlag = false; break; } } if (errorFlag) { ErrorFiles.Add(_tager.CurrentFile.Name, "Can't sync this file"); } }
private void SaveMp3File(IMp3File mp3File, bool enableBackup) { if (!enableBackup) { mp3File.Save(); return; } var backup = new FileBackuper(mp3File); using (backup) { try { mp3File.Save(); } catch (Exception e) { backup.RestoreFromBackup(); throw new Exception("File " + mp3File.FullName + " was restored from backup because of exception:", e); } } }
private string GetTagValueByTagPattern(IMp3File mp3File, string tagPattern) { switch (tagPattern) { case TagNames.Artist: return(mp3File.Tags.Artist); case TagNames.Title: return(mp3File.Tags.Title); case TagNames.Genre: return(mp3File.Tags.Genre); case TagNames.Album: return(mp3File.Tags.Album); case TagNames.Track: return(mp3File.Tags.Track.ToString()); default: throw new ArgumentException(tagPattern); } }
public abstract bool Call(Mask mask, Tager tager, IMp3File file);
public FileDifferences(IMp3File mp3File) { Mp3File = mp3File; Diffs = new Dictionary<TagType, Diff>(); }
public FileDifferences(IMp3File mp3File) { Mp3File = mp3File; Diffs = new Dictionary <TagType, Diff>(); }
public void Sync(IMp3File file, Mask mask, ISyncRule rule) { var errorFlag = true; _tager.CurrentFile = file; foreach (var operation in rule.OperationsList) { if (operation.Call(mask, _tager, file)) { OperationList.Add(operation); ModifiedFiles.Add(_tager.CurrentFile); errorFlag = false; break; } } if (errorFlag) ErrorFiles.Add(_tager.CurrentFile.Name, "Can't sync this file"); }
public AnalyseCommand(IMp3File mp3File, string mask, IWorker worker) { File = mp3File; _worker = worker; _maskParser = new MaskParser(mask); }
public Tager(IFileLoader fileLoader) { _fileLoader = fileLoader; _currentFile = null; }
public bool Load(string path) { _currentFile = _fileLoader.Load(path); return(_currentFile != null); }
public Mp3Song(IMp3File paramMp3File, IFileModifier paramFileModifier) { this.mp3File = paramMp3File; this.fileModifier = paramFileModifier; }
public abstract bool Call(Mask mask,Tager tager, IMp3File file);
public static void PrintCurrentFile(IMp3File file) { if (file == null) return; Console.WriteLine("________________"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Current file:"); Console.ResetColor(); Console.WriteLine(file.Name + ".mp3"); Console.WriteLine("________________"); }
public RenameCommand(IMp3File mp3File, string mask) { File = mp3File; _mask = mask; OldFullName = mp3File.FullName; }
public SyncCommand(IMp3File mp3File, string mask) { File = mp3File; _mask = mask; }
public bool Load(string path) { _currentFile = _fileLoader.Load(path); return _currentFile != null; }