private async Task<DatasetUpdates> PopulateListUpdatesAsync(string datasetName, long lastSyncCount, List<Record> records, string nextToken, CancellationToken cancellationToken) { ListRecordsRequest request = new ListRecordsRequest(); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; request.LastSyncCount = lastSyncCount; // mark it large enough to reduce # of requests request.MaxResults = 1024; request.NextToken = nextToken; ListRecordsResponse listRecordsResponse = await client.ListRecordsAsync(request, cancellationToken).ConfigureAwait(false); foreach (Amazon.CognitoSync.Model.Record remoteRecord in listRecordsResponse.Records) { records.Add(ModelToRecord(remoteRecord)); } // update last evaluated key nextToken = listRecordsResponse.NextToken; if (nextToken != null) await PopulateListUpdatesAsync(datasetName, lastSyncCount, records, nextToken, cancellationToken).ConfigureAwait(false); DatasetUpdates updates = new DatasetUpdates( datasetName, records, listRecordsResponse.DatasetSyncCount, listRecordsResponse.SyncSessionToken, listRecordsResponse.DatasetExists, listRecordsResponse.DatasetDeletedAfterRequestedSyncCount, listRecordsResponse.MergedDatasetNames ); return updates; }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.CognitoSync.Model.ListRecordsRequest(); if (cmdletContext.DatasetName != null) { request.DatasetName = cmdletContext.DatasetName; } if (cmdletContext.IdentityId != null) { request.IdentityId = cmdletContext.IdentityId; } if (cmdletContext.IdentityPoolId != null) { request.IdentityPoolId = cmdletContext.IdentityPoolId; } if (cmdletContext.LastSyncCount != null) { request.LastSyncCount = cmdletContext.LastSyncCount.Value; } if (cmdletContext.MaxResult != null) { request.MaxResults = AutoIterationHelpers.ConvertEmitLimitToServiceTypeInt32(cmdletContext.MaxResult.Value); } if (cmdletContext.NextToken != null) { request.NextToken = cmdletContext.NextToken; } 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 ListRecords operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListRecords 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 ListRecordsAsync(ListRecordsRequest request, AmazonServiceCallback<ListRecordsRequest, ListRecordsResponse> callback, AsyncOptions options = null) { options = options == null?new AsyncOptions():options; var marshaller = new ListRecordsRequestMarshaller(); var unmarshaller = ListRecordsResponseUnmarshaller.Instance; Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if(callback !=null ) callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult<ListRecordsRequest,ListRecordsResponse> responseObject = new AmazonServiceResult<ListRecordsRequest,ListRecordsResponse>((ListRecordsRequest)req, (ListRecordsResponse)res, ex , ao.State); callback(responseObject); }; BeginInvoke<ListRecordsRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
/// <summary> /// Initiates the asynchronous execution of the ListRecords operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListRecords 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<ListRecordsResponse> ListRecordsAsync(ListRecordsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new ListRecordsRequestMarshaller(); var unmarshaller = ListRecordsResponseUnmarshaller.Instance; return InvokeAsync<ListRecordsRequest,ListRecordsResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Gets paginated records, optionally changed after a particular sync count for a dataset /// and identity. With Amazon Cognito Sync, each identity has access only to its own data. /// Thus, the credentials used to make this API call need to have access to the identity /// data. /// /// /// <para> /// ListRecords can be called with temporary user credentials provided by Cognito Identity /// or with developer credentials. You should use Cognito Identity credentials to make /// this API call. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the ListRecords service method.</param> /// /// <returns>The response from the ListRecords service method, as returned by CognitoSync.</returns> /// <exception cref="Amazon.CognitoSync.Model.InternalErrorException"> /// Indicates an internal service error. /// </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.NotAuthorizedException"> /// Thrown when a user is not authorized to access the requested resource. /// </exception> /// <exception cref="Amazon.CognitoSync.Model.TooManyRequestsException"> /// Thrown if the request is throttled. /// </exception> public ListRecordsResponse ListRecords(ListRecordsRequest request) { var marshaller = new ListRecordsRequestMarshaller(); var unmarshaller = ListRecordsResponseUnmarshaller.Instance; return Invoke<ListRecordsRequest,ListRecordsResponse>(request, marshaller, unmarshaller); }
internal ListRecordsResponse ListRecords(ListRecordsRequest request) { var task = ListRecordsAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Initiates the asynchronous execution of the ListRecords operation. /// <seealso cref="Amazon.CognitoSync.IAmazonCognitoSync.ListRecords"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListRecords 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<ListRecordsResponse> ListRecordsAsync(ListRecordsRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new ListRecordsRequestMarshaller(); var unmarshaller = ListRecordsResponseUnmarshaller.GetInstance(); return Invoke<IRequest, ListRecordsRequest, ListRecordsResponse>(request, marshaller, unmarshaller, signer, cancellationToken); }
/// <summary> /// Initiates the asynchronous execution of the ListRecords operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListRecords 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 EndListRecords /// operation.</returns> public IAsyncResult BeginListRecords(ListRecordsRequest request, AsyncCallback callback, object state) { var marshaller = new ListRecordsRequestMarshaller(); var unmarshaller = ListRecordsResponseUnmarshaller.Instance; return BeginInvoke<ListRecordsRequest>(request, marshaller, unmarshaller, callback, state); }
private void PopulateListUpdatesAsync(string datasetName, long lastSyncCount, List<Record> records, string nextToken, AmazonCognitoSyncCallback<DatasetUpdates> callback, AsyncOptions options) { ListRecordsRequest request = new ListRecordsRequest(); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; request.LastSyncCount = lastSyncCount; // mark it large enough to reduce # of requests request.MaxResults = 1024; request.NextToken = nextToken; client.ListRecordsAsync(request, (responseObj) => { ListRecordsResponse res = responseObj.Response; Exception ex = responseObj.Exception; object obj = responseObj.state; if (ex != null) { InternalSDKUtils.AsyncExecutor(() => callback(new AmazonCognitoSyncResult<DatasetUpdates>(null, ex, obj)), options); ; } else { ListRecordsResponse listRecordsResponse = res; foreach (Amazon.CognitoSync.Model.Record remoteRecord in listRecordsResponse.Records) { //builder.addRecord(modelToRecord(remoteRecord)); records.Add(this.ModelToRecord(remoteRecord)); } if (listRecordsResponse.NextToken == null) { DatasetUpdates updates = new DatasetUpdates( datasetName, records, listRecordsResponse.DatasetSyncCount, listRecordsResponse.SyncSessionToken, listRecordsResponse.DatasetExists, listRecordsResponse.DatasetDeletedAfterRequestedSyncCount, listRecordsResponse.MergedDatasetNames ); InternalSDKUtils.AsyncExecutor(() => callback(new AmazonCognitoSyncResult<DatasetUpdates>(updates, ex, obj)), options); return; } // update last evaluated key nextToken = listRecordsResponse.NextToken; // emulating the while loop PopulateListUpdatesAsync(datasetName, lastSyncCount, records, nextToken, callback, new AsyncOptions() { ExecuteCallbackOnMainThread = false, State = obj }); } }, options); }
private Amazon.CognitoSync.Model.ListRecordsResponse CallAWSServiceOperation(IAmazonCognitoSync client, Amazon.CognitoSync.Model.ListRecordsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Cognito Sync", "ListRecords"); try { #if DESKTOP return(client.ListRecords(request)); #elif CORECLR return(client.ListRecordsAsync(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; } }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute var useParameterSelect = this.Select.StartsWith("^") || this.PassThru.IsPresent; #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute // create request and set iteration invariants var request = new Amazon.CognitoSync.Model.ListRecordsRequest(); if (cmdletContext.DatasetName != null) { request.DatasetName = cmdletContext.DatasetName; } if (cmdletContext.IdentityId != null) { request.IdentityId = cmdletContext.IdentityId; } if (cmdletContext.IdentityPoolId != null) { request.IdentityPoolId = cmdletContext.IdentityPoolId; } if (cmdletContext.LastSyncCount != null) { request.LastSyncCount = cmdletContext.LastSyncCount.Value; } if (cmdletContext.MaxResult != null) { request.MaxResults = AutoIterationHelpers.ConvertEmitLimitToServiceTypeInt32(cmdletContext.MaxResult.Value); } if (cmdletContext.SyncSessionToken != null) { request.SyncSessionToken = cmdletContext.SyncSessionToken; } // Initialize loop variant and commence piping var _nextToken = cmdletContext.NextToken; var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.NextToken)); var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); do { request.NextToken = _nextToken; CmdletOutput output; try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; if (!useParameterSelect) { pipelineOutput = cmdletContext.Select(response, this); } output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; _nextToken = response.NextToken; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } ProcessOutput(output); } while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextToken)); if (useParameterSelect) { WriteObject(cmdletContext.Select(null, this)); } return(null); }
private ListRecordsRequest PrepareListRecordsRequest(string datasetName, long lastSyncCount) { ListRecordsRequest request = new ListRecordsRequest(); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; request.LastSyncCount = lastSyncCount; // mark it large enough to reduce # of requests request.MaxResults = 1024; return request; }
IAsyncResult invokeListRecords(ListRecordsRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new ListRecordsRequestMarshaller(); var unmarshaller = ListRecordsResponseUnmarshaller.Instance; return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer); }
/// <summary> /// Initiates the asynchronous execution of the ListRecords operation. /// <seealso cref="Amazon.CognitoSync.IAmazonCognitoSync"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListRecords 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 EndListRecords /// operation.</returns> public IAsyncResult BeginListRecords(ListRecordsRequest request, AsyncCallback callback, object state) { return invokeListRecords(request, callback, state, false); }
/// <summary> /// Gets paginated records, optionally changed after a particular sync count for a dataset /// and identity. /// </summary> /// <param name="request">Container for the necessary parameters to execute the ListRecords service method.</param> /// /// <returns>The response from the ListRecords 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="NotAuthorizedException"> /// Thrown when a user is not authorized to access the requested resource. /// </exception> /// <exception cref="TooManyRequestsException"> /// Thrown if the request is throttled. /// </exception> public ListRecordsResponse ListRecords(ListRecordsRequest request) { IAsyncResult asyncResult = invokeListRecords(request, null, null, true); return EndListRecords(asyncResult); }