From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/FireBase/Offline/OfflineEntry.cs | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 dsa/FireBase/Offline/OfflineEntry.cs (limited to 'dsa/FireBase/Offline/OfflineEntry.cs') diff --git a/dsa/FireBase/Offline/OfflineEntry.cs b/dsa/FireBase/Offline/OfflineEntry.cs new file mode 100644 index 0000000..9feffa3 --- /dev/null +++ b/dsa/FireBase/Offline/OfflineEntry.cs @@ -0,0 +1,99 @@ +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))); + } + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf