/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.GameLift;
using Amazon.GameLift.Model;
namespace Amazon.PowerShell.Cmdlets.GML
{
///
/// Creates a multiplayer game session for players in a specific fleet location. This
/// operation prompts an available server process to start a game session and retrieves
/// connection information for the new game session. As an alternative, consider using
/// the Amazon GameLift game session placement feature with StartGameSessionPlacement
/// , which uses FleetIQ algorithms and queues to optimize the placement process.
///
///
///
/// When creating a game session, you specify exactly where you want to place it and provide
/// a set of game session configuration settings. The fleet must be in ACTIVE
/// status before a game session can be created in it.
///
/// This operation can be used in the following ways:
/// -
/// To create a game session on an instance in a fleet's home Region, provide a fleet
/// or alias ID along with your game session configuration.
///
-
/// To create a game session on an instance in a fleet's remote location, provide a fleet
/// or alias ID and a location name, along with your game session configuration.
///
/// If successful, a workflow is initiated to start a new game session. A GameSession
/// object is returned containing the game session configuration and status. When the
/// status is ACTIVE
, game session connection information is provided and
/// player sessions can be created for the game session. By default, newly created game
/// sessions are open to new players. You can restrict new player access by using UpdateGameSession
/// to change the game session's player session creation policy.
///
/// Game session logs are retained for all active game sessions for 14 days. To access
/// the logs, call GetGameSessionLogUrl
/// to download the log files.
/// Available in Amazon GameLift Local.Learn moreStart
/// a game sessionAll
/// APIs by task
///
[Cmdlet("New", "GMLGameSession", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.GameLift.Model.GameSession")]
[AWSCmdlet("Calls the Amazon GameLift Service CreateGameSession API operation.", Operation = new[] {"CreateGameSession"}, SelectReturnType = typeof(Amazon.GameLift.Model.CreateGameSessionResponse))]
[AWSCmdletOutput("Amazon.GameLift.Model.GameSession or Amazon.GameLift.Model.CreateGameSessionResponse",
"This cmdlet returns an Amazon.GameLift.Model.GameSession object.",
"The service call response (type Amazon.GameLift.Model.CreateGameSessionResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewGMLGameSessionCmdlet : AmazonGameLiftClientCmdlet, IExecutor
{
#region Parameter AliasId
///
///
/// A unique identifier for the alias associated with the fleet to create a game session
/// in. You can use either the alias ID or ARN value. Each request must reference either
/// a fleet ID or alias ID, but not both.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String AliasId { get; set; }
#endregion
#region Parameter CreatorId
///
///
/// A unique identifier for a player or entity creating the game session. If you add a resource creation limit policy to a fleet, the CreateGameSession
/// operation requires a CreatorId
. Amazon GameLift limits the number of
/// game session creation requests with the same CreatorId
in a specified
/// time period.If you your fleet doesn't have a resource creation limit policy and you provide a
/// CreatorId
in your CreateGameSession
requests, Amazon GameLift
/// limits requests to one request per CreatorId
per second.To not limit CreateGameSession
requests with the same CreatorId
,
/// don't provide a CreatorId
in your CreateGameSession
request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String CreatorId { get; set; }
#endregion
#region Parameter FleetId
///
///
/// A unique identifier for the fleet to create a game session in. You can use either
/// the fleet ID or ARN value. Each request must reference either a fleet ID or alias
/// ID, but not both.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String FleetId { get; set; }
#endregion
#region Parameter GameProperty
///
///
/// A set of custom properties for a game session, formatted as key:value pairs. These
/// properties are passed to a game server process with a request to start a new game
/// session (see Start
/// a Game Session).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("GameProperties")]
public Amazon.GameLift.Model.GameProperty[] GameProperty { get; set; }
#endregion
#region Parameter GameSessionData
///
///
/// A set of custom game session properties, formatted as a single string value. This
/// data is passed to a game server process with a request to start a new game session
/// (see Start
/// a Game Session).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String GameSessionData { get; set; }
#endregion
#region Parameter GameSessionId
///
///
/// This parameter is deprecated. Use IdempotencyToken
instead.Custom string that uniquely identifies a request for a new game session. Maximum token
/// length is 48 characters. If provided, this string is included in the new game session's
/// ID.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String GameSessionId { get; set; }
#endregion
#region Parameter IdempotencyToken
///
///
/// Custom string that uniquely identifies the new game session request. This is useful
/// for ensuring that game session requests with the same idempotency token are processed
/// only once. Subsequent requests with the same string return the original GameSession
/// object, with an updated status. Maximum token length is 48 characters. If provided,
/// this string is included in the new game session's ID. A game session ARN has the following
/// format: arn:aws:gamelift:<region>::gamesession/<fleet ID>/<custom
/// ID string or idempotency token>
. Idempotency tokens remain in use for 30
/// days after a game session has ended; game session objects are retained for this time
/// period and then deleted.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String IdempotencyToken { get; set; }
#endregion
#region Parameter Location
///
///
/// A fleet's remote location to place the new game session in. If this parameter is not
/// set, the new game session is placed in the fleet's home Region. Specify a remote location
/// with an Amazon Web Services Region code such as us-west-2
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Location { get; set; }
#endregion
#region Parameter MaximumPlayerSessionCount
///
///
/// The maximum number of players that can be connected simultaneously to the game session.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.Int32? MaximumPlayerSessionCount { get; set; }
#endregion
#region Parameter Name
///
///
/// A descriptive label that is associated with a game session. Session names do not need
/// to be unique.
///
///
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
public System.String Name { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'GameSession'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.GameLift.Model.CreateGameSessionResponse).
/// Specifying the name of a property of type Amazon.GameLift.Model.CreateGameSessionResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "GameSession";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the Name parameter.
/// The -PassThru parameter is deprecated, use -Select '^Name' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Name' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.Name), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-GMLGameSession (CreateGameSession)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.Name;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AliasId = this.AliasId;
context.CreatorId = this.CreatorId;
context.FleetId = this.FleetId;
if (this.GameProperty != null)
{
context.GameProperty = new List(this.GameProperty);
}
context.GameSessionData = this.GameSessionData;
context.GameSessionId = this.GameSessionId;
context.IdempotencyToken = this.IdempotencyToken;
context.Location = this.Location;
context.MaximumPlayerSessionCount = this.MaximumPlayerSessionCount;
#if MODULAR
if (this.MaximumPlayerSessionCount == null && ParameterWasBound(nameof(this.MaximumPlayerSessionCount)))
{
WriteWarning("You are passing $null as a value for parameter MaximumPlayerSessionCount which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.Name = this.Name;
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.GameLift.Model.CreateGameSessionRequest();
if (cmdletContext.AliasId != null)
{
request.AliasId = cmdletContext.AliasId;
}
if (cmdletContext.CreatorId != null)
{
request.CreatorId = cmdletContext.CreatorId;
}
if (cmdletContext.FleetId != null)
{
request.FleetId = cmdletContext.FleetId;
}
if (cmdletContext.GameProperty != null)
{
request.GameProperties = cmdletContext.GameProperty;
}
if (cmdletContext.GameSessionData != null)
{
request.GameSessionData = cmdletContext.GameSessionData;
}
if (cmdletContext.GameSessionId != null)
{
request.GameSessionId = cmdletContext.GameSessionId;
}
if (cmdletContext.IdempotencyToken != null)
{
request.IdempotencyToken = cmdletContext.IdempotencyToken;
}
if (cmdletContext.Location != null)
{
request.Location = cmdletContext.Location;
}
if (cmdletContext.MaximumPlayerSessionCount != null)
{
request.MaximumPlayerSessionCount = cmdletContext.MaximumPlayerSessionCount.Value;
}
if (cmdletContext.Name != null)
{
request.Name = cmdletContext.Name;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.GameLift.Model.CreateGameSessionResponse CallAWSServiceOperation(IAmazonGameLift client, Amazon.GameLift.Model.CreateGameSessionRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon GameLift Service", "CreateGameSession");
try
{
#if DESKTOP
return client.CreateGameSession(request);
#elif CORECLR
return client.CreateGameSessionAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String AliasId { get; set; }
public System.String CreatorId { get; set; }
public System.String FleetId { get; set; }
public List GameProperty { get; set; }
public System.String GameSessionData { get; set; }
public System.String GameSessionId { get; set; }
public System.String IdempotencyToken { get; set; }
public System.String Location { get; set; }
public System.Int32? MaximumPlayerSessionCount { get; set; }
public System.String Name { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.GameSession;
}
}
}