-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e4c0b6
commit 4b1cb2d
Showing
116 changed files
with
6,391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.