Exemplo n.º 1
0
        private void GetKeyInfo()
        {
            DescribeTableRequest req = new DescribeTableRequest
            {
                TableName = TableName
            };
            req.BeforeRequestEvent += new RequestEventHandler(this.UserAgentRequestEventHandlerSync);
            DescribeTableResult info = this.DDBClient.DescribeTable(req).DescribeTableResult;

            if (info.Table == null)
            {
                throw new ArgumentException(String.Format("Table name {0} does not exist", TableName));
            }

            HashKeyType = GetType(info.Table.KeySchema.HashKeyElement.AttributeType);
            HashKeyName = info.Table.KeySchema.HashKeyElement.AttributeName;

            if (info.Table.KeySchema.RangeKeyElement != null)
            {
                RangeKeyIsDefined = true;
                RangeKeyType = GetType(info.Table.KeySchema.RangeKeyElement.AttributeType);
                RangeKeyName = info.Table.KeySchema.RangeKeyElement.AttributeName;
                keyNames = new string[] { HashKeyName, RangeKeyName };
            }
            else
            {
                keyNames = new string[] { HashKeyName };
            }
        }
        private Table CreateTable()
        {
            CreateTableRequest createRequest = new CreateTableRequest()
                .WithTableName(this._tableName)
                .WithKeySchema(new KeySchema()
                    .WithHashKeyElement(new KeySchemaElement()
                        .WithAttributeName(ATTRIBUTE_SESSION_ID)
                        .WithAttributeType("S")))
                .WithProvisionedThroughput(new ProvisionedThroughput()
                    .WithReadCapacityUnits(this._initialReadUnits)
                    .WithWriteCapacityUnits(this._initialWriteUnits));
            createRequest.BeforeRequestEvent += this.UserAgentRequestEventHandler;

            CreateTableResponse response = this._ddbClient.CreateTable(createRequest);

            DescribeTableRequest descRequest = new DescribeTableRequest()
                .WithTableName(this._tableName);
            descRequest.BeforeRequestEvent += this.UserAgentRequestEventHandler;

            // Wait till table is active
            bool isActive = false;
            while (!isActive)
            {
                Thread.Sleep(DESCRIBE_INTERVAL);
                DescribeTableResponse descResponse = this._ddbClient.DescribeTable(descRequest);
                string tableStatus = descResponse.DescribeTableResult.Table.TableStatus;

                if (string.Equals(tableStatus, ACTIVE_STATUS, StringComparison.InvariantCultureIgnoreCase))
                    isActive = true;
            }

            Table table = Table.LoadTable(this._ddbClient, this._tableName, Table.DynamoDBConsumer.SessionStateProvider);
            return table;
        }
 IAsyncResult invokeDescribeTable(DescribeTableRequest describeTableRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new DescribeTableRequestMarshaller().Marshall(describeTableRequest);
     var unmarshaller = DescribeTableResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
 /// <summary>
 /// <para>Retrieves information about the table, including the current status of the table, the primary key schema and when the table was
 /// created.</para> <para>If the table does not exist, Amazon DynamoDB returns a <c>ResourceNotFoundException</c> .</para>
 /// </summary>
 /// 
 /// <param name="describeTableRequest">Container for the necessary parameters to execute the DescribeTable service method on
 ///          AmazonDynamoDB.</param>
 /// 
 /// <returns>The response from the DescribeTable service method, as returned by AmazonDynamoDB.</returns>
 /// 
 /// <exception cref="InternalServerErrorException"/>
 /// <exception cref="ResourceNotFoundException"/>
 public DescribeTableResponse DescribeTable(DescribeTableRequest describeTableRequest)
 {
     IAsyncResult asyncResult = invokeDescribeTable(describeTableRequest, null, null, true);
     return EndDescribeTable(asyncResult);
 }
 /// <summary>
 /// Initiates the asynchronous execution of the DescribeTable operation.
 /// <seealso cref="Amazon.DynamoDB.AmazonDynamoDB.DescribeTable"/>
 /// </summary>
 /// 
 /// <param name="describeTableRequest">Container for the necessary parameters to execute the DescribeTable operation on AmazonDynamoDB.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDescribeTable
 ///         operation.</returns>
 public IAsyncResult BeginDescribeTable(DescribeTableRequest describeTableRequest, AsyncCallback callback, object state)
 {
     return invokeDescribeTable(describeTableRequest, callback, state, false);
 }
 /// <summary>
 /// <para> Returns information about the table, including the current status of the table, the primary key schema and when the table was
 /// created. If the table does not exist, the server returns a ResourceNotFoundException. </para>
 /// </summary>
 /// 
 /// <param name="describeTableRequest">Container for the necessary parameters to execute the DescribeTable service method on
 ///           AmazonDynamoDB.</param>
 /// 
 /// <returns>The response from the DescribeTable service method, as returned by AmazonDynamoDB.</returns>
 /// 
 /// <exception cref="InternalServerErrorException"/>
 /// <exception cref="ResourceNotFoundException"/>
 public DescribeTableResponse DescribeTable(DescribeTableRequest describeTableRequest)
 {
     IRequest<DescribeTableRequest> request = new DescribeTableRequestMarshaller().Marshall(describeTableRequest);
     DescribeTableResponse response = Invoke<DescribeTableRequest, DescribeTableResponse> (request, this.signer, DescribeTableResponseUnmarshaller.GetInstance());
     return response;
 }