// // Copyright 2014-2015 Amazon.com, // Inc. or its affiliates. All Rights Reserved. // // SPDX-License-Identifier: Apache-2.0 // using System; using Amazon.CognitoSync.SyncManager.Internal; using System.Globalization; namespace Amazon.CognitoSync.SyncManager { /// /// A Record is the element stored in a . /// There can be up to 1k records or up to 1 MB in size in a . /// public sealed class Record { private readonly string _key; private readonly string _value; private readonly long _syncCount; private readonly DateTime? _lastModifiedDate; private readonly string _lastModifiedBy; private readonly DateTime? _deviceLastModifiedDate; private readonly bool _modified; /// /// The key of this record. It's a non empty string. /// /// The key associated with the Record public string Key { get { return this._key; } } /// /// The value of this record. If it's null, then the record is considered as deleted. /// /// The value. public string Value { get { return this._value; } } /// /// Equivalent to the version of this record. It's a increasing non negative /// long number. The value is returned from server. Do not set this value /// arbitrarily, or else update may fail. /// /// The sync count. public long SyncCount { get { return this._syncCount; } } /// /// The server timestamp of this record when it was last modified. /// /// The last modified date. public DateTime? LastModifiedDate { get { return this._lastModifiedDate; } } /// /// An identifier of the user or device which modified this record last. /// /// The last modified by. public string LastModifiedBy { get { return this._lastModifiedBy; } } /// /// The local timestamp of this record when it was last modified. /// /// The device last modified date. public DateTime? DeviceLastModifiedDate { get { return this._deviceLastModifiedDate; } } /// /// A flag that indicates whether this record is modified locally but hasn't /// been synced. /// /// true if modified; otherwise, false. public bool IsModified { get { return this._modified; } } /// /// Creates an instance of the Record. /// /// The key representing the record /// The value for the record /// THe number of times this record has been synchronized /// The last time the record was modified in UTC /// /// /// Flag indicating the record was modified public Record(string key, string value, long syncCount, DateTime? lastModifiedDate, string lastModifiedBy, DateTime? deviceLastModifiedDate, bool modified) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } this._key = key; this._value = value; this._syncCount = syncCount; this._lastModifiedDate = lastModifiedDate != null ? DatasetUtils.TruncateToSeconds(lastModifiedDate.Value.ToUniversalTime()) : lastModifiedDate; this._lastModifiedBy = lastModifiedBy; this._deviceLastModifiedDate = deviceLastModifiedDate != null ? DatasetUtils.TruncateToSeconds(deviceLastModifiedDate.Value.ToUniversalTime()) : deviceLastModifiedDate; this._modified = modified; } /// /// Gets whether the record is marked as deleted. True if value is null, /// false otherwise. /// /// true if the record is marked as deleted; otherwise, false. public bool IsDeleted { get { return Value == null; } } /// /// A string representation of the record /// /// public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "Key:[{0}], Value:[{1}], SyncCount:[{2}], LastModifiedDate:[{3}], LastModifiedBy:[{4}], DeviceLastModifiedDate:[{5}], IsModified:[{6}]", Key, Value, SyncCount, LastModifiedDate, LastModifiedBy, DeviceLastModifiedDate, IsModified); } } }