/// <summary>Move units between countries. Only allowed after placing. Cancels any attacks that the player had left before. Attacking is not /// possible anymore after moving.</summary> /// <param name="gameId">Id of the game</param> /// <param name="options">Options for the command</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>Success</returns> /// <exception cref="ImperaPlusException">A server side error occurred.</exception> public async Task<GameActionResult> PostMoveAsync(int gameId, MoveOptions options, CancellationToken cancellationToken) { var url_ = string.Format("{0}/{1}", BaseUrl, "api/games/{gameId}/play/move"); if (gameId == null) throw new ArgumentNullException("gameId"); url_ = url_.Replace("{gameId}", Uri.EscapeDataString(gameId.ToString())); var client_ = await CreateHttpClientAsync(cancellationToken).ConfigureAwait(false); var request_ = new HttpRequestMessage(); PrepareRequest(client_, ref url_); var content_ = new StringContent(JsonConvert.SerializeObject(options)); content_.Headers.ContentType.MediaType = "application/json"; request_.Content = content_; request_.Method = new HttpMethod("POST"); request_.RequestUri = new Uri(url_, UriKind.RelativeOrAbsolute); var response_ = await client_.SendAsync(request_, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false); ProcessResponse(client_, response_); var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "200") { var result_ = default(GameActionResult); try { if (responseData_.Length > 0) result_ = JsonConvert.DeserializeObject<GameActionResult>(Encoding.UTF8.GetString(responseData_, 0, responseData_.Length)); return result_; } catch (Exception exception) { throw new ImperaPlusException("Could not deserialize the response body.", status_, responseData_, exception); } } else { } throw new ImperaPlusException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null); }
/// <summary>Move units between countries. Only allowed after placing. Cancels any attacks that the player had left before. Attacking is not /// possible anymore after moving.</summary> /// <param name="gameId">Id of the game</param> /// <param name="options">Options for the command</param> /// <returns>Success</returns> /// <exception cref="ImperaPlusException">A server side error occurred.</exception> public Task<GameActionResult> PostMoveAsync(int gameId, MoveOptions options) { return PostMoveAsync(gameId, options, CancellationToken.None); }