Modelling and code generation in .NET at Icinetic
-
Upload
pedro-j-molina -
Category
Technology
-
view
480 -
download
2
Transcript of Modelling and code generation in .NET at Icinetic
Rubén Jiménez [email protected]
@rubenjmarrufo
Pedro J. Molina, PhD [email protected]
@pmolinam
@
Modelling and Code Generation
on the .NET Platform
Contents
Introduction
History of Microsoft Modeling
MDSD: Approaches
MDSD: Reference Framework
MDSD: Tour of features
Demos
© Icinetic 2012 2
Introduction
We do MDSD Tools for developers
Focused on .NET technologies &
Architecture Services
HQ in Seville, Spain
© Icinetic 2012 3
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
.NET & MDSD
© Icinetic 2012 5
Ready to dive?
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.
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
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
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
Metamodeling: Essential
© Icinetic 2012 10
namespace Meta { class MailMessage { Person From; List<Person> To; string Subject; string Message; } class Person { string FullName; string Email; } }
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
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)
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
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
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
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
Textual Model Editors
DDD Textual DSL
© Icinetic 2012 17
Essential Text Editor
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 18
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 19
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 20
Graphical Model Editors
MS DSL Tools
WinForms
WPF
Custom: WinForms
WPF
Third party tools: Visio, EA, etc.
© Icinetic 2012 21
Other Model Editors
Tables
Trees
© Icinetic 2012 22
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
Reverse Engineering
External assets to model
Sources:
Databases
EDMX Database importer
Services
Custom parsers
Legacy code
Custom parsers
© Icinetic 2012 24
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
Model Checkers: Validation Engine
MS DSL Tools
AOP
IDE integration
Hollywood
Principle
© Icinetic 2012 26
Models Checkers: Validation Engine
Essential AST + Visitor
Two phase checking
Syntax check
Model Merge
Reference resolver
Semantic check
Validation FWK
Extensible
© Icinetic 2012 27
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
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 29
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 30
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 31
Model Repositories
XML serialization to file
Text serialization to file
Relational DBMS
Documental DB / NoSQL
© Icinetic 2012 32
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
Transformations
M2T
Free text concatenation
XSL-T (No thanks!)
Text Template based
T4
StringTemplate
M2M
Imperative
Declarative
© Icinetic 2012 34
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
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
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$> >>
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
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
M2M: Imperative
© Icinetic 2012 40
M2M: Imperative
© Icinetic 2012 41
M2M: Declarative
Essential TRX
Rule-based language
Interpreted
© Icinetic 2012 42
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
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
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
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
Demo
© Icinetic 2012 47
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
Questions & (might be) Anwers
© Icinetic 2012 49
50
@RadarcNet
pjmolina.com/essential
www.radarc.net