本文整理汇总了C#中IMessageHandler.Handle方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageHandler.Handle方法的具体用法?C# IMessageHandler.Handle怎么用?C# IMessageHandler.Handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessageHandler
的用法示例。
在下文中一共展示了IMessageHandler.Handle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleMessage
private static bool HandleMessage(Task<Message> task, IMessageHandler handler, IMessage message)
{
if (message != null)
{
message.Headers[SystemHeaders.MessageID] = task.Result.Id;
}
return handler.Handle(message);
}
示例2: TryHandleMessage
private void TryHandleMessage(IMessage msg, IMessageHandler h)
{
try
{
h.Handle(msg);
}
catch (MessageHandlerException ex)
{
Logger.Write(ex.ToString());
}
}
示例3: Run
public void Run()
{
// Client initialization
config = new NetPeerConfiguration("stryferpg");
client = new NetClient(config);
client.Start();
client.Connect("localhost", 1234);
handler = new LoginMessageHandler();
// Messages receipt
NetIncomingMessage message;
while (!stop)
{
while ((message = client.ReadMessage()) != null)
{
switch (message.MessageType)
{
case NetIncomingMessageType.Data:
SROrderMessage msg = NetworkSerializer.DeserializeObject<SROrderMessage>(message.ReadBytes(message.LengthBytes));
handler.Handle(msg);
break;
case NetIncomingMessageType.StatusChanged:
switch (message.SenderConnection.Status)
{
case NetConnectionStatus.Connected:
Console.WriteLine("Connected");
Console.WriteLine("Asking for server list...");
SRActionMessage action = new SRActionMessage(ActionType.GetServerList, ServiceType.Login);
SendMessage(action);
break;
}
break;
case NetIncomingMessageType.DebugMessage:
Console.WriteLine(message.ReadString());
break;
default:
Console.WriteLine("unhandled message with type: "
+ message.MessageType);
break;
}
}
Thread.Sleep(1);
}
}
示例4: SendMessage
public void SendMessage(IMessageHandler receiver, IMessage msg)
{
if(receiver == null)
throw new ArgumentNullException("receiver");
receiver.Handle(msg);
}