otify other Objects when Settings are changed.
This commit is contained in:
parent
c5ff258793
commit
1e4c2db716
@ -14,7 +14,9 @@ using LitJson;
|
|||||||
namespace Fraunhofer.Fit.IoT.LoraMap.Model.Admin {
|
namespace Fraunhofer.Fit.IoT.LoraMap.Model.Admin {
|
||||||
class AdminModel {
|
class AdminModel {
|
||||||
public delegate void AdminEvent(Object sender, EventArgs e);
|
public delegate void AdminEvent(Object sender, EventArgs e);
|
||||||
#pragma warning disable 0067
|
|
||||||
|
//Supress never used warning (cause of reflection)
|
||||||
|
#pragma warning disable 0067
|
||||||
public event AdminEvent NamesUpdate;
|
public event AdminEvent NamesUpdate;
|
||||||
public event AdminEvent GeoUpdate;
|
public event AdminEvent GeoUpdate;
|
||||||
public event AdminEvent SettingsUpdate;
|
public event AdminEvent SettingsUpdate;
|
||||||
|
@ -12,6 +12,8 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model.Position {
|
|||||||
private readonly SortedDictionary<DateTime, Double[]> _history = new SortedDictionary<DateTime, Double[]>();
|
private readonly SortedDictionary<DateTime, Double[]> _history = new SortedDictionary<DateTime, Double[]>();
|
||||||
private String _lastHash = "";
|
private String _lastHash = "";
|
||||||
private Boolean _isdublicate = false;
|
private Boolean _isdublicate = false;
|
||||||
|
private Double _historycounter = 0;
|
||||||
|
private readonly Object lockHistory = new Object();
|
||||||
|
|
||||||
public Double Rssi { get; private set; }
|
public Double Rssi { get; private set; }
|
||||||
public Double Snr { get; private set; }
|
public Double Snr { get; private set; }
|
||||||
@ -35,6 +37,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model.Position {
|
|||||||
public PositionItem(LoraData data, NamesModel marker) {
|
public PositionItem(LoraData data, NamesModel marker) {
|
||||||
this.Update(data);
|
this.Update(data);
|
||||||
this.UpdateMarker(marker, data.Name);
|
this.UpdateMarker(marker, data.Name);
|
||||||
|
Settings.Instance.SettingsUpdate += this.UpdateSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateMarker(NamesModel marker, String id) {
|
public void UpdateMarker(NamesModel marker, String id) {
|
||||||
@ -104,28 +107,36 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model.Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void StoreHistory() {
|
private void StoreHistory() {
|
||||||
if(Settings.Instance.Internal.History.Enabled) {
|
lock(this.lockHistory) {
|
||||||
if(Settings.Instance.Internal.History.Amount != 0 && this._history.Count > Settings.Instance.Internal.History.Amount) {
|
if(Settings.Instance.Internal.History.Enabled) {
|
||||||
_ = this._history.Remove(this._history.Keys.ToList().First());
|
if(Settings.Instance.Internal.History.Amount != 0 && this._history.Count > Settings.Instance.Internal.History.Amount) {
|
||||||
}
|
_ = this._history.Remove(this._history.Keys.ToList().First());
|
||||||
if(Settings.Instance.Internal.History.Time != 0) {
|
}
|
||||||
List<DateTime> removeCandidates = new List<DateTime>();
|
if(Settings.Instance.Internal.History.Time != 0) {
|
||||||
DateTime now = DateTime.UtcNow;
|
List<DateTime> removeCandidates = new List<DateTime>();
|
||||||
foreach(KeyValuePair<DateTime, Double[]> item in this._history) {
|
DateTime now = DateTime.UtcNow;
|
||||||
if((now - item.Key).TotalSeconds > Settings.Instance.Internal.History.Time) {
|
foreach(KeyValuePair<DateTime, Double[]> item in this._history) {
|
||||||
removeCandidates.Add(item.Key);
|
if((now - item.Key).TotalSeconds > Settings.Instance.Internal.History.Time) {
|
||||||
|
removeCandidates.Add(item.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(removeCandidates.Count > 0) {
|
||||||
|
foreach(DateTime item in removeCandidates) {
|
||||||
|
_ = this._history.Remove(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(removeCandidates.Count > 0) {
|
if(!this._history.ContainsKey(this.Recievedtime)) {
|
||||||
foreach(DateTime item in removeCandidates) {
|
this._history.Add(this.Recievedtime, new Double[] { this.Latitude, this.Longitude, this._historycounter++ });
|
||||||
_ = this._history.Remove(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this._history.Clear();
|
||||||
}
|
}
|
||||||
if(!this._history.ContainsKey(this.Recievedtime)) {
|
}
|
||||||
this._history.Add(this.Recievedtime, new Double[] { this.Latitude, this.Longitude });
|
}
|
||||||
}
|
|
||||||
} else {
|
private void UpdateSettings(Object sender, EventArgs e) {
|
||||||
|
lock(this.lockHistory) {
|
||||||
this._history.Clear();
|
this._history.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,12 @@ using System.IO;
|
|||||||
|
|
||||||
namespace Fraunhofer.Fit.IoT.LoraMap.Model {
|
namespace Fraunhofer.Fit.IoT.LoraMap.Model {
|
||||||
public class Settings : OwnSingeton<Settings> {
|
public class Settings : OwnSingeton<Settings> {
|
||||||
|
|
||||||
private Int32 gridradius;
|
private Int32 gridradius;
|
||||||
|
|
||||||
|
public delegate void SettingsEvent(Object sender, EventArgs e);
|
||||||
|
public event SettingsEvent SettingsUpdate;
|
||||||
|
|
||||||
|
|
||||||
public PublicSettings External {
|
public PublicSettings External {
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
@ -139,6 +142,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
|
|||||||
this.gridradius = json.ContainsKey("GridRadius") && json["GridRadius"].IsInt && this.External.Startloclat != 0 && this.External.Startloclon != 0 ? (Int32)json["GridRadius"] : 0;
|
this.gridradius = json.ContainsKey("GridRadius") && json["GridRadius"].IsInt && this.External.Startloclat != 0 && this.External.Startloclon != 0 ? (Int32)json["GridRadius"] : 0;
|
||||||
this.GenerateGrid();
|
this.GenerateGrid();
|
||||||
this.FindMapLayer();
|
this.FindMapLayer();
|
||||||
|
this.SettingsUpdate?.Invoke(this, new EventArgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseGeoJson() {
|
private void ParseGeoJson() {
|
||||||
|
Loading…
Reference in New Issue
Block a user