-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete Refactoring for Sinks Pattern (#5)
- Obfuscated methods and classes from CSharp sink into the core Transpiler - Repurposed the `XmiTranspiler` into `TranspilerDispatcher` - Removed `CSharp` and `JavaScript` transpiler projects (look for them in separate Repositories)
- Loading branch information
Showing
18 changed files
with
323 additions
and
252 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
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
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,29 @@ | ||
using MtconnectTranspiler.Contracts; | ||
using System.IO; | ||
|
||
namespace MtconnectTranspiler | ||
{ | ||
/// <summary> | ||
/// Options for constructing an instance of <see cref="TranspilerDispatcher"/> by retrieving the <see cref="XmiDeserializer"/> using the <see cref="FromFileOptions.Filepath"/> as a reference to the <c>.xmi</c> of the MTConnect Standard SysML model. | ||
/// </summary> | ||
public class FromFileOptions : TranspilerDispatcherOptions | ||
{ | ||
/// <summary> | ||
/// Reference to a copy of the <c>.xmi</c> file (in XML format) representing the MTConnect Standard SysML model. | ||
/// </summary> | ||
public string Filepath { get; set; } = string.Empty; | ||
|
||
/// <inheritdoc /> | ||
/// <exception cref="FileNotFoundException"></exception> | ||
internal override XmiDeserializer GetDeserializer() | ||
{ | ||
if (!File.Exists(Filepath)) throw new FileNotFoundException("Could not find specified XMI file", Filepath); | ||
|
||
// NOTE: It's important for this method to handle transpile multiple languages at once isntead of iterating through the XMI multiple times for each language. | ||
// NOTE: Make sure multiple project options cane be supplied to this class to handle concurrently processing multiple languages as we process the XMI. | ||
|
||
var deserializer = XmiDeserializer.FromFile(Filepath); | ||
return deserializer; | ||
} | ||
} | ||
} |
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,42 @@ | ||
using MtconnectTranspiler.Contracts; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Net.Http; | ||
|
||
namespace MtconnectTranspiler | ||
{ | ||
/// <summary> | ||
/// Options for constructing an instance of <see cref="TranspilerDispatcher"/> by retrieving the <see cref="XmiDeserializer"/> using the <see cref="FromGitHubOptions.GitHubRelease"/> as a reference to the Release on GitHub to fetch the <c>.xmi</c> of the MTConnect Standard SysML model. | ||
/// </summary> | ||
public class FromGitHubOptions : TranspilerDispatcherOptions | ||
{ | ||
/// <summary> | ||
/// Reference to the GitHub Release Tag for the version of the MTConnect Standard SysML model to download from GitHub.<br/> | ||
/// **NOTE**: If you specify <c>latest</c>, the <c>.xmi</c> will be retrieved from the latest Release on GitHub. | ||
/// </summary> | ||
public string GitHubRelease { get; set; } = "latest"; | ||
|
||
/// <inheritdoc /> | ||
internal override XmiDeserializer GetDeserializer() | ||
{ | ||
if (string.IsNullOrEmpty(GitHubRelease)) throw new ArgumentNullException(); | ||
|
||
var gitUrl = MTConnectHelper.BuildModelUri(GitHubRelease); | ||
|
||
using (var client = new HttpClient()) | ||
{ | ||
var response = client.GetAsync(gitUrl).Result; | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
string xml = response.Content.ReadAsStringAsync().Result; | ||
|
||
var deserializer = XmiDeserializer.FromXml(xml); | ||
return deserializer; | ||
} else | ||
{ | ||
throw new InvalidEnumArgumentException(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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,31 @@ | ||
using MtconnectTranspiler.Xmi; | ||
|
||
namespace MtconnectTranspiler.Sinks.CSharp.Models | ||
{ | ||
/// <summary> | ||
/// Generic type for a model derived from <see cref="XmiElement" />. | ||
/// </summary> | ||
/// <typeparam name="T">The type of <see cref="XmiElement" />.</typeparam> | ||
public interface IModel<T> where T : XmiElement | ||
{ | ||
/// <summary> | ||
/// Represents a hyperlink reference to the documentation hosted on <see href="https://model.mtconnect.org/">model.mtconnect.org</see> | ||
/// </summary> | ||
string Href { get; } | ||
|
||
/// <summary> | ||
/// Represents the internal ID within the XMI model. | ||
/// </summary> | ||
string SysML_ID { get; } | ||
|
||
/// <summary> | ||
/// Represents the name of the source XMI element. | ||
/// </summary> | ||
string SysML_Name { get; } | ||
|
||
/// <summary> | ||
/// Reference to the source <see cref="XmiElement" />. | ||
/// </summary> | ||
T Source { get; } | ||
} | ||
} |
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,18 @@ | ||
using MtconnectTranspiler.Model; | ||
using System.Threading; | ||
|
||
namespace MtconnectTranspiler.Sinks | ||
{ | ||
/// <summary> | ||
/// Basic interface for transpiling the XMI model into another language. | ||
/// </summary> | ||
public interface ITranspilerSink | ||
{ | ||
/// <summary> | ||
/// Transpiles the XMI definition of the MTConnect Standard into some other format. | ||
/// </summary> | ||
/// <param name="model">Object-oriented copy of the XMI structure in the context of the MTConnect Standard.</param> | ||
/// <param name="cancellationToken">Reference to a cancellation token, the Transpile method may be a long running operation.</param> | ||
void Transpile(MTConnectModel model, CancellationToken cancellationToken = default); | ||
} | ||
} |
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,49 @@ | ||
using MtconnectTranspiler.Model; | ||
using MtconnectTranspiler.Xmi; | ||
using System.Linq; | ||
|
||
namespace MtconnectTranspiler.Sinks.CSharp.Models | ||
{ | ||
/// <summary> | ||
/// Generic type for a model derived from <see cref="XmiElement" /> which also might have normative versioning. | ||
/// </summary> | ||
/// <typeparam name="T">The type of <see cref="XmiElement" />.</typeparam> | ||
public abstract class VersionedObject : XmiModel<XmiElement> | ||
{ | ||
/// <summary> | ||
/// The version of MTConnect when this became normative. | ||
/// </summary> | ||
public string NormativeVersion { get; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The version of MTConnect when this became deprecated. | ||
/// </summary> | ||
public string DeprecatedVersion { get; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Constructs a new instance of the <see cref="VersionedObject"/>. | ||
/// </summary> | ||
/// <param name="model">Reference to the high-level <see cref="MTConnectModel"/>.</param> | ||
/// <param name="source">Reference to the source <see cref="XmiElement"/> that may have Normative and Deprecated references in the XMI model.</param> | ||
public VersionedObject(MTConnectModel model, XmiElement source) : base(source) | ||
{ | ||
var normative = model?.NormativeReferences?.FirstOrDefault(o => o.BaseElement == Source.Id); | ||
if (normative != null) | ||
{ | ||
NormativeVersion = lookupMtconnectVersion(normative.Version); | ||
var deprecated = model?.DeprecatedReferences?.FirstOrDefault(o => o.BaseElement == Source.Id); | ||
if (deprecated != null) | ||
{ | ||
DeprecatedVersion = lookupMtconnectVersion(deprecated.Version); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Looks up the appropriate representation of MTConnect Standard version in the current context. | ||
/// </summary> | ||
/// <param name="version">Reference to the version of MTConnect Standard as labeled in the XMI model. For example, <c>1.0</c> or <c>2.1</c>.</param> | ||
/// <returns>The representation of the MTConnect Standard version in the current context.</returns> | ||
protected abstract string lookupMtconnectVersion(string version); | ||
} | ||
} |
Oops, something went wrong.