197 lines
6.9 KiB
C#
197 lines
6.9 KiB
C#
namespace CommonConsole
|
|
{
|
|
using Common.Hardware.WaterMeter.eRegister.Features;
|
|
using Common.Hardware.WaterMeter.eRegister.Models;
|
|
|
|
using Stichproben.Cordonel;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
public static class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
var stichproben = new Stichproben(typeof(Program).Assembly.Location);
|
|
|
|
stichproben.ShouldBePressureTested(123);
|
|
}
|
|
|
|
|
|
public static void ___Main()
|
|
{
|
|
var features = new List<EregisterFeature>();
|
|
|
|
foreach (var featureInfo in typeof(EregisterFeatures).GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
var featurePamAttribute = featureInfo.GetCustomAttribute<PamAttribute>();
|
|
|
|
if (featurePamAttribute is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var featureType = featureInfo.PropertyType;
|
|
|
|
if (typeof(Pam).IsAssignableFrom(featureType))
|
|
{
|
|
var featurePam = Activator.CreateInstance(featureType) as Pam;
|
|
var feature = new EregisterFeature
|
|
{
|
|
FeatureType = featureType,
|
|
Cmd = featurePam.CmdHex,
|
|
IsSingleCmd = featurePamAttribute.IsSingleCmd,
|
|
OnlyProductionMode = featurePamAttribute.OnlyProductionMode,
|
|
AuthLevel = featurePamAttribute.AuthLevel,
|
|
};
|
|
|
|
foreach (var featurePropertyInfo in feature.FeatureType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
if (!featurePropertyInfo.CanRead || !featureInfo.CanWrite)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
feature.Add(new EregisterFeatureProperty
|
|
{
|
|
Name = featurePropertyInfo.Name,
|
|
Type = featurePropertyInfo.PropertyType,
|
|
Getter = featurePropertyInfo.GetValue,
|
|
Setter = featurePropertyInfo.SetValue,
|
|
});
|
|
}
|
|
|
|
features.Add(feature);
|
|
}
|
|
else if (featureType == typeof(EregisterDebugFeatures))
|
|
{
|
|
var feature = new EregisterDebugFeature
|
|
{
|
|
AuthLevel = AuthLevel.III,
|
|
Cmd = "F1",
|
|
FeatureType = featureType,
|
|
IsSingleCmd = true
|
|
};
|
|
|
|
foreach (var debugFeatureFeatureInfo in typeof(EregisterDebugFeatures).GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
var debugFeaturePamAttribute = debugFeatureFeatureInfo.GetCustomAttribute<PamAttribute>();
|
|
|
|
if (debugFeaturePamAttribute is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var debugFeatureType = debugFeatureFeatureInfo.PropertyType;
|
|
var debugFeaturePam = Activator.CreateInstance(debugFeatureType) as Pam;
|
|
var debugFeature = new EregisterDebugFeature
|
|
{
|
|
FeatureType = featureType,
|
|
Cmd = debugFeaturePam.CmdHex,
|
|
IsSingleCmd = featurePamAttribute.IsSingleCmd,
|
|
OnlyProductionMode = featurePamAttribute.OnlyProductionMode,
|
|
AuthLevel = featurePamAttribute.AuthLevel,
|
|
};
|
|
|
|
foreach (var debugFeaturePropertyInfo in debugFeatureType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
if (!debugFeaturePropertyInfo.CanRead || !featureInfo.CanWrite)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
debugFeature.Add(new EregisterFeatureProperty
|
|
{
|
|
Name = debugFeaturePropertyInfo.Name,
|
|
Type = debugFeaturePropertyInfo.PropertyType,
|
|
Getter = debugFeaturePropertyInfo.GetValue,
|
|
Setter = debugFeaturePropertyInfo.SetValue,
|
|
});
|
|
}
|
|
|
|
feature.Add(debugFeature);
|
|
}
|
|
|
|
features.Add(feature);
|
|
}
|
|
}
|
|
|
|
foreach (var feature in features)
|
|
{
|
|
foreach (var items in feature.GetItems())
|
|
{
|
|
Console.Write($"{items[0],40}");
|
|
Console.Write($"{items[1],5}");
|
|
Console.Write($"{items[2],5}");
|
|
Console.Write($"{items[3],5}");
|
|
Console.Write($"{items[4],5}");
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class EregisterFeature
|
|
{
|
|
private readonly ICollection<EregisterFeatureProperty> properties
|
|
= new List<EregisterFeatureProperty>();
|
|
|
|
public Type FeatureType { get; set; }
|
|
|
|
public string Cmd { get; set; }
|
|
|
|
public bool IsSingleCmd { get; set; }
|
|
|
|
public bool OnlyProductionMode { get; set; }
|
|
|
|
public AuthLevel AuthLevel { get; set; }
|
|
|
|
public virtual void Add(EregisterFeatureProperty eregisterFeatureProperty)
|
|
=> this.properties.Add(eregisterFeatureProperty);
|
|
|
|
public virtual IEnumerable<string[]> GetItems()
|
|
{
|
|
yield return new[]
|
|
{
|
|
this.FeatureType.Name,
|
|
this.Cmd,
|
|
$"{this.AuthLevel}",
|
|
this.IsSingleCmd ? "v" : " ",
|
|
this.OnlyProductionMode ? "v" : " "
|
|
};
|
|
}
|
|
}
|
|
|
|
public class EregisterDebugFeature : EregisterFeature
|
|
{
|
|
private readonly ICollection<EregisterFeature> features
|
|
= new List<EregisterFeature>();
|
|
|
|
public virtual void Add(EregisterFeature feature)
|
|
=> this.features.Add(feature);
|
|
|
|
public override IEnumerable<string[]> GetItems()
|
|
{
|
|
foreach (var feature in this.features)
|
|
{
|
|
foreach (var items in feature.GetItems())
|
|
{
|
|
yield return items;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class EregisterFeatureProperty
|
|
{
|
|
public string Name { get; set; }
|
|
|
|
public Type Type { get; set; }
|
|
|
|
public Func<object, object> Getter { get; set; }
|
|
|
|
public Action<object, object> Setter { get; set; }
|
|
}
|
|
} |