当前位置: 首页>>代码示例>>C#>>正文


C# Devices.Device类代码示例

本文整理汇总了C#中Microsoft.Azure.Devices.Device的典型用法代码示例。如果您正苦于以下问题:C# Device类的具体用法?C# Device怎么用?C# Device使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Device类属于Microsoft.Azure.Devices命名空间,在下文中一共展示了Device类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的Microsoft.Azure.Devices.Device类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。