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


C# Command.Parameter方法代码示例

本文整理汇总了C#中Command.Parameter方法的典型用法代码示例。如果您正苦于以下问题:C# Command.Parameter方法的具体用法?C# Command.Parameter怎么用?C# Command.Parameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Command的用法示例。


在下文中一共展示了Command.Parameter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        static async Task Run()
        {
            try
            {
                // create a ClientService used to communicate with the DeviceHive service
                // insert your assigned DeviceHive service URL, username and password here
                var service = new RestfulClientService("http://pg.devicehive.com/api", "admin", "");

                // get information about VirtualLed device
                var device = await service.GetDeviceAsync(new Guid("E50D6085-2ABA-48E9-B1C3-73C673E414BE"));
                if (device == null)
                {
                    Console.WriteLine("VirtualLed device does not exist on the server, please run VirtualLed device first!");
                    Console.ReadKey();
                    return;
                }
                Console.WriteLine("Found VirtualLed device with status: " + device.Status);

                // get information about current LED state
                var equipmentState = await service.GetEquipmentStateAsync(device.Id.Value);
                var ledEquipmentState = equipmentState.FirstOrDefault(e => e.Id == LED_CODE);
                if (ledEquipmentState != null)
                {
                    Console.WriteLine("Current state of the VirtualLed: " + ledEquipmentState.GetParameter<int>("state"));
                }

                // start the device notification handling task
                var cancellationSource = new CancellationTokenSource();
                var token = cancellationSource.Token;

                service.PollNotifications(HandleNotifications, device.Id.Value, DateTime.UtcNow, token);

                // read user input to send corresponding commands to the VirtualLed device
                Console.WriteLine("\nPlease enter a desired state of the led (either 0 or 1) or ESC to exit\n");
                while (true)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                        break;

                    if (key.KeyChar == '0' || key.KeyChar == '1')
                    {
                        Console.WriteLine(string.Format("Sending UpdateLedState command with state: {0}", key.KeyChar));
                        var command = new Command("UpdateLedState");
                        command.Parameter("equipment", LED_CODE);
                        command.Parameter("state", key.KeyChar);
                        await service.SendCommandAsync(device.Id.Value, command);
                    }
                }

                // stop the notification handling task
                cancellationSource.Cancel();
            }
            catch (Exception ex)
            {
                // handle the error
                Console.WriteLine("Error: " + ex);
                Console.ReadKey();
            }
        }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:60,代码来源:Program.cs

示例2: VirtualLedClientRoutine

        static async Task VirtualLedClientRoutine()
        {
            // create a DeviceHiveConnectionInfo object
            // insert your assigned DeviceHive service URL, username and password here
            var connectionInfo = new DeviceHiveConnectionInfo("http://localhost/DeviceHive.API", "dhadmin", "dhadmin_#911");

            // create a DeviceHiveClient object used to communicate with the DeviceHive service
            var client = new DeviceHiveClient(connectionInfo);

            // get information about the VirtualLed device
            var deviceGuid = "E50D6085-2ABA-48E9-B1C3-73C673E414BE";
            var device = await client.GetDevice(deviceGuid);
            if (device == null)
            {
                Console.WriteLine("VirtualLed device does not exist on the server, please run VirtualLed device first!");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("Found VirtualLed device with status: " + device.Status);

            // get information about current LED state
            var equipmentState = await client.GetEquipmentState(device.Id);
            var ledEquipmentState = equipmentState.FirstOrDefault(e => e.Id == LED_CODE);
            if (ledEquipmentState != null)
            {
                Console.WriteLine("Current state of the VirtualLed: " + ledEquipmentState.GetParameter<int>("state"));
            }

            // subscribe to device notifications
            var subscription = await client.AddNotificationSubscription(new[] { deviceGuid }, null, HandleNotification);

            // read user input to send corresponding commands to the VirtualLed device
            Console.WriteLine("\nPlease enter a desired state of the led (either 0 or 1) or ESC to exit\n");
            while (true)
            {
                var key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Escape)
                    break;

                if (key.KeyChar == '0' || key.KeyChar == '1')
                {
                    // send a command to the VirtualLed device to switch the LED state
                    Console.WriteLine(string.Format("Sending UpdateLedState command with state: {0}", key.KeyChar));
                    var command = new Command("UpdateLedState");
                    command.Parameter("equipment", LED_CODE);
                    command.Parameter("state", key.KeyChar);
                    await client.SendCommand(device.Id, command);
                }
            }

            // unsubscribe from notifications and dispose the client
            await client.RemoveSubscription(subscription);
            client.Dispose();
        }
开发者ID:EugeneTikhonov,项目名称:devicehive-.net,代码行数:54,代码来源:Program.cs

示例3: Main

        private const string LED_CODE = "LED";   // LED equipment code

        static void Main(string[] args)
        {
            try
            {
                // initialize logger
                log4net.Config.XmlConfigurator.Configure();

                // create a ClientService used to communicate with the DeviceHive service
                // insert your assigned DeviceHive service URL, username and password here
                var service = new RestfulClientService("http://localhost/DeviceHive.API", "dhadmin", "dhadmin_#911");

                // get information about VirtualLed device
                var deviceGuid = new Guid("E50D6085-2ABA-48E9-B1C3-73C673E414BE");
                var device = service.GetDevice(deviceGuid);
                if (device == null)
                {
                    Console.WriteLine("VirtualLed device does not exist on the server, please run VirtualLed device first!");
                    Console.ReadKey();
                    return;
                }
                Console.WriteLine("Found VirtualLed device with status: " + device.Status);

                // get information about current LED state
                var equipmentState = service.GetEquipmentState(device.Id.Value);
                var ledEquipmentState = equipmentState.FirstOrDefault(e => e.Id == LED_CODE);
                if (ledEquipmentState != null)
                {
                    Console.WriteLine("Current state of the VirtualLed: " + ledEquipmentState.GetParameter<int>("state"));
                }

                // subscribe to device notifications
                service.NotificationInserted += (s, e) => HandleNotification(e.Notification);
                service.SubscribeToNotifications(deviceGuid);
                
                service.ConnectionClosed += (s, e) =>
                {
                    if (service == null)
                        return;

                    while (true)
                    {
                        try
                        {
                            service.SubscribeToNotifications(deviceGuid);
                            break;
                        }
                        catch (ClientServiceException)
                        {
                            Thread.Sleep(100);
                        }
                    }                    
                };

                // read user input to send corresponding commands to the VirtualLed device
                Console.WriteLine("\nPlease enter a desired state of the led (either 0 or 1) or ESC to exit\n");
                while (true)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                        break;

                    if (key.KeyChar == '0' || key.KeyChar == '1')
                    {
                        Console.WriteLine(string.Format("Sending UpdateLedState command with state: {0}", key.KeyChar));
                        var command = new Command("UpdateLedState");
                        command.Parameter("equipment", LED_CODE);
                        command.Parameter("state", key.KeyChar);
                        service.SendCommand(device.Id.Value, command);
                    }
                }

                // unsubscribe from notifications
                service.Dispose();
                service = null;
            }
            catch (Exception ex)
            {
                // handle the error
                Console.WriteLine("Error: " + ex);
                Console.ReadKey();
            }
        }
开发者ID:oryol,项目名称:devicehive-.net,代码行数:84,代码来源:Program.cs


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