![Page 1: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/1.jpg)
Rubén Jiménez [email protected]
@rubenjmarrufo
Pedro J. Molina, PhD [email protected]
@pmolinam
@
Modelling and Code Generation
on the .NET Platform
![Page 2: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/2.jpg)
Contents
Introduction
History of Microsoft Modeling
MDSD: Approaches
MDSD: Reference Framework
MDSD: Tour of features
Demos
© Icinetic 2012 2
![Page 3: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/3.jpg)
Introduction
We do MDSD Tools for developers
Focused on .NET technologies &
Architecture Services
HQ in Seville, Spain
© Icinetic 2012 3
![Page 4: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/4.jpg)
History of Microsoft Modeling
© Icinetic 2012 4
2005: First release of MS DSL Tools
2007: First details about its plans for the “Oslo” project
2008: First Microsoft “Oslo” CTP
2009: Visual Studio 2010 V&M SDK Beta
2010: Microsoft “Oslo” is obliterated
2010: Visual Studio LightSwitch
2011: Visual Studio 11 V&M SDK Beta
![Page 5: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/5.jpg)
.NET & MDSD
© Icinetic 2012 5
Ready to dive?
![Page 6: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/6.jpg)
MDSD: Choose your path
© Icinetic 2012 6
MDSD
MDA DSLs
MDA/UML:
Metamodel is highly closed
Symbol and concept overloading
Not clear Semantics
Action Language
Domains not cover by UML
Abuse of profiles
Tools: many dialects of XMI
DSLs:
Cost of DSLs and tools required
to develop with it.
![Page 7: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/7.jpg)
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Checker
Model Transformation
Model
M2M M2T
Code Doc, etc.
Reverse Engineering
Metamodel(s)
7
Model repository
MDSD Reference FWK
© Icinetic 2012
![Page 8: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/8.jpg)
Metamodeling
The analysis, construction and development of the frames, rules,
constraints, models and theories applicable and useful for
modeling a predefined class of problems (Wikipedia)
Based in CARs
Classes / Entities / Objects
Attributes / Properties
Relationships
At Icinetic:
MS DSL Tools
Essential Meta
© Icinetic 2012 8
Customer Credit Card
1 *
Class
Properties
Relation
Cardinality
Source
Target
8
![Page 9: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/9.jpg)
Metamodeling: MS DSL Tools Visual Studio Visualization & Modeling SDK.
Features: Graphical meta-modeling.
Build graphical designers.
M2T: T4.
Model validations.
IDE: Visual Studio.
Benefits: Agile
Visual
Drawbacks: Generated designers performance:
“Magnify diagrams and multiply it”: Pascal Recchia.
© Icinetic 2012 9
![Page 10: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/10.jpg)
Metamodeling: Essential
© Icinetic 2012 10
namespace Meta { class MailMessage { Person From; List<Person> To; string Subject; string Message; } class Person { string FullName; string Email; } }
![Page 11: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/11.jpg)
Metamodeling: Essential META
namespace org.example.library
{
class Book
{
string title;
int pages;
List<Writer> authors opposite books;
}
enum BookCategory
{
Mistery,
ScienceFiction,
Biography
}
}
package org.example.library
class Book
{
String title
int pages
refers Writer[] authors opposite books
}
enum BookCategory
{
Mistery
ScienceFiction
Biography
}
© Icinetic 2012 11
Essential META 2009 XCore 2012
![Page 12: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/12.jpg)
MDSD: Models
© Icinetic 2012 12
Textual Model Editor
Visual Model Editor
IDE
Model Checker
Model Transformation
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
Model(s)
![Page 13: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/13.jpg)
Models: some Cases of Use
Model Checker
Model
1. Validation
Report
Interpreter
Model
Runtime interpretation
2. Interpretation
Code Generation
Model
3. Code Generation
Generated Code
Code
Metadata
Doc
Config.
Tests
...
13 © Icinetic 2012
![Page 14: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/14.jpg)
Models: Code generation techniques
1. Parse model
2. In-memory representation
AST / Object Model
3. Output building
Free text concatenation
XSL-T (No thanks!)
Text Template based
Input Model
AST Template
Output code
14 © Icinetic 2012
![Page 15: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/15.jpg)
Models: Parsers
© Icinetic 2012 15
Parsers License Url Grammar
notation
Parsing
algorithm
IDE Strengths
ANTLR BSD www.antlr
.org/ EBNF LL Yes Mature & widely
used
Irony.Net MIT irony.code
plex.com/ BNF LALR Yes Interpreted
Gold parser FW goldparse
r.org/ BNF LALR No Supported
languages: more than any other parsing system
Grammatica GNU grammati
ca.percede
rberg.net/
EBNF LL No Readable generated
parse code
![Page 16: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/16.jpg)
MDSD: Editors
© Icinetic 2012 16
Model(s)
IDE
Model Checker
Model Transformation
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
Textual Model Editor
Visual Model Editor
![Page 17: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/17.jpg)
Textual Model Editors
DDD Textual DSL
© Icinetic 2012 17
Essential Text Editor
![Page 18: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/18.jpg)
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 18
![Page 19: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/19.jpg)
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 19
![Page 20: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/20.jpg)
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 20
![Page 21: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/21.jpg)
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 21
![Page 22: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/22.jpg)
Other Model Editors
Tables
Trees
© Icinetic 2012 22
![Page 23: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/23.jpg)
MDSD: Reverse engineering
© Icinetic 2012 23
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Checker
Model Transformation
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
![Page 24: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/24.jpg)
Reverse Engineering
External assets to model
Sources:
Databases
EDMX Database importer
Services
Custom parsers
Legacy code
Custom parsers
© Icinetic 2012 24
![Page 25: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/25.jpg)
MDSD: Model Checkers
© Icinetic 2012 25
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Transformation
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
Model Checker
![Page 26: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/26.jpg)
Model Checkers: Validation Engine
MS DSL Tools
AOP
IDE integration
Hollywood
Principle
© Icinetic 2012 26
![Page 27: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/27.jpg)
Models Checkers: Validation Engine
Essential AST + Visitor
Two phase checking
Syntax check
Model Merge
Reference resolver
Semantic check
Validation FWK
Extensible
© Icinetic 2012 27
![Page 28: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/28.jpg)
MDSD: Model Repositories
© Icinetic 2012 28
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Checker
Model Transformation
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Reverse Engineering
Model repository
![Page 29: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/29.jpg)
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 29
![Page 30: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/30.jpg)
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 30
![Page 31: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/31.jpg)
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 31
![Page 32: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/32.jpg)
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 32
![Page 33: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/33.jpg)
MDSD: Transformations
© Icinetic 2012 33
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Checker
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
Model Transformation
![Page 34: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/34.jpg)
Transformations
M2T
Free text concatenation
XSL-T (No thanks!)
Text Template based
T4
StringTemplate
M2M
Imperative
Declarative
© Icinetic 2012 34
![Page 35: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/35.jpg)
MDSD: M2T
© Icinetic 2012 35
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Checker
Model Transformation
Model
M2M
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
M2T
![Page 36: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/36.jpg)
M2T: T4 Templates
Text Template Transformation Toolkit
Released in 2005 by Microsoft
Syntax:
Directives
Text blocks
Control blocks
Usages:
Standard
Precompiled: webResponseText=template.TransformText();
© Icinetic 2012. 36
![Page 37: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/37.jpg)
M2T: StringTemplate
Terrence Parr’s templates
Dynamic templates
Strong separation of
concerns: Model, View
and Control
Good maintanability
© Icinetic 2012. 37
group Templates; genMail(msg) ::= << From: $msg.From:genRecipient()$ To: $msg.To:genRecipient(); separator=", "$ Subject: $msg.Subject$ MESSAGE: ------------------------------ $msg.Message$ ------------------------------ >> genRecipient()::= << $it.FullName$ <$it.Email$> >>
![Page 38: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/38.jpg)
M2T: Template Engines
T4
StringTemplate
Precompiled T4
© Icinetic 2012 38
0
5
10
15
20
25
30
35
40
T4 StringTemplate T4 Precompiled
Time to generate 5000 files of 5 Kb of average
Write File
Generation
Load/compile
T4 StringTemplate Precompiled T4
Total time (ms) 392.935 56.483 48.894
Time(ms)/file 78,587 11,297 9,779
Time(ms)/MB 4.066,142 876,654 505,961
Improvement/T4 base x 7 x 8
![Page 39: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/39.jpg)
MDSD: M2M
© Icinetic 2012 39
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Checker
Model Transformation
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
![Page 40: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/40.jpg)
M2M: Imperative
© Icinetic 2012 40
![Page 41: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/41.jpg)
M2M: Imperative
© Icinetic 2012 41
![Page 42: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/42.jpg)
M2M: Declarative
Essential TRX
Rule-based language
Interpreted
© Icinetic 2012 42
![Page 43: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/43.jpg)
MDSD: IDE Integration
© Icinetic 2012 43
Textual Model Editor
Model(s) Visual Model Editor
IDE
Model Checker
Model Transformation
Model
M2M M2T
Code Doc, etc.
Metamodel(s)
Model repository
Reverse Engineering
![Page 44: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/44.jpg)
IDE Integration
© Icinetic 2012 44
3. Model to Text
Folders & Projects
Generated & custom code coexistence
Generated assets tracking
1. Model Editors
VS packages
2. Model checkers Errors validation
![Page 45: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/45.jpg)
Making sense of it all
Radarc
Plug-in on the top of Visual Studio
Modelling environment and code generation
packetized by architectures
© Icinetic 2012 45
![Page 46: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/46.jpg)
Radarc Formulas
A Formula is a code
generator including:
Models / DSLs
Editors
Traceability rules
Best practices
Templates
© Icinetic 2012 46
Formulas available
ASP.NET WebForms
ASP.NET MVC
MVC + Azure
Windows Phone 7
DDD N-Layered
… and growing
![Page 47: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/47.jpg)
Demo
© Icinetic 2012 47
![Page 48: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/48.jpg)
Conclusions
Modelling and code generation
technologies have matured a lot
in the latest years
The .NET platform has a strong
base of tools to make MDSD
approaches feasible.
MDSD is not more a luxury, is a
precision tool. Take profit!
© Icinetic 2012 48
![Page 49: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/49.jpg)
Questions & (might be) Anwers
© Icinetic 2012 49
![Page 50: Modelling and code generation in .NET at Icinetic](https://reader033.vdocuments.us/reader033/viewer/2022052622/559764011a28abf0778b48a5/html5/thumbnails/50.jpg)
50
@RadarcNet
pjmolina.com/essential
www.radarc.net