Beispiel #1
0
        static void sort(string seqStr)
        {
            /*
             +----------+----------+------+----------+------------+
             | old jobs |  old seq |  --> | new jobs |  input seq |
             +----------+----------+------+----------+------------+
             | job_a    |  0       |  --> | job_b    |  1         |
             +----------+----------+------+----------+------------+
             | job_b    |  1       |  --> | job_c    |  2         |
             +----------+----------+------+----------+------------+
             | job_c    |  2       |  --> | job_a    |  0         |
             +----------+----------+------+----------+------------+
             */
            if (manager == null)
            {
                return;
            }
            var seq = seqStr.Split(new char[] { ',' });

            HashSet <string> sets = new HashSet <string>(seq);

            if (sets.Count != manager.JobCount)
            {
                Console.WriteLine("user input numbers have duplicated value");
                return;
            }
            int jobCount = manager.JobCount;

            foreach (string index in seq)
            {
                int _index = 0;
                if (!int.TryParse(index, out _index) || _index < 0 || _index >= jobCount)
                {
                    Console.WriteLine("user input numbers are invalid");
                    return;
                }
            }

            List <CogJob> jobs     = new List <CogJob>();
            List <string> jobNames = new List <string>();

            for (int i = 0; i < jobCount; i++)
            {
                var job = manager.Job(Convert.ToInt32(seq[i])); // 1, 2, 0 --> b, c, a
                jobs.Add(job);
                jobNames.Add(job.Name);
            }
            foreach (var name in jobNames)
            {
                manager.JobRemove(name);
            }
            foreach (var item in jobs)
            {
                manager.JobAdd(item);
            }
            Console.WriteLine("sorted:");
            listJobs();
        }