本文整理汇总了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();
}
}
示例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();
}
示例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();
}
}