public override void RefreshDatasetMetadataAsync(AmazonCognitoCallback callback, object state) { AmazonCognitoResult callbackResult = new AmazonCognitoResult(state); cognitoCredentials.GetCredentialsAsync(delegate(AmazonServiceResult getCredentialsResult) { if (getCredentialsResult.Exception != null) { callbackResult.Exception = getCredentialsResult.Exception; AmazonMainThreadDispatcher.ExecCallback(callback, callbackResult); return; } remote.GetDatasetsAsync(delegate(AmazonCognitoResult result) { if (result.Exception != null) { callbackResult.Exception = result.Exception; } else { GetDatasetsResponse response = result.Response as GetDatasetsResponse; local.UpdateDatasetMetadata(GetIdentityId(), response.Datasets); callbackResult.Response = response; } AmazonMainThreadDispatcher.ExecCallback(callback, callbackResult); }, state); }, null); }
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); }
public override void DeleteDatasetAsync(string datasetName, AmazonCognitoCallback callback, object state) { DeleteDatasetRequest request = new DeleteDatasetRequest(); //appendUserAgent(request, userAgent); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); request.DatasetName = datasetName; client.DeleteDatasetAsync(request, delegate(AmazonServiceResult deleteDatasetResult) { AmazonCognitoResult result = new AmazonCognitoResult(state); if (deleteDatasetResult.Exception == null) { result.Exception = HandleException(deleteDatasetResult.Exception, "Failed to delete dataset: " + datasetName); } else { result.Exception = new Exception("Unsupported DeleteDatasetAsync"); //result.Response = deleteDatasetResult.Response; } AmazonMainThreadDispatcher.ExecCallback(callback, result); }, null); }
private void PopulateGetDatasets(string nextToken, List <DatasetMetadata> datasets, AmazonCognitoCallback callback, object state) { ListDatasetsRequest request = new ListDatasetsRequest(); //appendUserAgent(request, userAgent); request.IdentityPoolId = identityPoolId; request.IdentityId = this.GetCurrentIdentityId(); // a large enough number to reduce # of requests request.MaxResults = 64; request.NextToken = nextToken; client.ListDatasetsAsync(request, delegate(AmazonServiceResult result) { if (result.Exception != null) { AmazonMainThreadDispatcher.ExecCallback(callback, new AmazonCognitoResult(null, HandleException(result.Exception, "Failed to list dataset metadata"), state)); return; } ListDatasetsResponse response = result.Response as ListDatasetsResponse; foreach (Amazon.CognitoSync.Model.Dataset dataset in response.Datasets) { datasets.Add(ModelToDatasetMetadata(dataset)); } nextToken = response.NextToken; if (nextToken == null) { GetDatasetsResponse getDatasetsResponse = new GetDatasetsResponse { Datasets = datasets }; AmazonMainThreadDispatcher.ExecCallback(callback, new AmazonCognitoResult(getDatasetsResponse, null, state)); return; } PopulateGetDatasets(nextToken, datasets, callback, state); }, null); }
/// <summary> /// Gets a list of {@link DatasetMetadata}s. /// </summary> /// <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> /// <exception cref="DataStorageException"></exception> public override void GetDatasetsAsync(AmazonCognitoCallback callback, object state) { PopulateGetDatasets(null, new List <DatasetMetadata>(), callback, state); }
private void PopulateListUpdates(string datasetName, long lastSyncCount, List <Record> records, string nextToken, AmazonCognitoCallback callback, object state) { { ListRecordsRequest request = new ListRecordsRequest(); //appendUserAgent(request, userAgent); 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, delegate(AmazonServiceResult result) { if (result.Exception != null) { AmazonMainThreadDispatcher.ExecCallback(callback, new AmazonCognitoResult(null, HandleException(result.Exception, "Failed to list records in dataset: " + datasetName), state)); return; } ListRecordsResponse listRecordsResponse = result.Response as ListRecordsResponse; foreach (Amazon.CognitoSync.Model.Record remoteRecord in listRecordsResponse.Records) { //builder.addRecord(modelToRecord(remoteRecord)); records.Add(this.ModelToRecord(remoteRecord)); } if (listRecordsResponse.NextToken == null) { DatasetUpdatesImpl updates = new DatasetUpdatesImpl( datasetName, records, listRecordsResponse.DatasetSyncCount, listRecordsResponse.SyncSessionToken, listRecordsResponse.DatasetExists, listRecordsResponse.DatasetDeletedAfterRequestedSyncCount, listRecordsResponse.MergedDatasetNames ); ListUpdatesResponse listUpdatesResponse = new ListUpdatesResponse { DatasetUpdates = updates }; AmazonMainThreadDispatcher.ExecCallback(callback, new AmazonCognitoResult(listUpdatesResponse, null, state)); return; } // update last evaluated key nextToken = listRecordsResponse.NextToken; // emulating the while loop PopulateListUpdates(datasetName, lastSyncCount, records, nextToken, callback, state); }, state); } }
public override void PutRecordsAsync(string datasetName, List <Record> records, string syncSessionToken, AmazonCognitoCallback callback, object state) { UpdateRecordsRequest request = new UpdateRecordsRequest(); //appendUserAgent(request, userAgent); 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, delegate(AmazonServiceResult result) { AmazonCognitoResult callbackResult = new AmazonCognitoResult(state); if (result.Exception != null) { callbackResult.Exception = HandleException(result.Exception, "Failed to update records in dataset: " + datasetName); } else { UpdateRecordsResponse updateRecordsResponse = result.Response as UpdateRecordsResponse; foreach (Amazon.CognitoSync.Model.Record remoteRecord in updateRecordsResponse.Records) { updatedRecords.Add(ModelToRecord(remoteRecord)); } callbackResult.Response = new PutRecordsResponse { UpdatedRecords = updatedRecords }; } AmazonMainThreadDispatcher.ExecCallback(callback, callbackResult); }, null); }
internal static void ExecCallback(AmazonCognitoCallback callback, AmazonCognitoResult result) { _callbackQueue.Enqueue(new AmazonCognitoCallbackState(callback, result)); }
public override void ListUpdatesAsync(string datasetName, long lastSyncCount, AmazonCognitoCallback callback, object state) { PopulateListUpdates(datasetName, lastSyncCount, new List <Record>(), null, callback, state); }
/// <summary> /// Deletes a dataset. /// </summary> /// <param name="datasetName">Dataset name.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when /// the operation completes with AmazonServiceResult result</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> /// <exception cref="DatasetNotFoundException"></exception> public abstract void DeleteDatasetAsync(string datasetName, AmazonCognitoCallback callback, object state);
public AmazonCognitoCallbackState(AmazonCognitoCallback callback, AmazonCognitoResult result) { this._callback = callback; this._result = result; }
/// <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="callback">An AsyncCallback delegate that is invoked when /// the operation completes with AmazonServiceResult result</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> /// <exception cref="DatasetNotFoundException"></exception> /// <exception cref="DataConflictException"></exception> public abstract void PutRecordsAsync(string datasetName, List <Record> records, string syncSessionToken, AmazonCognitoCallback callback, object state);
/// <summary> /// Gets a list of records which have been updated since lastSyncCount /// (inclusive). If the value of a record equals null, then the record is /// deleted. If you pass 0 as lastSyncCount, the full list of records will be /// returned. /// </summary> /// <returns>A list of records which have been updated since lastSyncCount.</returns> /// <param name="datasetName">Dataset name.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when /// the operation completes with AmazonServiceResult result</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> /// <param name="lastSyncCount">Last sync count.</param> /// <exception cref="DataStorageException"></exception> public abstract void ListUpdatesAsync(string datasetName, long lastSyncCount, AmazonCognitoCallback callback, object state);
/// <summary> /// Retrieves the metadata of a dataset. /// </summary> /// <param name="datasetName">Dataset name.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when /// the operation completes with AmazonServiceResult result</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> /// <exception cref="DataStorageException"></exception> public abstract void GetDatasetMetadataAsync(string datasetName, AmazonCognitoCallback callback, object state);
/// <summary> /// Gets a list of {@link DatasetMetadata}s. /// </summary> /// <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> /// <exception cref="DataStorageException"></exception> public abstract void GetDatasetsAsync(AmazonCognitoCallback callback, object state);
/// <summary> /// Refreshes dataset metadata. Dataset metadata is pulled from remote /// storage and stored in local storage. Their record data isn't pulled down /// until you sync each dataset. Note: this is a network request, so calling /// this method in the main thread will result in /// NetworkOnMainThreadException. /// </summary> /// <exception cref="DataStorageException">thrown when fail to fresh dataset metadata</exception> public abstract void RefreshDatasetMetadataAsync(AmazonCognitoCallback callback, object state);