first commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public abstract class AMqttMessage {
|
||||
public String Datatype {
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
public DateTime Date {
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
protected AMqttMessage(String datatype) {
|
||||
this.Datatype = datatype;
|
||||
this.Date = DateTime.Now;
|
||||
}
|
||||
|
||||
protected AMqttMessage(String datatype, JsonData json) {
|
||||
this.Datatype = datatype;
|
||||
this.Date = DateTime.Parse(json.ToString(), new System.Globalization.CultureInfo("en-US", false));
|
||||
}
|
||||
|
||||
public virtual String ToJson() => JsonMapper.ToJson(this);
|
||||
|
||||
public static Boolean CheckJson(String message, Type t) {
|
||||
try {
|
||||
return CheckJson(JsonMapper.ToObject(message), t);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean CheckJson(JsonData json, Type t) {
|
||||
try {
|
||||
foreach(PropertyInfo p_info in t.GetProperties()) {
|
||||
if(p_info.Name == "Item") {
|
||||
continue;
|
||||
}
|
||||
if(p_info.CanRead) {
|
||||
if(p_info.PropertyType == typeof(String)) {
|
||||
if(!(json.ContainsKey(p_info.Name) && json[p_info.Name] != null && json[p_info.Name].IsString)) {
|
||||
return false;
|
||||
}
|
||||
} else if(p_info.PropertyType == typeof(DateTime)) {
|
||||
if(!(json.ContainsKey(p_info.Name) && json[p_info.Name] != null && json[p_info.Name].IsString)) {
|
||||
return false;
|
||||
}
|
||||
} else if(p_info.PropertyType == typeof(Boolean)) {
|
||||
if(!(json.ContainsKey(p_info.Name) && json[p_info.Name] != null && json[p_info.Name].IsBoolean)) {
|
||||
return false;
|
||||
}
|
||||
} else if(p_info.PropertyType == typeof(Double)) {
|
||||
if(!(json.ContainsKey(p_info.Name) && json[p_info.Name] != null && (json[p_info.Name].IsInt || json[p_info.Name].IsDouble || json[p_info.Name].IsLong))) {
|
||||
return false;
|
||||
}
|
||||
} else if(p_info.PropertyType.BaseType == typeof(AMqttMessage)) {
|
||||
if(json.ContainsKey(p_info.Name) && (json[p_info.Name] == null || json[p_info.Name].IsObject)) {
|
||||
if(json[p_info.Name] != null && !CheckJson(json[p_info.Name], p_info.PropertyType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public class AddFilter : AMqttMessage {
|
||||
public String Ric {
|
||||
get;
|
||||
}
|
||||
public String Task {
|
||||
get;
|
||||
}
|
||||
public String Sender {
|
||||
get;
|
||||
}
|
||||
|
||||
public AddFilter(String ric, String task, String sender) : base("add-filter") {
|
||||
this.Ric = ric;
|
||||
this.Task = task;
|
||||
this.Sender = sender;
|
||||
}
|
||||
|
||||
public AddFilter(JsonData json) : base("add-filter", json["Date"]) {
|
||||
this.Ric = json["Ric"].ToString();
|
||||
this.Task = json["Task"].ToString();
|
||||
this.Sender = json["Sender"].ToString();
|
||||
}
|
||||
|
||||
public static AddFilter ConvertJson(String message) => new AddFilter(JsonMapper.ToObject(message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public class GeoData : AMqttMessage {
|
||||
public Double Latitude {
|
||||
get;
|
||||
}
|
||||
public Double Longitude {
|
||||
get;
|
||||
}
|
||||
|
||||
public GeoData(Double latitude, Double longitude) : base("geo-data") {
|
||||
this.Latitude = latitude;
|
||||
this.Longitude = longitude;
|
||||
}
|
||||
|
||||
public GeoData(LitJson.JsonData json) : base("geo-data", json["Date"]) {
|
||||
this.Latitude = Double.Parse(json["Latitude"].ToString().Replace(',', '.'), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
|
||||
this.Longitude = Double.Parse(json["Longitude"].ToString().Replace(',', '.'), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public class InfluxStorage : AMqttMessage {
|
||||
public String Text {
|
||||
get;
|
||||
}
|
||||
|
||||
public InfluxStorage(String text) : base("bosmon") => this.Text = text;
|
||||
|
||||
public InfluxStorage(JsonData json) : base("bosmon", json["Date"]) => this.Text = "";
|
||||
|
||||
public override String ToString() => this.Text;
|
||||
|
||||
public static InfluxStorage ConvertJson(String _) => new InfluxStorage("");
|
||||
|
||||
public override String ToJson() => this.Text;
|
||||
|
||||
public static new Boolean CheckJson(String _1, Type _2) => false;
|
||||
|
||||
public static new Boolean CheckJson(JsonData _1, Type _2) => false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public class Message : AMqttMessage {
|
||||
public String Text {
|
||||
get;
|
||||
}
|
||||
|
||||
public Message(String text) : base("message") => this.Text = text;
|
||||
|
||||
public Message(JsonData json) : base("message", json["Date"]) => this.Text = json["Text"].ToString();
|
||||
|
||||
public override String ToString() => this.Text;
|
||||
|
||||
public static Message ConvertJson(String message) => new Message(JsonMapper.ToObject(message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public class PocsagHttp : AMqttMessage {
|
||||
public String Function {
|
||||
get;
|
||||
}
|
||||
public String Flags {
|
||||
get;
|
||||
}
|
||||
public String Message {
|
||||
get;
|
||||
}
|
||||
public String Type {
|
||||
get;
|
||||
}
|
||||
public String Address {
|
||||
get;
|
||||
}
|
||||
|
||||
|
||||
public PocsagHttp(String function, String flags, String message, String type, String address) : base("pocsag-http") {
|
||||
this.Function = function;
|
||||
this.Flags = flags;
|
||||
this.Message = message;
|
||||
this.Type = type;
|
||||
this.Address = address;
|
||||
}
|
||||
|
||||
public PocsagHttp(JsonData json) : base("pocsag-http", json["Date"]) {
|
||||
this.Function = json["Function"].ToString();
|
||||
this.Flags = json["Flags"].ToString();
|
||||
this.Message = json["Message"].ToString();
|
||||
this.Type = json["Type"].ToString();
|
||||
this.Address = json["Address"].ToString();
|
||||
}
|
||||
|
||||
public PocsagHttp(String function, String flags, String message, String type, String address, Double timestamp) : base("pocsag-http") {
|
||||
this.Function = function;
|
||||
this.Flags = flags;
|
||||
this.Message = message;
|
||||
this.Type = type;
|
||||
this.Address = address;
|
||||
this.Date = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timestamp).ToLocalTime();
|
||||
}
|
||||
|
||||
public static PocsagHttp ConvertJson(String message) => new PocsagHttp(JsonMapper.ToObject(message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public class PocsagParsed : AMqttMessage {
|
||||
public PocsagHttp Raw {
|
||||
get;
|
||||
}
|
||||
public String Funktion {
|
||||
get;
|
||||
}
|
||||
public String Name {
|
||||
get;
|
||||
}
|
||||
public RicDescription Ric {
|
||||
get;
|
||||
}
|
||||
public GeoData Geo {
|
||||
get;
|
||||
}
|
||||
public Boolean Sendonline {
|
||||
get;
|
||||
}
|
||||
public Boolean Isprivate {
|
||||
get;
|
||||
}
|
||||
|
||||
public PocsagParsed(PocsagHttp raw, String funktion, String name, RicDescription ric, GeoData geo, Boolean sendonline, Boolean isprivate) : base("pocsag-parsed") {
|
||||
this.Raw = raw;
|
||||
this.Funktion = funktion;
|
||||
this.Name = name;
|
||||
this.Ric = ric;
|
||||
this.Geo = geo;
|
||||
this.Sendonline = sendonline;
|
||||
this.Isprivate = isprivate;
|
||||
}
|
||||
|
||||
public PocsagParsed(JsonData json) : base("pocsag-parsed", json["Date"]) {
|
||||
this.Raw = new PocsagHttp(json["Raw"]);
|
||||
this.Funktion = json["Funktion"].ToString();
|
||||
this.Name = json["Name"].ToString();
|
||||
this.Ric = json["Ric"] is null ? null : new RicDescription(json["Ric"]);
|
||||
this.Geo = json["Geo"] is null ? null : new GeoData(json["Geo"]);
|
||||
this.Sendonline = (Boolean)json["Sendonline"];
|
||||
this.Isprivate = (Boolean)json["Isprivate"];
|
||||
}
|
||||
|
||||
public PocsagParsed(PocsagHttp raw, String funktion, String name, RicDescription ric, GeoData geo, Boolean sendonline, Boolean isprivate, DateTime date) : base("pocsag-parsed") {
|
||||
this.Raw = raw;
|
||||
this.Funktion = funktion;
|
||||
this.Name = name;
|
||||
this.Ric = ric;
|
||||
this.Geo = geo;
|
||||
this.Sendonline = sendonline;
|
||||
this.Isprivate = isprivate;
|
||||
this.Date = date;
|
||||
}
|
||||
|
||||
public override String ToString() => "[" + this.Funktion + "] " + this.Name + ": " + this.Raw.Message;
|
||||
|
||||
public String ToTextString() => System.Text.RegularExpressions.Regex.Replace(this.Raw.Message, @"#C(?<lon>.+?),(?<lat>.+?)#", "").Trim();
|
||||
|
||||
public String ToTitleString() => this.Ric is RicDescription && this.Ric.ShortDescription != "" ? this.Ric.ShortDescription : this.Name;
|
||||
|
||||
public static PocsagParsed ConvertJson(String message) => new PocsagParsed(JsonMapper.ToObject(message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt {
|
||||
public class RicDescription : AMqttMessage {
|
||||
public String Address {
|
||||
get;
|
||||
}
|
||||
|
||||
public String Location {
|
||||
get;
|
||||
}
|
||||
|
||||
public String ShortDescription {
|
||||
get;
|
||||
}
|
||||
|
||||
public String LongDescription {
|
||||
get;
|
||||
}
|
||||
|
||||
public RicDescription(String address, String location, String shortdescription, String longdescription) : base("ric-description") {
|
||||
this.Address = address;
|
||||
this.Location = location;
|
||||
this.ShortDescription = shortdescription;
|
||||
this.LongDescription = longdescription;
|
||||
}
|
||||
|
||||
public RicDescription(JsonData json) : base("ric-description", json["Date"]) {
|
||||
this.Address = json["Address"].ToString();
|
||||
this.Location = json["Location"].ToString();
|
||||
this.ShortDescription = json["ShortDescription"].ToString();
|
||||
this.LongDescription = json["LongDescription"].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user