Skip to content

Commit

Permalink
Added DataItem Description, Units, etc. lookups and updated Entity Fo…
Browse files Browse the repository at this point in the history
…rmatters to support Device, Component, Composition, and DataItem
  • Loading branch information
PatrickRitchie committed May 20, 2023
1 parent 9a54aa3 commit 61253d3
Show file tree
Hide file tree
Showing 19 changed files with 691 additions and 42 deletions.
48 changes: 48 additions & 0 deletions src/MTConnect.NET-Common/Devices/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Component : IComponent
private static readonly object _lock = new object();

private static Dictionary<string, Type> _types;
private static Dictionary<string, string> _typeDescriptions;


public MTConnectEntityType EntityType => MTConnectEntityType.Component;
Expand Down Expand Up @@ -753,6 +754,38 @@ public static Component Create(Type type)
return new Component();
}

public static IEnumerable<string> GetTypes()
{
if (_types == null) _types = GetAllTypes();

return _types.Keys;
}

public static IEnumerable<KeyValuePair<string, string>> GetTypeDescriptions()
{
if (_typeDescriptions == null)
{
if (_types == null) _types = GetAllTypes();

if (!_types.IsNullOrEmpty())
{
_typeDescriptions = new Dictionary<string, string>();

foreach (var type in _types)
{
var instance = Create(type.Value);
if (instance != null)
{
_typeDescriptions.Remove(instance.Type);
_typeDescriptions.Add(instance.Type, instance.TypeDescription);
}
}
}
}

return _typeDescriptions;
}

private static Type GetComponentType(string type)
{
if (!string.IsNullOrEmpty(type))
Expand Down Expand Up @@ -782,6 +815,21 @@ private static Type GetComponentType(string type)
return typeof(Component);
}

//private static string GetComponentTypeDescription(string type)
//{
// var t = GetComponentType(type);
// if (t != null)
// {
// var field = t.GetField(nameof(DescriptionText));
// if (field != null)
// {
// return field.GetValue()
// }
// }

// return null;
//}

private static Dictionary<string, Type> GetAllTypes()
{
var assemblies = Assemblies.Get();
Expand Down
7 changes: 7 additions & 0 deletions src/MTConnect.NET-Common/Devices/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ public static Composition Create(Type type)
return new Composition();
}

public static IEnumerable<string> GetTypes()
{
if (_types == null) _types = GetAllTypes();

return _types.Keys;
}

private static Type GetCompositionType(string type)
{
if (!string.IsNullOrEmpty(type))
Expand Down
Loading

0 comments on commit 61253d3

Please sign in to comment.