本文整理汇总了C#中Amazon.DynamoDBv2.Model.PutItemRequest类的典型用法代码示例。如果您正苦于以下问题:C# PutItemRequest类的具体用法?C# PutItemRequest怎么用?C# PutItemRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PutItemRequest类属于Amazon.DynamoDBv2.Model命名空间,在下文中一共展示了PutItemRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAccountItem
public virtual void CreateAccountItem(AmazonDynamoDBClient ddbClient, string tableName, Account account)
{
// Create the request
var putItemRequest = new PutItemRequest
{
TableName = tableName,
Item = new Dictionary<string, AttributeValue>
{
{"Company", new AttributeValue {S = account.Company}},
{"Email", new AttributeValue {S = account.Email}}
}
};
// Only add attributes if the coresponding property in the account object is not empty.
if (!String.IsNullOrEmpty(account.First))
{
putItemRequest.Item.Add("First", new AttributeValue {S = account.First});
}
if (!String.IsNullOrEmpty(account.Last))
{
putItemRequest.Item.Add("Last", new AttributeValue {S = account.Last});
}
if (!String.IsNullOrEmpty(account.Age))
{
putItemRequest.Item.Add("Age", new AttributeValue {N = account.Age});
}
// Submit the request
ddbClient.PutItem(putItemRequest);
}
示例2: SaveNewVideo
public void SaveNewVideo()
{
var client = new AmazonDynamoDBClient();
var request = new PutItemRequest();
request.TableName = "Local.Area";
request.Item = new Dictionary<string, AttributeValue>();
var value1 = new AttributeValue
{
S = "103"
};
request.Item.Add("Description", value1);
}
示例3: CreateUser
/// <summary>
/// Creates a user and sets the values in the GCLogin DynamoDB Table
/// </summary>
/// <param name="email">User's email address</param>
/// <param name="password">Users Password</param>
/// <returns>0 if successful, otherwise > 0</returns>
public int CreateUser(GCUser.LoginInfo loginInfo, string password)
{
int response = (int)DBEnum.DBResponseCodes.DEFAULT_VALUE;
PutItemRequest request = new PutItemRequest();
GetItemResponse giResponse = new GetItemResponse(); // created just to dump response but won't be used ever
// If user does NOT exist...Create User
if ((int)DBEnum.DBResponseCodes.DOES_NOT_EXIST == dbManager.GetItem(primaryKey, loginInfo.Email, TABLE, out giResponse))
{
try // Try to create User
{
string accountGuid = Guid.NewGuid().ToString(); // AccountId GUID
string emailVerificationGuid = Guid.NewGuid().ToString(); // Email verification hash
char[] delimeter = { ':' }; // delimeter for password hashing
string[] split = pwh.CreateHash(password).Split(delimeter); // create a hash based on the pw and split it using delimeter
// set table to "GCLogin"
request.TableName = TABLE;
// set items to add
request.Item.Add(primaryKey, new AttributeValue { S = loginInfo.Email });
request.Item.Add(ACCOUNT_ID, new AttributeValue { S = accountGuid });
request.Item.Add(ENCRYPTION, new AttributeValue { S = split[(int)DBEnum.GCLoginIndex.ENCRYPTION_INDEX] });
request.Item.Add(ITERATIONS, new AttributeValue { S = split[(int)DBEnum.GCLoginIndex.ITERATION_INDEX] });
request.Item.Add(SALT_HASH, new AttributeValue { S = split[(int)DBEnum.GCLoginIndex.SALT_INDEX] });
request.Item.Add(PASSWORD_HASH, new AttributeValue { S = split[(int)DBEnum.GCLoginIndex.PBKDF2_INDEX] });
request.Item.Add(EMAIL_VERIFICATION_GUID, new AttributeValue { S = emailVerificationGuid });
request.Item.Add(ACCOUNT_VALIDATED, new AttributeValue { BOOL = false });
// put items in DB
dbManager.PutItem(request);
response = (int)DBEnum.DBResponseCodes.SUCCESS;
logger.WriteLog(GameLogger.LogLevel.Debug, string.Format("Created user {0} in Table {1}", loginInfo.Email, TABLE));
}
catch // If creation fails
{
response = (int)DBEnum.DBResponseCodes.DYNAMODB_EXCEPTION;
logger.WriteLog(GameLogger.LogLevel.Error, string.Format("Failed to create user {0} due to DynamoDB Exception.", loginInfo.Email));
}
}
// if user DOES exist or error
else
{
logger.WriteLog(GameLogger.LogLevel.Debug, string.Format("Failed to create user {0}, it already exists or another error happened.", loginInfo.Email));
response = (int)DBEnum.DBResponseCodes.USER_EXIST;
}
return response;
}
示例4: AddImage
public virtual void AddImage(AmazonDynamoDBClient dynamoDbClient, string tableName, AmazonS3Client s3Client, string bucketName, string imageKey, string filePath)
{
try
{
if (File.Exists(filePath))
{
// Create the upload request
var putObjectRequest = new PutObjectRequest
{
BucketName = bucketName,
Key = imageKey,
FilePath = filePath
};
// Upload the object
s3Client.PutObject(putObjectRequest);
// Create the put item request to submit to DynamoDB
var putItemRequest = new PutItemRequest
{
TableName = tableName,
Item = new Dictionary<string, AttributeValue>
{
{"Key", new AttributeValue {S = imageKey}},
{"Bucket", new AttributeValue {S = bucketName}}
}
};
dynamoDbClient.PutItem(putItemRequest);
_Default.LogMessageToPage("Added imageKey: {0}", imageKey);
}
else
{
_Default.LogMessageToPage("Skipped imageKey: {0}", imageKey);
}
}
catch (Exception ex)
{
_Default.LogMessageToPage("AddImage Error: {0}", ex.Message);
}
}
示例5: PutItemAsync
/// <summary>
/// Initiates the asynchronous execution of the PutItem operation.
/// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB.PutItem"/>
/// </summary>
///
/// <param name="request">Container for the necessary parameters to execute the PutItem operation.</param>
/// <param name="cancellationToken">
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
/// </param>
/// <returns>The task object representing the asynchronous operation.</returns>
public async Task<PutItemResponse> PutItemAsync(PutItemRequest request, CancellationToken cancellationToken = default(CancellationToken))
{
var marshaller = new PutItemRequestMarshaller();
var unmarshaller = PutItemResponseUnmarshaller.GetInstance();
var response = await Invoke<IRequest, PutItemRequest, PutItemResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
return response;
}
示例6: BeginPutItem
/// <summary>
/// Initiates the asynchronous execution of the PutItem operation.
/// </summary>
///
/// <param name="request">Container for the necessary parameters to execute the PutItem operation on AmazonDynamoDBClient.</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 EndPutItem
/// operation.</returns>
public IAsyncResult BeginPutItem(PutItemRequest request, AsyncCallback callback, object state)
{
var marshaller = new PutItemRequestMarshaller();
var unmarshaller = PutItemResponseUnmarshaller.Instance;
return BeginInvoke<PutItemRequest>(request, marshaller, unmarshaller,
callback, state);
}
示例7: ApplyExpression
internal void ApplyExpression(PutItemRequest request, DynamoDBEntryConversion conversion)
{
request.ConditionExpression = this.ExpressionStatement;
request.ExpressionAttributeNames = new Dictionary<string, string>(this.ExpressionAttributeNames);
request.ExpressionAttributeValues = ConvertToAttributeValues(this.ExpressionAttributeValues, conversion);
}
示例8: InsertData1
public static void InsertData1()
{
for (int i = 11; i <= 20; i++)
{
var Req = new PutItemRequest
{
TableName = "TestID",
Item = new Dictionary<string, AttributeValue>() {
{"Id",new AttributeValue{N=i.ToString()}},
{"Msg",new AttributeValue{S="Test"+i}},
{"Memo",new AttributeValue{S="Memo "+i}}
}
};
var Rsp = client.PutItem(Req);
}
}
示例9: PutItemAsync
/// <summary>
/// Initiates the asynchronous execution of the PutItem operation.
/// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB"/>
/// </summary>
///
/// <param name="request">Container for the necessary parameters to execute the PutItem operation.</param>
/// <param name="cancellationToken">
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
/// </param>
/// <returns>The task object representing the asynchronous operation.</returns>
public Task<PutItemResponse> PutItemAsync(PutItemRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
{
var marshaller = new PutItemRequestMarshaller();
var unmarshaller = PutItemResponseUnmarshaller.Instance;
return InvokeAsync<PutItemRequest,PutItemResponse>(request, marshaller,
unmarshaller, cancellationToken);
}
示例10: PutItem
/// <summary>
/// <para>Creates a new item, or replaces an old item with a new item. If an item already exists in the specified table with the same primary
/// key, the new item completely replaces the existing item. You can perform a conditional put (insert a new item if one with the specified
/// primary key doesn't exist), or replace an existing item if it has certain attribute values. </para> <para>In addition to putting an item,
/// you can also return the item's attribute values in the same operation, using the <i>ReturnValues</i> parameter.</para> <para>When you add an
/// item, the primary key attribute(s) are the only required attributes. Attribute values cannot be null. String and binary type attributes must
/// have lengths greater than zero. Set type attributes cannot be empty. Requests with empty values will be rejected with a
/// <i>ValidationException</i> .</para> <para>You can request that <i>PutItem</i> return either a copy of the old item (before the update) or a
/// copy of the new item (after the update). For more information, see the <i>ReturnValues</i> description.</para> <para><b>NOTE:</b> To prevent
/// a new item from replacing an existing item, use a conditional put operation with Exists set to false for the primary key attribute, or
/// attributes. </para> <para>For more information about using this API, see Working with Items in the <i>Amazon DynamoDB Developer Guide</i>
/// .</para>
/// </summary>
///
/// <param name="putItemRequest">Container for the necessary parameters to execute the PutItem service method on AmazonDynamoDBv2.</param>
///
/// <returns>The response from the PutItem service method, as returned by AmazonDynamoDBv2.</returns>
///
/// <exception cref="ItemCollectionSizeLimitExceededException"/>
/// <exception cref="ResourceNotFoundException"/>
/// <exception cref="ConditionalCheckFailedException"/>
/// <exception cref="ProvisionedThroughputExceededException"/>
/// <exception cref="InternalServerErrorException"/>
public PutItemResponse PutItem(PutItemRequest putItemRequest)
{
IAsyncResult asyncResult = invokePutItem(putItemRequest, null, null, true);
return EndPutItem(asyncResult);
}
示例11: invokePutItem
IAsyncResult invokePutItem(PutItemRequest putItemRequest, AsyncCallback callback, object state, bool synchronized)
{
IRequest irequest = new PutItemRequestMarshaller().Marshall(putItemRequest);
var unmarshaller = PutItemResponseUnmarshaller.GetInstance();
AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
Invoke(result);
return result;
}
示例12: PutItemAsync
/// <summary>
/// <para>Creates a new item, or replaces an old item with a new item. If an item already exists in the specified table with the same primary
/// key, the new item completely replaces the existing item. You can perform a conditional put (insert a new item if one with the specified
/// primary key doesn't exist), or replace an existing item if it has certain attribute values. </para> <para>In addition to putting an item,
/// you can also return the item's attribute values in the same operation, using the <i>ReturnValues</i> parameter.</para> <para>When you add an
/// item, the primary key attribute(s) are the only required attributes. Attribute values cannot be null. String and binary type attributes must
/// have lengths greater than zero. Set type attributes cannot be empty. Requests with empty values will be rejected with a
/// <i>ValidationException</i> .</para> <para>You can request that <i>PutItem</i> return either a copy of the old item (before the update) or a
/// copy of the new item (after the update). For more information, see the <i>ReturnValues</i> description.</para> <para><b>NOTE:</b> To prevent
/// a new item from replacing an existing item, use a conditional put operation with Exists set to false for the primary key attribute, or
/// attributes. </para> <para>For more information about using this API, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html">Working with Items</a> in the Amazon DynamoDB
/// Developer Guide.</para>
/// </summary>
///
/// <param name="putItemRequest">Container for the necessary parameters to execute the PutItem service method on AmazonDynamoDBv2.</param>
///
/// <returns>The response from the PutItem service method, as returned by AmazonDynamoDBv2.</returns>
///
/// <exception cref="T:Amazon.DynamoDBv2.Model.ItemCollectionSizeLimitExceededException" />
/// <exception cref="T:Amazon.DynamoDBv2.Model.ResourceNotFoundException" />
/// <exception cref="T:Amazon.DynamoDBv2.Model.ConditionalCheckFailedException" />
/// <exception cref="T:Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException" />
/// <exception cref="T:Amazon.DynamoDBv2.Model.InternalServerErrorException" />
/// <param name="cancellationToken">
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
/// </param>
public Task<PutItemResponse> PutItemAsync(PutItemRequest putItemRequest, CancellationToken cancellationToken = default(CancellationToken))
{
var marshaller = new PutItemRequestMarshaller();
var unmarshaller = PutItemResponseUnmarshaller.GetInstance();
return Invoke<IRequest, PutItemRequest, PutItemResponse>(putItemRequest, marshaller, unmarshaller, signer, cancellationToken);
}
示例13: PutItemAsync
/// <summary>
/// Creates a new item, or replaces an old item with a new item. If an item that has the
/// same primary key as the new item already exists in the specified table, the new item
/// completely replaces the existing item. You can perform a conditional put operation
/// (add a new item if one with the specified primary key doesn't exist), or replace an
/// existing item if it has certain attribute values.
///
///
/// <para>
/// In addition to putting an item, you can also return the item's attribute values in
/// the same operation, using the <i>ReturnValues</i> parameter.
/// </para>
///
/// <para>
/// When you add an item, the primary key attribute(s) are the only required attributes.
/// Attribute values cannot be null. String and Binary type attributes must have lengths
/// greater than zero. Set type attributes cannot be empty. Requests with empty values
/// will be rejected with a <i>ValidationException</i> exception.
/// </para>
///
/// <para>
/// You can request that <i>PutItem</i> return either a copy of the original item (before
/// the update) or a copy of the updated item (after the update). For more information,
/// see the <i>ReturnValues</i> description below.
/// </para>
/// <note>
/// <para>
/// To prevent a new item from replacing an existing item, use a conditional put operation
/// with <i>ComparisonOperator</i> set to <code>NULL</code> for the primary key attribute,
/// or attributes.
/// </para>
/// </note>
/// <para>
/// For more information about using this API, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html">Working
/// with Items</a> in the <i>Amazon DynamoDB Developer Guide</i>.
/// </para>
/// </summary>
/// <param name="tableName">The name of the table to contain the item.</param>
/// <param name="item">A map of attribute name/value pairs, one for each attribute. Only the primary key attributes are required; you can optionally provide other attribute name-value pairs for the item. You must provide all of the attributes for the primary key. For example, with a hash type primary key, you only need to provide the hash attribute. For a hash-and-range type primary key, you must provide both the hash attribute and the range attribute. If you specify any attributes that are part of an index key, then the data types for those attributes must match those of the schema in the table's attribute definition. For more information about primary keys, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModelPrimaryKey">Primary Key</a> in the <i>Amazon DynamoDB Developer Guide</i>. Each element in the <i>Item</i> map is an <i>AttributeValue</i> object.</param>
/// <param name="returnValues">Use <i>ReturnValues</i> if you want to get the item attributes as they appeared before they were updated with the <i>PutItem</i> request. For <i>PutItem</i>, the valid values are: <ul> <li> <code>NONE</code> - If <i>ReturnValues</i> is not specified, or if its value is <code>NONE</code>, then nothing is returned. (This setting is the default for <i>ReturnValues</i>.) </li> <li> <code>ALL_OLD</code> - If <i>PutItem</i> overwrote an attribute name-value pair, then the content of the old item is returned. </li> </ul> <note>Other "Valid Values" are not relevant to PutItem.</note></param>
/// <param name="cancellationToken">
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
/// </param>
///
/// <returns>The response from the PutItem service method, as returned by DynamoDB.</returns>
/// <exception cref="Amazon.DynamoDBv2.Model.ConditionalCheckFailedException">
/// A condition specified in the operation could not be evaluated.
/// </exception>
/// <exception cref="Amazon.DynamoDBv2.Model.InternalServerErrorException">
/// An error occurred on the server side.
/// </exception>
/// <exception cref="Amazon.DynamoDBv2.Model.ItemCollectionSizeLimitExceededException">
/// An item collection is too large. This exception is only returned for tables that have
/// one or more local secondary indexes.
/// </exception>
/// <exception cref="Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException">
/// Your request rate is too high. The AWS SDKs for DynamoDB automatically retry requests
/// that receive this exception. Your request is eventually successful, unless your retry
/// queue is too large to finish. Reduce the frequency of requests and use exponential
/// backoff. For more information, go to <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html#APIRetries">Error
/// Retries and Exponential Backoff</a> in the <i>Amazon DynamoDB Developer Guide</i>.
/// </exception>
/// <exception cref="Amazon.DynamoDBv2.Model.ResourceNotFoundException">
/// The operation tried to access a nonexistent table or index. The resource might not
/// be specified correctly, or its status might not be <code>ACTIVE</code>.
/// </exception>
public Task<PutItemResponse> PutItemAsync(string tableName, Dictionary<string, AttributeValue> item, ReturnValue returnValues, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
{
var request = new PutItemRequest();
request.TableName = tableName;
request.Item = item;
request.ReturnValues = returnValues;
return PutItemAsync(request, cancellationToken);
}
示例14: PutSample
private void PutSample()
{
{
#region PutItem Sample 1
// Create a client
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
// Define item attributes
Dictionary<string, AttributeValue> attributes = new Dictionary<string, AttributeValue>();
// Author is hash-key
attributes["Author"] = new AttributeValue { S = "Mark Twain" };
// Title is range-key
attributes["Title"] = new AttributeValue { S = "The Adventures of Tom Sawyer" };
// Other attributes
attributes["Year"] = new AttributeValue { N = "1876" };
attributes["Setting"] = new AttributeValue { S = "Missouri" };
attributes["Pages"] = new AttributeValue { N = "275" };
attributes["Genres"] = new AttributeValue
{
SS = new List<string> { "Satire", "Folk", "Children's Novel" }
};
// Create PutItem request
PutItemRequest request = new PutItemRequest
{
TableName = "SampleTable",
Item = attributes
};
// Issue PutItem request
client.PutItem(request);
#endregion
}
}
示例15: PutItemAsync
/// <summary>
/// Initiates the asynchronous execution of the PutItem operation.
/// </summary>
///
/// <param name="request">Container for the necessary parameters to execute the PutItem operation on AmazonDynamoDBClient.</param>
/// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
/// <param name="options">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>
public void PutItemAsync(PutItemRequest request, AmazonServiceCallback<PutItemRequest, PutItemResponse> callback, AsyncOptions options = null)
{
options = options == null?new AsyncOptions():options;
var marshaller = new PutItemRequestMarshaller();
var unmarshaller = PutItemResponseUnmarshaller.Instance;
Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
if(callback !=null )
callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => {
AmazonServiceResult<PutItemRequest,PutItemResponse> responseObject
= new AmazonServiceResult<PutItemRequest,PutItemResponse>((PutItemRequest)req, (PutItemResponse)res, ex , ao.State);
callback(responseObject);
};
BeginInvoke<PutItemRequest>(request, marshaller, unmarshaller, options, callbackHelper);
}