master
ygl 3 years ago
commit e231c49bc8
  1. 3
      realm_cli/FodyWeavers.xml
  2. 34
      realm_cli/FodyWeavers.xsd
  3. 226
      realm_cli/LiveData.cs
  4. 59
      realm_cli/Program.cs
  5. 14
      realm_cli/realm_cli.csproj

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Realm />
</Weavers>

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Realm" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="DisableAnalytics" type="xs:boolean">
<xs:annotation>
<xs:documentation>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</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

@ -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}";
}
}

@ -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<LiveData>().Where(i1 => i1.ItemId == i);
Console.WriteLine(cs.FirstOrDefault());
}
}
//await InsertLiveData();
await QueryLiveData();

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Realm" Version="10.18.0" />
</ItemGroup>
</Project>
Loading…
Cancel
Save