summaryrefslogtreecommitdiff
path: root/FireBase/Offline/OfflineEntry.cs
diff options
context:
space:
mode:
authorTrueKuehli <rctcoaster2000@hotmail.de>2018-09-29 17:19:43 +0200
committerTrueKuehli <rctcoaster2000@hotmail.de>2018-09-29 17:19:43 +0200
commitb83fc90abacc73262e0f8404cebadf6d64eb10ae (patch)
treed63b921c9bcdf8d381fc02ecfb0a1dd425ebb561 /FireBase/Offline/OfflineEntry.cs
parent586d564f3c4c509c1aae931331e96f0382178f80 (diff)
parent680967aee589e4a8d277044b204de07cbe32f41e (diff)
Merge branch 'WebApi' of https://github.com/TrueDoctor/DiscoBot into WebApi
Merged the stuffs
Diffstat (limited to 'FireBase/Offline/OfflineEntry.cs')
-rw-r--r--FireBase/Offline/OfflineEntry.cs116
1 files changed, 116 insertions, 0 deletions
diff --git a/FireBase/Offline/OfflineEntry.cs b/FireBase/Offline/OfflineEntry.cs
new file mode 100644
index 0000000..3b862cb
--- /dev/null
+++ b/FireBase/Offline/OfflineEntry.cs
@@ -0,0 +1,116 @@
+namespace Firebase.Database.Offline
+{
+ using System;
+
+ using Newtonsoft.Json;
+
+ /// <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)
+ {
+ this.Key = key;
+ this.Priority = priority;
+ this.Data = data;
+ this.Timestamp = DateTime.UtcNow;
+ this.SyncOptions = syncOptions;
+ this.IsPartial = isPartial;
+
+ this.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)(this.dataInstance ?? (this.dataInstance = JsonConvert.DeserializeObject<T>(this.Data)));
+ }
+ }
+}