Skip to content

Commit

Permalink
Update SysML Import
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Nov 2, 2023
1 parent a08a551 commit ededffe
Show file tree
Hide file tree
Showing 30 changed files with 945 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<Compile Remove="Assets.cs" />
<Compile Remove="ClientRequests.cs" />
<Compile Remove="CppAgentJsonClient.cs" />
<Compile Remove="CppAgentMqttClient.cs" />
<Compile Remove="CurrentStream.cs" />
<Compile Remove="EntityClient.cs" />
<Compile Remove="SampleStream.cs" />
Expand All @@ -20,7 +20,7 @@
<ItemGroup>
<None Include="Assets.cs" />
<None Include="ClientRequests.cs" />
<None Include="CppAgentJsonClient.cs" />
<None Include="CppAgentMqttClient.cs" />
<None Include="CurrentStream.cs" />
<None Include="EntityClient.cs" />
<None Include="SampleStream.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MTConnect.SysML.Models.Assets;

namespace MTConnect.SysML.Json_cppagent
{
public class CuttingToolMeasurementsModel
{
public List<MTConnectCuttingToolMeasurementModel> Types { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Scriban;
using MTConnect.SysML.Models.Assets;
using Scriban;

namespace MTConnect.SysML.Json_cppagent
{
Expand All @@ -11,6 +12,7 @@ public static void Render(MTConnectModel mtconnectModel, string outputPath)
WriteComponents(mtconnectModel, outputPath);
WriteEvents(mtconnectModel, outputPath);
WriteSamples(mtconnectModel, outputPath);
WriteCuttingToolMeasurements(mtconnectModel, outputPath);
}
}

Expand Down Expand Up @@ -128,5 +130,43 @@ private static void WriteSamples(MTConnectModel mtconnectModel, string outputPat
}
}
}

private static void WriteCuttingToolMeasurements(MTConnectModel mtconnectModel, string outputPath)
{
var measurementsModel = new CuttingToolMeasurementsModel();

var measurements = mtconnectModel.AssetInformationModel.CuttingTools.Classes.Where(o => typeof(MTConnectCuttingToolMeasurementModel).IsAssignableFrom(o.GetType()));
foreach (var measurement in measurements.OrderBy(o => o.Name)) measurementsModel.Types.Add((MTConnectCuttingToolMeasurementModel)measurement);

var templateFilename = $"Measurements.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "json-cppagent", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
var result = template.Render(measurementsModel);
if (result != null)
{
var resultPath = $"Assets/CuttingTools/JsonMeasurements";
resultPath = Path.Combine(outputPath, resultPath);
resultPath = $"{resultPath}.g.cs";

var resultDirectory = Path.GetDirectoryName(resultPath);
if (!Directory.Exists(resultDirectory)) Directory.CreateDirectory(resultDirectory);

File.WriteAllText(resultPath, result);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using MTConnect.Assets.CuttingTools;
using MTConnect.Assets.CuttingTools.Measurements;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MTConnect.Assets.Json.CuttingTools
{
public class JsonMeasurements
{
{{- for type in types }}
[JsonPropertyName("{{type.type_id}}")]
public List<JsonMeasurement> {{type.name}}s { get; set; }

{{ end }}

public JsonMeasurements() { }

public JsonMeasurements(IEnumerable<IMeasurement> measurements)
{
if (!measurements.IsNullOrEmpty())
{
foreach (var measurement in measurements)
{
switch (measurement.Type)
{
{{- for type in types }}
case {{type.name}}.TypeId:
if ({{type.name}}s == null) {{type.name}}s = new List<JsonMeasurement>();
{{type.name}}s.Add(new JsonMeasurement(measurement));
break;

{{ end }}
}
}
}
}


public IEnumerable<IMeasurement> ToMeasurements()
{
var measurements = new List<IMeasurement>();

{{ for type in types }}
if (!{{type.name}}s.IsNullOrEmpty()) foreach (var measurement in {{type.name}}s) measurements.Add(measurement.ToMeasurement({{type.name}}.TypeId));
{{- end }}

return measurements;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<None Update="Json-cppagent\Templates\Components.scriban">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Json-cppagent\Templates\Measurements.scriban">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Xml\Templates\XmlCuttingItem.scriban">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class CuttingItem : ICuttingItem
/// <summary>
/// Number or numbers representing the individual cutting item or items on the tool.Indices **SHOULD** start numbering with the inserts or CuttingItem furthest from the gauge line and increasing in value as the items get closer to the gauge line. Items at the same distance **MAY** be arbitrarily numbered.> Note: In XML, the representation **MUST** be a single number ('1') or a comma separated set of individual elements ('1,2,3,4'), or as a inclusive range of values as in ('1-10') or any combination of ranges and numbers as in '1-4,6-10,22'. There **MUST NOT** be spaces or non-integer values in the text representation.
/// </summary>
public System.Collections.Generic.IEnumerable<string> Indices { get; set; }
public string Indices { get; set; }

/// <summary>
/// Manufacturer identifier of this cutting item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial interface ICuttingItem
/// <summary>
/// Number or numbers representing the individual cutting item or items on the tool.Indices **SHOULD** start numbering with the inserts or CuttingItem furthest from the gauge line and increasing in value as the items get closer to the gauge line. Items at the same distance **MAY** be arbitrarily numbered.> Note: In XML, the representation **MUST** be a single number ('1') or a comma separated set of individual elements ('1,2,3,4'), or as a inclusive range of values as in ('1-10') or any combination of ranges and numbers as in '1-4,6-10,22'. There **MUST NOT** be spaces or non-integer values in the text representation.
/// </summary>
System.Collections.Generic.IEnumerable<string> Indices { get; }
string Indices { get; }

/// <summary>
/// Manufacturer identifier of this cutting item.
Expand Down
12 changes: 1 addition & 11 deletions src/MTConnect.NET-HTTP/Clients/MTConnectHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -930,16 +930,6 @@ private IComponentStream ProcessComponentStream(string deviceUuid, IComponentStr
{
foreach (var inputObservation in inputComponentStream.Observations)
{




Console.WriteLine($"{inputObservation.DataItemId} = {inputObservation.Representation}");





var dataItem = GetCachedDataItem(deviceUuid, inputObservation.DataItemId);
if (dataItem != null)
{
Expand Down Expand Up @@ -981,7 +971,7 @@ private async void CheckAssetChanged(IEnumerable<IObservation> observations, Can
{
if (observations != null && observations.Count() > 0)
{
var assetsChanged = observations.Where(o => o.Type == Devices.DataItems.AssetChangedDataItem.TypeId.ToPascalCase());
var assetsChanged = observations.Where(o => o.Type == Devices.DataItems.AssetChangedDataItem.TypeId);
if (assetsChanged != null)
{
foreach (var assetChanged in assetsChanged)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using MTConnect.Assets.CuttingTools;
using System.Text.Json.Serialization;

namespace MTConnect.Assets.Json.CuttingTools
{
public class JsonCutterStatus
{
[JsonPropertyName("value")]
public string Value { get; set; }


public JsonCutterStatus() { }

public JsonCutterStatus(CutterStatusType cutterStatus)
{
Value = cutterStatus.ToString();
}


public CutterStatusType ToCutterStatus()
{
return Value.ConvertEnum<CutterStatusType>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using MTConnect.Assets.CuttingTools;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MTConnect.Assets.Json.CuttingTools
{
public class JsonCutterStatusCollection
{
[JsonPropertyName("Status")]
public IEnumerable<JsonCutterStatus> Status { get; set; }


public JsonCutterStatusCollection() { }

public JsonCutterStatusCollection(IEnumerable<CutterStatusType> cutterStatuses)
{
if (!cutterStatuses.IsNullOrEmpty())
{
var status = new List<JsonCutterStatus>();
foreach (var cutterStatus in cutterStatuses)
{
status.Add(new JsonCutterStatus(cutterStatus));
}
Status = status;
}
}


public IEnumerable<CutterStatusType> ToCutterStatus()
{
if (!Status.IsNullOrEmpty())
{
var statuses = new List<CutterStatusType>();

foreach (var status in Status)
{
statuses.Add(status.ToCutterStatus());
}

return statuses;
}

return null;
}
}
}
Loading

0 comments on commit ededffe

Please sign in to comment.