コード例 #1
0
        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);
        }
コード例 #2
0
        //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());
                }
            }
        }
コード例 #3
0
        //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()));
                }
            }
        }
コード例 #4
0
 public ChangeTagsCommand(IMp3File mp3File, string mask)
 {
     File        = mp3File;
     _maskParser = new MaskParser(mask);
     OldTags     = new Mp3Tags();
     File.Tags.CopyTo(OldTags);
 }
コード例 #5
0
        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";
        }
コード例 #6
0
ファイル: FileBackuper.cs プロジェクト: Confirmit/Students
 public FileBackuper(IMp3File sourceFile)
 {
     if (sourceFile == null)
         throw new InvalidOperationException();
     _disposed = false;
     _sourceFile = sourceFile;
     _tempFile = MakeBackup();
 }
コード例 #7
0
        public Mp3TagChanger(IMp3File mp3File, string mask, ISaver backuper)
        {
            Mp3 = mp3File;

            Backuper = backuper;
            _mask    = mask;

            Mp3RealName    = Path.GetFileNameWithoutExtension(mp3File.FilePath);
            _dataExtracter = new DataExtracter(_mask);
        }
コード例 #8
0
ファイル: Mp3TagChanger.cs プロジェクト: Confirmit/Students
        public Mp3TagChanger(IMp3File mp3File, string mask, ISaver backuper)
        {
            Mp3 = mp3File;

            Backuper = backuper;
            _mask = mask;

            Mp3RealName = Path.GetFileNameWithoutExtension(mp3File.FilePath);
            _dataExtracter = new DataExtracter(_mask);
        }
コード例 #9
0
ファイル: FileBackuper.cs プロジェクト: taler0n/Students
 public FileBackuper(IMp3File sourceFile)
 {
     if (sourceFile == null)
     {
         throw new InvalidOperationException();
     }
     _disposed   = false;
     _sourceFile = sourceFile;
     _tempFile   = MakeBackup();
 }
コード例 #10
0
ファイル: Menu.cs プロジェクト: taler0n/Students
        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("_____________________________");
            }
        }
コード例 #11
0
        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;
        }
コード例 #12
0
        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;
        }
コード例 #13
0
ファイル: Menu.cs プロジェクト: taler0n/Students
 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("________________");
 }
コード例 #14
0
ファイル: FileBackuper.cs プロジェクト: Confirmit/Students
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed) return;

            if (disposing)
            {
                _tempFile.Delete();
                _tempFile = null;
                _sourceFile = null;
            }

            _disposed = true;
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: FileBackuper.cs プロジェクト: taler0n/Students
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _tempFile.Delete();
                _tempFile   = null;
                _sourceFile = null;
            }

            _disposed = true;
        }
コード例 #17
0
ファイル: Changetags.cs プロジェクト: Confirmit/Students
        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;
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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());
        }
コード例 #20
0
ファイル: CommandFactory.cs プロジェクト: Confirmit/Students
        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!");
            }
        }
コード例 #21
0
ファイル: CommandFactory.cs プロジェクト: taler0n/Students
        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!");
            }
        }
コード例 #22
0
ファイル: Menu.cs プロジェクト: Confirmit/Students
 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("_____________________________");
     }
 }
コード例 #23
0
ファイル: Retag.cs プロジェクト: Confirmit/Students
        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;
            }
        }
コード例 #24
0
ファイル: Retag.cs プロジェクト: taler0n/Students
        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);
            }
        }
コード例 #25
0
        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");
            }
        }
コード例 #26
0
ファイル: Application.cs プロジェクト: Confirmit/Students
        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);
                }
            }
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
ファイル: Application.cs プロジェクト: taler0n/Students
        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);
                }
            }
        }
コード例 #29
0
ファイル: SyncOperation.cs プロジェクト: taler0n/Students
 public abstract bool Call(Mask mask, Tager tager, IMp3File file);
コード例 #30
0
ファイル: FileDifferences.cs プロジェクト: Confirmit/Students
 public FileDifferences(IMp3File mp3File)
 {
     Mp3File = mp3File;
     Diffs = new Dictionary<TagType, Diff>();
 }
コード例 #31
0
 public FileDifferences(IMp3File mp3File)
 {
     Mp3File = mp3File;
     Diffs   = new Dictionary <TagType, Diff>();
 }
コード例 #32
0
ファイル: Synchronizer.cs プロジェクト: Confirmit/Students
        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");
        }
コード例 #33
0
 public AnalyseCommand(IMp3File mp3File, string mask, IWorker worker)
 {
     File        = mp3File;
     _worker     = worker;
     _maskParser = new MaskParser(mask);
 }
コード例 #34
0
ファイル: Tager.cs プロジェクト: taler0n/Students
 public Tager(IFileLoader fileLoader)
 {
     _fileLoader  = fileLoader;
     _currentFile = null;
 }
コード例 #35
0
ファイル: Tager.cs プロジェクト: taler0n/Students
 public bool Load(string path)
 {
     _currentFile = _fileLoader.Load(path);
     return(_currentFile != null);
 }
コード例 #36
0
 public Mp3Song(IMp3File paramMp3File, IFileModifier paramFileModifier)
 {
     this.mp3File      = paramMp3File;
     this.fileModifier = paramFileModifier;
 }
コード例 #37
0
ファイル: SyncOperation.cs プロジェクト: Confirmit/Students
 public abstract bool Call(Mask mask,Tager tager, IMp3File file);
コード例 #38
0
ファイル: Menu.cs プロジェクト: Confirmit/Students
 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("________________");
 }
コード例 #39
0
ファイル: RenameCommand.cs プロジェクト: taler0n/Students
 public RenameCommand(IMp3File mp3File, string mask)
 {
     File        = mp3File;
     _mask       = mask;
     OldFullName = mp3File.FullName;
 }
コード例 #40
0
ファイル: SyncCommand.cs プロジェクト: taler0n/Students
 public SyncCommand(IMp3File mp3File, string mask)
 {
     File  = mp3File;
     _mask = mask;
 }
コード例 #41
0
ファイル: Tager.cs プロジェクト: Confirmit/Students
 public bool Load(string path)
 {
     _currentFile = _fileLoader.Load(path);
     return _currentFile != null;
 }
コード例 #42
0
ファイル: Tager.cs プロジェクト: Confirmit/Students
 public Tager(IFileLoader fileLoader)
 {
     _fileLoader = fileLoader;
     _currentFile = null;
 }