Skip to content

Commit

Permalink
Added SysML project
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Oct 25, 2023
1 parent 6e4c0b6 commit 4b1cb2d
Show file tree
Hide file tree
Showing 116 changed files with 6,391 additions and 0 deletions.
122 changes: 122 additions & 0 deletions src/MTConnect.NET-SysML/CSharp/ClassModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using MTConnect.SysML.Xmi;
using MTConnect.SysML.Xmi.UML;
using Scriban;
using System;
using System.IO;
using System.Linq;

namespace MTConnect.SysML.CSharp
{
internal class ClassModel : MTConnectClassModel, ITemplateModel
{
public string Namespace => NamespaceHelper.GetNamespace(Id);

public bool IsPartial { get; set; }

public string MaximumVersionEnum => MTConnectVersion.GetVersionEnum(MaximumVersion);

public string MinimumVersionEnum => MTConnectVersion.GetVersionEnum(MinimumVersion);


public ClassModel() { }

public ClassModel(XmiDocument xmiDocument, string id, UmlClass umlClass) : base(xmiDocument, id, umlClass) { }


public static ClassModel Create(MTConnectClassModel importModel)
{
if (importModel != null)
{
var type = typeof(ClassModel);

var importProperties = importModel.GetType().GetProperties();
var exportProperties = type.GetProperties();

if (importProperties != null && exportProperties != null)
{
var exportModel = new ClassModel();

foreach (var importProperty in importProperties)
{
var propertyValue = importProperty.GetValue(importModel);

var exportProperty = exportProperties.FirstOrDefault(o => o.Name == importProperty.Name);
if (exportProperty != null)
{
exportProperty.SetValue(exportModel, propertyValue);
}
}

foreach (var propertyModel in exportModel.Properties)
{
// Convert to Interface
if (propertyModel.DataType.ToLower() != propertyModel.DataType && propertyModel.DataType != "System.DateTime" && !propertyModel.DataType.EndsWith("Enum"))
{
if (!propertyModel.DataType.StartsWith("I")) propertyModel.DataType = $"I{propertyModel.DataType}";
}

// Remove 'Enum' suffix
if (propertyModel.DataType.EndsWith("Enum"))
{
var suffix = "Enum";
if (propertyModel.DataType.EndsWith(suffix)) propertyModel.DataType = propertyModel.DataType.Substring(0, propertyModel.DataType.Length - suffix.Length);
}
}

return exportModel;
}
}

return null;
}


public string RenderModel()
{
var templateFilename = $"Model.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "csharp", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
return template.Render(this);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

return null;
}

public string RenderInterface()
{
var templateFilename = $"Interface.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "csharp", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
return template.Render(this);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

return null;
}
}
}
83 changes: 83 additions & 0 deletions src/MTConnect.NET-SysML/CSharp/ComponentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using MTConnect.SysML.Models.Devices;
using MTConnect.SysML.Xmi;
using MTConnect.SysML.Xmi.UML;
using Scriban;
using System;
using System.IO;
using System.Linq;

namespace MTConnect.SysML.CSharp
{
public class ComponentType : MTConnectComponentType, ITemplateModel
{
public string Namespace => NamespaceHelper.GetNamespace(Id);

public string MaximumVersionEnum => MTConnectVersion.GetVersionEnum(MaximumVersion);

public string MinimumVersionEnum => MTConnectVersion.GetVersionEnum(MinimumVersion);


public ComponentType() { }

public ComponentType(XmiDocument xmiDocument, string idPrefix, UmlClass umlClass) : base (xmiDocument, idPrefix, umlClass) { }


public static ComponentType Create(MTConnectComponentType importModel)
{
if (importModel != null)
{
var type = typeof(ComponentType);

var importProperties = importModel.GetType().GetProperties();
var exportProperties = type.GetProperties();

if (importProperties != null && exportProperties != null)
{
var exportModel = new ComponentType();

foreach (var importProperty in importProperties)
{
var propertyValue = importProperty.GetValue(importModel);

var exportProperty = exportProperties.FirstOrDefault(o => o.Name == importProperty.Name);
if (exportProperty != null)
{
exportProperty.SetValue(exportModel, propertyValue);
}
}

return exportModel;
}
}

return null;
}


public string RenderModel()
{
var templateFilename = $"Devices.ComponentType.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "csharp", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
return template.Render(this);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

return null;
}

public string RenderInterface() => null;
}
}
83 changes: 83 additions & 0 deletions src/MTConnect.NET-SysML/CSharp/CompositionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using MTConnect.SysML.Models.Devices;
using MTConnect.SysML.Xmi;
using MTConnect.SysML.Xmi.UML;
using Scriban;
using System;
using System.IO;
using System.Linq;

namespace MTConnect.SysML.CSharp
{
public class CompositionType : MTConnectCompositionType, ITemplateModel
{
public string Namespace => NamespaceHelper.GetNamespace(Id);

public string MaximumVersionEnum => MTConnectVersion.GetVersionEnum(MaximumVersion);

public string MinimumVersionEnum => MTConnectVersion.GetVersionEnum(MinimumVersion);


public CompositionType() { }

public CompositionType(XmiDocument xmiDocument, string idPrefix, UmlEnumerationLiteral umlEnumerationLiteral) : base (xmiDocument, idPrefix, umlEnumerationLiteral) { }


public static CompositionType Create(MTConnectCompositionType importModel)
{
if (importModel != null)
{
var type = typeof(CompositionType);

var importProperties = importModel.GetType().GetProperties();
var exportProperties = type.GetProperties();

if (importProperties != null && exportProperties != null)
{
var exportModel = new CompositionType();

foreach (var importProperty in importProperties)
{
var propertyValue = importProperty.GetValue(importModel);

var exportProperty = exportProperties.FirstOrDefault(o => o.Name == importProperty.Name);
if (exportProperty != null)
{
exportProperty.SetValue(exportModel, propertyValue);
}
}

return exportModel;
}
}

return null;
}


public string RenderModel()
{
var templateFilename = $"Devices.CompositionType.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "csharp", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
return template.Render(this);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

return null;
}

public string RenderInterface() => null;
}
}
87 changes: 87 additions & 0 deletions src/MTConnect.NET-SysML/CSharp/DataItemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using MTConnect.SysML.Models.Devices;
using MTConnect.SysML.Xmi;
using MTConnect.SysML.Xmi.UML;
using Scriban;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace MTConnect.SysML.CSharp
{
public class DataItemType : MTConnectDataItemType, ITemplateModel
{
public string Namespace => NamespaceHelper.GetNamespace(Id);

public string UnitsEnum => Units != null ? $"Devices.Units.{Units}" : null;

public string MaximumVersionEnum => MTConnectVersion.GetVersionEnum(MaximumVersion);

public string MinimumVersionEnum => MTConnectVersion.GetVersionEnum(MinimumVersion);


public DataItemType() { }

public DataItemType(XmiDocument xmiDocument, string category, string idPrefix, UmlClass umlClass, UmlEnumerationLiteral umlEnumerationLiteral, IEnumerable<UmlClass> subClasses = null)
: base (xmiDocument, category, idPrefix, umlClass, umlEnumerationLiteral, subClasses) { }


public static DataItemType Create(MTConnectDataItemType importModel)
{
if (importModel != null)
{
var type = typeof(DataItemType);

var importProperties = importModel.GetType().GetProperties();
var exportProperties = type.GetProperties();

if (importProperties != null && exportProperties != null)
{
var exportModel = new DataItemType();

foreach (var importProperty in importProperties)
{
var propertyValue = importProperty.GetValue(importModel);

var exportProperty = exportProperties.FirstOrDefault(o => o.Name == importProperty.Name);
if (exportProperty != null)
{
exportProperty.SetValue(exportModel, propertyValue);
}
}

return exportModel;
}
}

return null;
}


public string RenderModel()
{
var templateFilename = $"Devices.DataItemType.scriban";
var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "csharp", "templates", templateFilename);
if (File.Exists(templatePath))
{
try
{
var templateContents = File.ReadAllText(templatePath);
if (templateContents != null)
{
var template = Template.Parse(templateContents);
return template.Render(this);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

return null;
}

public string RenderInterface() => null;
}
}
Loading

0 comments on commit 4b1cb2d

Please sign in to comment.