Skip to content

Commit

Permalink
v2.4.0 Update (#5)
Browse files Browse the repository at this point in the history
* Bump update

* Bump update

* Bump update

* Migrating to generating all SysML model

* Need to add deep search

* SC Meeting updates

* Success!

* Update .gitignore

* Included packages

* Added static root model

 - MtconnectModel is the intended entry point into the MTConnect SysML model.
 - Successful build

* Transpiled code

* Update MtconnectTranspiler.Sinks.CSharp.csproj

* Re-ran transpiler

* Updated transpiler

* Transpiler updates

 - Fixed DefaultValue
 - Fixed Generalization
 - Added property inheritance
 - Fixed naming to match SysML

* Expanded Enum definitions

* Set EnumMetaClass as instance type

* Bump update

* Bump update

* Update Program.cs

* Bump update

* Logging

* Update Program.cs

* Bump update

* Bump update

* Update CSharp.Class.scriban

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Update CSharp.Class.scriban

* Bump update

* Update summary access to comments

* Updated all summary templates

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Added summary prefix

* Reintroduced includes for summaries

* Updated all summaries

 - Fully implemented new MarkdownInterpreter and CodeFormatter for converting SysML Comments into different formats.

* Update MtconnectTranspiler.Sinks.CSharp.csproj

* Updated navigator

* Update UmlCommentsSummaryContent.scriban

* Include Enums in Packages

 - Added Enums to Packages
 - Removed unnecessary XML summary prefixes (///)

* Added Profile Packages

 - Added Profile Packages to root MtconnectModel

* Applied new keyword

Attempting to override the IClass.Properties with the custom PropertyList

* Update MtconnectTranspiler.Sinks.CSharp.csproj

* Added virtual/overrides to classes

* Update MtconnectTranspiler.Sinks.CSharp.csproj

* Changed SuperClass to Category

Changed property name/type to reflect observation type categories

* Added help info

 - Added ReferenceId to IEnum
 - Added HelpUrl property and constant to IClass, IEnum, and IPackage
 - Refactored "normative remarks" in XML summary.

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Introducing constant strings

* Added XML summary for constants

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Suppress obsolete warnings in generated code

* Transpiled with latest

* Added help url

 - Added help url to observation type in navigation extensions

* Attempted fix at navigating summary for types/sub-types

* Ordinal comparison

 - Changed comparison of Observation Type names ordinal with a removal of '_' characters on both sides between IClass and IEnum comparisons

* Scoped sub-types

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Addressed debug environment

* Update MtconnectTranspiler.Sinks.CSharp.Example.csproj

* Ran transpiler

 - Used the Example transpiler to generate files

* Update MtconnectTranspiler.Sinks.CSharp.csproj

* Update MtconnectTranspiler.Sinks.CSharp.csproj
  • Loading branch information
tbm0115 authored Sep 3, 2024
1 parent 5ed1eb4 commit 4fa4b86
Show file tree
Hide file tree
Showing 1,387 changed files with 299,294 additions and 701 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ PublishScripts/
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# except in Models
!**/[Mm]odels/[Pp]ackages/*
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
Expand Down Expand Up @@ -360,4 +362,5 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/MtconnectTranspiler.Sinks.CSharp.Example/appsettings.Development.json
175 changes: 175 additions & 0 deletions MtconnectTranspiler.Sinks.CSharp.Example/Models/CSharpClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using CaseExtensions;
using MtconnectTranspiler.CodeGenerators.ScribanTemplates;
using MtconnectTranspiler.Sinks.CSharp.Example;
using MtconnectTranspiler.Xmi;
using MtconnectTranspiler.Xmi.UML;

namespace MtconnectTranspiler.Sinks.CSharp.Models
{
/// <summary>
/// Represents a C# class
/// </summary>
[ScribanTemplate("CSharp.Class.scriban")]
public partial class CSharpClass : CsharpType, IFileSource
{
/// <summary>
/// Reference to the xmi:id
/// </summary>
public string? ReferenceId { get; set; }

/// <summary>
/// Reference to the <c>name</c> attribute.
/// </summary>
public string? NormativeName { get; set; }

/// <summary>
/// Reference to any Comments written in the SysML model to be converted into a C# format <c>&lt;summary /&gt;</c>
/// </summary>
public Summary? Summary { get; protected set; }

/// <summary>
/// Internal reference to the class filename.
/// </summary>
protected string? _filename { get; set; }
/// <inheritdoc />
public virtual string Filename
{
get
{
if (string.IsNullOrEmpty(_filename))
_filename = $"{CategoryFunctions.ToPathSafe(Namespace.Substring(Namespace.LastIndexOf(".")+1))}/{CategoryFunctions.ToPathSafe(Name.ToPascalCase())}.cs";
return _filename;
}
set { _filename = value; }
}

/// <summary>
/// Internal list of <see cref="Property"/>, used by <see cref="Properties"/>.
/// </summary>
protected List<Property> _properties = new List<Property>();
/// <summary>
/// Collection of <inheritdoc cref="Property"/>
/// </summary>
public IEnumerable<Property> Properties => _properties;

/// <summary>
/// Internal list of <see cref="Constraint"/>, used by <see cref="Constraints"/>.
/// </summary>
protected List<Constraint> _constraints = new List<Constraint>();
/// <summary>
/// Collection of <inheritdoc cref="Constraint"/>
/// </summary>
public IEnumerable<Constraint> Constraints => _constraints;

/// <summary>
/// Remote type of the generalization
/// </summary>
public string? Generalization { get; set; }

/// <summary>
/// Original <c>generalization</c> value from the XMI
/// </summary>
public string? GeneralizationId { get; set; }

private XmiElement? _remoteType { get; set; }

/// <summary>
/// Constructs an <see cref="CSharpClass"/> more generically. <b>NOTE</b>: You'll need to add items manually from here.
/// </summary>
/// <param name="model"><inheritdoc cref="XmiDocument" path="/summary"/></param>
/// <param name="source"><inheritdoc cref="XmiElement" path="/summary"/></param>
public CSharpClass(XmiDocument model, UmlClass source) : base(model, source)
{
ReferenceId = source.Id;

if (source.Comments?.Length > 0)
Summary = new Summary(source.Comments);

if (source.IsAbstract)
Modifier = "abstract";

AccessModifier = "public";

_properties = source.Properties
?.Where(o => !string.IsNullOrEmpty(o.Name))
?.Select(o => new Property(model, o))
?.ToList()
?? new List<Property>();
var propertyGroupings = _properties.GroupBy(o => o.Name);
foreach (var propertyGrouping in propertyGroupings)
{
if (propertyGrouping.Count() <= 1)
continue;
var properties = _properties.Where(o => o.Name == propertyGrouping.Key).ToList();
foreach (var property in properties)
{
if (property.Type.EndsWith("Class"))
{
string remoteClassName = property.Type.Replace("Class", string.Empty);
if (!property.Name.EndsWith(remoteClassName))
{
property.Name += remoteClassName;
}
}
}
}

_constraints = source.Constraints
?.Where(o => !string.IsNullOrEmpty(o.Name))
?.Select(o => new Constraint(model, o))
?.ToList()
?? new List<Constraint>();

GeneralizationId = source.Generalization?.Name ?? source.Generalization?.General;
if (!string.IsNullOrEmpty(GeneralizationId))
{
XmiElement? remoteType = null;
Generalization = CSharpHelperMethods.ToPrimitiveType(GeneralizationId)?.Name
?? CSharpHelperMethods.TypeDeepSearch(model, GeneralizationId, out remoteType)
?? "";
}

Name = GetClassName(model, source);
NormativeName = source.Name;
}

/// <summary>
/// Adds a new <see cref="Property"/>
/// </summary>
/// <param name="property">Reference to the source <see cref="Property"/> to add</param>
public void Add(Property property)
=> _properties.Add(property);

public static string GetClassName(XmiDocument model, UmlClass umlClass)
{
string name = CSharpHelperMethods.ToPascalCase(umlClass.Name);

string? generalization = umlClass.Generalization?.Name ?? umlClass.Generalization?.Id;
if (!string.IsNullOrEmpty(generalization))
{
string? generalizedType = CSharpHelperMethods.TypeDeepSearch(model, generalization, out XmiElement? remoteType);
if (!string.IsNullOrEmpty(generalizedType) && generalizedType.EndsWith("Class"))
{
string remoteGeneralization = generalizedType.Replace("Class", string.Empty);
if (name.EndsWith(remoteGeneralization, StringComparison.OrdinalIgnoreCase))
{
name += "Generalization";
}
else
{
name += "Class";
}
}
else
{
name += "Class";
}
} else
{
name += "Class";
}
return name;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using MtconnectTranspiler.Sinks.ScribanTemplates;
using CaseExtensions;
using MtconnectTranspiler.CodeGenerators.ScribanTemplates;
using MtconnectTranspiler.Sinks.CSharp.Example;
using MtconnectTranspiler.Xmi;
using MtconnectTranspiler.Xmi.UML;
using System.Collections.Generic;
using System.Linq;

namespace MtconnectTranspiler.Sinks.CSharp.Models
{
/// <summary>
/// Represents a C# <see cref="Enum"/>.
/// Represents a C# <see cref="CSharpEnum"/>.
/// </summary>
[ScribanTemplate("Enum.scriban")]
public class Enum : CsharpType, IFileSource
[ScribanTemplate("CSharp.Enum.scriban")]
public class CSharpEnum : CsharpType, IFileSource
{
/// <summary>
/// Reference to the xmi:id
Expand All @@ -36,45 +36,51 @@ public class Enum : CsharpType, IFileSource
/// </summary>
protected string _filename { get; set; }
/// <inheritdoc />
public string Filename
public virtual string Filename
{
get
{
if (string.IsNullOrEmpty(_filename))
_filename = $"{Name}.cs";
_filename = $"{CategoryFunctions.ToPathSafe(Namespace.Substring(Namespace.LastIndexOf(".") + 1))}/{CategoryFunctions.ToPathSafe(Name.ToPascalCase())}.cs";
return _filename;
}
set { _filename = value; }
}

// NOTE: Only used for CATEGORY types that have subTypes.
public Dictionary<string, string> SubTypes { get; set; } = new Dictionary<string, string>();

// NOTE: Only used for CATEGORY types that have value enums.
public Dictionary<string, string> ValueTypes { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Constructs an <see cref="Enum"/> more generically. <b>NOTE</b>: You'll need to add items manually from here.
/// Constructs an <see cref="CSharpEnum"/> more generically. <b>NOTE</b>: You'll need to add items manually from here.
/// </summary>
/// <param name="model"><inheritdoc cref="XmiDocument" path="/summary"/></param>
/// <param name="source"><inheritdoc cref="XmiElement" path="/summary"/></param>
/// <param name="name"><inheritdoc cref="CsharpType.Name" path="/summary"/></param>
public Enum(XmiDocument model, XmiElement source, string name) : base(model,source)
public CSharpEnum(XmiDocument model, XmiElement source, string name) : base(model,source)
{
Name = name;
ReferenceId = source.Id;
}

/// <summary>
/// <inheritdoc cref="Enum(XmiDocument, XmiElement, string)"/>
/// <inheritdoc cref="CSharpEnum(XmiDocument, XmiElement, string)"/>
/// </summary>
/// <param name="model"><inheritdoc cref="Enum(XmiDocument, XmiElement, string)" path="/param[@name='model']"/></param>
/// <param name="source">The source <see cref="UmlEnumeration"/> to convert into an <see cref="Enum"/></param>
public Enum(XmiDocument model, UmlEnumeration source) : this(model, source, source.Name)
/// <param name="model"><inheritdoc cref="CSharpEnum(XmiDocument, XmiElement, string)" path="/param[@name='model']"/></param>
/// <param name="source">The source <see cref="UmlEnumeration"/> to convert into an <see cref="CSharpEnum"/></param>
public CSharpEnum(XmiDocument model, UmlEnumeration source) : this(model, source, source.Name)
{
AddRange(model, source.Items);
}

/// <summary>
/// <inheritdoc cref="Enum(XmiDocument, XmiElement, string)"/>
/// <inheritdoc cref="CSharpEnum(XmiDocument, XmiElement, string)"/>
/// </summary>
/// <param name="model"><inheritdoc cref="Enum(XmiDocument, XmiElement, string)" path="/param[@name='model']"/></param>
/// <param name="source">The source <see cref="UmlPackage"/> to convert into an <see cref="Enum"/></param>
public Enum(XmiDocument model, UmlPackage source) : this(model, source, source.Name)
/// <param name="model"><inheritdoc cref="CSharpEnum(XmiDocument, XmiElement, string)" path="/param[@name='model']"/></param>
/// <param name="source">The source <see cref="UmlPackage"/> to convert into an <see cref="CSharpEnum"/></param>
public CSharpEnum(XmiDocument model, UmlPackage source) : this(model, source, source.Name)
{
AddRange(model, source.Classes.ToList());

Expand All @@ -83,11 +89,11 @@ public Enum(XmiDocument model, UmlPackage source) : this(model, source, source.N
}

/// <summary>
/// <inheritdoc cref="Enum(XmiDocument, XmiElement, string)"/>
/// <inheritdoc cref="CSharpEnum(XmiDocument, XmiElement, string)"/>
/// </summary>
/// <param name="model"><inheritdoc cref="Enum(XmiDocument, XmiElement, string)" path="/param[@name='model']"/></param>
/// <param name="source">The source <see cref="UmlClass"/> to convert into an <see cref="Enum"/></param>
public Enum(XmiDocument model, UmlClass source) : this(model, source, source.Name)
/// <param name="model"><inheritdoc cref="CSharpEnum(XmiDocument, XmiElement, string)" path="/param[@name='model']"/></param>
/// <param name="source">The source <see cref="UmlClass"/> to convert into an <see cref="CSharpEnum"/></param>
public CSharpEnum(XmiDocument model, UmlClass source) : this(model, source, source.Name)
{
AddRange(model, source.Properties.ToList());

Expand All @@ -100,7 +106,10 @@ public Enum(XmiDocument model, UmlClass source) : this(model, source, source.Nam
/// </summary>
/// <param name="item">Reference to <see cref="EnumItem"/> to add to the internal list</param>
public void Add(EnumItem item)
=> _items.Add(item);
{
item.Namespace = $"{this.Namespace}.{this.Name}";
_items.Add(item);
}

/// <summary>
/// Adds a new <see cref="EnumItem"/>
Expand Down
Loading

0 comments on commit 4fa4b86

Please sign in to comment.