// // Copyright 2014-2015 Amazon.com, // Inc. or its affiliates. All Rights Reserved. // // SPDX-License-Identifier: Apache-2.0 // using System; namespace Amazon.CognitoSync.SyncManager { /// /// A model which stores conflicting record from the remote storage and the local storage. /// public class SyncConflict { private readonly string _key; private readonly Record _remoteRecord; private readonly Record _localRecord; /// /// The record Key /// public string Key { get { return this._key; } } /// /// Return the record which is present on the server /// public Record RemoteRecord { get { return this._remoteRecord; } } /// /// Return the record which is present locally on the device /// public Record LocalRecord { get { return this._localRecord; } } /// /// Constructs a SyncConflict object. /// /// record from remote storage /// record from local storage public SyncConflict(Record remoteRecord, Record localRecord) { if (remoteRecord == null || localRecord == null) { throw new ArgumentException("Record can't be null"); } if (!remoteRecord.Key.Equals(localRecord.Key)) { throw new ArgumentException("The keys of remote record and local record don't match"); } this._key = remoteRecord.Key; this._remoteRecord = remoteRecord; this._localRecord = localRecord; } /// /// Resolves conflict with remote record /// /// Resolved record public Record ResolveWithRemoteRecord() { return new Record( this.Key, this.RemoteRecord.Value, this.RemoteRecord.SyncCount, this.RemoteRecord.LastModifiedDate, this.RemoteRecord.LastModifiedBy, this.RemoteRecord.DeviceLastModifiedDate, false ); } /// /// Resolves conflict with local record /// /// Resolved record public Record ResolveWithLocalRecord() { return new Record( this.Key, this.LocalRecord.Value, this.RemoteRecord.SyncCount, this.LocalRecord.LastModifiedDate, this.LocalRecord.LastModifiedBy, this.LocalRecord.DeviceLastModifiedDate, true ); } /// /// Resolves conflict with a new value. /// /// Resolved record. /// new value of the record public Record ResolveWithValue(string newValue) { return new Record( this.Key, newValue, this.RemoteRecord.SyncCount, this.LocalRecord.LastModifiedDate, this.LocalRecord.LastModifiedBy, this.LocalRecord.DeviceLastModifiedDate, true ); } } }