agones.dev/agones@v1.53.0/examples/allocator-client-csharp/Program.cs (about)

     1  using System;
     2  using System.Threading;
     3  using System.Threading.Tasks;
     4  using System.IO;
     5  using Grpc.Core;
     6  using Allocation;
     7  using System.Net.Http;
     8  
     9  namespace AllocatorClient
    10  {
    11      class Program
    12      {
    13          static async Task Main(string[] args)
    14          {
    15              if (args.Length < 6) {
    16                  throw new Exception("Arguments are missing. Expecting: <private key> <public key> <server CA> <external IP> <namespace> <enable multi-cluster>");
    17              }
    18  
    19              string clientKey    = File.ReadAllText(args[0]);
    20              string clientCert   = File.ReadAllText(args[1]);
    21              string serverCa     = File.ReadAllText(args[2]);
    22              string externalIp   = args[3];
    23              string namespaceArg = args[4];
    24              bool   multicluster = bool.Parse(args[5]);
    25  
    26              var creds = new SslCredentials(serverCa, new KeyCertificatePair(clientCert, clientKey));
    27              var channel = new Channel(externalIp + ":443", creds);
    28              var client = new AllocationService.AllocationServiceClient(channel);
    29  
    30             try {
    31                  var response = await client.AllocateAsync(new AllocationRequest { 
    32                      Namespace = namespaceArg,
    33                      MultiClusterSetting = new Allocation.MultiClusterSetting {
    34                          Enabled = multicluster,
    35                      }
    36                  });
    37                  Console.WriteLine(response);
    38              } 
    39              catch(RpcException e)
    40              {
    41                  Console.WriteLine($"gRPC error: {e}");
    42              }
    43          }
    44      }
    45  }