diff options
author | uzvkl <dennis.kobert@student.kit.edu> | 2019-06-11 23:05:52 +0200 |
---|---|---|
committer | uzvkl <dennis.kobert@student.kit.edu> | 2019-06-11 23:05:52 +0200 |
commit | e6181c24124d97f2fbc932b8a68311e625463156 (patch) | |
tree | c1f097c344ca266b7941c9668590b0fd35c7870a /dsa/FireBase/Offline/OfflineEntry.cs | |
parent | 2490ad5d31fe2ac778ff9303776f0e91f47a2862 (diff) |
Move dsa related stuff to subfolder
Diffstat (limited to 'dsa/FireBase/Offline/OfflineEntry.cs')
-rw-r--r-- | dsa/FireBase/Offline/OfflineEntry.cs | 99 |
1 files changed, 99 insertions, 0 deletions
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 +{ + /// <summary> + /// Represents an object stored in offline storage. + /// </summary> + public class OfflineEntry + { + private object dataInstance; + + /// <summary> + /// Initializes a new instance of the <see cref="OfflineEntry" /> class with an already serialized object. + /// </summary> + /// <param name="key"> The key. </param> + /// <param name="obj"> The object. </param> + /// <param name="priority"> + /// The priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. + /// </param> + /// <param name="syncOptions"> The sync options. </param> + 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; + } + + /// <summary> + /// Initializes a new instance of the <see cref="OfflineEntry" /> class. + /// </summary> + /// <param name="key"> The key. </param> + /// <param name="obj"> The object. </param> + /// <param name="priority"> + /// The priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. + /// </param> + /// <param name="syncOptions"> The sync options. </param> + public OfflineEntry(string key, object obj, int priority, SyncOptions syncOptions, bool isPartial = false) + : this(key, obj, JsonConvert.SerializeObject(obj), priority, syncOptions, isPartial) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="OfflineEntry" /> class. + /// </summary> + public OfflineEntry() + { + } + + /// <summary> + /// Gets or sets the key of this entry. + /// </summary> + public string Key { get; set; } + + /// <summary> + /// Gets or sets the priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. + /// </summary> + public int Priority { get; set; } + + /// <summary> + /// Gets or sets the timestamp when this entry was last touched. + /// </summary> + public DateTime Timestamp { get; set; } + + /// <summary> + /// Gets or sets the <see cref="SyncOptions" /> which define what sync state this entry is in. + /// </summary> + public SyncOptions SyncOptions { get; set; } + + /// <summary> + /// Gets or sets serialized JSON data. + /// </summary> + public string Data { get; set; } + + /// <summary> + /// Specifies whether this is only a partial object. + /// </summary> + public bool IsPartial { get; set; } + + /// <summary> + /// Deserializes <see cref="Data" /> into <typeparamref name="T" />. The result is cached. + /// </summary> + /// <typeparam name="T"> Type of object to deserialize into. </typeparam> + /// <returns> Instance of <typeparamref name="T" />. </returns> + public T Deserialize<T>() + { + return (T) (dataInstance ?? (dataInstance = JsonConvert.DeserializeObject<T>(Data))); + } + } +}
\ No newline at end of file |