Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 01b005a

Browse files
Konstantina Chremmoulindig
authored andcommitted
Generate the MessageTypes using a mustache template.
Signed-off-by: Konstantina Chremmou <[email protected]>
1 parent 468a374 commit 01b005a

File tree

3 files changed

+65
-28
lines changed

3 files changed

+65
-28
lines changed

csharp/gen_csharp_binding.ml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ let api_members = ref []
8787
let rec main() =
8888
render_file ("Proxy.mustache", "Proxy.cs") (gen_proxy CommonFunctions.XmlRpc) templdir destdir;
8989
render_file ("JsonRpcClient.mustache", "JsonRpcClient.cs") (gen_proxy CommonFunctions.JsonRpc) templdir destdir;
90+
91+
let msgJson = `O ["message_types", `A (List.map (fun x -> `O ["message_type", `String (fst x)];) !Api_messages.msgList); ] in
92+
render_file ("Message2.mustache", "Message2.cs") msgJson templdir destdir;
93+
9094
classes |> List.filter (fun x-> x.name <> "session") |> List.iter gen_class_file;
9195
TypeSet.iter gen_enum !enums;
9296
gen_maps();
@@ -296,34 +300,6 @@ namespace XenAPI
296300
(escape_xml cls.description) (if publishedInfo = "" then "" else "\n /// "^publishedInfo)
297301
exposed_class_name exposed_class_name;
298302

299-
(* Generate bits for Message type *)
300-
if cls.name = "message" then
301-
begin
302-
print "
303-
public enum MessageType { %s };
304-
305-
public MessageType Type
306-
{
307-
get
308-
{
309-
switch (this.name)
310-
{"
311-
(String.concat ", " ((List.map fst !Api_messages.msgList) @ ["unknown"]));
312-
313-
List.iter (fun x -> print "
314-
case \"%s\":
315-
return MessageType.%s;" x x) (List.map fst !Api_messages.msgList);
316-
317-
print
318-
"
319-
default:
320-
return MessageType.unknown;
321-
}
322-
}
323-
}
324-
"
325-
end;
326-
327303
print
328304
"
329305
#region Constructors

csharp/templates/Message2.mustache

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) Citrix Systems, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1) Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* 2) Redistributions in binary form must reproduce the above
13+
* copyright notice, this list of conditions and the following
14+
* disclaimer in the documentation and/or other materials
15+
* provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
* OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
32+
namespace XenAPI
33+
{
34+
public partial class Message : XenObject<Message>
35+
{
36+
public enum MessageType
37+
{
38+
{{#message_types}}
39+
{{{message_type}}},
40+
{{/message_types}}
41+
unknown
42+
}
43+
44+
public MessageType Type
45+
{
46+
get
47+
{
48+
switch (this.name)
49+
{
50+
{{#message_types}}
51+
case "{{{message_type}}}":
52+
return MessageType.{{{message_type}}};
53+
{{/message_types}}
54+
default:
55+
return MessageType.unknown;
56+
}
57+
}
58+
}
59+
}
60+
}

csharp/templates/XenServer.csproj.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="JsonRpc.cs" />
6161
<Compile Include="JsonRpcClient.cs" />
6262
<Compile Include="Marshalling.cs" />
63+
<Compile Include="Message2.cs" />
6364
<Compile Include="Response.cs" />
6465
<Compile Include="Session.cs" />
6566
<Compile Include="Subject2.cs" />

0 commit comments

Comments
 (0)