AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Dataset is the container of Amazon.CognitoSync.SyncManager.Records. It can have up to 1k Amazon.CognitoSync.SyncManager.Record or 1 MB in size. A typical use of Dataset is the following.

//open or create dataset
Dataset dataset = cognitoSyncManger.OpenOrCreateDataset("new dataset");
// synchronize. It pulls down latest changes from remote storage
// and push local changes to remote storage
dataset.Synchronize();
// reads value
String highScore = dataset.Get("high_score");
String name = dataset.Get("name");
// sets value
dataset.Put("high_score", "90");
dataset.Put("name", "John");
// push changes to remote if needed
dataset.Synchronize();
            

Inheritance Hierarchy

System.Object
  Amazon.CognitoSync.SyncManager.Dataset

Namespace: Amazon.CognitoSync.SyncManager
Assembly: AWSSDK.CognitoSync.dll
Version: 3.x.y.z

Syntax

C#
public class Dataset
         IDisposable

The Dataset type exposes the following members

Properties

NameTypeDescription
Public Property ActiveRecords System.Collections.Generic.IDictionary<System.String, System.String>

Gets the Key/Value representation of all records of this dataset. Datasets marked as deleted records are excluded.

Public Property Metadata Amazon.CognitoSync.SyncManager.DatasetMetadata

Retrieves the associated Amazon.CognitoSync.SyncManager.DatasetMetadata from local storage.

Public Property Records System.Collections.Generic.IList<Amazon.CognitoSync.SyncManager.Record>

Retrieves all raw records, including those marked as deleted, from local storage.

Public Property TotalSizeInBytes System.Int64

Gets the total size in bytes of this dataset. Records that are marked as deleted don't contribute to the total size. The size is calculated as sum of UTF-8 string length of key and value for all the records

Methods

Note:

Asynchronous operations (methods ending with Async) in the table below are for .NET 4.5 or higher. For .NET 3.5 the SDK follows the standard naming convention of BeginMethodName and EndMethodName to indicate asynchronous operations - these method pairs are not shown in the table below.

NameDescription
Public Method ClearAllDelegates()

Clears all the delegates

Public Method Delete()

Delete this Amazon.CognitoSync.SyncManager.Dataset. You cannot do any more operations on this dataset.

Public Method Dispose()

Releases the resources consumed by this object

Public Method Get(string)

Gets the value of a Amazon.CognitoSync.SyncManager.Record with the given key. If the Amazon.CognitoSync.SyncManager.Record doesn't exist or is marked deleted, null will be returned.

Public Method GetRecord(string)

Gets the Amazon.CognitoSync.SyncManager.Record with the given key. If the Amazon.CognitoSync.SyncManager.Record doesn't exist or is marked deleted, null will be returned.

Public Method GetSizeInBytes(string)

Gets the size of a record with the given key. If the key is deleted, -1 will be returned. The size is calculated as sum of UTF-8 string length of record key and value

Public Method IsModified(string)

Retrieves the status of a record.

Public Method Put(string, string)

Puts a Amazon.CognitoSync.SyncManager.Record with the given key and value into the Dataset. If a Amazon.CognitoSync.SyncManager.Record with the same key exists, its value will be overwritten. If a Amazon.CognitoSync.SyncManager.Record is marked as deleted previously, then it will be resurrected with new value while the sync count continues with previous value. No matter whether the value changes or not, the record is considered as updated, and it will be written to Cognito Sync service on next synchronize operation. If value is null, a ArgumentNullException will be thrown.

Public Method PutAll(IDictionary<String, String>)

Populates a dataset with a dictionary of key/value pairs

Public Method Remove(string)

Marks a Amazon.CognitoSync.SyncManager.Record with the given key as deleted. Nothing happens if the Amazon.CognitoSync.SyncManager.Record doesn't exist or is deleted already.

Public Method Resolve(List<Record>)

Saves resolved conflicting Amazon.CognitoSync.SyncManager.Record into local storage. This is used inside Amazon.CognitoSync.SyncManager.Dataset.SyncConflictDelegate after you resolve all conflicts.

Public Method SynchronizeAsync(CancellationToken)

Synchronize Amazon.CognitoSync.SyncManager.Dataset between local storage and remote storage.

Public Method SynchronizeOnConnectivity(CancellationToken)

Attempt to synchronize Amazon.CognitoSync.SyncManager.Dataset when connectivity is available. If the connectivity is available right away, it behaves the same as Amazon.CognitoSync.SyncManager.Dataset.SynchronizeAsync(System.Threading.CancellationToken). Otherwise it listens to connectivity changes, and will do a sync once the connectivity is back. Note that if this method is called multiple times, only the last synchronize request is kept. If either the dataset or the callback is garbage collected , this method will not perform a sync and the callback won't fire.

Events

NameDescription
Event OnSyncFailure
Event OnSyncSuccess

Fields

NameTypeDescription
Field OnDatasetDeleted Amazon.CognitoSync.SyncManager.Dataset.DatasetDeletedDelegate

This is triggered when the given dataset is deleted remotely. Return true if you want to remove local dataset, or false if you want to keep it.

Field OnDatasetMerged Amazon.CognitoSync.SyncManager.Dataset.DatasetMergedDelegate

If two or more datasets are merged as a result of identity merge, this will be triggered. A list of names of merged datasets' is passed in. The merged dataset name will be appended with its old identity id. One can open the merged dataset, synchronize the content, reconcile with the current dataset, and remove it. This callback will fire off until the merged dataset is removed.

Field OnSyncConflict Amazon.CognitoSync.SyncManager.Dataset.SyncConflictDelegate

This can be triggered during two phases. One is when the remote changes are about to be written to local storage. The other is when local changes are uploaded to remote storage and got rejected. Here is an example:

playerInfo.OnSyncConflict = this.HandleSyncConflict;
            
private bool HandleSyncConflict(Dataset dataset, List conflicts)
{
    List resolved = new List();
    for (SyncConflict conflict in conflicts) 
    {
        resolved.add(conflicts.resolveWithRemoteRecord());
    }
    dataset.Resolve(resolved);
    return true;
}
            

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

Portable Class Library:
Supported in: Windows Store Apps
Supported in: Windows Phone 8.1
Supported in: Xamarin Android
Supported in: Xamarin iOS (Unified)
Supported in: Xamarin.Forms

Unity:
Supported Versions: 4.6 and above
Supported Platforms: Android, iOS, Standalone