Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RDMSharp/Metadata/DataTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace RDMSharp.Metadata
{
#pragma warning disable CS8632
public readonly struct DataTree : IEquatable<DataTree>
{
public readonly string Name;
Expand Down Expand Up @@ -97,4 +98,5 @@ public override int GetHashCode()
return !(left == right);
}
}
}
}
#pragma warning restore CS8632
44 changes: 28 additions & 16 deletions RDMSharp/Metadata/DataTreeBranch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RDMSharp.Metadata.JSON;
using Microsoft.Extensions.Logging;
using RDMSharp.Metadata.JSON;
using RDMSharp.Metadata.JSON.OneOfTypes;
using System;
using System.Collections;
Expand All @@ -13,6 +14,7 @@ namespace RDMSharp.Metadata
{
public readonly struct DataTreeBranch : IEquatable<DataTreeBranch>
{
private static ILogger Logger = null;
public static readonly DataTreeBranch Empty = new DataTreeBranch();
public static readonly DataTreeBranch Unset = new DataTreeBranch(true);

Expand Down Expand Up @@ -43,21 +45,21 @@ private DataTreeBranch(object parsedObject, params DataTree[] children) : this(c
{
ParsedObject = parsedObject;
}
public DataTreeBranch(MetadataJSONObjectDefine define, Command.ECommandDublicte commandType, params DataTree[] children) : this(children)
public DataTreeBranch(MetadataJSONObjectDefine define, Command.ECommandDublicate commandType, params DataTree[] children) : this(children)
{
if (define == null)
throw new ArgumentNullException();

ParsedObject = this.getParsedObject(define, commandType);
}

private object getParsedObject(MetadataJSONObjectDefine define, Command.ECommandDublicte commandType)
private object getParsedObject(MetadataJSONObjectDefine define, Command.ECommandDublicate commandType)
{
ushort pid = define.PID;
var definedDataTreeObjectType = MetadataFactory.GetDefinedDataTreeObjectType(define, commandType);
return getParsedObject(pid, definedDataTreeObjectType, commandType);
}
private object getParsedObject(ushort pid, Type definedDataTreeObjectType, Command.ECommandDublicte commandType)
private object getParsedObject(ushort pid, Type definedDataTreeObjectType, Command.ECommandDublicate commandType)
{
if (IsEmpty || IsUnset)
return null;
Expand Down Expand Up @@ -176,7 +178,10 @@ object createObjectFromDataTree(DataTree[] children)
}
catch (Exception e)
{
Logger.LogError(e);
#pragma warning disable CA2200
throw e;
#pragma warning restore CA2200
}

throw new NotImplementedException();
Expand Down Expand Up @@ -216,16 +221,16 @@ public static DataTreeBranch FromObject(object obj, object key, ParameterBag par

switch (cmd.Value.EnumValue)
{
case Command.ECommandDublicte.GetRequest:
case Command.ECommandDublicate.GetRequest:
cmd = define.GetRequest;
break;
case Command.ECommandDublicte.GetResponse:
case Command.ECommandDublicate.GetResponse:
cmd = define.GetResponse;
break;
case Command.ECommandDublicte.SetRequest:
case Command.ECommandDublicate.SetRequest:
cmd = define.SetRequest;
break;
case Command.ECommandDublicte.SetResponse:
case Command.ECommandDublicate.SetResponse:
cmd = define.SetResponse;
break;
}
Expand Down Expand Up @@ -274,8 +279,15 @@ public static DataTreeBranch FromObject(object obj, object key, ERDM_Command com

var tryGetValueMethod = type.GetMethod("TryGetValue");
object[] parameters = { key, null };

bool found = (bool)tryGetValueMethod.Invoke(obj, parameters);
bool found = false;
try
{
found = (bool)tryGetValueMethod.Invoke(obj, parameters);
}
catch(Exception e)
{
Logger.LogError(e);
}

if (found)
{
Expand All @@ -291,7 +303,7 @@ public static DataTreeBranch FromObject(object obj, object key, ERDM_Command com
if (isArray)
type = type.GetElementType();

if (type.GetCustomAttributes<DataTreeObjectAttribute>().FirstOrDefault(a => a.Parameter == parameter && a.Command == Tools.ConvertCommandDublicteToCommand(command) && a.IsArray == isArray) is not DataTreeObjectAttribute dataTreeObjectAttribute)
if (type.GetCustomAttributes<DataTreeObjectAttribute>().FirstOrDefault(a => a.Parameter == parameter && a.Command == Tools.ConvertCommandDublicateToCommand(command) && a.IsArray == isArray) is not DataTreeObjectAttribute dataTreeObjectAttribute)
return DataTreeBranch.Unset;

List<DataTree> children = new List<DataTree>();
Expand Down Expand Up @@ -342,7 +354,7 @@ public static DataTreeBranch FromObject(object obj, object key, ERDM_Command com

static DataTree[] convertToDataTree(object value, PropertyInfo[] properties, ERDM_Parameter parameter)
{
List<DataTree> innetChildren = new List<DataTree>();
List<DataTree> innerChildren = new List<DataTree>();
Dictionary<string, List<DataTree>> deeperChildren = new Dictionary<string, List<DataTree>>();
foreach (var property in properties)
{
Expand All @@ -368,15 +380,15 @@ static DataTree[] convertToDataTree(object value, PropertyInfo[] properties, ERD
ddc.Add(new DataTree(path[1], attribute.Index, val));
}
else
innetChildren.Add(new DataTree(attribute.Name, attribute.Index, val));
innerChildren.Add(new DataTree(attribute.Name, attribute.Index, val));
}
}
foreach (var dC in deeperChildren)
{
var index = FindMissingNumbers(innetChildren.Select(ic => (int)ic.Index)).FirstOrDefault();
innetChildren.Add(new DataTree(dC.Key, (uint)index, children: dC.Value.OrderBy(c => c.Index).ToArray()));
var index = FindMissingNumbers(innerChildren.Select(ic => (int)ic.Index)).FirstOrDefault();
innerChildren.Add(new DataTree(dC.Key, (uint)index, children: dC.Value.OrderBy(c => c.Index).ToArray()));
}
return innetChildren.OrderBy(iC => iC.Index).ToArray();
return innerChildren.OrderBy(iC => iC.Index).ToArray();

static IEnumerable<int> FindMissingNumbers(IEnumerable<int> numbers)
{
Expand Down
10 changes: 5 additions & 5 deletions RDMSharp/Metadata/DataTreeObjectAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ namespace RDMSharp.Metadata;
public class DataTreeObjectAttribute : Attribute
{
public readonly ERDM_Parameter Parameter;
public readonly Command.ECommandDublicte Command;
public readonly Command.ECommandDublicate Command;
public readonly EManufacturer Manufacturer = EManufacturer.ESTA;

public readonly bool IsArray;
public readonly string Path;

public DataTreeObjectAttribute(ERDM_Parameter parameter, Command.ECommandDublicte command, bool isArray = false, string path = null)
public DataTreeObjectAttribute(ERDM_Parameter parameter, Command.ECommandDublicate command, bool isArray = false, string path = null)
{
Parameter = parameter;
Command = command;
IsArray = isArray;
Path = path;
}
public DataTreeObjectAttribute(EManufacturer manufacturer, ERDM_Parameter parameter, Command.ECommandDublicte command, bool isArray = false, string path = null)
public DataTreeObjectAttribute(EManufacturer manufacturer, ERDM_Parameter parameter, Command.ECommandDublicate command, bool isArray = false, string path = null)
: this(parameter, command, isArray, path)
{
Manufacturer = manufacturer;
Expand All @@ -30,12 +30,12 @@ public DataTreeObjectAttribute(EManufacturer manufacturer, ERDM_Parameter parame
public class DataTreeEnumAttribute : DataTreeObjectAttribute
{
public readonly string Name;
public DataTreeEnumAttribute(ERDM_Parameter parameter, Command.ECommandDublicte command, string name, bool isArray = false, string path = null)
public DataTreeEnumAttribute(ERDM_Parameter parameter, Command.ECommandDublicate command, string name, bool isArray = false, string path = null)
: base(parameter, command, isArray, path)
{
Name = name;
}
public DataTreeEnumAttribute(EManufacturer manufacturer, ERDM_Parameter parameter, Command.ECommandDublicte command, string name, bool isArray = false, string path = null)
public DataTreeEnumAttribute(EManufacturer manufacturer, ERDM_Parameter parameter, Command.ECommandDublicate command, string name, bool isArray = false, string path = null)
: base(manufacturer, parameter, command, isArray, path)
{
Name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class DataTreeObjectDependeciePropertyAttribute : Attribute
{
public readonly string Name;
public readonly ERDM_Parameter Parameter;
public readonly Command.ECommandDublicte Command;
public readonly Command.ECommandDublicate Command;
public readonly DataTreeObjectDependeciePropertyBag Bag;

public DataTreeObjectDependeciePropertyAttribute(string name, ERDM_Parameter parameter, Command.ECommandDublicte command)
public DataTreeObjectDependeciePropertyAttribute(string name, ERDM_Parameter parameter, Command.ECommandDublicate command)
{
Name = name;
Parameter = parameter;
Expand Down
4 changes: 2 additions & 2 deletions RDMSharp/Metadata/DataTreeObjectDependeciePropertyBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public readonly struct DataTreeObjectDependeciePropertyBag
{
public readonly string Name;
public readonly ERDM_Parameter Parameter;
public readonly Command.ECommandDublicte Command;
public readonly Command.ECommandDublicate Command;
public readonly object Value;

internal DataTreeObjectDependeciePropertyBag(string name, ERDM_Parameter parameter, Command.ECommandDublicte command)
internal DataTreeObjectDependeciePropertyBag(string name, ERDM_Parameter parameter, Command.ECommandDublicate command)
{
Name = name;
Parameter = parameter;
Expand Down
10 changes: 6 additions & 4 deletions RDMSharp/Metadata/JSON/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

namespace RDMSharp.Metadata.JSON
{
#pragma warning disable CS8632
[JsonConverter(typeof(CommandConverter))]
public readonly struct Command
{
[JsonConverter(typeof(CustomEnumConverter<ECommandDublicte>))]
public enum ECommandDublicte
[JsonConverter(typeof(CustomEnumConverter<ECommandDublicate>))]
public enum ECommandDublicate
{
[JsonPropertyName("get_request")]
GetRequest,
Expand All @@ -26,7 +27,7 @@ public enum ECommandDublicte
DifferentDid
}
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public readonly ECommandDublicte? EnumValue { get; }
public readonly ECommandDublicate? EnumValue { get; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public readonly OneOf? SingleField { get; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
Expand All @@ -43,7 +44,7 @@ public bool GetIsEmpty()

return true;
}
public Command(ECommandDublicte enumValue)
public Command(ECommandDublicate enumValue)
{
EnumValue = enumValue;
}
Expand Down Expand Up @@ -92,3 +93,4 @@ public override string ToString()
}
}
}
#pragma warning restore CS8632
3 changes: 3 additions & 0 deletions RDMSharp/Metadata/JSON/CommonPropertiesForNamed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace RDMSharp.Metadata.JSON
{
#pragma warning disable CS8632
public abstract class CommonPropertiesForNamed
{
[JsonPropertyName("name")]
Expand All @@ -14,6 +15,7 @@ public abstract class CommonPropertiesForNamed
[JsonPropertyName("notes")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public abstract string? Notes { get; }

[JsonPropertyName("resources")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public abstract string[]? Resources { get; }
Expand All @@ -32,3 +34,4 @@ public override string ToString()
}
}
}
#pragma warning restore CS8632
2 changes: 1 addition & 1 deletion RDMSharp/Metadata/JSON/Converter/CommandConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public override Command Read(ref Utf8JsonReader reader, Type typeToConvert, Json
{
if (reader.TokenType == JsonTokenType.String)
{
var enumValue = JsonSerializer.Deserialize<Command.ECommandDublicte>(ref reader, options);
var enumValue = JsonSerializer.Deserialize<Command.ECommandDublicate>(ref reader, options);
return new Command(enumValue);
}
else if (reader.TokenType == JsonTokenType.StartObject)
Expand Down
10 changes: 5 additions & 5 deletions RDMSharp/Metadata/JSON/OneOfTypes/IntegerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public IntegerType(string name,
PrefixMultiplyer = Math.Pow(PrefixBase ?? 10, PrefixPower ?? 0);
}

private static void validateType<T>(EIntegerType type, T dummy = default)
private static void validateType<T_In>(EIntegerType type, T_In dummy = default)
{
switch (dummy)
{
Expand Down Expand Up @@ -153,10 +153,10 @@ public override PDL GetDataLength()
return new PDL(16);
}

private T convertFormatedValueToRaw<T>(object formated)
private TOutput convertFormatedValueToRaw<TOutput>(object formated) where TOutput: T
{
if (PrefixMultiplyer == 1)
return (T)formated;
return (TOutput)formated;

object rawValue = null;
switch (formated)
Expand All @@ -172,11 +172,11 @@ private T convertFormatedValueToRaw<T>(object formated)
break;

default:
return (T)formated;
return (TOutput)formated;
}

if (rawValue is not null)
return (T)Convert.ChangeType(rawValue, typeof(T));
return (TOutput)Convert.ChangeType(rawValue, typeof(T));

throw new NotImplementedException();
}
Expand Down
12 changes: 7 additions & 5 deletions RDMSharp/Metadata/JSON/OneOfTypes/ReferenceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public readonly struct ReferenceType
[JsonPropertyName("$ref")]
public readonly string URI { get; }
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public readonly Command.ECommandDublicte Command { get; }
public readonly Command.ECommandDublicate Command { get; }
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public readonly ushort Pointer { get; }
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
#pragma warning disable CS8632
public readonly CommonPropertiesForNamed? ReferencedObject { get; }
#pragma warning restore CS8632

[JsonConstructor]
public ReferenceType(string uri)
Expand All @@ -28,16 +30,16 @@ public ReferenceType(string uri)
switch (segments[0])
{
case "get_request":
Command = JSON.Command.ECommandDublicte.GetRequest;
Command = JSON.Command.ECommandDublicate.GetRequest;
break;
case "get_response":
Command = JSON.Command.ECommandDublicte.GetResponse;
Command = JSON.Command.ECommandDublicate.GetResponse;
break;
case "set_request":
Command = JSON.Command.ECommandDublicte.SetRequest;
Command = JSON.Command.ECommandDublicate.SetRequest;
break;
case "set_response":
Command = JSON.Command.ECommandDublicte.SetResponse;
Command = JSON.Command.ECommandDublicate.SetResponse;
break;
}
Pointer = ushort.Parse(segments[1]);
Expand Down
Loading