Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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 static List <Record> ExtractRecords(UpdateRecordsResponse response)
        {
            List <Record> updatedRecords = new List <Record>();

            foreach (Amazon.CognitoSync.Model.Record remoteRecord in response.Records)
            {
                updatedRecords.Add(ModelToRecord(remoteRecord));
            }
            return(updatedRecords);
        }
 /// <summary>
 /// Finishes the asynchronous execution of the PutRecords operation.
 /// </summary>
 ///
 /// <param name="asyncResult">The IAsyncResult returned by the call to BeginPutRecords.</param>
 public List <Record> EndPutRecords(IAsyncResult asyncResult)
 {
     try
     {
         UpdateRecordsResponse response = client.EndUpdateRecords(asyncResult);
         return(ExtractRecords(response));
     }
     catch (Exception ex)
     {
         throw HandleException(ex, "Failed to update records in dataset");
     }
 }
        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);
        }
        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);
        }
Ejemplo n.º 7
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            UpdateRecordsResponse response = new UpdateRecordsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Records", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Record, RecordUnmarshaller>(RecordUnmarshaller.Instance);
                    response.Records = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        /// <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>
        /// <exception cref="Amazon.CognitoSync.SyncManager.DatasetNotFoundException"></exception>
        /// <exception cref="Amazon.CognitoSync.SyncManager.DataConflictException"></exception>
        public List <Record> PutRecords(string datasetName, List <Record> records, string syncSessionToken)
        {
            UpdateRecordsResponse response = client.UpdateRecords(PrepareUpdateRecordsRequest(datasetName, records, syncSessionToken));

            return(ExtractRecords(response));
        }