Run() public méthode

This should be called by the Main after all the setup is done this passes control to the _node and won't return until the program is exiting. (It is synchronous.)
public Run ( ) : void
Résultat void
Exemple #1
0
 /**
 <summary>Runs the BasicNode.  This should be implemented in all inherited
 classes.</summary>
 <remarks>
 <para>To execute this at a command-line using Mono:</para>
 <code>
 mono BasicNode.exe path/to/node_config
 </code>
 <para>To execute this at a command-line using Windows .NET:</para>
 <code>
 BasicNode.exe path/to/node_config
 </code>
 </remarks>
 <param name="args">The command line argument required is a path to a
 NodeConfig</param>
 */
 public static int Main(String[] args) {
   BasicNode node = new BasicNode(args[0]);
   node.Run();
   return 0;
 }
Exemple #2
0
    public static int Main(String[] args) {
      string node_config_path = string.Empty;
      string str_count = string.Empty;
      int count = 1;
      bool show_help = false;

      OptionSet opts = new OptionSet() {
        { "n|NodeConfig=", "Path to a NodeConfig file.",
          v => node_config_path = v },
        { "c|Count=", "Number of nodes to instantiate.",
          v => str_count = v },
        { "h|help", "Display this help and exit.",
          v => show_help = v != null },
      };

      try {
        opts.Parse(args);
      } catch (OptionException e) {
        Console.WriteLine("P2PNode: ");
        Console.WriteLine(e.Message);
        Console.WriteLine("Try `P2PNode --help' for more information.");
        return -1;
      }

      if(show_help) {
        ShowHelp(opts);
        return -1;
      }

      if(node_config_path == string.Empty || !File.Exists(node_config_path)) {
        Console.WriteLine("P2PNode: ");
        Console.WriteLine("\tMissing NodeConfig.");
        Console.WriteLine("Try `P2PNode --help' for more information.");
        return -1;
      }

      if(str_count != string.Empty && !Int32.TryParse(str_count, out count) && count > 0) {
        Console.WriteLine("P2PNode: ");
        Console.WriteLine("\tInvalid count.  Count must be a positive integer.");
        Console.WriteLine("Try `P2PNode --help' for more information.");
        return -1;
      }

      NodeConfig node_config = null;
      try {
        ConfigurationValidator cv = new ConfigurationValidator();
        cv.Validate(node_config_path, "Node.xsd");
        node_config = Utils.ReadConfig<NodeConfig>(node_config_path);
        node_config.Path = node_config_path;
      } catch (Exception e) {
        Console.WriteLine("Invalid NodeConfig file:");
        Console.WriteLine("\t" + e);
        return -1;
      }

      if(node_config.NodeAddress == null) {
        node_config.NodeAddress = (Utils.GenerateAHAddress()).ToString();
        node_config.WriteConfig();
      }

      if(count == 1) {
        BasicNode node = new BasicNode(node_config);
        node.Run();
      } else {
        MultiNode node = new MultiNode(node_config, count);
        node.Run();
      }
      return 0;
    }