commit e231c49bc8f2529d68f6192df5ce946853bf299f Author: ygl Date: Fri Nov 11 03:19:03 2022 +0800 first diff --git a/realm_cli/FodyWeavers.xml b/realm_cli/FodyWeavers.xml new file mode 100644 index 0000000..9918007 --- /dev/null +++ b/realm_cli/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/realm_cli/FodyWeavers.xsd b/realm_cli/FodyWeavers.xsd new file mode 100644 index 0000000..4fcc6ff --- /dev/null +++ b/realm_cli/FodyWeavers.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + Disables anonymized usage information from being sent on build. Read more about what data is being collected and why here: https://github.com/realm/realm-dotnet/blob/main/Realm/Realm.Weaver/Analytics.cs + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/realm_cli/LiveData.cs b/realm_cli/LiveData.cs new file mode 100644 index 0000000..d1701cd --- /dev/null +++ b/realm_cli/LiveData.cs @@ -0,0 +1,226 @@ +using MongoDB.Bson; +using Realms; + +namespace realm_cli; + +public class LiveData : RealmObject +{ + [PrimaryKey] public ObjectId ObjId { get; set; } = ObjectId.GenerateNewId(); + + private int ecu_id; + + public int EcuId + { + get => this.ecu_id; + set + { + this.ecu_id = value; + OnPropertyChanged(nameof(EcuId)); + } + } + + private ushort block_id; + + public ushort BlockId + { + get => this.block_id; + set + { + this.block_id = value; + OnPropertyChanged(nameof(BlockId)); + } + } //reserved + + + [MapTo("item_id")] + public int ItemId { get; set; } + + private string display_name; + + public string DisplayName + { + get => this.display_name; + set + { + this.display_name = value; + OnPropertyChanged(nameof(DisplayName)); + } + } + + private string val_unit = string.Empty; + + public string ValUnit + { + get => this.val_unit; + set + { + this.val_unit = value; + OnPropertyChanged(nameof(ValUnit)); + } + } + + public float? Val { get; set; } + + private string _display_value = ""; + + public string DisplayValue + { + get => this._display_value; + set + { + this._display_value = value; + this.OnPropertyChanged(nameof(DisplayValue)); + } + } + + public string ValueLabel { get; set; } + + private DateTime? _uts; + + public DateTime? Uts + { + get => this._uts; + set + { + this._uts = value; + OnPropertyChanged(nameof(Uts)); + } + } + + private double min_; + + public double Min + { + get => this.min_; + set + { + this.min_ = value; + OnPropertyChanged(nameof(Min)); + } + } + + private double max_; + + public double Max + { + get => this.max_; + set + { + this.max_ = value; + OnPropertyChanged(nameof(Max)); + } + } + + private double gauge_range_start1; + + public double GaugeRangeStart1 + { + get => this.gauge_range_start1; + set + { + this.gauge_range_start1 = value; + OnPropertyChanged(nameof(GaugeRangeStart1)); + } + } + + private double gauge_range_end1; + + public double GaugeRangeEnd1 + { + get => this.gauge_range_end1; + set + { + this.gauge_range_end1 = value; + OnPropertyChanged(nameof(GaugeRangeEnd1)); + } + } + + private double gauge_range_start2; + + public double GaugeRangeStart2 + { + get => this.gauge_range_start2; + set + { + this.gauge_range_start2 = value; + OnPropertyChanged(nameof(GaugeRangeStart2)); + } + } + + private double gauge_range_end2; + + public double GaugeRangeEnd2 + { + get => this.gauge_range_end2; + set + { + this.gauge_range_end2 = value; + OnPropertyChanged(nameof(GaugeRangeEnd2)); + } + } + + private double gauge_range_start3; + + public double GaugeRangeStart3 + { + get => this.gauge_range_start3; + set + { + this.gauge_range_start3 = value; + OnPropertyChanged(nameof(GaugeRangeStart3)); + } + } + + private double gauge_range_end3; + + public double GaugeRangeEnd3 + { + get => this.gauge_range_end3; + set + { + this.gauge_range_end3 = value; + OnPropertyChanged(nameof(GaugeRangeEnd3)); + } + } + + private double gauge_range_start4; + + public double GaugeRangeStart4 + { + get => this.gauge_range_start4; + set + { + this.gauge_range_start4 = value; + OnPropertyChanged(nameof(GaugeRangeStart4)); + } + } + + private double gauge_range_end4; + + public double GaugeRangeEnd4 + { + get => this.gauge_range_end4; + set + { + this.gauge_range_end4 = value; + OnPropertyChanged(nameof(GaugeRangeEnd4)); + } + } + + private double gauge_scale_interval; + + public double GaugeScaleInterval + { + get => this.gauge_scale_interval; + set + { + this.gauge_scale_interval = value; + OnPropertyChanged(nameof(GaugeScaleInterval)); + } + } + + public override string ToString() + { + return $"ecu: {EcuId} item: {ItemId} value: {Val} name: {this.DisplayName} display value: {this.DisplayValue}"; + } +} \ No newline at end of file diff --git a/realm_cli/Program.cs b/realm_cli/Program.cs new file mode 100644 index 0000000..0a987a7 --- /dev/null +++ b/realm_cli/Program.cs @@ -0,0 +1,59 @@ +// See https://aka.ms/new-console-template for more information + +using System.ComponentModel; +using realm_cli; +using Realms; + + +Realm GetDB() +{ + var cfg = new RealmConfiguration("c:/prjs/realm_test.db"); + cfg.SchemaVersion = 2; + return Realm.GetInstance(cfg); +} + +Realm GetMemDB() +{ + return Realm.GetInstance(new InMemoryConfiguration("test")); +} + +void PropChanged(object arg, PropertyChangedEventArgs e) +{ + var src = (LiveData) arg; + if (e.PropertyName == nameof(src.ItemId)) + { + Console.WriteLine(src); + } +} + +async Task InsertLiveData() +{ + var b = DateTime.Now; + for (var i = 0; i != 10; ++i) + { + var item = new LiveData() {ItemId = i, EcuId = 0, Val = new Random().NextSingle()*i}; + //item.PropertyChanged += PropChanged; + item.ItemId = i; + item.ValueLabel = item.Val.ToString(); + var db = GetDB(); + await db.WriteAsync((realm => + { + realm.Add(item); + })); + } + Console.WriteLine($"insert needs {(DateTime.Now - b).TotalSeconds} secs"); +} + +async Task QueryLiveData() +{ + var b = DateTime.Now; + for (var i = 0; i != 100; ++i) + { + var db = GetDB(); + var cs = db.All().Where(i1 => i1.ItemId == i); + Console.WriteLine(cs.FirstOrDefault()); + } +} + +//await InsertLiveData(); +await QueryLiveData(); diff --git a/realm_cli/realm_cli.csproj b/realm_cli/realm_cli.csproj new file mode 100644 index 0000000..a9db1cf --- /dev/null +++ b/realm_cli/realm_cli.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + +