forked from I-Sokolov/RDFGeomApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
132 lines (115 loc) · 5.16 KB
/
Program.cs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using CommandLine;
namespace RDFWrappers
{
class Program
{
public class Options
{
[CommandLine.Option("model", HelpText = "Pathname of the model containing the ontology to generate wrapper classes for. If no model is given, it will generate classes for GeometryKernel (GEOM).")]
public string modelFile { get; set; }
[CommandLine.Option("cs", HelpText = "Pathnamte of c# file to be generated. Default is model name.")]
public string csFile { get; set; }
[CommandLine.Option('h', HelpText = "Pathname of c++ header file to be generated. Default is model name.")]
public string hFile { get; set; }
[CommandLine.Option("namespace", HelpText = "Namespase. Default is model name.")]
public string Namespace { get; set; }
[CommandLine.Option("printClasses", Default = false, HelpText = "Print model classes with properties.")]
public bool printClasses { get; set; }
}
static int Main(string[] args)
{
try
{
Options options = null;
Parser.Default.ParseArguments<Options>(args).WithParsed<Options>(o => { options = o; });
if (options == null)
{
return -1;//--help option
}
//
Console.WriteLine("This application generates C# and C++ header files with helper classes to work with RDF models.");
Console.WriteLine("Use --help to ptint more information and visit http://www.rdf.bg");
Console.WriteLine("");
//
// Update and validate options
//
if (string.IsNullOrWhiteSpace (options.modelFile))
{
options.modelFile = null;
}
else
{
Generator.Verify(System.IO.File.Exists(options.modelFile), "File does not exist: " + options.modelFile);
}
string baseNameSmall = (options.modelFile == null ? "geom" : System.IO.Path.GetFileNameWithoutExtension (options.modelFile));
string baseNameCapital = (options.modelFile == null ? "GEOM" : System.IO.Path.GetFileNameWithoutExtension(options.modelFile));
string defaultOutDir = @"..\..\..\API.generated\";
if (!System.IO.Directory.Exists (defaultOutDir))
{
defaultOutDir = "";
}
if (string.IsNullOrWhiteSpace (options.csFile))
{
options.csFile = defaultOutDir + baseNameSmall + ".cs";
options.csFile = System.IO.Path.GetFullPath(options.csFile);
}
if (string.IsNullOrWhiteSpace (options.hFile))
{
options.hFile = defaultOutDir + baseNameSmall + ".h";
options.hFile = System.IO.Path.GetFullPath(options.hFile);
}
if (string.IsNullOrWhiteSpace (options.Namespace))
{
options.Namespace = baseNameCapital;
}
options.Namespace = Generator.ValidateIdentifier(options.Namespace);
//
// Main course
//
Console.WriteLine("Generating classes for " + baseNameCapital);
var model = RDF.engine.OpenModel(options.modelFile);
Console.WriteLine();
var schema = new Schema(model);
if (options.printClasses)
{
schema.ToConsole();
Console.WriteLine();
}
//
//
if (!string.IsNullOrWhiteSpace(options.csFile))
{
Console.WriteLine("Generate C# file " + options.csFile);
Generator csgen = new Generator(schema, true, options.Namespace);
csgen.WriteWrapper(options.csFile);
}
else
{
Console.WriteLine("Do not create C# file");
}
System.Console.WriteLine();
if (!string.IsNullOrWhiteSpace(options.hFile))
{
Console.WriteLine("Generate C++ header file " + options.hFile);
Generator cppgen = new Generator(schema, false, options.Namespace);
cppgen.WriteWrapper(options.hFile);
}
else
{
Console.WriteLine("Do not create C++ header file");
}
System.Console.WriteLine();
RDF.engine.CloseModel(model);
return 0;
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine("ERROR:");
Console.WriteLine(e.ToString());
return 13;
}
}
}
}