Esempio n. 1
0
        public void Test_CheckArgs_InvalidMissFilePathAndMask()
        {
            var data        = new[] { "-data1", "filePath", "-data", "{a}-{b}", "-action", "file-rename" };
            var argsManager = new ArgsManager(data);

            argsManager.CheckArgsValidity();
        }
Esempio n. 2
0
        public void Test_CheckArgs_InvalidOrder_2()
        {
            var data        = new[] { "-path", "-mask", "filePath", "{a}-{b}", "-action", "file-rename" };
            var argsManager = new ArgsManager(data);

            argsManager.CheckArgsValidity();
        }
Esempio n. 3
0
        public void Test_CheckArgs_Valid()
        {
            var data        = new[] { "-path", "filePath", "-mask", "{a}-{b}", "-action", "file-rename" };
            var argsManager = new ArgsManager(data);

            Assert.AreEqual(true, argsManager.CheckArgsValidity());
        }
Esempio n. 4
0
        public MainForm(string[] args)
        {
            args      = args ?? new string[0];
            this.args = new ArgsManager(args);

            InitializeComponent();
            ShowInTaskbar = true;
        }
Esempio n. 5
0
        public void Test_ExtractArgs()
        {
            var validator = new ArgsManager(new[] { "-path", "something", "-mask", "{asd}{dsa}", "-action", "file-rename" });

            validator.CheckArgsValidity();
            var args = validator.ExtactArgs();

            Assert.AreEqual(args.Path, "something");
            Assert.AreEqual(args.Mask, "{asd}{dsa}");
        }
Esempio n. 6
0
        public void ArgsManagerTestSimplePasses()
        {
            string sArg = "--name = Eriri --full-name = \"Sawamura Spencer Eriri\" --enable --CV= \"Oonishi Saori\"";

            string[] args = ArgsUtil.ParseArgsText(sArg).ToArray();
            var      mgr  = new ArgsManager();

            mgr.AddArgs(args);

            Assert.AreEqual(mgr.GetValue("name"), "Eriri");
            Assert.AreEqual(mgr.GetValue("full-name"), "Sawamura Spencer Eriri");
            Assert.IsTrue(mgr.GetBool("enable"));
            Assert.AreEqual(mgr.GetValue("CV"), "Oonishi Saori");
        }
Esempio n. 7
0
        public XCore()
        {
            if (_MainInstance == null)
            {
                lock (_lock_obj)
                {
                    if (_MainInstance == null)
                    {
                        _MainInstance = this;
                    }
                }
            }

            //mCatApp = CatLib.Application.New();
            m_ServiceContainer = new ServiceContainer(this);
            UnityEngine.Application.quitting += OnUnityQuit;
            m_ArgsManager = new ArgsManager();
        }
Esempio n. 8
0
        public static void Main(string[] _args)
        {
            var settings = null as Settings;
            if(File.Exists("vote_settings.json"))
            {
                settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText("vote_settings.json"));
            }
            else
            {
                settings = new Settings();
                File.WriteAllText("vote_settings.json", JsonConvert.SerializeObject(settings));
            }

            args = new ArgsManager<Args>(_args);

            var levelsFile = args.GetValue(Args.OptionLevelsFile);
            var votesFile = args.GetValue(Args.OptionVotesFile);

            if(!File.Exists(levelsFile))
            {
                Console.WriteLine("Couldn't find levels file: {0}", levelsFile);
                Console.ReadKey();
                return;
            }

            if (!File.Exists(votesFile))
            {
                Console.WriteLine("Couldn't find votes file: {0}", votesFile);
                Console.ReadKey();
                return;
            }

            try
            {
                // load the levels
                var _levels = File.ReadAllLines(levelsFile);
                var levels = new List<Level>();

                foreach (var _level in _levels)
                {
                    levels.Add(new Level(_level, settings));
                }

                // load the votes
                var _votes = File.ReadAllLines(votesFile);
                var voters = new List<Voter>();
                var voter = null as Voter;

                int line = 0;
                foreach (var _vote in _votes)
                {
                    line++;
                    if (Char.IsLetter(_vote[0]))
                        continue;

                    if (_vote[0] == '/')
                    {
                        voter = new Voter(_vote.Substring(1), settings);
                        voters.Add(voter);
                    }
                    else
                        voter.AddVote(new Vote(_vote, line));
                }

                // match the votes to the levels

                Console.WriteLine("Some votes may have been mispelled. Please verify the following fuzzy matches:");
                foreach (var _voter in voters)
                {
                    if (!_voter.IsComplete())
                        throw new Exception("User " + _voter.Username + " voted incorrectly.");

                    foreach(var vote in _voter.Votes)
                    {
                        var match = vote.FindClosestMatch(levels);

                        if (!match.IsExact)
                            Console.WriteLine("Fuzzy Matched: {0}\n" +
                                              "         with: {1}\n", vote.Level, match.Level.FullTitle);

                        match.Level.Vote(vote.VoteNumber);
                    }
                }

                // output the results

                // first calculate the column widths
                int place = 0;
                int[] cols = { 0, 0, 0 };
                foreach (var level in levels)
                {
                    int c1 = (place + ".").Length + 1;
                    int c2 = Math.Min(level.FullTitle.Length+1, 60);
                    int c3 = (level.Points.ToString("0.0") + " points ("+level.NthVotes[0]+" 1st place votes)").Length;

                    if (c1 > cols[0]) cols[0] = c1;
                    if (c2 > cols[1]) cols[1] = c2;
                    if (c3 > cols[2]) cols[2] = c3;

                    place++;
                }

                // now output
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("############  RESULTS  ############");
                levels.Sort(delegate (Level x, Level y) {
                    int cmp = y.Points.CompareTo(x.Points);
                    if (cmp == 0)
                        cmp = y.NthVotes[0].CompareTo(x.NthVotes[0]);

                    return cmp;
                });

                place = 0;
                foreach (var level in levels)
                {
                    place++;
                    PrintColumn(place + ".", cols[0]);
                    PrintColumn(level.FullTitle, cols[1]);
                    PrintColumn(level.Points.ToString("0.0") + " points (" + level.NthVotes[0] + " 1st place votes)", cols[2]);

                    Console.WriteLine();
                }
            }
            catch(Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }

            Console.WriteLine();
            Console.WriteLine();

            Console.ReadKey();
        }
Esempio n. 9
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();
             * }*/
        }