From de0f076ef9ff546c9a90513259ad6c42cd2224b3 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Sat, 29 Sep 2018 16:51:26 +0200 Subject: added firebase api --- FireBase/Offline/OfflineEntry.cs | 116 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 FireBase/Offline/OfflineEntry.cs (limited to 'FireBase/Offline/OfflineEntry.cs') 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; + + /// + /// 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) + { + this.Key = key; + this.Priority = priority; + this.Data = data; + this.Timestamp = DateTime.UtcNow; + this.SyncOptions = syncOptions; + this.IsPartial = isPartial; + + this.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)(this.dataInstance ?? (this.dataInstance = JsonConvert.DeserializeObject(this.Data))); + } + } +} -- cgit v1.2.3-70-g09d2