public static List <JobRule> ParseJobNotificationRules(ParInput pars, JobOutput outp) { List <JobRule> _rules = new List <JobRule>(); object[] _args = pars.GetPar("rule").argValues; string _temp; foreach (object _arg in _args) { _temp = (string)_arg; // parse rule. JobRule _rule = ParseRule(_temp); // then check if there is a outdescriptor matching the name OutputDescriptor _desc = outp.GetOutputDesc(_rule.outDescName); if (_desc == null) { throw new Exception("No OutputDescriptor with the name '" + _rule.outDescName + "' found!"); } // then check if the type is supported if (!_rule.IsOperatorSupported(_desc.dataType)) { throw new Exception("OutputDescriptor-Type is not supported!"); } _rules.Add(_rule); } return(_rules); }
public JobNotificationSettings ParseJobNotificationSettings(ParInput pars) { JobNotificationSettings _settings = new JobNotificationSettings(); string[] _temp = pars.GetPar(NOTI_SMTP_ENDPOINT).argValues[0].ToString().Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); if (_temp.Length == 2) { _settings.login.smtpAddr = _temp[0]; try { _settings.login.port = Int32.Parse(_temp[1]); } catch (Exception) { throw new Exception(CLIError.Error(CLIError.ErrorType.ArgumentTypeError, "Could not parse SMTP-Port!", true)); } } else { throw new Exception(CLIError.Error(CLIError.ErrorType.SyntaxError, "SMTP-Endpoint could not be parsed correctly!", true)); } string[] _temp2 = pars.GetPar(NOTI_SMTP_LOGIN).argValues[0].ToString().Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); if (_temp2.Length == 2) { try { _settings.login.mail = new MailAddress(_temp2[0]); } catch (Exception) { throw new Exception(CLIError.Error(CLIError.ErrorType.ArgumentTypeError, "Could not parse MailAddress!", true)); } _settings.login.password = _temp2[1]; } else { throw new Exception(CLIError.Error(CLIError.ErrorType.SyntaxError, "SMTP-Login could not be parsed correctly!", true)); } _settings.mailAddr = new MailAddress[1] { (MailAddress)pars.GetPar(NOTI_SMTP_MAILS).argValues[0] }; return(_settings); }
private ParInput GetParamtersFromInput(string input) { ParInput _temp = new ParInput(); string[] _buffer = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Parameter _par = null; List <string> _args = new List <string>(); for (int i = 0; i < _buffer.Length; i++) { if (_buffer[i].StartsWith("-")) { if (_par != null) { _par.argValues = _args.ToArray(); _temp.pars.Add(_par); _args.Clear(); } _par = new Parameter(_buffer[i].Remove(0, 1), null); } else { if (_par != null) { _args.Add(_buffer[i]); } } } if (_par != null) { _par.argValues = _args.ToArray(); _temp.pars.Add(_par); } return(_temp); }
/* * This method checks the pars and args of their validity. * If everything is alright, the command object will be set. * It returns the string 'VALID_PARAMETERS' when the pars and args are valid. * If the par are not valid it returns the error text, which get displayed onto * the CLI. When the parsing was successful, the Command-Object will be set and be ready * for execution. */ protected string CLIInterpreter(ref Command command, string cliInput) { string _commandInput = GetCommandName(cliInput); CommandOptions _commandOptions = GetCommandOptions(_commandInput); if (_commandOptions == null) { return(CLIError.Error(CLIError.ErrorType.CommandError, "Command '" + _commandInput + "' not known!", true)); } ParInput _parInput = GetParamtersFromInput(cliInput); Type _commandType = _commandOptions.commandType; ConstructorInfo _cInfo; // Check if the command need any objects. if (_commandOptions.commandObjects == null) { // Command does not need any objects for its constructor. _cInfo = _commandType.GetConstructor(new Type[0]); // Invoke the constructor. command = (Command)_cInfo.Invoke(null); } else { // Command need some objects for its constructor. _cInfo = _commandType.GetConstructor(new Type[1] { typeof(object[]) }); // Invoke the constructor. command = (Command)_cInfo.Invoke(new object[] { _commandOptions.commandObjects }); } command.pars = _parInput; return(CLIFramework.ValidPar(command)); }