Skip to main content

NMF: A Multi-platform Modeling Framework

  • Conference paper
  • First Online:
Book cover Theory and Practice of Model Transformation (ICMT 2018)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 10888))

Abstract

For its promises in terms of increased productivity, Model-driven engineering (MDE) is getting applied increasingly often in both industry and academia. However, most tools currently available are based on the Eclipse Modeling Framework (EMF) and hence based on the Java platform whereas tool support for other platforms is limited. This leads to a language and tool adoption problem for developers of other platforms such as .NET. As a result, few projects on the .NET platform adopt MDE. In this paper, we present the .NET Modeling Framework (NMF), a tool set for model repositories, model-based incrementalization, model transformation, model synchronization and code generation that is now available for a multitude of different operating systems, including Windows, Linux, Android, iOS and Mac. The framework makes intensive use of the C# language as host language for model transformation and synchronization languages, whereas the model repository serialization is compatible with EMF. This solves the language adoption problem for C# programmers and creates a bridge to the EMF platform.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    A list of supported linux distributions is available under https://github.com/dotnet/core/blob/master/release-notes/2.0/2.0-supported-os.md.

  2. 2.

    http://www.xamarin.com/platform.

  3. 3.

    https://youtu.be/NIMYuwTltVs.

  4. 4.

    http://msdn.microsoft.com/en-us/library/bb394939.aspx.

  5. 5.

    https://github.com/NMFCode/NMFDemo.

  6. 6.

    https://youtu.be/NIMYuwTltVs.

  7. 7.

    http://www.nuget.org.

  8. 8.

    https://github.com/NMFCode/NMFDemo.

  9. 9.

    https://github.com/NMFCode/NMFDemo/blob/master/Example.fsm.

  10. 10.

    https://github.com/NMFCode/NMFDemo/blob/master/FSM2PN.cs.

References

  1. Vaquero-Melchor, D., Palomares, J., Guerra, E., de Lara, J.: Active domainspecific languages: making every mobile user a modeller. In: 2017 ACM/IEEE 20th International Conference on Model Driven Engineering Languages and Systems (MODELS), pp. 75–82. IEEE (2017)

    Google Scholar 

  2. Hinkel, G., Happe, L.: Using component frameworks for model transformations by an internal DSL. In: Proceedings of the 1st International Workshop on Model-Driven Engineering for Component-Based Software Systems Co-located with ACM/IEEE 17th International Conference on Model Driven Engineering Languages & Systems (MoDELS 2014), ser. CEURWorkshop Proceedings, vol. 1281, CEUR-WS.org, pp. 6–15 (2014)

    Google Scholar 

  3. Hinkel, G., Happe, L.: An NMF solution to the TTC train benchmark case. In: Proceedings of the 8th Transformation Tool Contest, a Part of the Software Technologies: Applications and Foundations (STAF 2015) Federation of Conferences, ser. CEUR Workshop Proceedings, vol. 1524, CEUR-WS.org, pp. 142–146 (2015)

    Google Scholar 

  4. Hinkel, G.: An approach to maintainable model transformations using an internal DSL. Master’s thesis, Karlsruhe Institute of Technology (2013)

    Google Scholar 

  5. Hinkel, G., Goldschmidt, T.: Tool support for model transformations: on solutions using internal languages. In: Modellierung 2016 (2016)

    Google Scholar 

  6. Wagelaar, D., Van Der Straeten, R., Deridder, D.: Module superimposition: a composition technique for rule-based model transformation languages. Softw. Syst. Model. 9(3), 285–309 (2010)

    Article  Google Scholar 

  7. Hinkel, G., Burger, E.: Change propagation and bidirectionality in internal transformation DSLs. Software & Systems Modeling (2017)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Georg Hinkel .

Editor information

Editors and Affiliations

A Tutorial of NMF

A Tutorial of NMF

The following instructions will describe how to set up a project with NMF and create a model transformation from state machines to Petri nets. Although the tutorial is specifically written for a usage in Visual Studio, the tutorial can be adapted to any IDE on the .NET platform. The tutorial also assumes that you have already started to create a metamodel and some instances of it in EMF, i.e. Eclipse.

If you get stuck at any point, there is a ready-made solution available on GitHubFootnote 5 that can be just downloaded and tried. Furthermore, there is a YouTube video availableFootnote 6 demonstrating creating a new project, loading, altering and saving a model.

1.1 A.1 Create a Project

NMF is a framework that can be easily installed through the NuGet Package-managerFootnote 7. Therefore, first create a new project. In Visual Studio, click on File \(\rightarrow \)New\(\rightarrow \) Project, select a C# console application as project type and name it as you wish, though in the remainder we will assume the name NMFDemo. Note that NMF is generally not restricted to console applications nor to C#, you can use it in any .NET project.

To import NMF, go to Tools\(\rightarrow \)NuGet Package-manager\(\rightarrow \)Manage NuGet packages for this project and search for NMF. You should find the package NMF-Basics. Install it by hitting the Install button while your project is selected.

Alternatively, there is also a NuGet console at the bottom, where you can install NMF as follows:

figure b

NuGet will download the package for you together will all of its dependencies and add all the contained libraries as references into the current project. There is no strict 1:1-mapping from NuGet packages to libraries so there are multiple libraries being installed that may be not needed.

1.2 A.2 Import Metamodels from Ecore

Metamodels are at the core of any model-driven development process. Thus, as a first step, we will generate code in order to be able to load any models for a given metamodel in our .NET application. For this, the NuGet package NMF-Basics contains the console application Ecore2Code. After a restart of Visual Studio, NuGet will automatically add Ecore2Code to the Path variable used inside Visual Studio, so you can just use the NuGet Package-manager console. If run without any arguments, this application prints a help information showing its correct usage (cf. Fig. 1).

Fig. 1.
figure 1

The console application Ecore2Code to generate model representation code.

Now, use this tool to generate the code for the state machine metamodel and the Petri net metamodel. You can download these metamodels from our examples projectFootnote 8. First copy the metamodels into your project folder, then generate the code for them. The complete commandline for the latter is as follows:

figure c

The generated code now has to be added to your project. Thus, first display all files in the projects folder by clicking on Show All Files in the project explorer, then include the generated folder Metamodels and the generated NMeta metamodels into your project (right-click and Include In Project).

As soon as the generated code is added to the project, it is already possible to programatically create and save models. However, the metamodel is not yet registered and thus no models can be loaded. To register the metamodel, we first need to include the NMeta metamodel in the assembly as an embedded resource and then register the metamodel. To make the metamodel an embedded resource, simply change its Build Option to Embedded Resource in the properties view while the metamodel is selected.

The metamodel registration is done through an assembly-wide attribute, which can be specified anywhere in the project. The typical place for this registration, however, would be the AssemblyInfo.cs file in the properties folder. At the top of this file, add the following two lines:

figure d

This is all there is, even if you compile your project not as an executable but as a reusable library. As a reason, when loading the serializer, NMF looks for these attributes in all assemblies referenced by the executing assembly and loads any metamodel registrations it can get.

1.3 A.3 Loading a Model

In NMF, models are loaded by resolving their URI in a model repository. If the repository does not contain a model with the given URI, then the model is automatically loaded into the repository, provided NMF is able to locate it. Repositories are closed under cross-reference, meaning that all references to other model elements are always resolved within the repository or its parent repository.

To create a repository, we simply need to create an object of type ModelRepository. With the default configuration, this repository is able to deserialize any models conforming to metamodels registered in referenced assemblies, as all repositories implicitly use the meta repository where the metamodels are loaded into.

figure e

For example, the code needed to load a model from the file Example.fsmFootnote 9 representing a small order process is depicted in Listing 2. Add these lines to the main method. You can now launch the application and validate that the model can be loaded successfully.

1.4 A.4 Incrementalization

The generated model representation classes for the metamodel support change notifications through the .NET de-facto standard interfaces INotifyPropertyChanged and INotifyCollectionChanged. Thus, the generated classes raise events whenever some properties have been changed or elements have been added to or removed from collections. NMF is able to combine these elementary change notifications to deduct when the value for a combined expression has changed.

For example, let us analyze hubs in the finite state machines, i.e. states that have the maximum incoming transitions. A set of such states can be deducted through the analysis depicted in Listing 3.

figure f

Verify that the variable stateHubs is of type IEnumerable<string>, i.e. a standard collection of strings. Now, we need to add a using statement at the top of the program file to the query implementation of NMF Expressions. Add the code from Listing 4 to the top of the program file.

figure g

As a consequence, the query implementation of NMF Expressions is used and thus, the variable stateHubs has the type IEnumerableExpression<string>. This adds a method to obtain an incrementalized version of the query through the AsNotifiable method.

figure h

To verify the change propagation, visualize changes made to the state hub analysis through the code shown in Listing 5. Normally, the method AsNotifiable is a very expensive operation, thus one would save the return value.

figure i

Add some change operations after registering the handler, step through the console application and see how new hubs are immediately shown in the console. For example, you can use the code listed in Listing 6 to create a new transition to skip payment when items of the order process are for free. As a consequence of this change, a message will pop up in the console that a new hub has been detected directly after Line 2–5 of Listing 6 have been executed.

1.5 A.5 Creating a Model Transformation

Now, we are going to transform the state machine model into a different model, for instance in a Petri net.

At first, we need to add the libraries to run model transformations in NTL. The easiest way to get them is to download them as another NuGet package. Install NMF Transformations through the NuGet command shown in Listing 7 or again through the GUI.

figure j

A model transformation in NMF Transformations is a special class, inheriting from ReflectiveTransformation. Thus, create a new class by adding a new class to the project. Download the model transformation FSM2PN from finite state machines to Petri nets from the examples pageFootnote 10 and copy its contents into the new file.

To run this model transformation, we need to instantiate the model transformation, initialize it and run it. The initialization can be reused for multiple passes of a model transformation, in case the model transformation initialization is costly. To apply the model transformation, we need to pass the source and target model type as generic parameters. The transformation then selects an appropriate rule to start with and traverses the transformation through the rule dependencies. Thus, we can ask the transformation to transform states or entire state machines.

figure k

After the transformation, the context object can be used for tracing purposes.

1.6 A.6 Saving Result Model to a File

In NMF, the serialization information of model elements is attached directly to the model representation classes. The NMF serializer uses this information and interprets how the model should be serialized to XMI. To serialize the Petri net, we simply save it into our model repository (or create a new one). Any referenced model element already contained in another existing file is referenced through a fully qualified reference.

figure l

To save a model element to a file, it is sufficient to call the Save method on the repository such as shown in Listing 9. Verify that you can open this file in Eclipse.

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer International Publishing AG, part of Springer Nature

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Hinkel, G. (2018). NMF: A Multi-platform Modeling Framework. In: Rensink, A., Sánchez Cuadrado, J. (eds) Theory and Practice of Model Transformation. ICMT 2018. Lecture Notes in Computer Science(), vol 10888. Springer, Cham. https://doi.org/10.1007/978-3-319-93317-7_10

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-93317-7_10

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-93316-0

  • Online ISBN: 978-3-319-93317-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics