public async stt::Task GetGameServerDeploymentRequestObjectAsync()
        {
            moq::Mock <GameServerDeploymentsService.GameServerDeploymentsServiceClient> mockGrpcClient = new moq::Mock <GameServerDeploymentsService.GameServerDeploymentsServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetGameServerDeploymentRequest request = new GetGameServerDeploymentRequest
            {
                GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"),
            };
            GameServerDeployment expectedResponse = new GameServerDeployment
            {
                GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"),
                CreateTime = new wkt::Timestamp(),
                UpdateTime = new wkt::Timestamp(),
                Labels     =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                Etag        = "etage8ad7218",
                Description = "description2cf9da67",
            };

            mockGrpcClient.Setup(x => x.GetGameServerDeploymentAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <GameServerDeployment>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            GameServerDeploymentsServiceClient client = new GameServerDeploymentsServiceClientImpl(mockGrpcClient.Object, null);
            GameServerDeployment responseCallSettings = await client.GetGameServerDeploymentAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            GameServerDeployment responseCancellationToken = await client.GetGameServerDeploymentAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>
        /// Updates game deployment
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        /// <returns>Game server deployment name</returns>
        public string UpdateDeployment(
            string projectId    = "YOUR-PROJECT-ID",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            string parent         = $"projects/{projectId}/locations/global";
            string deploymentName = $"{parent}/gameServerDeployments/{deploymentId}";

            // Construct the request
            var deployment = new GameServerDeployment
            {
                Name   = deploymentName,
                Labels = { { "key", "value" } }
            };
            var fieldMask = new FieldMask {
                Paths = { "labels" }
            };

            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Call the API
            try
            {
                var updated = client.UpdateGameServerDeployment(deployment, fieldMask);

                // Inspect the result
                return($"Game server deployment updated for deployment {deploymentId}. Operation Id: {updated.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"UpdateGameServerDeployment error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
        public void GetGameServerDeploymentRequestObject()
        {
            moq::Mock <GameServerDeploymentsService.GameServerDeploymentsServiceClient> mockGrpcClient = new moq::Mock <GameServerDeploymentsService.GameServerDeploymentsServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetGameServerDeploymentRequest request = new GetGameServerDeploymentRequest
            {
                GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"),
            };
            GameServerDeployment expectedResponse = new GameServerDeployment
            {
                GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"),
                CreateTime = new wkt::Timestamp(),
                UpdateTime = new wkt::Timestamp(),
                Labels     =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                Etag        = "etage8ad7218",
                Description = "description2cf9da67",
            };

            mockGrpcClient.Setup(x => x.GetGameServerDeployment(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            GameServerDeploymentsServiceClient client = new GameServerDeploymentsServiceClientImpl(mockGrpcClient.Object, null);
            GameServerDeployment response             = client.GetGameServerDeployment(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
    public async Task <GameServerDeployment> UpdateDeploymentAsync(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerDeployment deployment = new GameServerDeployment
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };

        deployment.Labels.Add("label-key-1", "label-value-1");
        deployment.Labels.Add("label-key-2", "label-value-2");

        UpdateGameServerDeploymentRequest request = new UpdateGameServerDeploymentRequest
        {
            GameServerDeployment = deployment,
            UpdateMask           = new FieldMask {
                Paths = { "labels" }
            }
        };

        // Make the request.
        Operation <GameServerDeployment, OperationMetadata> response = await client.UpdateGameServerDeploymentAsync(request);

        Operation <GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result. This result will NOT contain the updated labels.
        // If you want to get the updated resource, use a GET request on the resource.
        return(completedResponse.Result);
    }
예제 #5
0
    public async Task <GameServerDeployment> CreateDeploymentAsync(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerDeployment deployment = new GameServerDeployment()
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };
        CreateGameServerDeploymentRequest request = new CreateGameServerDeploymentRequest
        {
            DeploymentId         = deploymentId,
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, "global"),
            GameServerDeployment = deployment
        };

        // Make the request.
        Operation <GameServerDeployment, OperationMetadata> response = await client.CreateGameServerDeploymentAsync(request);

        // Poll until the returned long-running operation is complete.
        Operation <GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return(completedResponse.Result);
    }
    public GameServerDeployment GetDeployment(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.Create();

        GetGameServerDeploymentRequest request = new GetGameServerDeploymentRequest
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };

        // Make the request.
        GameServerDeployment response = client.GetGameServerDeployment(request);

        return(response);
    }
예제 #7
0
        /// <summary>
        /// Creates a new game deployment
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        public string CreateDeployment(
            string projectId    = "YOUR-PROJECT-ID",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            // Build a spec as shown at https://agones.dev/site/docs/reference/gameserver/
            var container = new JObject();

            container.Add("name", "default");
            container.Add("image", "gcr.io/agones-images/default:1.0");
            var containers = new JArray();

            containers.Add(container);

            var spec = new JObject();

            spec.Add("containers", containers);

            var template = new JObject();

            template.Add("spec", spec);

            var port = new JObject();

            port.Add("name", "default");

            var ports = new JArray();

            ports.Add(port);

            var specObject = new JObject();

            specObject.Add("ports", ports);
            specObject.Add("template", template);

            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string parent             = $"projects/{projectId}/locations/global";
            string deploymentName     = $"{parent}/gameServerDeployments/{deploymentId}";
            var    gameServerTemplate = new GameServerTemplate
            {
                Spec       = specObject.ToString(),
                TemplateId = "default"
            };
            var gameServerDeployment = new GameServerDeployment
            {
                Name = deploymentName,
                NewGameServerTemplate = gameServerTemplate,
            };
            var request = new CreateGameServerDeploymentRequest
            {
                Parent               = parent,
                DeploymentId         = deploymentId,
                GameServerDeployment = gameServerDeployment,
            };

            // Call the API
            try
            {
                var created = client.CreateGameServerDeployment(request);

                // Inspect the result
                return($"Game server deployment created for {deploymentId}. OperationId: {created.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"CreateGameServerDeployment error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }