public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.CognitoSync.Model.UpdateRecordsRequest(); if (cmdletContext.ClientContext != null) { request.ClientContext = cmdletContext.ClientContext; } if (cmdletContext.DatasetName != null) { request.DatasetName = cmdletContext.DatasetName; } if (cmdletContext.DeviceId != null) { request.DeviceId = cmdletContext.DeviceId; } if (cmdletContext.IdentityId != null) { request.IdentityId = cmdletContext.IdentityId; } if (cmdletContext.IdentityPoolId != null) { request.IdentityPoolId = cmdletContext.IdentityPoolId; } if (cmdletContext.RecordPatch != null) { request.RecordPatches = cmdletContext.RecordPatch; } if (cmdletContext.SyncSessionToken != null) { request.SyncSessionToken = cmdletContext.SyncSessionToken; } 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); }
/// <summary> /// Initiates the asynchronous execution of the UpdateRecords operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the UpdateRecords operation on AmazonCognitoSyncClient.</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 UpdateRecordsAsync(UpdateRecordsRequest request, AmazonServiceCallback<UpdateRecordsRequest, UpdateRecordsResponse> callback, AsyncOptions options = null) { options = options == null?new AsyncOptions():options; var marshaller = new UpdateRecordsRequestMarshaller(); var unmarshaller = UpdateRecordsResponseUnmarshaller.Instance; Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if(callback !=null ) callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult<UpdateRecordsRequest,UpdateRecordsResponse> responseObject = new AmazonServiceResult<UpdateRecordsRequest,UpdateRecordsResponse>((UpdateRecordsRequest)req, (UpdateRecordsResponse)res, ex , ao.State); callback(responseObject); }; BeginInvoke<UpdateRecordsRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
/// <summary> /// Initiates the asynchronous execution of the UpdateRecords operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the UpdateRecords 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<UpdateRecordsResponse> UpdateRecordsAsync(UpdateRecordsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new UpdateRecordsRequestMarshaller(); var unmarshaller = UpdateRecordsResponseUnmarshaller.Instance; return InvokeAsync<UpdateRecordsRequest,UpdateRecordsResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Posts updates to records and adds and deletes records for a dataset and user. /// /// /// <para> /// The sync count in the record patch is your last known sync count for that record. /// The server will reject an UpdateRecords request with a ResourceConflictException if /// you try to patch a record with a new value but a stale sync count. /// </para> /// /// <para> /// For example, if the sync count on the server is 5 for a key called highScore and you /// try and submit a new highScore with sync count of 4, the request will be rejected. /// To obtain the current sync count for a record, call ListRecords. On a successful update /// of the record, the response returns the new sync count for that record. You should /// present that sync count the next time you try to update that same record. When the /// record does not exist, specify the sync count as 0. /// </para> /// /// <para> /// This API can be called with temporary user credentials provided by Cognito Identity /// or with developer credentials. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the UpdateRecords service method.</param> /// /// <returns>The response from the UpdateRecords service method, as returned by CognitoSync.</returns> /// <exception cref="Amazon.CognitoSync.Model.InternalErrorException"> /// Indicates an internal service error. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.InvalidLambdaFunctionOutputException"> /// The AWS Lambda function returned invalid output or an exception. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.InvalidParameterException"> /// Thrown when a request parameter does not comply with the associated constraints. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.LambdaThrottledException"> /// AWS Lambda throttled your account, please contact AWS Support /// </exception> /// <exception cref="Amazon.CognitoSync.Model.LimitExceededException"> /// Thrown when the limit on the number of objects or operations has been exceeded. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.NotAuthorizedException"> /// Thrown when a user is not authorized to access the requested resource. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.ResourceConflictException"> /// Thrown if an update can't be applied because the resource was changed by another call /// and this would result in a conflict. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.ResourceNotFoundException"> /// Thrown if the resource doesn't exist. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.TooManyRequestsException"> /// Thrown if the request is throttled. /// </exception> public UpdateRecordsResponse UpdateRecords(UpdateRecordsRequest request) { var marshaller = new UpdateRecordsRequestMarshaller(); var unmarshaller = UpdateRecordsResponseUnmarshaller.Instance; return Invoke<UpdateRecordsRequest,UpdateRecordsResponse>(request, marshaller, unmarshaller); }
internal UpdateRecordsResponse UpdateRecords(UpdateRecordsRequest request) { var task = UpdateRecordsAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Initiates the asynchronous execution of the UpdateRecords operation. /// <seealso cref="Amazon.CognitoSync.IAmazonCognitoSync.UpdateRecords"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the UpdateRecords 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<UpdateRecordsResponse> UpdateRecordsAsync(UpdateRecordsRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new UpdateRecordsRequestMarshaller(); var unmarshaller = UpdateRecordsResponseUnmarshaller.GetInstance(); return Invoke<IRequest, UpdateRecordsRequest, UpdateRecordsResponse>(request, marshaller, unmarshaller, signer, cancellationToken); }
/// <summary> /// Initiates the asynchronous execution of the UpdateRecords operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the UpdateRecords operation on AmazonCognitoSyncClient.</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 EndUpdateRecords /// operation.</returns> public IAsyncResult BeginUpdateRecords(UpdateRecordsRequest request, AsyncCallback callback, object state) { var marshaller = new UpdateRecordsRequestMarshaller(); var unmarshaller = UpdateRecordsResponseUnmarshaller.Instance; return BeginInvoke<UpdateRecordsRequest>(request, marshaller, unmarshaller, callback, state); }
public void PutRecordsAsync(string datasetName, List<Record> records, string syncSessionToken, AmazonCognitoSyncCallback<List<Record>> callback, AsyncOptions options = null) { options = options ?? new AsyncOptions(); UpdateRecordsRequest request = new UpdateRecordsRequest(); request.DatasetName = datasetName; request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.SyncSessionToken = syncSessionToken; // create patches List<RecordPatch> patches = new List<RecordPatch>(); foreach (Record record in records) { patches.Add(this.RecordToPatch(record)); } request.RecordPatches = patches; List<Record> updatedRecords = new List<Record>(); client.UpdateRecordsAsync(request, (responseObj) => { Exception ex = responseObj.Exception; UpdateRecordsResponse updateRecordsResponse = responseObj.Response; Exception putRecordsException = null; object obj = responseObj.state; if (ex != null) { putRecordsException = HandleException(ex, "Failed to update records in dataset: " + datasetName); } else { foreach (Amazon.CognitoSync.Model.Record remoteRecord in updateRecordsResponse.Records) { updatedRecords.Add(ModelToRecord(remoteRecord)); } } InternalSDKUtils.AsyncExecutor(() => callback(new AmazonCognitoSyncResult<List<Record>>(updatedRecords, putRecordsException, obj)), options); }, options); }
private UpdateRecordsRequest PrepareUpdateRecordsRequest(string datasetName, List<Record> records, string syncSessionToken) { UpdateRecordsRequest request = new UpdateRecordsRequest(); request.DatasetName = datasetName; request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.SyncSessionToken = syncSessionToken; // create patches List<RecordPatch> patches = new List<RecordPatch>(); foreach (Record record in records) { patches.Add(RecordToPatch(record)); } request.RecordPatches = patches; return request; }
/// <summary> /// Post updates to remote storage. Each record has a sync count. If the sync /// count doesn't match what's on the remote storage, i.e. the record is /// modified by a different device, this operation throws ConflictException. /// Otherwise it returns a list of records that are updated successfully. /// </summary> /// <returns>The records.</returns> /// <param name="datasetName">Dataset name.</param> /// <param name="records">Records.</param> /// <param name="syncSessionToken">Sync session token.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <exception cref="Amazon.CognitoSync.SyncManager.DatasetNotFoundException"></exception> /// <exception cref="Amazon.CognitoSync.SyncManager.DataConflictException"></exception> public async Task<List<Record>> PutRecordsAsync(string datasetName, List<Record> records, string syncSessionToken, CancellationToken cancellationToken) { UpdateRecordsRequest request = new UpdateRecordsRequest(); request.DatasetName = datasetName; request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.SyncSessionToken = syncSessionToken; // create patches List<RecordPatch> patches = new List<RecordPatch>(); foreach (Record record in records) { patches.Add(RecordToPatch(record)); } request.RecordPatches = patches; List<Record> updatedRecords = new List<Record>(); try { UpdateRecordsResponse updateRecordsResponse = await client.UpdateRecordsAsync(request, cancellationToken).ConfigureAwait(false); foreach (Amazon.CognitoSync.Model.Record remoteRecord in updateRecordsResponse.Records) { updatedRecords.Add(ModelToRecord(remoteRecord)); } return updatedRecords; } catch (Exception ex) { throw HandleException(ex, "Failed to update records in dataset: " + datasetName); } }
private Amazon.CognitoSync.Model.UpdateRecordsResponse CallAWSServiceOperation(IAmazonCognitoSync client, Amazon.CognitoSync.Model.UpdateRecordsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Cognito Sync", "UpdateRecords"); try { #if DESKTOP return(client.UpdateRecords(request)); #elif CORECLR return(client.UpdateRecordsAsync(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; } }
IAsyncResult invokeUpdateRecords(UpdateRecordsRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new UpdateRecordsRequestMarshaller(); var unmarshaller = UpdateRecordsResponseUnmarshaller.Instance; return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer); }
/// <summary> /// Initiates the asynchronous execution of the UpdateRecords operation. /// <seealso cref="Amazon.CognitoSync.IAmazonCognitoSync"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the UpdateRecords operation on AmazonCognitoSyncClient.</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 EndUpdateRecords /// operation.</returns> public IAsyncResult BeginUpdateRecords(UpdateRecordsRequest request, AsyncCallback callback, object state) { return invokeUpdateRecords(request, callback, state, false); }
/// <summary> /// Posts updates to records and add and delete records for a dataset and user. /// </summary> /// <param name="request">Container for the necessary parameters to execute the UpdateRecords service method.</param> /// /// <returns>The response from the UpdateRecords service method, as returned by CognitoSync.</returns> /// <exception cref="InternalErrorException"> /// Indicates an internal service error. /// </exception> /// <exception cref="InvalidParameterException"> /// Thrown when a request parameter does not comply with the associated constraints. /// </exception> /// <exception cref="LimitExceededException"> /// Thrown when the limit on the number of objects or operations has been exceeded. /// </exception> /// <exception cref="NotAuthorizedException"> /// Thrown when a user is not authorized to access the requested resource. /// </exception> /// <exception cref="ResourceConflictException"> /// Thrown if an update can't be applied because the resource was changed by another call /// and this would result in a conflict. /// </exception> /// <exception cref="ResourceNotFoundException"> /// Thrown if the resource doesn't exist. /// </exception> /// <exception cref="TooManyRequestsException"> /// Thrown if the request is throttled. /// </exception> public UpdateRecordsResponse UpdateRecords(UpdateRecordsRequest request) { IAsyncResult asyncResult = invokeUpdateRecords(request, null, null, true); return EndUpdateRecords(asyncResult); }
/// <summary> /// Post updates to remote storage. Each record has a sync count. If the sync /// count doesn't match what's on the remote storage, i.e. the record is /// modified by a different device, this operation sets the exception in the /// callback response to ConflictException. Otherwise it returns a list of /// records that are updated successfully. /// </summary> /// <returns>The records.</returns> /// <param name="datasetName">Dataset name.</param> /// <param name="records">Records.</param> /// <param name="syncSessionToken">Sync session token.</param> public List<Record> PutRecords(string datasetName, List<Record> records, string syncSessionToken) { UpdateRecordsRequest request = new UpdateRecordsRequest(); request.DatasetName = datasetName; request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.SyncSessionToken = syncSessionToken; List<Record> updatedRecords = new List<Record>(); // create patches List<RecordPatch> patches = new List<RecordPatch>(); foreach (Record record in records) { patches.Add(RecordToPatch(record)); } request.RecordPatches = patches; try { UpdateRecordsResponse updateRecordsResponse = client.UpdateRecords(request); foreach (Amazon.CognitoSync.Model.Record remoteRecord in updateRecordsResponse.Records) { updatedRecords.Add(ModelToRecord(remoteRecord)); } } catch (Exception e) { throw HandleException(e, "Failed to update records in dataset: " + datasetName); } return updatedRecords; }