/
MyAppConnector_cs.tt
108 lines (99 loc) · 3.5 KB
/
MyAppConnector_cs.tt
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
<#
// Copyright (c) Knowledge & Experience. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#>
<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
// ------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
// ランタイム バージョン: <#= Version #>
//
// このファイルへの変更は、正しくない動作の原因になる可能性があり、
// コードが再生成されると失われます。
// </auto-generated>
// ------------------------------------------------------------------------------
using Kae.IoT.Framework;
using Microsoft.Azure.Devices.Client;
using Microsoft.Azure.Devices.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace <#= nameSpace #>
{
class <#= className #> : Kae.IoT.Framework.IoTAppConnector
{
private IIoTApp iotApp;
public <#= className #>(IoTAppConfig appConfig, IIoTApp app) : base(appConfig)
{
iotApp = app;
}
public override async Task<(byte[] result, int statusCode)> InvokeDirectMethodAsync(MethodRequest methodRequest)
{
byte[] result = null;
int statusCode = (int)System.Net.HttpStatusCode.OK;
try
{
switch (methodRequest.Name)
{
<#
foreach (var dmName in syncDirectMethods.Keys)
{
#>
case "<#= dmName #>":
result = System.Text.Encoding.UTF8.GetBytes(iotApp.<#= dmName #>(methodRequest.DataAsJson));
break;
<#
}
#>
<#
foreach (var dmName in asyncDirectMethods.Keys)
{
#>
case "<#= dmName #>":
result = System.Text.Encoding.UTF8.GetBytes(iotApp.<#= dmName #>(methodRequest.DataAsJson));
break;
<#
}
#>
default:
statusCode = (int)System.Net.HttpStatusCode.BadRequest;
break;
}
}
catch (Exception ex)
{
result = System.Text.Encoding.UTF8.GetBytes(ex.Message);
statusCode = (int)System.Net.HttpStatusCode.InternalServerError;
}
return (result, statusCode);
}
public override async Task NotifyC2DMessageAsync(Message msg)
{
await iotApp.ReceivedC2DDataAsync(msg);
}
public override async Task NotifyDeviceTwinsDesiredPropertiesAsync(TwinCollection dp)
{
iotApp.DesiredProperties.Deserialize(dp.ToJson());
await iotApp.UpdatedDTDesiredPropertiesAsync(iotApp.DesiredProperties);
}
public override TwinCollection ResolveDeviceTwinsReportedProperties(IoTData appRP)
{
TwinCollection rp = new TwinCollection(appRP.Serialize());
return rp;
}
public override IoTDataWithProperties GetAppD2CData()
{
return iotApp.GetAppD2CData();
}
public override Task NotifyE2DMessageAsync(Message msg, string inputPort)
{
throw new NotImplementedException();
}
}
}