internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = doc.ToAttributeMap() }; req.BeforeRequestEvent += isAsync ? new RequestEventHandler(UserAgentRequestEventHandlerAsync) : new RequestEventHandler(UserAgentRequestEventHandlerSync); if (currentConfig.Expected != null) { req.Expected = currentConfig.Expected.ToExpectedAttributeMap(); } if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { req.ReturnValues = EnumToStringMapper.Convert(currentConfig.ReturnValues); } var resp = DDBClient.PutItem(req); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = Document.FromAttributeMap(resp.Attributes); } return(ret); }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/> /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <param name="callback">The callback that will be invoked when the asynchronous operation completes.</param> /// <param name="asyncOptions">An instance of AsyncOptions that specifies how the async method should be executed.</param> public void PutItemAsync(Document doc, PutItemOperationConfig config, AmazonDynamoDBCallback <Document> callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync <Document>( () => { return(PutItemHelper(doc, config, true)); }, asyncOptions, callback); }
/// <summary> /// Puts a document into DynamoDB, using optional configs. /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <returns>True if put is successful or false if the condition in the config was not met.</returns> public bool TryPutItem(Document doc, PutItemOperationConfig config = null) { try { PutItemHelper(doc, config, false); return true; } catch (ConditionalCheckFailedException) { return false; } }
/// <summary> /// Puts a document into DynamoDB, using specified configs. /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <returns>True if put was successful or false if the condition in the config was not met.</returns> public bool TryPutItem(Document doc, PutItemOperationConfig config) { try { PutItemHelper(doc, config); return(true); } catch (ConditionalCheckFailedException) { return(false); } }
internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = doc.ToAttributeMap(Conversion) }; ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)req).AddBeforeRequestHandler(isAsync ? new RequestEventHandler(UserAgentRequestEventHandlerAsync) : new RequestEventHandler(UserAgentRequestEventHandlerSync)); if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues); } ValidateConditional(currentConfig); if (currentConfig.Expected != null) { req.Expected = currentConfig.Expected.ToExpectedAttributeMap(Conversion); } else if (currentConfig.ExpectedState != null && currentConfig.ExpectedState.ExpectedValues != null && currentConfig.ExpectedState.ExpectedValues.Count > 0) { req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(Conversion); if (req.Expected.Count > 1) { req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator); } } else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet) { currentConfig.ConditionalExpression.ApplyExpression(req, this.Conversion); } var resp = DDBClient.PutItem(req); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = Document.FromAttributeMap(resp.Attributes); } return(ret); }
internal async Task <Document> PutItemHelperAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = this.ToAttributeMap(doc) }; this.AddRequestHandler(req, isAsync: true); if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues); } ValidateConditional(currentConfig); if (currentConfig.Expected != null) { req.Expected = this.ToExpectedAttributeMap(currentConfig.Expected); } else if (currentConfig.ExpectedState != null && currentConfig.ExpectedState.ExpectedValues != null && currentConfig.ExpectedState.ExpectedValues.Count > 0) { req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(this); if (req.Expected.Count > 1) { req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator); } } else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet) { currentConfig.ConditionalExpression.ApplyExpression(req, this); } var resp = await DDBClient.PutItemAsync(req, cancellationToken).ConfigureAwait(false); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = this.FromAttributeMap(resp.Attributes); } return(ret); }
internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = doc.ToAttributeMap() }; req.BeforeRequestEvent += isAsync ? new RequestEventHandler(UserAgentRequestEventHandlerAsync) : new RequestEventHandler(UserAgentRequestEventHandlerSync); if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues); } if (currentConfig.Expected != null && currentConfig.ExpectedState != null) { throw new InvalidOperationException("Expected and ExpectedState cannot be set at the same time"); } if (currentConfig.Expected != null) { req.Expected = currentConfig.Expected.ToExpectedAttributeMap(); } if (currentConfig.ExpectedState != null && currentConfig.ExpectedState.ExpectedValues != null && currentConfig.ExpectedState.ExpectedValues.Count > 0) { req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(); if (req.Expected.Count > 1) { req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator); } } var resp = DDBClient.PutItem(req); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = Document.FromAttributeMap(resp.Attributes); } return(ret); }
/// <summary> /// Puts a document into DynamoDB, using optional configs. /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <returns>Null or updated attributes, depending on config.</returns> public Document PutItem(Document doc, PutItemOperationConfig config = null) { return(PutItemHelper(doc, config, false)); }
/// <summary> /// Puts a document into DynamoDB, using specified configs. /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <returns>Null or updated attributes, depending on config.</returns> public Document PutItem(Document doc, PutItemOperationConfig config) { return(PutItemHelper(doc, config)); }
internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = doc.ToAttributeMap() }; req.BeforeRequestEvent += isAsync ? new RequestEventHandler(UserAgentRequestEventHandlerAsync) : new RequestEventHandler(UserAgentRequestEventHandlerSync); if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues); if (currentConfig.Expected != null && currentConfig.ExpectedState != null) throw new InvalidOperationException("Expected and ExpectedState cannot be set at the same time"); if (currentConfig.Expected != null) req.Expected = currentConfig.Expected.ToExpectedAttributeMap(); if (currentConfig.ExpectedState != null && currentConfig.ExpectedState.ExpectedValues != null && currentConfig.ExpectedState.ExpectedValues.Count > 0) { req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(); if (req.Expected.Count > 1) req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator); } var resp = DDBClient.PutItem(req); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = Document.FromAttributeMap(resp.Attributes); } return ret; }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <param name="callback">The callback that will be invoked when the asynchronous operation completes.</param> /// <param name="asyncOptions">An instance of AsyncOptions that specifies how the async method should be executed.</param> public void PutItemAsync(Document doc, PutItemOperationConfig config, AmazonDynamoDBCallback<Document> callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync<Document>( () => { return PutItemHelper(doc, config, true); }, asyncOptions, callback); }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/> /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <param name="cancellationToken">Token which can be used to cancel the task.</param> /// <returns>A Task that can be used to poll or wait for results, or both.</returns> public Task <Document> PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { return(PutItemHelperAsync(doc, config, cancellationToken)); }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/> /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <param name="cancellationToken">Token which can be used to cancel the task.</param> /// <returns>A Task that can be used to poll or wait for results, or both.</returns> public Task <Document> PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { return(AsyncRunner.Run(() => PutItemHelper(doc, config, true), cancellationToken)); }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/> /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</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(Document doc, PutItemOperationConfig config, AsyncCallback callback, object state) { return(DynamoDBAsyncExecutor.BeginOperation(() => PutItemHelper(doc, config, true), callback, state)); }
/// <summary> /// Puts a document into DynamoDB, using optional configs. /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <returns>Null or updated attributes, depending on config.</returns> public Document PutItem(Document doc, PutItemOperationConfig config = null) { return PutItemHelper(doc, config, false); }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// Puts a document into DynamoDB, using specified configs. /// Returns updated Document in callback /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <param name="callback">An AmazonDynamoCallback 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>void</returns> public void PutItemAsync(Document doc, PutItemOperationConfig config, AmazonDynamoCallback <Document> callback, object state) { DynamoDBAsyncExecutor.AsyncOperation <Document>(() => PutItemHelper(doc, config, true), "PutItemAsync", callback, state); }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/> /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</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(Document doc, PutItemOperationConfig config, AsyncCallback callback, object state) { return DynamoDBAsyncExecutor.BeginOperation(() => PutItemHelper(doc, config, true), callback, state); }
internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = doc.ToAttributeMap() }; req.BeforeRequestEvent += isAsync ? new RequestEventHandler(UserAgentRequestEventHandlerAsync) : new RequestEventHandler(UserAgentRequestEventHandlerSync); if (currentConfig.Expected != null) req.Expected = currentConfig.Expected.ToExpectedAttributeMap(); if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { req.ReturnValues = EnumToStringMapper.Convert(currentConfig.ReturnValues); } var resp = DDBClient.PutItem(req); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = Document.FromAttributeMap(resp.Attributes); } return ret; }
/// <summary> /// Puts a document into DynamoDB, using specified configs. /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <returns>Null or updated attributes, depending on config.</returns> internal Document PutItem(Document doc, PutItemOperationConfig config) { DynamoDBAsyncExecutor.IsMainThread("PutItemAsync"); return(PutItemHelper(doc, config, false)); }
internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = doc.ToAttributeMap(Conversion) }; ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)req).AddBeforeRequestHandler(isAsync ? new RequestEventHandler(UserAgentRequestEventHandlerAsync) : new RequestEventHandler(UserAgentRequestEventHandlerSync)); if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues); ValidateConditional(currentConfig); if (currentConfig.Expected != null) { req.Expected = currentConfig.Expected.ToExpectedAttributeMap(Conversion); } else if (currentConfig.ExpectedState != null && currentConfig.ExpectedState.ExpectedValues != null && currentConfig.ExpectedState.ExpectedValues.Count > 0) { req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(Conversion); if (req.Expected.Count > 1) req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator); } else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet) { currentConfig.ConditionalExpression.ApplyExpression(req, this.Conversion); } var resp = DDBClient.PutItem(req); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = Document.FromAttributeMap(resp.Attributes); } return ret; }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/> /// </summary> /// <param name="doc">Document to save.</param> /// <param name="config">Configuration to use.</param> /// <param name="cancellationToken">Token which can be used to cancel the task.</param> /// <returns>A Task that can be used to poll or wait for results, or both.</returns> public Task<Document> PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { return AsyncRunner.Run(() => PutItemHelper(doc, config, true), cancellationToken); }