示例#1
0
        public void Test_GetDataFromFileName()
        {
            var communicator = new TestCommunicator(userInput: new[]{
                "1",
                "1",
            });

            var item = new TestMp3File("2. name2 - title2.mp3") { TrackId = "1", Title = "title2", Artist = "name1" };

            var files = new[] {item};

            var syncer = new Mp3Syncing(files, "{id}. {artist} - {title}", communicator, new TestRollbackSaver(new[] { "" }));
            syncer.SyncFiles();

            Assert.AreEqual(item.TrackId, "2");
            Assert.AreEqual(item.Artist, "name2");
            Assert.AreEqual(item.Title, "title2");
        }
示例#2
0
        public void Test_GetDataFromUser()
        {
            var communicator = new TestCommunicator(userInput: new[]{
                "3",
                "3", //it's entering a value
            });

            var item = new TestMp3File("1. name3 - title3.mp3") { TrackId = "3", Title = "title3", Artist = "name3" };

            var files = new[] {item};

            var syncer = new Mp3Syncing(files, "{id}. {artist} - {title}", communicator, new TestRollbackSaver(new[] { "" }));
            syncer.SyncFiles();

            Assert.AreEqual(item.TrackId, "3");
            Assert.AreEqual(item.Artist, "name3");
            Assert.AreEqual(item.Title, "title3");
        }
示例#3
0
        public static void Main(string[] args)
        {
            /*try
            {*/
            var argsManager = new ArgsManager(args);
            argsManager.CheckArgsValidity();

            var data = argsManager.ExtactArgs();
            Mp3File mp3;
            IEnumerable<IMp3File> mp3Files;
            switch (data.Action)
            {
                case ProgramAction.Analyse:
                    mp3Files = Directory.GetFiles(data.Path, "*.mp3").Select(file => new Mp3File(file, new FileSaver(file))).ToArray();
                    var pathAnalyser = new Mp3FileAnalyser(mp3Files, data.Mask);

                    var differences = pathAnalyser.GetDifferences();
                    new CommunicationWithUser().ShowDifferences(differences, new ConsoleCommunication());

                    foreach (var mp3File in mp3Files)
                    {
                        mp3File?.Dispose();
                    }

                    break;

                case ProgramAction.Mp3Edit:
                    using (mp3 = new Mp3File(data.Path, new FileSaver(data.Path)))
                    {
                        var tagsChanger = new Mp3TagChanger(mp3, data.Mask, new FileSaver(RollbackData));
                        tagsChanger.ChangeTags();
                    }
                    break;

                case ProgramAction.FileRename:
                    using (mp3 = new Mp3File(data.Path, new FileSaver(data.Path)))
                    {
                        var renamer = new Mp3FileNameChanger(mp3, data.Mask, new FileSaver(RollbackData));
                        var newFileName = renamer.GetNewFileName();
                        mp3.ChangeFileName(newFileName);
                    }
                    break;

                case ProgramAction.Sync:
                    mp3Files = Directory.GetFiles(data.Path, "*.mp3").Select(file => new Mp3File(file, new FileSaver(file))).ToArray();
                    var syncer = new Mp3Syncing(mp3Files, data.Mask, new ConsoleCommunication(), new FileSaver(RollbackData));
                    syncer.SyncFiles();

                    foreach (var mp3File in mp3Files)
                    {
                        mp3File?.Dispose();
                    }

                    break;

                case ProgramAction.Rollback:

                    using (var rollbackSystem = new RollbackManager(new FileSaver(RollbackData)))
                    {
                        var state = rollbackSystem.Rollback();

                        Console.WriteLine(
                            state.State == RollbackState.Fail
                                ? $"Error occured while trying doing rollback. Details : \n\tError:{state.FailReason}"
                                : $"Rollback success.");
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }

            Console.WriteLine("Done!");
            /*}
            catch (Exception e)
            {
            #if DEBUG
                Console.WriteLine("Exeption: \r\n{0} \r\n\nAt:\n{1}", e.Message, e.StackTrace);
            #else
                Console.WriteLine("Error occured: {0}", e.Message);
            #endif
            }
            finally
            {
                Console.ReadKey();
            }*/
        }