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); }
/* * 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)); }
public static string ValidPar(Command command) { List <ParOption> _rPar = command.rPar; List <ParOption> _oPar = command.oPar; Parameter _temp; ParOption _tempOptions; int _requiredArgsFound = 0; // Check every parameter. for (int i = 0; i < command.pars.pars.Count; i++) { _temp = command.pars.pars[i]; _tempOptions = CLIFramework.GetParOptions(_rPar, _oPar, _temp.par); // Check if the parameter is known. if (_tempOptions == null) { return(CLIError.Error(CLIError.ErrorType.ParameterError, "Parameter '" + _temp.par + "' does not exist for this command!", true)); } // Check if parameter has been used befor. if (_tempOptions.IsUsed) { return(CLIError.Error(CLIError.ErrorType.ParameterError, "Parameter '" + _temp.par + "' cannot be used multiple times!", true)); } // Mark the parameter as 'used'. _tempOptions.SetUsedFlag(); // If it is a required parameter, increase _requiredArgsFound. // If _requiredArgsFound is equal to the lengh of the _requiredParamters, // all required parameter has been found in the input of the cli. if (IsRequiredPar(_rPar, _temp)) { _requiredArgsFound++; } // Check if the given parameter can have a value or not. if (_tempOptions.argEmpty) { // Check if the arg is not null. if (_temp.argValues.Length != 0) { return(CLIError.Error(CLIError.ErrorType.SyntaxError, "The parameter '" + _temp.par + "' does not need any args!", true)); } } else { if (_temp.argValues.Length == 0) { return(CLIError.Error(CLIError.ErrorType.SyntaxError, "The par '" + _temp.par + "' needs one or more args!", true)); } if (!_tempOptions.multiargs) { // Check if more than one arg is given. if (_temp.argValues.Length > 1) { return(CLIError.Error(CLIError.ErrorType.SyntaxError, "The par '" + _temp.par + "' can't have multiple args!", true)); } } /* Try to convert the given args into the specific types. * If it cannot convert all args into ONE type, it will fail. */ object[] _args = new object[_temp.argValues.Length]; bool _allArgsConverted = false; foreach (Type _type in _tempOptions.argTypes) { int _argsConverted = 0; for (int i2 = 0; i2 < _temp.argValues.Length; i2++) { _args[i2] = CLIFramework.Convert((string)_temp.argValues[i2], _type); if (_args[i2] != null) { _argsConverted++; } else { break; } } if (_argsConverted == _args.Length) { _allArgsConverted = true; break; } } if (!_allArgsConverted) { return(CLIError.Error(CLIError.ErrorType.ArgumentTypeError, "The argument of the parameter '" + _temp.par + "' could not be parsed correctly!", true)); } _temp.argValues = _args; } } // Check if all required pars has been found. if (_rPar.Count != _requiredArgsFound) { return(CLIError.Error(CLIError.ErrorType.SyntaxError, "Some required parameters are missing!", true)); } return("VALID_PARAMETERS"); }