本文整理汇总了C#中Microsoft.Azure.Devices.Device类的典型用法代码示例。如果您正苦于以下问题:C# Device类的具体用法?C# Device怎么用?C# Device使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Device类属于Microsoft.Azure.Devices命名空间,在下文中一共展示了Device类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateDeviceConnectionString
private String CreateDeviceConnectionString(Device device)
{
StringBuilder deviceConnectionString = new StringBuilder();
var hostName = String.Empty;
var tokenArray = iotHubConnectionString.Split(';');
for (int i = 0; i < tokenArray.Length; i++)
{
var keyValueArray = tokenArray[i].Split('=');
if (keyValueArray[0] == "HostName")
{
hostName = tokenArray[i] + ';';
break;
}
}
if (!String.IsNullOrWhiteSpace(hostName))
{
deviceConnectionString.Append(hostName);
deviceConnectionString.AppendFormat("DeviceId={0}", device.Id);
if (device.Authentication != null &&
device.Authentication.SymmetricKey != null)
{
deviceConnectionString.AppendFormat(";SharedAccessKey={0}", device.Authentication.SymmetricKey.PrimaryKey);
}
if (this.protocolGatewayHostName.Length > 0)
{
deviceConnectionString.AppendFormat(";GatewayHostName=ssl://{0}:8883", this.protocolGatewayHostName);
}
}
return deviceConnectionString.ToString();
}
开发者ID:Fricsay,项目名称:azure-iot-sdks,代码行数:35,代码来源:DevicesProcessor.cs
示例2: DeviceAuthenticationGoodAuthConfigTest2
public async Task DeviceAuthenticationGoodAuthConfigTest2()
{
var deviceGoodAuthConfig = new Device("123")
{
ConnectionState = DeviceConnectionState.Connected,
Authentication = new AuthenticationMechanism()
{
SymmetricKey = null,
X509Thumbprint = new X509Thumbprint()
{
PrimaryThumbprint = "921BC9694ADEB8929D4F7FE4B9A3A6DE58B0790B",
SecondaryThumbprint = "921BC9694ADEB8929D4F7FE4B9A3A6DE58B0790B"
}
}
};
var restOpMock = new Mock<IHttpClientHelper>();
restOpMock.Setup(
restOp =>
restOp.PutAsync(It.IsAny<Uri>(), It.IsAny<Device>(), It.IsAny<PutOperationType>(),
It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(),
It.IsAny<CancellationToken>())).ReturnsAsync(deviceGoodAuthConfig);
var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
await registryManager.AddDeviceAsync(deviceGoodAuthConfig);
}
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:25,代码来源:DeviceAuthenticationTests.cs
示例3: AddDeviceAsync
public override Task<Device> AddDeviceAsync(Device device, CancellationToken cancellationToken)
{
this.EnsureInstanceNotClosed();
if (device == null)
{
throw new ArgumentNullException("device");
}
if (string.IsNullOrWhiteSpace(device.Id))
{
throw new ArgumentException(ApiResources.DeviceIdNotSet);
}
if (!string.IsNullOrEmpty(device.ETag))
{
throw new ArgumentException(ApiResources.ETagSetWhileRegisteringDevice);
}
// auto generate keys if not specified
if (device.Authentication == null)
{
device.Authentication = new AuthenticationMechanism();
}
ValidateDeviceAuthentication(device);
return this.httpClientHelper.PutAsync(GetRequestUri(device.Id), device, PutOperationType.CreateEntity, null, cancellationToken);
}
开发者ID:jasoneilts,项目名称:azure-iot-sdks,代码行数:29,代码来源:HttpRegistryManager.cs
示例4: ExportImportDevice
/// <summary>
/// ctor which takes a Device object along with import mode
/// </summary>
/// <param name="device"></param>
/// <param name="importmode"></param>
public ExportImportDevice(Device device, ImportMode importmode)
{
this.Id = device.Id;
this.ETag = device.ETag;
this.ImportMode = importmode;
this.Status = device.Status;
this.StatusReason = device.StatusReason;
this.Authentication = device.Authentication;
}
开发者ID:MSFTImagine,项目名称:azure-iot-sdks,代码行数:14,代码来源:ExportImportDevice.cs
示例5: RegisterDeviceAsyncTest
public async Task RegisterDeviceAsyncTest()
{
var deviceToReturn = new Device("123") { ConnectionState = DeviceConnectionState.Connected };
var restOpMock = new Mock<IHttpClientHelper>();
restOpMock.Setup(restOp => restOp.PutAsync(It.IsAny<Uri>(), It.IsAny<Device>(), It.IsAny<PutOperationType>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), It.IsAny<CancellationToken>())).ReturnsAsync(deviceToReturn);
var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
var returnedDevice = await registryManager.AddDeviceAsync(deviceToReturn);
Assert.AreSame(deviceToReturn, returnedDevice);
restOpMock.VerifyAll();
}
开发者ID:stefangordon,项目名称:azure-iot-sdks,代码行数:11,代码来源:RegistryManagerTests.cs
示例6: RegisterDeviceAsync
private static async Task RegisterDeviceAsync()
{
try
{
device = await registryManager.AddDeviceAsync(new Device(deviceId));
}
catch (DeviceAlreadyExistsException)
{
device = await registryManager.GetDeviceAsync(deviceId);
}
deviceKey = device.Authentication.SymmetricKey.PrimaryKey;
}
开发者ID:ritasker,项目名称:Presentations,代码行数:12,代码来源:Program.cs
示例7: GetDeviceAsyncTest
public async Task GetDeviceAsyncTest()
{
const string DeviceId = "123";
var deviceToReturn = new Device(DeviceId) { ConnectionState = DeviceConnectionState.Connected };
var restOpMock = new Mock<IHttpClientHelper>();
restOpMock.Setup(restOp => restOp.GetAsync<Device>(It.IsAny<Uri>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), null, false, It.IsAny<CancellationToken>())).ReturnsAsync(deviceToReturn);
var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
var device = await registryManager.GetDeviceAsync(DeviceId);
Assert.AreSame(deviceToReturn, device);
restOpMock.VerifyAll();
}
开发者ID:stefangordon,项目名称:azure-iot-sdks,代码行数:12,代码来源:RegistryManagerTests.cs
示例8: DeviceCreatedForm
public DeviceCreatedForm(Device device)
{
InitializeComponent();
if (device.Authentication.SymmetricKey != null)
{
richTextBox.Text = $"ID={device.Id}\nPrimaryKey={device.Authentication.SymmetricKey.PrimaryKey}\nSecondaryKey={device.Authentication.SymmetricKey.SecondaryKey}";
}
else if (device.Authentication.X509Thumbprint != null)
{
richTextBox.Text = $"ID={device.Id}\nPrimaryThumbPrint={device.Authentication.X509Thumbprint.PrimaryThumbprint}\nSecondaryThumbPrint={device.Authentication.X509Thumbprint.SecondaryThumbprint}";
}
}
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:12,代码来源:DeviceCreatedForm.cs
示例9: createButton_Click
private async void createButton_Click(object sender, EventArgs e)
{
try
{
if (String.IsNullOrEmpty(deviceIDTextBox.Text))
{
throw new ArgumentNullException("DeviceId cannot be empty!");
}
var device = new Device(deviceIDTextBox.Text);
device.Authentication = new AuthenticationMechanism();
if (keysRadioButton.Checked)
{
device.Authentication.SymmetricKey.PrimaryKey = primaryKeyTextBox.Text;
device.Authentication.SymmetricKey.SecondaryKey = secondaryKeyTextBox.Text;
}
else if (x509RadioButton.Checked)
{
device.Authentication.SymmetricKey = null;
device.Authentication.X509Thumbprint = new X509Thumbprint()
{
PrimaryThumbprint = primaryKeyTextBox.Text,
SecondaryThumbprint = secondaryKeyTextBox.Text
};
}
await registryManager.AddDeviceAsync(device);
var deviceCreated = new DeviceCreatedForm(device);
deviceCreated.ShowDialog();
this.Close();
}
catch (Exception ex)
{
using (new CenterDialog(this))
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:42,代码来源:CreateDeviceForm.cs
示例10: createButton_Click
private async void createButton_Click(object sender, EventArgs e)
{
try
{
Device device = new Device(deviceIDTextBox.Text);
await registryManager.AddDeviceAsync(device);
device = await registryManager.GetDeviceAsync(device.Id);
device.Authentication.SymmetricKey.PrimaryKey = primaryKeyTextBox.Text;
device.Authentication.SymmetricKey.SecondaryKey = secondaryKeyTextBox.Text;
device = await registryManager.UpdateDeviceAsync(device);
string deviceInfo = String.Format("ID={0}\nPrimaryKey={1}\nSecondaryKey={2}", device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);
DeviceCreatedForm deviceCreated = new DeviceCreatedForm(device.Id, device.Authentication.SymmetricKey.PrimaryKey, device.Authentication.SymmetricKey.SecondaryKey);
deviceCreated.ShowDialog();
this.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
开发者ID:neo7206,项目名称:azure-iot-sdks,代码行数:23,代码来源:CreateDeviceForm.cs
示例11: AddDeviceAsync
/// <summary>
/// Register a new device with the system
/// </summary>
/// <param name="device">
/// The Device object to be registered.
/// </param>
/// <param name="cancellationToken">
/// The token which allows the the operation to be cancelled.
/// </param>
/// <returns>echoes back the Device object with the generated keys and etags</returns>
public abstract Task<Device> AddDeviceAsync(Device device, CancellationToken cancellationToken);
开发者ID:Fricsay,项目名称:azure-iot-sdks,代码行数:11,代码来源:RegistryManager.cs
示例12: ValidateDeviceAuthentication
static void ValidateDeviceAuthentication(Device device)
{
if (device.Authentication.SymmetricKey != null)
{
// either both keys should be specified or neither once should be specified (in which case
// we will create both the keys in the service)
if (string.IsNullOrWhiteSpace(device.Authentication.SymmetricKey.PrimaryKey) ^ string.IsNullOrWhiteSpace(device.Authentication.SymmetricKey.SecondaryKey))
{
throw new ArgumentException(ApiResources.DeviceKeysInvalid);
}
}
}
开发者ID:jasoneilts,项目名称:azure-iot-sdks,代码行数:12,代码来源:HttpRegistryManager.cs
示例13: RemoveDeviceAsync
public override Task RemoveDeviceAsync(Device device)
{
return this.RemoveDeviceAsync(device, CancellationToken.None);
}
开发者ID:jasoneilts,项目名称:azure-iot-sdks,代码行数:4,代码来源:HttpRegistryManager.cs
示例14: RemoveDeviceAsync
/// <summary>
/// Deletes a previously registered device from the system.
/// </summary>
/// <param name="device">
/// The device to be deleted.
/// </param>
/// <param name="cancellationToken">
/// The token which allows the the operation to be cancelled.
/// </param>
public abstract Task RemoveDeviceAsync(Device device, CancellationToken cancellationToken);
开发者ID:Fricsay,项目名称:azure-iot-sdks,代码行数:10,代码来源:RegistryManager.cs
示例15: DeleteDevices2AsyncWithDeviceIdNullTest
public async Task DeleteDevices2AsyncWithDeviceIdNullTest()
{
var goodDevice = new Device("123") { ConnectionState = DeviceConnectionState.Connected, ETag = "234" };
var badDevice = new Device();
var restOpMock = new Mock<IHttpClientHelper>();
var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
await registryManager.RemoveDevices2Async(new List<Device>() { goodDevice, badDevice });
Assert.Fail("DeleteDevices API did not throw exception when deviceId was null.");
}
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:9,代码来源:RegistryManagerTests.cs
示例16: CreateDevices
static async Task CreateDevices(Options options)
{
if (string.IsNullOrEmpty(options.DeviceKey))
{
throw new ArgumentException("Device key was not specified.");
}
RegistryManager registryManager = RegistryManager.CreateFromConnectionString(options.IotHubConnectionString);
await registryManager.OpenAsync();
const int BatchSize = 500;
var tasks = new List<Task>(BatchSize);
foreach (List<int> pack in Enumerable.Range(options.DeviceStartingFrom, options.CreateDeviceCount).InSetsOf(BatchSize))
{
tasks.Clear();
Console.WriteLine("Creating devices {0}..{1}", pack.First(), pack.Last());
foreach (int i in pack)
{
string deviceId = string.Format(options.DeviceNamePattern, i);
var device = new Device(deviceId)
{
Authentication = new AuthenticationMechanism
{
SymmetricKey = new SymmetricKey
{
PrimaryKey = options.DeviceKey,
SecondaryKey = options.DeviceKey2
}
}
};
tasks.Add(registryManager.AddDeviceAsync(device));
}
await Task.WhenAll(tasks);
}
}
开发者ID:kdotchkoff,项目名称:azure-iot-protocol-gateway,代码行数:34,代码来源:Program.cs
示例17: UpdateDeviceAsync
public override Task<Device> UpdateDeviceAsync(Device device, bool forceUpdate)
{
return this.UpdateDeviceAsync(device, forceUpdate, CancellationToken.None);
}
开发者ID:jasoneilts,项目名称:azure-iot-sdks,代码行数:4,代码来源:HttpRegistryManager.cs
示例18: RegisterDevices2AsyncWithETagsSetTest
public async Task RegisterDevices2AsyncWithETagsSetTest()
{
var goodDevice = new Device("123") { ConnectionState = DeviceConnectionState.Connected };
var badDevice = new Device("234") { ConnectionState = DeviceConnectionState.Connected, ETag = "234" };
var restOpMock = new Mock<IHttpClientHelper>();
var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
await registryManager.AddDevices2Async(new List<Device>() { goodDevice, badDevice });
Assert.Fail("RegisterDevices API did not throw exception when ETag was used.");
}
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:9,代码来源:RegistryManagerTests.cs
示例19: DeviceAuthenticationBadAuthConfigTest7
public async Task DeviceAuthenticationBadAuthConfigTest7()
{
var deviceBadAuthConfig = new Device("123")
{
ConnectionState = DeviceConnectionState.Connected,
Authentication = new AuthenticationMechanism()
{
SymmetricKey = new SymmetricKey()
{
PrimaryKey = CryptoKeyGenerator.GenerateKey(32),
SecondaryKey = null
},
X509Thumbprint = null
}
};
var restOpMock = new Mock<IHttpClientHelper>();
restOpMock.Setup(
restOp =>
restOp.PutAsync(It.IsAny<Uri>(), It.IsAny<Device>(), It.IsAny<PutOperationType>(),
It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(),
It.IsAny<CancellationToken>())).ReturnsAsync(deviceBadAuthConfig);
var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
await registryManager.AddDeviceAsync(deviceBadAuthConfig);
}
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:25,代码来源:DeviceAuthenticationTests.cs
示例20: UpdateDevices2AsyncWithNullDeviceTest
public async Task UpdateDevices2AsyncWithNullDeviceTest()
{
var goodDevice = new Device("123") { ConnectionState = DeviceConnectionState.Connected, ETag = "234" };
Device badDevice = null;
var restOpMock = new Mock<IHttpClientHelper>();
var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
await registryManager.UpdateDevices2Async(new List<Device>() { goodDevice, badDevice });
Assert.Fail("UpdateDevices API did not throw exception when Null device was used.");
}
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:9,代码来源:RegistryManagerTests.cs
注:本文中的Microsoft.Azure.Devices.Device类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论