This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
const filterMap = (om, dtmi, kind) => Object.entries(om).filter(e => e[1].EntityKind === kind && e[1].ChildOf === dtmi).map(e => e[1]) | |
export class InterfaceInfo { | |
constructor (om, dtmi) { | |
/** @type import("./DtdlOM").DtdlObjectModel */ | |
this.om = om | |
this.telemetries = filterMap(om, dtmi, "Telemetry") | |
this.properties = filterMap(om, dtmi, "Property") | |
this.commands = filterMap(om, dtmi, "Command") | |
this.components = filterMap(om, dtmi, "Component") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
var number = 45673; | |
var multiples = Multiples(number); | |
Console.WriteLine($"{number} is " + | |
$"{(multiples.Any() ? "not " : "")}prime"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$root = gci "cert:\CurrentUser\my\<ca-thumbprint>" | |
Write-Host "Creating a Leaf Certificate chained to root:" | |
Write-Host " Root Subject:" $root.Subject.Substring(3) | |
Write-Host " Root Thumprint:" $root.Thumbprint | |
$certName = Read-Host "Device ID?" | |
$keyPwd = Read-Host "Key Password?" -AsSecureString | |
$cert = New-SelfSignedCertificate ` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN CERTIFICATE----- | |
MIICyzCCAbOgAwIBAgIUPh/CfFW2v2IAAHPPRoOn2DTd86UwDQYJKoZIhvcNAQEL | |
BQAwFTETMBEGA1UEAwwKcmlkb2NhZnkyMjAeFw0yMTA5MjEwNDE0NDdaFw0yMzAy | |
MDMwNDE0NDdaMBUxEzARBgNVBAMMCnJpZG9jYWZ5MjIwggEiMA0GCSqGSIb3DQEB | |
AQUAA4IBDwAwggEKAoIBAQCrXflb9C84jYfU6VEK0gwv3ejvkv7dFkxhu1SxU71x | |
nabSen8zhswq1o5L2ogR97eInZXV76AXqvJ51gaF/yCIktFsIIALKWL2Lmihu79P | |
UAY2+5lbFji+W95yPhta8EPywjm7OIUQvj9cuHxy1FLvY1bDE07axRkALgmptZfX | |
EH8VSWwBQaJKw7Tlo5+27CyvraY2+Q/kOU9ibBfGhEaeK/VG9RkwXQlUmxg0IOQ3 | |
uJj7E5K1T7nJBr/f1LR+fAqt/6g5Bv096mrYG8LpFwK6sDQPz8/mYzPe98zpK1KP | |
6VEYOxf+s6n3VJCVY/86UyaJvWawe59yRYmNXH8e99HJAgMBAAGjEzARMA8GA1Ud |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DeviceHttpDemo; | |
public class Config | |
{ | |
public string host = ""; | |
public string did = ""; | |
public string key = ""; | |
} | |
internal class SasAuth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openapi: '3.0.2' | |
info: | |
title: MyIoTAPI | |
version: '1.0' | |
paths: | |
/readDeviceInfo: | |
get: | |
operationId: "readDeviceInfo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MQTTnet.Client.Options; | |
using System.Text; | |
namespace demistify_iothub | |
{ | |
public static class MqttNetExtensions | |
{ | |
public static MqttClientOptionsBuilder WithAzureIoTHubCredentialsSas(this MqttClientOptionsBuilder builder, string hostName, string deviceId, string sasKey, string modelId = "", int sasMinutes = 60) | |
{ | |
(string username, string password) = SasAuth.GenerateHubSasCredentials(hostName, deviceId, sasKey, modelId, sasMinutes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static MqttClientOptionsBuilder WithAzureIoTHubCredentialsSas(this MqttClientOptionsBuilder builder, string hostName, string deviceId, string sasKey, string modelId, int sasMinutes = 60) | |
{ | |
(string username, string password) = SasAuth.GenerateHubSasCredentials(hostName, deviceId, sasKey, modelId, sasMinutes); | |
builder | |
.WithTcpServer(hostName, 8883) | |
.WithTls() | |
.WithClientId($"{deviceId}") | |
.WithCredentials(username, password); | |
return builder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Rido.MqttCore | |
{ | |
public class SasAuth | |
{ | |
private const string apiversion_2020_09_30 = "2020-09-30"; | |
public static string GetUserName(string hostName, string deviceId, string modelId = "") => | |
$"{hostName}/{deviceId}/?api-version={apiversion_2020_09_30}&model-id={modelId}"; | |
private static string Sign(string requestString, string key) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$root = gci "cert:\CurrentUser\my\d8c5cd7502cd699783d9b2c031636ca48ae4229f" | |
$rootSubject = $root.Subject.Substring(3) | |
Write-Host "Root Certificate" $root.Thumbprint | |
$certName = "myCustomCert" | |
$cert = New-SelfSignedCertificate ` | |
-CertStoreLocation cert:\CurrentUser\my ` |
NewerOlder