-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGettingStarted.txt
More file actions
89 lines (74 loc) · 4.82 KB
/
GettingStarted.txt
File metadata and controls
89 lines (74 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Note: This tutorial does not work yet. Still under construction.
Step 1: Define a model:
<!DOCTYPE CbXdl_V1>
#|Class |Property |Attribute |Value |NotUsed| Comment
+| | |Include |../DotNet/DotNet.xdl | | Include definitions for .NET Framework
+| | |Include |../Sys/Sys.xdl | | Include definitions for Entity-System
+| | |ModelName |MyCbOrmApp | | Define the name of the model.
+| | |Namespace |MyCbOrmApp | | Define the namespace for the model'S generated source code.
+|MyParent | |Base |CEntityObject | | Define class 'MyParent' of basetype 'EntityObject'
+|MyParent |MyString |Typ |String | | Define property 'MyString' of type 'String' in class 'MyParent'
+|MyParent |MyChildren |Typ |MyChild | | Define property 'MyChildren' of type 'MyChild' in class 'MyParent'
+|MyParent |MyChild |Typ |MyChild | | Define property 'MyChild' of type 'MyChild' in class 'MyParent'
+|MyParent |MyChild |Cardinality |11C | | Define property 'MyChild' of cardinality '1:1'
+|MyChild | |Base |CEntityObject | | Define class 'MyChild' of basetype 'EntityObject'
+|MyChild |MyProperty |Typ |Boolean | | Define property 'MyBoolean' of typ 'Boolean'
Some words about this Model definition language (MDL):
You see, the mdl constists of rows and columns, separated by a pipe character '|'.
Actually it's a csv format - the mother of all file formats ;-)
Thus It can be easily stored in a database or converted into a small binary file by indexing the identifier strings.
By defining columns class, Property, Attribute (MetaProperty) and value it is object oriented and extensible and refers directly to a object model with custom reflection info.
The NotUsed column i used for datamapping in another project. However this column is not used in this project but i reserved it.
The last column includes a comment and is not processed.
Either if the row stars with #| the rest of the row will be ignored. This is inteded to be used for comments
Either if the row starts with a -| the rest of the row is ignored. This is intendend to deactivate interpretation of valid row definitions.
I did it like i did it because it is very compact. My model at office consists of about 10k-20k of such rows.
If i would have keywords or xml tag names in between i would get mad typing all those keywords again and again.
I use excel to edit the rows and like this i can easily handle large object models with about 6k-12k fields.
And i only need to type what is really necessary - the identifiers.
But now let's continue to get the sample app to work:
Step 2: Save the model definition in folder CbOrm\App\MyCbOrmApp\GeneratorInput\MyCbOrmApp.xdl
Step 3: Run the cb_orm.exe. It will generate the code in CbOrm\App\MyCbOrmApp\GeneratorOutput
- Either from the development environment: Just run the exe through the VS-IDE
- Or from commandline:
cb_orm.exe Command="GenerateOrm" ModelInputFile="App\MyCbOrmApp\GeneratorInput\MyCbOrmApp.xdl"
Step 4: Write some test code to work with the generated code.
// c# Code:
using CbOrm.FileSys;
using MyCbOrmApp;
using System.IO;
class Program
{
static void main()
{
var aDirectoryInfo = new DirectoryInfo(@"C:\Temp\MyAppStorage");
var aTestString = "Hello world";
var aTestBool1 = true;
var aTestBool2 = false;
{ // Create some persistent objects
var aObjectStorage = new CFileSystemStorage(MyCbOrmAppSchema.Singleton, aDirectoryInfo);
aObjectStorage.Connect();
aObjectStorage.Clear();
var aMyParent = aObjectStorage.CreateObject<MyParent>();
aMyParent.MyString = aTestString;
aMyParent.MyChild.MyBoolean = aTestBool1;
var aMyChildItem = aMyParent.MyChildren.Add();
aMYChildItem.TestBoolean = aTestBool2;
aObjectStorage.Save();
}
{ // Load objects and check the data
var aObjectStorage = new CFileSystemStorage(MyCbOrmAppSchema.Singleton, aDirectoryInfo);
var aMyParent = aObjectStorage.LoadObjects<MyParent>().Single();
Assert(aMyParent.MyString == aTestString);
Assert(aMyParent.MyChild.MyBoolean1 = aTestBool1);
Assert(aMyParent.MyChildren.Single().MyBoolean == aTestBool2);
}
{ // Delete the objects.
var aObjectStorage = new CFileSystemStorage(MyCbOrmAppSchema.Singleton, aDirectoryInfo);
var aMyParent = aObjectStorage.LoadObjects<MyParent>().Single();
aMyParent.Delete();
aObjectStorage.Save();
Assert(aObjectStorage.LoadObjects<CEntityObject>().Count() == 0);
}
}
}