@polytric/openws-sdkgen 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
1
+ import { Spec, Endpoint } from '@polytric/openws-spec/types';
2
+
3
+ interface PipelineContext {
4
+ argv: string[];
5
+ rawInput?: RawInput;
6
+ request?: BuildRequest;
7
+ spec?: Spec;
8
+ ir?: IR;
9
+ plan?: PlanStep[];
10
+ }
11
+ interface RawInput {
12
+ spec: string;
13
+ out: string;
14
+ project: string;
15
+ hostRole: string[];
16
+ language: 'csharp' | 'javascript';
17
+ environment: 'unity' | 'node' | 'browser';
18
+ frameworks?: string[];
19
+ }
20
+ interface BuildRequest {
21
+ specPath: string;
22
+ outputPath: string;
23
+ project: string;
24
+ hostRoles: string[];
25
+ target: {
26
+ csharp?: {
27
+ environment: 'unity';
28
+ frameworks?: string[];
29
+ };
30
+ javascript?: {
31
+ environment: 'node' | 'browser';
32
+ frameworks?: string[];
33
+ };
34
+ };
35
+ }
36
+ interface IR {
37
+ package: IRPackage;
38
+ networks: IRNetwork[];
39
+ assemblyName?: string;
40
+ }
41
+ interface IRPackage {
42
+ project: string;
43
+ service: string;
44
+ description?: string;
45
+ version?: string;
46
+ }
47
+ interface IRNetwork {
48
+ name: string;
49
+ description?: string;
50
+ version?: string;
51
+ roles: IRRole[];
52
+ handlers: IRHandler[];
53
+ messages: IRMessage[];
54
+ models: IRModel[];
55
+ }
56
+ interface IRRole {
57
+ name: string;
58
+ description?: string;
59
+ isHost: boolean;
60
+ endpoints: Endpoint[];
61
+ }
62
+ interface IRHandler {
63
+ roleName: string;
64
+ handlerName: string;
65
+ description?: string;
66
+ modelClassName?: string;
67
+ messageName?: string;
68
+ methodName?: string;
69
+ }
70
+ interface IRMessage {
71
+ roleName: string;
72
+ handlerName: string;
73
+ description?: string;
74
+ modelClassName?: string;
75
+ messageName?: string;
76
+ methodName?: string;
77
+ }
78
+ interface IRModel {
79
+ scopeName: string;
80
+ modelName: string;
81
+ type: string;
82
+ description?: string;
83
+ properties?: IRProperty[];
84
+ namespace?: string;
85
+ className?: string;
86
+ }
87
+ interface IRProperty {
88
+ type: string;
89
+ scopeName: string;
90
+ modelName: string;
91
+ description?: string;
92
+ required?: boolean;
93
+ items?: {
94
+ type: string;
95
+ scopeName: string;
96
+ modelName: string;
97
+ description?: string;
98
+ };
99
+ propertyName?: string;
100
+ typeName?: string;
101
+ }
102
+ interface PlanStep {
103
+ name: string;
104
+ command: 'copy' | 'render';
105
+ input?: string;
106
+ output: string;
107
+ template?: string;
108
+ getData?: () => unknown;
109
+ }
110
+
111
+ declare function createPlan(ctx: PipelineContext): PipelineContext;
112
+
113
+ export { createPlan as default };
@@ -0,0 +1,113 @@
1
+ import { Spec, Endpoint } from '@polytric/openws-spec/types';
2
+
3
+ interface PipelineContext {
4
+ argv: string[];
5
+ rawInput?: RawInput;
6
+ request?: BuildRequest;
7
+ spec?: Spec;
8
+ ir?: IR;
9
+ plan?: PlanStep[];
10
+ }
11
+ interface RawInput {
12
+ spec: string;
13
+ out: string;
14
+ project: string;
15
+ hostRole: string[];
16
+ language: 'csharp' | 'javascript';
17
+ environment: 'unity' | 'node' | 'browser';
18
+ frameworks?: string[];
19
+ }
20
+ interface BuildRequest {
21
+ specPath: string;
22
+ outputPath: string;
23
+ project: string;
24
+ hostRoles: string[];
25
+ target: {
26
+ csharp?: {
27
+ environment: 'unity';
28
+ frameworks?: string[];
29
+ };
30
+ javascript?: {
31
+ environment: 'node' | 'browser';
32
+ frameworks?: string[];
33
+ };
34
+ };
35
+ }
36
+ interface IR {
37
+ package: IRPackage;
38
+ networks: IRNetwork[];
39
+ assemblyName?: string;
40
+ }
41
+ interface IRPackage {
42
+ project: string;
43
+ service: string;
44
+ description?: string;
45
+ version?: string;
46
+ }
47
+ interface IRNetwork {
48
+ name: string;
49
+ description?: string;
50
+ version?: string;
51
+ roles: IRRole[];
52
+ handlers: IRHandler[];
53
+ messages: IRMessage[];
54
+ models: IRModel[];
55
+ }
56
+ interface IRRole {
57
+ name: string;
58
+ description?: string;
59
+ isHost: boolean;
60
+ endpoints: Endpoint[];
61
+ }
62
+ interface IRHandler {
63
+ roleName: string;
64
+ handlerName: string;
65
+ description?: string;
66
+ modelClassName?: string;
67
+ messageName?: string;
68
+ methodName?: string;
69
+ }
70
+ interface IRMessage {
71
+ roleName: string;
72
+ handlerName: string;
73
+ description?: string;
74
+ modelClassName?: string;
75
+ messageName?: string;
76
+ methodName?: string;
77
+ }
78
+ interface IRModel {
79
+ scopeName: string;
80
+ modelName: string;
81
+ type: string;
82
+ description?: string;
83
+ properties?: IRProperty[];
84
+ namespace?: string;
85
+ className?: string;
86
+ }
87
+ interface IRProperty {
88
+ type: string;
89
+ scopeName: string;
90
+ modelName: string;
91
+ description?: string;
92
+ required?: boolean;
93
+ items?: {
94
+ type: string;
95
+ scopeName: string;
96
+ modelName: string;
97
+ description?: string;
98
+ };
99
+ propertyName?: string;
100
+ typeName?: string;
101
+ }
102
+ interface PlanStep {
103
+ name: string;
104
+ command: 'copy' | 'render';
105
+ input?: string;
106
+ output: string;
107
+ template?: string;
108
+ getData?: () => unknown;
109
+ }
110
+
111
+ declare function createPlan(ctx: PipelineContext): PipelineContext;
112
+
113
+ export { createPlan as default };
@@ -0,0 +1,192 @@
1
+ // src/plans/dotnet.ts
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ var __dirname = path.dirname(fileURLToPath(import.meta.url));
5
+ var TEMPLATE_DIR = path.join(__dirname, "../templates/dotnet");
6
+ function pascalCase(str) {
7
+ return str.charAt(0).toUpperCase() + str.slice(1);
8
+ }
9
+ function camelCase(str) {
10
+ return str.charAt(0).toLowerCase() + str.slice(1);
11
+ }
12
+ function createPlan(ctx) {
13
+ const { ir, request } = ctx;
14
+ if (!ir) throw new Error("ir is required");
15
+ if (!request) throw new Error("request is required");
16
+ const assemblyName = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.Sdk`;
17
+ ir.assemblyName = assemblyName;
18
+ const plan = [
19
+ {
20
+ name: "assembly definition",
21
+ command: "render",
22
+ getData: () => ir,
23
+ template: path.join(TEMPLATE_DIR, "Service.asmdef.ejs"),
24
+ output: path.join(request.outputPath, assemblyName, `${assemblyName}.asmdef`)
25
+ },
26
+ {
27
+ name: "user assembly reference",
28
+ command: "render",
29
+ getData: () => ir,
30
+ template: path.join(TEMPLATE_DIR, "UserService.asmref.ejs"),
31
+ output: path.join(
32
+ request.outputPath,
33
+ `${assemblyName}.User`,
34
+ `${assemblyName}.User.asmref`
35
+ )
36
+ }
37
+ ];
38
+ for (const networkIr of ir.networks) {
39
+ const networkNamespace = `${pascalCase(ir.package.project)}.${pascalCase(ir.package.service)}.${pascalCase(networkIr.name)}`;
40
+ const networkClassName = `${pascalCase(networkIr.name)}Network`;
41
+ const networkOutputPath = path.join(
42
+ request.outputPath,
43
+ assemblyName,
44
+ pascalCase(networkIr.name)
45
+ );
46
+ const userNetworkOutputPath = path.join(
47
+ request.outputPath,
48
+ `${assemblyName}.User`,
49
+ pascalCase(networkIr.name)
50
+ );
51
+ const hostRoles = [];
52
+ const remoteRoles = [];
53
+ for (const role of networkIr.roles) {
54
+ const roleInfo = {
55
+ roleName: role.name,
56
+ className: pascalCase(role.name),
57
+ varName: camelCase(role.name),
58
+ description: role.description || "",
59
+ baseClassName: role.isHost ? "HostRole" : "RemoteRole",
60
+ endpoints: role.endpoints || []
61
+ };
62
+ if (role.isHost) {
63
+ hostRoles.push(roleInfo);
64
+ } else {
65
+ remoteRoles.push(roleInfo);
66
+ }
67
+ }
68
+ const allRoles = [...hostRoles, ...remoteRoles];
69
+ const allModelImports = allRoles.map((role) => `${networkNamespace}.Models.${role.className}`);
70
+ plan.push({
71
+ name: `network ${networkIr.name}`,
72
+ command: "render",
73
+ getData: () => ({
74
+ namespace: networkNamespace,
75
+ networkClassName,
76
+ networkName: networkIr.name,
77
+ description: networkIr.description,
78
+ version: networkIr.version,
79
+ allRoles
80
+ }),
81
+ template: path.join(TEMPLATE_DIR, "Network.cs.ejs"),
82
+ output: path.join(networkOutputPath, `${networkClassName}.cs`)
83
+ });
84
+ for (const modelIr of networkIr.models) {
85
+ modelIr.namespace = `${networkNamespace}.Models.${pascalCase(modelIr.scopeName)}`;
86
+ modelIr.className = pascalCase(modelIr.modelName);
87
+ if (modelIr.properties) {
88
+ for (const propertyIr of modelIr.properties) {
89
+ propertyIr.propertyName = pascalCase(propertyIr.modelName);
90
+ propertyIr.typeName = mapType(propertyIr);
91
+ }
92
+ }
93
+ }
94
+ for (const handlerIr of networkIr.handlers) {
95
+ handlerIr.modelClassName = pascalCase(handlerIr.handlerName) + "Payload";
96
+ handlerIr.messageName = handlerIr.handlerName;
97
+ handlerIr.methodName = pascalCase(handlerIr.handlerName);
98
+ }
99
+ for (const messageIr of networkIr.messages) {
100
+ messageIr.modelClassName = pascalCase(messageIr.handlerName) + "Payload";
101
+ messageIr.messageName = messageIr.handlerName;
102
+ messageIr.methodName = pascalCase(messageIr.handlerName);
103
+ }
104
+ for (const hostRole of hostRoles) {
105
+ const roleHandlers = networkIr.handlers.filter((h) => h.roleName === hostRole.roleName);
106
+ const modelImports = [`${networkNamespace}.Models.${hostRole.className}`];
107
+ plan.push({
108
+ name: `host role ${hostRole.className}`,
109
+ command: "render",
110
+ getData: () => ({
111
+ namespace: `${networkNamespace}.Roles`,
112
+ handlers: roleHandlers,
113
+ remoteRoles,
114
+ modelImports,
115
+ ...hostRole
116
+ }),
117
+ template: path.join(TEMPLATE_DIR, "HostRole.cs.ejs"),
118
+ output: path.join(networkOutputPath, "Roles", `${hostRole.className}.cs`)
119
+ });
120
+ plan.push({
121
+ name: `user host role ${hostRole.className}`,
122
+ command: "render",
123
+ getData: () => ({
124
+ namespace: `${networkNamespace}.Roles`,
125
+ handlers: roleHandlers,
126
+ remoteRoles,
127
+ modelImports: allModelImports,
128
+ ...hostRole
129
+ }),
130
+ template: path.join(TEMPLATE_DIR, "UserHostRole.cs.ejs"),
131
+ output: path.join(userNetworkOutputPath, "Roles", `${hostRole.className}.cs`)
132
+ });
133
+ }
134
+ for (const remoteRole of remoteRoles) {
135
+ const roleMessages = networkIr.messages.filter((m) => m.roleName === remoteRole.roleName);
136
+ const modelImports = [`${networkNamespace}.Models.${remoteRole.className}`];
137
+ plan.push({
138
+ name: `remote role ${remoteRole.className}`,
139
+ command: "render",
140
+ getData: () => ({
141
+ namespace: `${networkNamespace}.Roles`,
142
+ messages: roleMessages,
143
+ modelImports,
144
+ ...remoteRole
145
+ }),
146
+ template: path.join(TEMPLATE_DIR, "RemoteRole.cs.ejs"),
147
+ output: path.join(networkOutputPath, "Roles", `${remoteRole.className}.cs`)
148
+ });
149
+ }
150
+ for (const modelIr of networkIr.models) {
151
+ if (modelIr.type !== "object") continue;
152
+ plan.push({
153
+ name: `model ${modelIr.className}`,
154
+ command: "render",
155
+ getData: () => modelIr,
156
+ template: path.join(TEMPLATE_DIR, "Model.cs.ejs"),
157
+ output: path.join(
158
+ networkOutputPath,
159
+ "Models",
160
+ pascalCase(modelIr.scopeName),
161
+ `${modelIr.className}.cs`
162
+ )
163
+ });
164
+ }
165
+ }
166
+ return {
167
+ ...ctx,
168
+ plan
169
+ };
170
+ }
171
+ function mapType(property) {
172
+ switch (property.type) {
173
+ case "string":
174
+ return "string";
175
+ case "number":
176
+ return "double";
177
+ case "integer":
178
+ return "int";
179
+ case "boolean":
180
+ return "bool";
181
+ case "array":
182
+ if (!property.items) return "List<object>";
183
+ return `List<${mapType(property.items)}>`;
184
+ case "object":
185
+ return pascalCase(property.modelName);
186
+ default:
187
+ return "object";
188
+ }
189
+ }
190
+ export {
191
+ createPlan as default
192
+ };
@@ -0,0 +1,67 @@
1
+ using System;
2
+ using System.Threading.Tasks;
3
+ using Newtonsoft.Json.Linq;
4
+ using Polytric.OpenWs.Core;
5
+ <% for (const modelImport of ctx.modelImports) { -%>
6
+ using <%= modelImport %>;
7
+ <% } -%>
8
+
9
+ namespace <%= ctx.namespace %>
10
+ {
11
+ public partial class <%= ctx.className %> : <%= ctx.baseClassName %>
12
+ {
13
+ public string Name => "<%= ctx.roleName %>";
14
+ public string Description => "<%= ctx.description ?? '' %>";
15
+
16
+ public override void HandleOpen(RemoteRole remoteRole)
17
+ {
18
+ <% for (const remoteRole of ctx.remoteRoles) { %>
19
+ if (remoteRole is <%= remoteRole.className %> <%= remoteRole.varName %>)
20
+ {
21
+ HandleOpen(<%= remoteRole.varName %>);
22
+ }
23
+ <% } -%>
24
+ }
25
+
26
+ <% for (const remoteRole of ctx.remoteRoles) { -%>
27
+ partial void HandleOpen(<%= remoteRole.className %> <%= remoteRole.varName %>);
28
+ <% } -%>
29
+
30
+ public override void HandleMessage(string messageName, JToken payload, RemoteRole remoteRole)
31
+ {
32
+ switch (messageName)
33
+ {
34
+ <% for (const handler of ctx.handlers) { %>
35
+ case "<%= handler.messageName %>":
36
+ {
37
+ var message = payload.ToObject<<%= handler.modelClassName %>>();
38
+ Handle<%= handler.methodName %>(payload);
39
+ Handle<%= handler.methodName %>(message);
40
+ On<%= handler.methodName %>?.Invoke(message);
41
+
42
+ <% for (const remoteRole of ctx.remoteRoles) { %>
43
+ Handle<%= handler.methodName %>(payload, remoteRole as <%= remoteRole.className %>);
44
+ HandleMessage(message, remoteRole as <%= remoteRole.className %>);
45
+ On<%= handler.methodName %>From<%= remoteRole.className %>?.Invoke(message, remoteRole as <%= remoteRole.className %>);
46
+
47
+ <% } -%>
48
+ break;
49
+ }
50
+ <% } -%>
51
+ }
52
+ }
53
+
54
+ <% for (const handler of ctx.handlers) { -%>
55
+ public event Action<<%= handler.modelClassName -%>> On<%= handler.methodName -%>;
56
+ partial void Handle<%= handler.methodName %>(JToken payload);
57
+ partial void Handle<%= handler.methodName %>(<%= handler.modelClassName -%> payload);
58
+
59
+ <% for (const remoteRole of ctx.remoteRoles) { -%>
60
+ public event Action<<%= handler.modelClassName -%>, <%= remoteRole.className -%>> On<%= handler.methodName -%>From<%= remoteRole.className -%>;
61
+ partial void Handle<%= handler.methodName %>(JToken payload, <%= remoteRole.className -%> <%= remoteRole.varName -%>);
62
+ partial void HandleMessage(<%= handler.modelClassName -%> payload, <%= remoteRole.className -%> <%= remoteRole.varName -%>);
63
+
64
+ <% } -%>
65
+ <% } -%>
66
+ }
67
+ }
@@ -2,7 +2,7 @@ using Newtonsoft.Json;
2
2
 
3
3
  namespace <%= ctx.namespace %>
4
4
  {
5
- public class <%= ctx.className %>
5
+ public partial class <%= ctx.className %>
6
6
  {
7
7
  <% for (const property of ctx.properties) { -%>
8
8
  [JsonProperty("<%= property.modelName %>")]
@@ -14,7 +14,7 @@ namespace <%= ctx.namespace %>
14
14
  public override string Name { get; set; } = "<%= ctx.roleName %>";
15
15
  public override string Description { get; set; } = "<%= ctx.description ?? '' %>";
16
16
  <% if (ctx.endpoints && ctx.endpoints.length > 0) { -%>
17
- public override IReadOnlyList<Endpoint> Endpoints { get; set; } = new List<Endpoint>
17
+ public static IReadOnlyList<Endpoint> Endpoints => new List<Endpoint>
18
18
  {
19
19
  <% for (const ep of ctx.endpoints) { -%>
20
20
  new Endpoint { Scheme = "<%= ep.scheme %>", Host = "<%= ep.host %>", Port = <%= ep.port %>, Path = "<%= ep.path %>" },
@@ -25,7 +25,12 @@ namespace <%= ctx.namespace %>
25
25
  <% for (const message of ctx.messages) { -%>
26
26
  public async Task <%= message.methodName %>Async(string fromRole, <%= message.modelClassName %> message)
27
27
  {
28
- await SendMessageAsync(fromRole, "<%= message.messageName %>", message).ConfigureAwait(false);
28
+ await InternalSendMessageAsync(fromRole, "<%= message.messageName %>", message).ConfigureAwait(false);
29
+ }
30
+
31
+ public void <%= message.methodName %>(string fromRole, <%= message.modelClassName %> message)
32
+ {
33
+ InternalQueueMessage(fromRole, "<%= message.messageName %>", message);
29
34
  }
30
35
 
31
36
  <% } -%>
@@ -0,0 +1,51 @@
1
+ using System.Threading.Tasks;
2
+ using Newtonsoft.Json.Linq;
3
+ using Polytric.OpenWs.Core;
4
+ <% for (const modelImport of ctx.modelImports) { -%>
5
+ using <%= modelImport %>;
6
+ <% } %>
7
+ namespace <%= ctx.namespace %>
8
+ {
9
+ public partial class <%= ctx.className %>
10
+ {
11
+ <% for (const remoteRole of ctx.remoteRoles) { -%>
12
+ partial void HandleOpen(<%= remoteRole.className %> <%= remoteRole.varName %>)
13
+ {
14
+ // TODO: Implement connection handling for <%= remoteRole.className %>
15
+ }
16
+
17
+ <% } -%>
18
+ <% for (const handler of ctx.handlers) { -%>
19
+ partial void Handle<%= handler.methodName %>(JToken payload)
20
+ {
21
+ // TODO: Handle <%= handler.messageName %>
22
+ // Or implement the concrete payload method above. You only need to implement one.
23
+ // Removing this partial method will instruct the compiler to eliminate the call to save performance.
24
+ }
25
+
26
+ partial void Handle<%= handler.methodName %>(<%= handler.modelClassName %> payload)
27
+ {
28
+ // TODO: Handle <%= handler.messageName %>
29
+ // Or implement the JToken method above. You only need to implement one.
30
+ // Removing this partial method will instruct the compiler to eliminate the call to save performance.
31
+ }
32
+
33
+ <% for (const remoteRole of ctx.remoteRoles) { -%>
34
+ partial void HandleMessage(<%= handler.modelClassName %> payload, <%= remoteRole.className %> <%= remoteRole.varName %>)
35
+ {
36
+ // TODO: Handle <%= handler.messageName %> from <%= remoteRole.className %>
37
+ // Or implement the JToken method below. You only need to implement one.
38
+ // Removing this partial method will instruct the compiler to eliminate the call to save performance.
39
+ }
40
+
41
+ partial void Handle<%= handler.methodName %>(JToken payload, <%= remoteRole.className %> <%= remoteRole.varName %>)
42
+ {
43
+ // TODO: Handle <%= handler.messageName %> from <%= remoteRole.className %>
44
+ // Or implement the concrete payload method above. You only need to implement one.
45
+ // Removing this partial method will instruct the compiler to eliminate the call to save performance.
46
+ }
47
+
48
+ <% } -%>
49
+ <% } -%>
50
+ }
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polytric/openws-sdkgen",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "OpenWS SDK generator CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,7 +8,6 @@
8
8
  },
9
9
  "files": [
10
10
  "dist",
11
- "src/dotnet/template",
12
11
  "LICENSE",
13
12
  "README.md"
14
13
  ],
@@ -35,8 +34,10 @@
35
34
  },
36
35
  "dependencies": {
37
36
  "@pocketgems/schema": "^0.1.3",
37
+ "ajv": "^8.17.1",
38
38
  "ejs": "^3.1.10",
39
- "yargs": "^18.0.0"
39
+ "yargs": "^18.0.0",
40
+ "@polytric/openws-spec": "0.0.4"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@types/ejs": "^3.1.5",
@@ -49,7 +50,6 @@
49
50
  "scripts": {
50
51
  "build": "tsup",
51
52
  "typecheck": "tsc --noEmit",
52
- "generate": "tsx src/main.ts",
53
- "test:csharp:unity": "tsx src/main.ts --spec ./test/spec.json --out ./generated/dotnet/unity --project Example --hostRole client --language csharp --environment unity"
53
+ "test:csharp:unity": "node dist/main.cjs --spec ./test/spec.json --out ./generated/dotnet/unity --project Example --hostRole client --language csharp --environment unity"
54
54
  }
55
55
  }
@@ -1,52 +0,0 @@
1
- using System.Threading.Tasks;
2
- using Newtonsoft.Json.Linq;
3
- using Polytric.OpenWs.Core;
4
- <% for (const modelImport of ctx.modelImports) { -%>
5
- using <%= modelImport %>;
6
- <% } -%>
7
-
8
- namespace <%= ctx.namespace %>
9
- {
10
- public partial class <%= ctx.className %> : <%= ctx.baseClassName %>
11
- {
12
- public override string Name { get; set; } = "<%= ctx.roleName %>";
13
- public override string Description { get; set; } = "<%= ctx.description ?? '' %>";
14
-
15
- public override async Task HandleOpenAsync(RemoteRole remoteRole)
16
- {
17
- <% for (const remoteRole of ctx.remoteRoles) { %>
18
- if (remoteRole is <%= remoteRole.className %> <%= remoteRole.varName %>)
19
- {
20
- await HandleOpenAsync(<%= remoteRole.varName %>).ConfigureAwait(false);
21
- }
22
- <% } -%>
23
- }
24
-
25
- <% for (const remoteRole of ctx.remoteRoles) { -%>
26
- private partial Task HandleOpenAsync(<%= remoteRole.className %> <%= remoteRole.varName %>);
27
- <% } -%>
28
-
29
- public override async Task HandleMessageAsync(string messageName, JToken payload, RemoteRole remoteRole)
30
- {
31
- switch (messageName)
32
- {
33
- <% for (const handler of ctx.handlers) { %>
34
- case "<%= handler.messageName %>":
35
- {
36
- var message = payload.ToObject<<%= handler.modelClassName %>>();
37
- <% for (const remoteRole of ctx.remoteRoles) { %>
38
- await HandleMessageAsync(message, remoteRole as <%= remoteRole.className %>).ConfigureAwait(false);
39
- <% } -%>
40
- break;
41
- }
42
- <% } -%>
43
- }
44
- }
45
-
46
- <% for (const handler of ctx.handlers) { -%>
47
- <% for (const remoteRole of ctx.remoteRoles) { -%>
48
- private partial Task HandleMessageAsync(<%= handler.modelClassName %> payload, <%= remoteRole.className %> <%= remoteRole.varName %>);
49
- <% } -%>
50
- <% } -%>
51
- }
52
- }
@@ -1,29 +0,0 @@
1
- using System.Threading.Tasks;
2
- using Polytric.OpenWs.Core;
3
- <% for (const modelImport of ctx.modelImports) { -%>
4
- using <%= modelImport %>;
5
- <% } %>
6
- namespace <%= ctx.namespace %>
7
- {
8
- public partial class <%= ctx.className %>
9
- {
10
- <% for (const remoteRole of ctx.remoteRoles) { -%>
11
- private partial Task HandleOpenAsync(<%= remoteRole.className %> <%= remoteRole.varName %>)
12
- {
13
- // TODO: Implement connection handling for <%= remoteRole.className %>
14
- return Task.CompletedTask;
15
- }
16
-
17
- <% } -%>
18
- <% for (const handler of ctx.handlers) { -%>
19
- <% for (const remoteRole of ctx.remoteRoles) { -%>
20
- private partial Task HandleMessageAsync(<%= handler.modelClassName %> payload, <%= remoteRole.className %> <%= remoteRole.varName %>)
21
- {
22
- // TODO: Handle <%= handler.messageName %> from <%= remoteRole.className %>
23
- return Task.CompletedTask;
24
- }
25
-
26
- <% } -%>
27
- <% } -%>
28
- }
29
- }