本文整理汇总了C#中ICommandService.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# ICommandService.Execute方法的具体用法?C# ICommandService.Execute怎么用?C# ICommandService.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommandService
的用法示例。
在下文中一共展示了ICommandService.Execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommandQueuePoller
public static void CommandQueuePoller(ICommandService service)
{
//Trace.WriteLine("LogPoller has started -- seeing if there's anything in the queue for me!!");
CloudQueueMessage msg = CommandQueue.GetMessage();
if (msg == null)
{
//Trace.TraceInformation("COMMAND QUEUE nothing found - going back to sleep");
}
while (msg != null)
{
//do something
string myMessage = msg.AsString;
CommandQueue.DeleteMessage(msg);
Trace.TraceInformation("Got message {0}", myMessage);
//split the ID from the type -- first item is ID, second is type
string[] messageParts = myMessage.Split(new char[] {':'}, StringSplitOptions.RemoveEmptyEntries);
if (messageParts.Length!=2)
{
Trace.TraceError("COMMAND QUEUE message improperly formed. {0}", myMessage);
continue;
}
CloudBlockBlob theBlob = CommandBlobContainer.GetBlockBlobReference(messageParts[0]);
Type commandType = Type.GetType(messageParts[1]);
CommandBase theCommand = null;
using (MemoryStream msBlob = new MemoryStream())
{
byte[] logBytes = theBlob.DownloadByteArray();
msBlob.Write(logBytes, 0, logBytes.Length);
BinaryFormatter bf = new BinaryFormatter();
msBlob.Position = 0;
object theObject = bf.Deserialize(msBlob);
theCommand = Convert.ChangeType(theObject, commandType) as CommandBase;
}
if (theCommand != null)
{
service.Execute(theCommand);
}
else
{
Trace.TraceInformation("COMMAND BLOB Could not deserialize message from queue id {0}", myMessage);
}
msg = CommandQueue.GetMessage();
}
}