public void GetDatasetMetadataAsync(string datasetName, AmazonCognitoSyncCallback <DatasetMetadata> callback, AsyncOptions options = null) { options = options ?? new AsyncOptions(); DescribeDatasetRequest request = new DescribeDatasetRequest(); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; client.DescribeDatasetAsync(request, (responseObj) => { Exception dataStorageException = null; DatasetMetadata metadata = null; if (responseObj.Exception != null) { dataStorageException = new DataStorageException("Failed to get metadata of dataset: " + datasetName, responseObj.Exception); } else { metadata = ModelToDatasetMetadata(responseObj.Response.Dataset); } InternalSDKUtils.AsyncExecutor(() => callback(new AmazonCognitoSyncResult <DatasetMetadata>(metadata, dataStorageException, responseObj.state)), options); }, options); }
/// <summary> /// Initiates the asynchronous execution of the DescribeDataset operation. /// <seealso cref="Amazon.CognitoSync.IAmazonCognitoSync"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeDataset 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 <DescribeDatasetResponse> DescribeDatasetAsync(DescribeDatasetRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DescribeDatasetRequestMarshaller(); var unmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(Invoke <IRequest, DescribeDatasetRequest, DescribeDatasetResponse>(request, marshaller, unmarshaller, signer, cancellationToken)); }
public override void GetDatasetMetadataAsync(string datasetName, AmazonCognitoCallback callback, object state) { DescribeDatasetRequest request = new DescribeDatasetRequest(); //appendUserAgent(request, userAgent); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; client.DescribeDatasetAsync(request, delegate(AmazonServiceResult describeDatasetResult) { AmazonCognitoResult callbackResult = new AmazonCognitoResult(state); if (describeDatasetResult.Exception != null) { callbackResult.Exception = new DataStorageException("Failed to get metadata of dataset: " + datasetName, describeDatasetResult.Exception); } else { callbackResult.Response = new DatasetMetadataResponse { Metadata = ModelToDatasetMetadata((describeDatasetResult.Response as DescribeDatasetResponse).Dataset) }; } AmazonMainThreadDispatcher.ExecCallback(callback, callbackResult); }, null); }
internal virtual DescribeDatasetResponse DescribeDataset(DescribeDatasetRequest request) { var marshaller = DescribeDatasetRequestMarshaller.Instance; var unmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(Invoke <DescribeDatasetRequest, DescribeDatasetResponse>(request, marshaller, unmarshaller)); }
IAsyncResult invokeDescribeDataset(DescribeDatasetRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new DescribeDatasetRequestMarshaller(); var unmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer)); }
/// <summary> /// Gets metadata about a dataset by identity and dataset name. /// </summary> /// <param name="request">Container for the necessary parameters to execute the DescribeDataset service method.</param> /// /// <returns>The response from the DescribeDataset 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="ResourceNotFoundException"> /// Thrown if the resource doesn't exist. /// </exception> public DescribeDatasetResponse DescribeDataset(DescribeDatasetRequest request) { var marshaller = new DescribeDatasetRequestMarshaller(); var unmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(Invoke <DescribeDatasetRequest, DescribeDatasetResponse>(request, marshaller, unmarshaller)); }
/// <summary> /// Initiates the asynchronous execution of the DescribeDataset operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeDataset 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> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/cognito-sync-2014-06-30/DescribeDataset">REST API Reference for DescribeDataset Operation</seealso> public virtual Task <DescribeDatasetResponse> DescribeDatasetAsync(DescribeDatasetRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = DescribeDatasetRequestMarshaller.Instance; var unmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(InvokeAsync <DescribeDatasetRequest, DescribeDatasetResponse>(request, marshaller, unmarshaller, cancellationToken)); }
/// <summary> /// Initiates the asynchronous execution of the DescribeDataset operation. /// <seealso cref="Amazon.CognitoSync.IAmazonCognitoSync"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeDataset 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 EndDescribeDataset /// operation.</returns> public IAsyncResult BeginDescribeDataset(DescribeDatasetRequest request, AsyncCallback callback, object state) { var marshaller = new DescribeDatasetRequestMarshaller(); var unmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(BeginInvoke <DescribeDatasetRequest>(request, marshaller, unmarshaller, callback, state)); }
internal virtual DescribeDatasetResponse DescribeDataset(DescribeDatasetRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = DescribeDatasetRequestMarshaller.Instance; options.ResponseUnmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(Invoke <DescribeDatasetResponse>(request, options)); }
/// <summary> /// Initiates the asynchronous execution of the DescribeDataset operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeDataset 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> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/cognito-sync-2014-06-30/DescribeDataset">REST API Reference for DescribeDataset Operation</seealso> public virtual Task <DescribeDatasetResponse> DescribeDatasetAsync(DescribeDatasetRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = DescribeDatasetRequestMarshaller.Instance; options.ResponseUnmarshaller = DescribeDatasetResponseUnmarshaller.Instance; return(InvokeAsync <DescribeDatasetResponse>(request, options, cancellationToken)); }
private DescribeDatasetRequest PrepareDescribeDatasetRequest(string datasetName) { DescribeDatasetRequest request = new DescribeDatasetRequest(); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; return(request); }
internal DescribeDatasetResponse DescribeDataset(DescribeDatasetRequest request) { var task = DescribeDatasetAsync(request); try { return(task.Result); } catch (AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return(null); } }
/// <summary> /// Initiates the asynchronous execution of the DescribeDataset operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeDataset 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 DescribeDatasetAsync(DescribeDatasetRequest request, AmazonServiceCallback <DescribeDatasetRequest, DescribeDatasetResponse> callback, AsyncOptions options = null) { options = options == null?new AsyncOptions():options; var marshaller = new DescribeDatasetRequestMarshaller(); var unmarshaller = DescribeDatasetResponseUnmarshaller.Instance; Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if (callback != null) { callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult <DescribeDatasetRequest, DescribeDatasetResponse> responseObject = new AmazonServiceResult <DescribeDatasetRequest, DescribeDatasetResponse>((DescribeDatasetRequest)req, (DescribeDatasetResponse)res, ex, ao.State); callback(responseObject); } } ; BeginInvoke <DescribeDatasetRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
/// <summary> /// Retrieves the metadata of a dataset. /// </summary> /// <param name="datasetName">Dataset name.</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.DataStorageException"></exception> public async Task <DatasetMetadata> GetDatasetMetadataAsync(string datasetName, CancellationToken cancellationToken) { DescribeDatasetRequest request = new DescribeDatasetRequest(); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; try { DescribeDatasetResponse describeDatasetResponse = await client.DescribeDatasetAsync(request, cancellationToken).ConfigureAwait(false); return(ModelToDatasetMetadata(describeDatasetResponse.Dataset)); } catch (Exception ex) { throw new DataStorageException("Failed to get metadata of dataset: " + datasetName, ex); } }
/// <summary> /// Retrieves the metadata of a dataset. /// </summary> /// <returns>The records.</returns> /// <param name="datasetName">Dataset name.</param> public DatasetMetadata GetDatasetMetadata(string datasetName) { DescribeDatasetRequest request = new DescribeDatasetRequest(); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; DatasetMetadata metadata = null; try { var describeResponse = client.DescribeDataset(request); metadata = ModelToDatasetMetadata(describeResponse.Dataset); } catch (Exception e) { throw new DataStorageException("Failed to get metadata of dataset: " + datasetName, e); } return(metadata); }
public void IdentityTests() { CognitoIdentity.CreateIdentityPool(out poolId, out poolName); var usages = GetAllIdentityPoolUsages(); Assert.IsNotNull(usages); Assert.AreNotEqual(0, usages.Count); int usagesCount = usages.Count; var identityId = CognitoIdentity.CreateIdentity(poolId, poolName); usages = GetAllIdentityPoolUsages(); Assert.IsNotNull(usages); Assert.AreNotEqual(0, usages.Count); Assert.AreEqual(usagesCount, usages.Count); var datasets = GetAllDatasets(poolId, identityId); Assert.AreEqual(0, datasets.Count); string datasetName = "sample-dataset"; var recordsResult = Client.ListRecords(new ListRecordsRequest { DatasetName = datasetName, IdentityPoolId = poolId, IdentityId = identityId, MaxResults = 1 }); Assert.IsNotNull(recordsResult); Assert.AreEqual(0, recordsResult.Count); Assert.IsFalse(recordsResult.DatasetDeletedAfterRequestedSyncCount); Assert.IsFalse(recordsResult.DatasetExists); Assert.AreEqual(0, recordsResult.DatasetSyncCount); Assert.IsNull(recordsResult.LastModifiedBy); Assert.AreEqual(0, recordsResult.MergedDatasetNames.Count); Assert.AreEqual(0, recordsResult.Records.Count); Assert.IsFalse(string.IsNullOrEmpty(recordsResult.SyncSessionToken)); // Some operations require an authenticated client using (var authenticatedClient = CreateAuthenticatedClient(poolId, poolName, identityId, out roleName)) { string key1 = "key1"; var updateRequest = new UpdateRecordsRequest { DatasetName = datasetName, IdentityPoolId = poolId, IdentityId = identityId, RecordPatches = new List <RecordPatch> { new RecordPatch { Op = Operation.Replace, SyncCount = 0, Key = key1, Value = key1 } }, SyncSessionToken = recordsResult.SyncSessionToken }; // Add retries in case the identity pool is not ready yet. List <Record> records = null; for (int retries = 0; retries < 5 && records == null; retries++) { Thread.Sleep(1000 * retries); try { records = authenticatedClient.UpdateRecords(updateRequest).Records; } catch (AmazonCognitoSyncException e) { if (e.StatusCode == System.Net.HttpStatusCode.Forbidden) { continue; } throw; } } Assert.AreEqual(1, records.Count); recordsResult = Client.ListRecords(new ListRecordsRequest { DatasetName = datasetName, IdentityPoolId = poolId, IdentityId = identityId, MaxResults = 1 }); Assert.IsNotNull(recordsResult); Assert.AreEqual(1, recordsResult.Count); Assert.IsFalse(recordsResult.DatasetDeletedAfterRequestedSyncCount); Assert.IsTrue(recordsResult.DatasetExists); Assert.AreEqual(1, recordsResult.DatasetSyncCount); Assert.AreEqual(0, recordsResult.MergedDatasetNames.Count); Assert.AreEqual(1, recordsResult.Records.Count); Assert.IsFalse(string.IsNullOrEmpty(recordsResult.SyncSessionToken)); updateRequest = new UpdateRecordsRequest { DatasetName = datasetName, IdentityPoolId = poolId, IdentityId = identityId, RecordPatches = new List <RecordPatch> { new RecordPatch { Op = Operation.Replace, SyncCount = 1, Key = key1, Value = key1 } }, SyncSessionToken = recordsResult.SyncSessionToken }; records = authenticatedClient.UpdateRecords(updateRequest).Records; var allRecords = GetAllRecords(datasetName, poolId, identityId); Assert.AreEqual(1, records.Count); } var describeRequest = new DescribeDatasetRequest { DatasetName = datasetName, IdentityId = identityId, IdentityPoolId = poolId }; var dataset = Client.DescribeDataset(describeRequest).Dataset; Assert.IsNotNull(dataset); Assert.AreEqual(datasetName, dataset.DatasetName); var poolUsage = Client.DescribeIdentityPoolUsage(new DescribeIdentityPoolUsageRequest { IdentityPoolId = poolId }).IdentityPoolUsage; Assert.IsNotNull(poolUsage.LastModifiedDate); var identityUsage = Client.DescribeIdentityUsage(new DescribeIdentityUsageRequest { IdentityId = identityId, IdentityPoolId = poolId }).IdentityUsage; Assert.IsNotNull(identityUsage); Assert.AreEqual(identityId, identityUsage.IdentityId); Assert.AreEqual(poolId, identityUsage.IdentityPoolId); datasets = GetAllDatasets(poolId, identityId); Assert.AreEqual(1, datasets.Count); Client.DeleteDataset(new DeleteDatasetRequest { DatasetName = datasetName, IdentityPoolId = poolId, IdentityId = identityId }); datasets = GetAllDatasets(poolId, identityId); Assert.AreEqual(0, datasets.Count); AssertExtensions.ExpectException(() => Client.DescribeDataset(describeRequest)); }
/// <summary> /// Initiates the asynchronous execution of the DescribeDataset operation. /// <seealso cref="Amazon.CognitoSync.IAmazonCognitoSync"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DescribeDataset 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 EndDescribeDataset /// operation.</returns> public IAsyncResult BeginDescribeDataset(DescribeDatasetRequest request, AsyncCallback callback, object state) { return(invokeDescribeDataset(request, callback, state, false)); }
private void TestAuthenticatedClient(bool usePoolRoles) { // Some operations require an authenticated client CognitoAWSCredentials credentials; using (var authenticatedClient = CreateAuthenticatedClient(poolId, usePoolRoles, out credentials)) { var datasets = GetAllDatasets(Client, poolId, credentials.GetIdentityId()); Assert.AreEqual(0, datasets.Count); datasets = GetAllDatasets(authenticatedClient, poolId, credentials.GetIdentityId()); Assert.AreEqual(0, datasets.Count); string datasetName = "sample-dataset"; TestDataCalls(datasetName, authenticatedClient); var describeRequest = new DescribeDatasetRequest { DatasetName = datasetName, //IdentityId = identityId, //IdentityPoolId = poolId }; var dataset = authenticatedClient.DescribeDataset(describeRequest).Dataset; Assert.IsNotNull(dataset); Assert.AreEqual(datasetName, dataset.DatasetName); // Use unauthenticated client to get usage info { var poolUsage = Client.DescribeIdentityPoolUsage(new DescribeIdentityPoolUsageRequest { IdentityPoolId = poolId }).IdentityPoolUsage; Assert.IsNotNull(poolUsage.LastModifiedDate); var identityUsage = Client.DescribeIdentityUsage(new DescribeIdentityUsageRequest { IdentityId = credentials.GetIdentityId(), IdentityPoolId = poolId }).IdentityUsage; Assert.IsNotNull(identityUsage); Assert.AreEqual(credentials.GetIdentityId(), identityUsage.IdentityId); Assert.AreEqual(poolId, identityUsage.IdentityPoolId); } datasets = GetAllDatasets(authenticatedClient, poolId, credentials.GetIdentityId()); Assert.AreEqual(1, datasets.Count); authenticatedClient.DeleteDataset(new DeleteDatasetRequest { DatasetName = datasetName, IdentityPoolId = poolId, IdentityId = credentials.GetIdentityId() }); datasets = GetAllDatasets(authenticatedClient, poolId, credentials.GetIdentityId()); Assert.AreEqual(0, datasets.Count); AssertExtensions.ExpectException(() => authenticatedClient.DescribeDataset(describeRequest)); } }
/// <summary> /// Gets metadata about a dataset by identity and dataset name. /// </summary> /// <param name="request">Container for the necessary parameters to execute the DescribeDataset service method.</param> /// /// <returns>The response from the DescribeDataset 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="ResourceNotFoundException"> /// Thrown if the resource doesn't exist. /// </exception> public DescribeDatasetResponse DescribeDataset(DescribeDatasetRequest request) { IAsyncResult asyncResult = invokeDescribeDataset(request, null, null, true); return(EndDescribeDataset(asyncResult)); }