Beispiel #1
0
        private static ScheduleCommandData ParseScheduleInput(string input, out string[] commandUserInput)
        {
            if (string.IsNullOrEmpty(input) || string.IsNullOrEmpty(ScheduleJobCommand) || AvailableJobsToSchedule == null)
            {
                throw new ParseCommandException("missing arguments");
            }

            ScheduleCommandData output = new ScheduleCommandData();

            commandUserInput = input.Split(' ');

            if (commandUserInput.Length > 4 || commandUserInput.Length < 2)
            {
                throw new ParseCommandException($"unsupported number of arguments: {commandUserInput.Length - 1}");
            }
            if (commandUserInput[0] != ScheduleJobCommand)
            {
                throw new ParseCommandException($"unknown command: {commandUserInput[0]}");
            }
            if (!AvailableJobsToSchedule.ContainsKey(commandUserInput[1]))
            {
                throw new ParseCommandException($"unsupported job type: {commandUserInput[1]}");
            }

            output.JobName  = AvailableJobsToSchedule[commandUserInput[1]];
            output.Argument = string.Empty;
            output.Priority = JobPriority.Normal;

            if (commandUserInput.Length == 3)
            {
                JobPriority?priority = GetPriority(commandUserInput[2]);
                if (priority.HasValue)
                {
                    output.Priority = priority.Value;
                    return(output);
                }
            }

            if (commandUserInput.Length > 2)
            {
                output.Argument = commandUserInput[2];
            }

            if (commandUserInput.Length > 3)
            {
                JobPriority?priority = GetPriority(commandUserInput[3]);
                if (priority.HasValue)
                {
                    output.Priority = priority.Value;
                }
                else
                {
                    throw new ParseCommandException($"unknown priority: {commandUserInput[3]}");
                }
            }

            return(output);
        }
Beispiel #2
0
        /// <summary>
        /// Schedules job extracted from user input
        /// (in case of incorrect format, error message should be displyed in console)
        /// </summary>
        /// <param name="lowerCaseInput">user input</param>
        public static void ProcessScheduleCommand(string lowerCaseInput)
        {
            try
            {
                string[]            commandUserInput;
                ScheduleCommandData data  = ParseScheduleInput(lowerCaseInput, out commandUserInput);
                ScheduleParams      param = new ScheduleParams(data.Priority, data.Argument, commandUserInput);

                Job processedJob = JobResolver.Resolve(param, data.JobName);
                JobScheduler.ScheduleJob(processedJob);
            }
            catch (ParseCommandException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }