Esempio n. 1
0
		public static RoiModel Parse(CommandLineArgModel args)
		{
			var roi = args.Parameters.FirstOrDefault(arg => Regex.IsMatch(arg, "^" + RoiPattern + "$", RegexOptions.IgnoreCase));
			if (String.IsNullOrEmpty(roi)) return null;

			var values = roi
				.Substring(roi.IndexOf(':') + 1)
				.Split(',')
				.Select(value => Convert.ToInt32(value.Trim()))
				.ToArray();

			return new RoiModel
			{
				Region = new Rectangle(values[0], values[1], values[2], values[3])
			};
		}
		private List<CommandLineArgModel> parse(string[] args)
		{
			CommandLineArgModel currentArgument = null;
			var parameters = new List<string>();
			var arguments = new List<CommandLineArgModel>();

			foreach (var arg in args.Where(arg => !String.IsNullOrEmpty(arg)))
			{
				if (arg.StartsWith("-"))
				{
					if (currentArgument != null)
					{
						currentArgument.Parameters = parameters.ToArray();
						arguments.Add(currentArgument);
					}

					var argument = arg.Substring(1);

					CommandsLineArg commandLineArg;
					if (!Enum.TryParse(argument, true, out commandLineArg))
						throw new ArgumentException(String.Format("The argument \"{0}\" is not recognized.", argument));

					parameters.Clear();

					currentArgument = new CommandLineArgModel
					{
						Argument = commandLineArg
					};
				}
				else if (currentArgument == null)
				{
					throw new ArgumentException("the first command line argument must be an argument (i.e. -Input)");
				}
				else
				{
					parameters.Add(arg);
				}
			}

			if (currentArgument != null)
			{
				currentArgument.Parameters = parameters.ToArray();
				arguments.Add(currentArgument);
			}

			return arguments;
		}