Brunet.Applications.RuntimeParameters.Parse C# (CSharp) Метод

Parse() публичный Метод

public Parse ( string args ) : int
args string
Результат int
    public virtual int Parse(string[] args)
    {
      try {
        _options.Parse(args);
      } catch(Exception e) {
        _error_message = e.Message;
        return -1;
      }

      if(_node_config_path == string.Empty || !System.IO.File.Exists(_node_config_path)) {
        _error_message = "Missing NodeConfig";
        return -1;
      }

      try {
        Validator.Validate(_node_config_path, NODE_XSD);
        _node_config = Utils.ReadConfig<NodeConfig>(_node_config_path);
        _node_config.Path = _node_config_path;
      } catch (Exception e) {
        _error_message = "Invalid NodeConfig file: " + e.Message;
        Console.WriteLine(e);
        return -1;
      }

      return 0;
    }

Usage Example

Пример #1
0
    public static int Main(string [] args) {
      // Create a new RuntimeParameters to parse the args
      RuntimeParameters parameters = new RuntimeParameters(
          "HelloWorldNodeDataHandler",
          "HelloWorld using IDataHandler/ISender paradigm");

      // Parse the args, if we don't get 0 back, there was an error
      if(parameters.Parse(args) != 0) {
        // Print the error and help
        Console.WriteLine(parameters.ErrorMessage);
        parameters.ShowHelp();
        // exit after error
        return -1;
      } else if(parameters.Help) {
        // Caller asked for help, let's print it
        parameters.ShowHelp();
        // exit after printing help
        return 0;
      }

      // Instantiate a new inherited node of your choice
      HelloWorldNodeDataHandler hwn =
        new HelloWorldNodeDataHandler(parameters.NodeConfig);
      // And run it... this hijacks the current thread, we'll return once the node disconnects
      hwn.Run();

      Console.WriteLine("Exiting...");

      return 0;
    }