using System; using Newtonsoft.Json; namespace Firebase.Database.Offline { /// /// Represents an object stored in offline storage. /// public class OfflineEntry { private object dataInstance; /// /// Initializes a new instance of the class with an already serialized object. /// /// The key. /// The object. /// /// The priority. Objects with higher priority will be synced first. Higher number indicates higher /// priority. /// /// The sync options. public OfflineEntry(string key, object obj, string data, int priority, SyncOptions syncOptions, bool isPartial = false) { Key = key; Priority = priority; Data = data; Timestamp = DateTime.UtcNow; SyncOptions = syncOptions; IsPartial = isPartial; dataInstance = obj; } /// /// Initializes a new instance of the class. /// /// The key. /// The object. /// /// The priority. Objects with higher priority will be synced first. Higher number indicates higher /// priority. /// /// The sync options. public OfflineEntry(string key, object obj, int priority, SyncOptions syncOptions, bool isPartial = false) : this(key, obj, JsonConvert.SerializeObject(obj), priority, syncOptions, isPartial) { } /// /// Initializes a new instance of the class. /// public OfflineEntry() { } /// /// Gets or sets the key of this entry. /// public string Key { get; set; } /// /// Gets or sets the priority. Objects with higher priority will be synced first. Higher number indicates higher /// priority. /// public int Priority { get; set; } /// /// Gets or sets the timestamp when this entry was last touched. /// public DateTime Timestamp { get; set; } /// /// Gets or sets the which define what sync state this entry is in. /// public SyncOptions SyncOptions { get; set; } /// /// Gets or sets serialized JSON data. /// public string Data { get; set; } /// /// Specifies whether this is only a partial object. /// public bool IsPartial { get; set; } /// /// Deserializes into . The result is cached. /// /// Type of object to deserialize into. /// Instance of . public T Deserialize() { return (T) (dataInstance ?? (dataInstance = JsonConvert.DeserializeObject(Data))); } } }