├── device-provisioning-sample
├── .gitignore
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── CertificateFactory.cs
├── Device.cs
├── Program.cs
├── README.md
└── device-provisioning-sample.csproj
├── generator-sample
├── .gitignore
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── Program.cs
├── TelemtryMessage.cs
└── generator-sample.csproj
└── machine-sample
├── .gitignore
├── .vscode
├── launch.json
└── tasks.json
├── Program.cs
├── TelemtryMessage.cs
└── machine-sample.csproj
/device-provisioning-sample/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
332 |
333 | cert.cer
--------------------------------------------------------------------------------
/device-provisioning-sample/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/device-provisioning-sample.dll",
14 | "args": [""],
15 | "cwd": "${workspaceFolder}",
16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17 | "console": "internalConsole",
18 | "stopAtEntry": false,
19 | "internalConsoleOptions": "openOnSessionStart"
20 | },
21 | {
22 | "name": ".NET Core Attach",
23 | "type": "coreclr",
24 | "request": "attach",
25 | "processId": "${command:pickProcess}"
26 | }
27 | ,]
28 | }
--------------------------------------------------------------------------------
/device-provisioning-sample/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/device-provisioning-sample.csproj"
11 | ],
12 | "problemMatcher": "$msCompile"
13 | },
14 | {
15 | "label": "run",
16 | "command": "dotnet",
17 | "type": "process",
18 | "args": [
19 | "run",
20 | "${workspaceFolder}/device-provisioning-sample.csproj"
21 | ],
22 | "problemMatcher": "$msCompile"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/device-provisioning-sample/CertificateFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 | using System.Security.Cryptography.X509Certificates;
5 |
6 | namespace DeviceProvisioningSample
7 | {
8 | public static class CertificateFactory
9 | {
10 | public static void CreateTestCert()
11 | {
12 | var ticks = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
13 | var rsa = RSA.Create(2048);
14 | var request = new CertificateRequest($"cn=globomantics-dev-{ticks}", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
15 | var certificate = request.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddYears(1));
16 |
17 | // Create PFX (PKCS #12) with private key
18 | var keyPath = Path.GetFullPath("key.pfx");
19 | Console.WriteLine($"Writing private key to {keyPath}...");
20 | File.WriteAllBytes(keyPath, certificate.Export(X509ContentType.Pfx));
21 |
22 | // Create Base 64 encoded CER (public key only)
23 | var certPath = Path.GetFullPath("cert.cer");
24 | Console.WriteLine($"Writing public certificate to {certPath}...");
25 | File.WriteAllText(certPath, Convert.ToBase64String(certificate.Export(X509ContentType.Cert)));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/device-provisioning-sample/Device.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography.X509Certificates;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.Azure.Devices.Provisioning.Client;
7 | using Microsoft.Azure.Devices.Provisioning.Client.Transport;
8 | using Microsoft.Azure.Devices.Shared;
9 | using Microsoft.Azure.Devices.Client;
10 |
11 | namespace DeviceProvisioningSample
12 | {
13 | public class Device
14 | {
15 | private string scopeId;
16 | private string assignedHub;
17 | private DeviceAuthenticationWithX509Certificate auth;
18 |
19 | public Device(string scopeId)
20 | {
21 | this.scopeId = scopeId;
22 | }
23 |
24 | public async Task Provision()
25 | {
26 | var certificate = LoadPrivateKey("key.pfx");
27 |
28 | using (var securityProvider = new SecurityProviderX509Certificate(certificate))
29 | using (var transport = new ProvisioningTransportHandlerAmqp(TransportFallbackType.TcpOnly))
30 | {
31 | var client = ProvisioningDeviceClient.Create("global.azure-devices-provisioning.net", this.scopeId, securityProvider, transport);
32 |
33 | var result = await client.RegisterAsync();
34 |
35 | Console.WriteLine($"Provisioning result: {result.Status}");
36 |
37 | if (result.Status != ProvisioningRegistrationStatusType.Assigned)
38 | {
39 | throw new InvalidOperationException("Something went wrong while trying to provision.");
40 | }
41 |
42 | this.assignedHub = result.AssignedHub;
43 | this.auth = new DeviceAuthenticationWithX509Certificate(result.DeviceId, securityProvider.GetAuthenticationCertificate());
44 | }
45 | }
46 |
47 | private static X509Certificate2 LoadPrivateKey(string key)
48 | {
49 | if (!File.Exists(key))
50 | {
51 | Console.WriteLine("No private key found. Execute `dotnet run setup` first.");
52 | Environment.Exit(-1);
53 | }
54 |
55 | var certificateCollection = new X509Certificate2Collection();
56 | certificateCollection.Import(key);
57 |
58 | foreach (var element in certificateCollection)
59 | {
60 | if (element.HasPrivateKey)
61 | {
62 | return element;
63 | }
64 | else
65 | {
66 | element.Dispose();
67 | }
68 | }
69 |
70 | throw new InvalidOperationException("No private key found. Execute `dotnet run setup` first.");
71 | }
72 |
73 | internal async Task ConnectAndRun()
74 | {
75 | using (var client = DeviceClient.Create(this.assignedHub, this.auth, TransportType.Amqp))
76 | {
77 | Console.Write($"Connecting to hub: {this.assignedHub}... ");
78 | await client.OpenAsync();
79 | Console.WriteLine("Connected!");
80 |
81 | Console.Write("Sending D2C message... ");
82 | await client.SendEventAsync(new Message(Encoding.UTF8.GetBytes("Hello from a provisioned device!")));
83 | Console.WriteLine("Sent!");
84 |
85 | Console.Write("Closing connection... ");
86 | await client.CloseAsync();
87 | Console.WriteLine("Connection Closed!");
88 | }
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/device-provisioning-sample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography.X509Certificates;
4 | using System.Threading.Tasks;
5 |
6 | namespace DeviceProvisioningSample
7 | {
8 | class Program
9 | {
10 | static async Task Main(string[] args)
11 | {
12 | if (args == null || args.Length < 1)
13 | {
14 | Console.WriteLine("You must specify an action!");
15 | return;
16 | }
17 |
18 | if (args[0] == "setup")
19 | {
20 | CertificateFactory.CreateTestCert();
21 | }
22 | else
23 | {
24 | var scopeId = args[0];
25 | var device = new Device(scopeId);
26 | await device.Provision();
27 | await device.ConnectAndRun();
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/device-provisioning-sample/README.md:
--------------------------------------------------------------------------------
1 | # Device Provisioning Sample App
2 |
3 | This app is a companion for my "Create IoT Solutions" course at Pluralsight.
4 |
5 | ## Creating a certificate
6 |
7 | Execute the following command:
8 |
9 | `dotnet run setup`
10 |
11 | This will create the certificate, which can then be used to create an individual enrollment.
12 |
13 | ## Simulate a device
14 |
15 | Execute the following command:
16 |
17 | `dotnet run {id-scope}`
18 |
19 | The `{id-scope}` parameter is the ID Scope of your device provisioning service.
20 |
--------------------------------------------------------------------------------
/device-provisioning-sample/device-provisioning-sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | DeviceProvisioningSample
7 | latest
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/generator-sample/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
332 |
333 | cert.cer
--------------------------------------------------------------------------------
/generator-sample/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/generator-sample.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}",
16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17 | "console": "internalConsole",
18 | "stopAtEntry": false,
19 | "internalConsoleOptions": "openOnSessionStart"
20 | },
21 | {
22 | "name": ".NET Core Attach",
23 | "type": "coreclr",
24 | "request": "attach",
25 | "processId": "${command:pickProcess}"
26 | }
27 | ,]
28 | }
--------------------------------------------------------------------------------
/generator-sample/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/generator-sample.csproj"
11 | ],
12 | "problemMatcher": "$msCompile"
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/generator-sample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using Microsoft.Azure.Devices.Client;
6 | using Newtonsoft.Json;
7 |
8 | namespace GeneratorSample
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | if (args == null || args.Length < 1)
15 | {
16 | Console.WriteLine("You must specify a device connection string!");
17 | return;
18 | }
19 |
20 | var device = DeviceClient.CreateFromConnectionString(args[0]);
21 |
22 | Console.WriteLine("Starting simulated generator, press enter to exit!");
23 | RunSimulatedGeneratorDataAsync(device);
24 | Console.ReadLine();
25 | }
26 |
27 | private static async System.Threading.Tasks.Task RunSimulatedGeneratorDataAsync(DeviceClient device)
28 | {
29 | var rand = new Random();
30 |
31 | var nextAnomalousEvent = DateTime.Now.AddSeconds(30);
32 |
33 | while (true)
34 | {
35 | var temperature = new TelemetryMessage
36 | {
37 | SensorName = "Temperature",
38 | Value = rand.Next(50, 100)
39 | };
40 |
41 | var rpms = new TelemetryMessage
42 | {
43 | SensorName = "RPMs",
44 | Value = rand.Next(500, 600)
45 | };
46 |
47 | if (nextAnomalousEvent < DateTime.Now)
48 | {
49 | Console.WriteLine("**GENERATING ANOMALY!");
50 | temperature.Value = rand.Next(200, 250);
51 | rpms.Value = rand.Next(750, 900);
52 | nextAnomalousEvent = DateTime.Now.AddSeconds(30);
53 | }
54 | else
55 | {
56 | Console.WriteLine("Sending normal message...");
57 | }
58 |
59 | await SendMessageTo(device, temperature);
60 | await SendMessageTo(device, rpms);
61 |
62 | Thread.Sleep(1000);
63 | }
64 | }
65 |
66 | private static async Task SendMessageTo(DeviceClient device, TelemetryMessage telemetry)
67 | {
68 | var json = JsonConvert.SerializeObject(telemetry);
69 | var message = new Message(Encoding.ASCII.GetBytes(json));
70 |
71 | await device.SendEventAsync(message);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/generator-sample/TelemtryMessage.cs:
--------------------------------------------------------------------------------
1 | namespace GeneratorSample
2 | {
3 | public class TelemetryMessage
4 | {
5 | public string SensorName { get; internal set; }
6 | public int Value { get; internal set; }
7 | }
8 | }
--------------------------------------------------------------------------------
/generator-sample/generator-sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | GeneratorSample
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/machine-sample/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
332 |
333 | cert.cer
--------------------------------------------------------------------------------
/machine-sample/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/generator-sample.dll",
14 | "args": ["HostName=globomanticshub.azure-devices.net;DeviceId=test-machine;SharedAccessKey=BJsBjcLPVcoMkt9VZV1/9Gw9oQ39VZVhcXElcNrt2IU="],
15 | "cwd": "${workspaceFolder}",
16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17 | "console": "internalConsole",
18 | "stopAtEntry": false,
19 | "internalConsoleOptions": "openOnSessionStart"
20 | },
21 | {
22 | "name": ".NET Core Attach",
23 | "type": "coreclr",
24 | "request": "attach",
25 | "processId": "${command:pickProcess}"
26 | }
27 | ,]
28 | }
--------------------------------------------------------------------------------
/machine-sample/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/generator-sample.csproj"
11 | ],
12 | "problemMatcher": "$msCompile"
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/machine-sample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using Microsoft.Azure.Devices.Client;
6 | using Newtonsoft.Json;
7 |
8 | namespace MachineSample
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | if (args == null || args.Length < 1)
15 | {
16 | Console.WriteLine("You must specify a device connection string!");
17 | return;
18 | }
19 |
20 | var device = DeviceClient.CreateFromConnectionString(args[0]);
21 |
22 | Console.WriteLine("Starting simulated machine, press enter to exit!");
23 | RunSimulatedMachine(device);
24 | Console.ReadLine();
25 | }
26 |
27 | private static async Task RunSimulatedMachine(DeviceClient device)
28 | {
29 | var rand = new Random();
30 |
31 | var startTime = DateTime.Now.AddMinutes(1);
32 | while (DateTime.Now < startTime)
33 | {
34 | await SendStatus(device,
35 | temperature: RandomBetween(rand, 70, 71),
36 | oilPressure: 0,
37 | coolantLevel: 75,
38 | vibrationLevel: 0);
39 |
40 | Thread.Sleep(1000);
41 | }
42 |
43 | //var eventTime = DateTime.Now.AddMinutes(10);
44 | var eventTime = DateTime.Now.AddMinutes(2);
45 | while (DateTime.Now < eventTime)
46 | {
47 | await SendStatus(device,
48 | temperature: RandomBetween(rand, 125, 127),
49 | oilPressure: RandomBetween(rand, 50, 55),
50 | coolantLevel: 75,
51 | vibrationLevel: RandomBetween(rand, 25, 30));
52 |
53 | Thread.Sleep(1000);
54 | }
55 |
56 | //The BANG
57 | await SendStatus(device,
58 | temperature: RandomBetween(rand, 125, 127),
59 | oilPressure: RandomBetween(rand, 50, 55),
60 | coolantLevel: 75,
61 | vibrationLevel: 100);
62 |
63 | Thread.Sleep(1000);
64 |
65 | var catastrophicEventTime = DateTime.Now.AddMinutes(2);
66 | var temperature = 127m;
67 | var oilPressure = 55m;
68 | var coolantLevel = 75m;
69 | var vibrationLevel = 50m;
70 | while (DateTime.Now < catastrophicEventTime)
71 | {
72 | coolantLevel = RandomBetween(rand, coolantLevel-2, coolantLevel);
73 |
74 | if (coolantLevel < 50)
75 | {
76 | temperature = RandomBetween(rand, temperature, temperature+5);
77 | oilPressure = RandomBetween(rand, oilPressure, oilPressure+5);
78 | vibrationLevel = RandomBetween(rand, vibrationLevel, vibrationLevel+2);
79 | }
80 | else
81 | {
82 | temperature = RandomBetween(rand, 125, 127);
83 | oilPressure = RandomBetween(rand, 50, 55);
84 | vibrationLevel = RandomBetween(rand, 40, 50);
85 | }
86 |
87 | await SendStatus(device,
88 | temperature,
89 | oilPressure,
90 | coolantLevel,
91 | vibrationLevel);
92 |
93 | Thread.Sleep(1000);
94 | }
95 |
96 | DrawExplosion();
97 | }
98 |
99 | private static async Task SendStatus(DeviceClient device, decimal temperature, decimal oilPressure, decimal coolantLevel, decimal vibrationLevel)
100 | {
101 | Console.Write(".");
102 | await SendMessageTo(device, new TelemetryMessage
103 | {
104 | SensorName = "Temperature",
105 | Value = temperature
106 | });
107 | await SendMessageTo(device, new TelemetryMessage
108 | {
109 | SensorName = "OilPressure",
110 | Value = oilPressure
111 | });
112 | await SendMessageTo(device, new TelemetryMessage
113 | {
114 | SensorName = "CoolantLevel",
115 | Value = coolantLevel
116 | });
117 | await SendMessageTo(device, new TelemetryMessage
118 | {
119 | SensorName = "VibrationLevel",
120 | Value = vibrationLevel
121 | });
122 | }
123 |
124 | private static void DrawExplosion()
125 | {
126 | Console.WriteLine("");
127 | Console.WriteLine("-------------------------------------------------");
128 | Console.WriteLine("Bob: Hey, should it be smoking like that?");
129 | Console.WriteLine("Steve: No, probably not...");
130 | Console.WriteLine("-------------------------------------------------");
131 | Console.WriteLine(@"
132 | _.-^^---....,,--
133 | _-- --_
134 | < BOOOOOOM >)
135 | | |
136 | \._ _./
137 | ```--. . , ; .--'''
138 | | | |
139 | .-=|| | |=-.
140 | `-=*******=-'
141 | | ; :|
142 | _____.,-----------,._____
143 | ");
144 | Console.WriteLine("-------------------------------------------------");
145 | Console.WriteLine("(no virtual beings were harmed in this catastrophic event)");
146 | }
147 |
148 | private static decimal RandomBetween(Random rand, decimal lowValue, decimal highValue)
149 | {
150 | return lowValue + (decimal)rand.NextDouble() * (highValue - lowValue);
151 | }
152 |
153 | private static async Task SendMessageTo(DeviceClient device, TelemetryMessage telemetry)
154 | {
155 | var json = JsonConvert.SerializeObject(telemetry);
156 | var message = new Message(Encoding.ASCII.GetBytes(json));
157 |
158 | await device.SendEventAsync(message);
159 | }
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/machine-sample/TelemtryMessage.cs:
--------------------------------------------------------------------------------
1 | namespace MachineSample
2 | {
3 | public class TelemetryMessage
4 | {
5 | public string SensorName { get; internal set; }
6 | public decimal Value { get; internal set; }
7 | }
8 | }
--------------------------------------------------------------------------------
/machine-sample/machine-sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | MachineSample
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------