本文整理汇总了C#中MessageHandler类的典型用法代码示例。如果您正苦于以下问题:C# MessageHandler类的具体用法?C# MessageHandler怎么用?C# MessageHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageHandler类属于命名空间,在下文中一共展示了MessageHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SocketClient
/// <summary>
/// Constructor for client support
/// </summary>
/// <param name="sizeOfRawBuffer"> The size of the raw buffer </param>
/// <param name="userArg"> A Reference to the Users arguments </param>
/// <param name="messageHandler"> Reference to the user defined message handler method </param>
/// <param name="closeHandler"> Reference to the user defined close handler method </param>
/// <param name="errorHandler"> Reference to the user defined error handler method </param>
public SocketClient(int sizeOfRawBuffer, object userArg,
MessageHandler messageHandler, CloseHandler closeHandler,
ErrorHandler errorHandler, ConnectHandler connectHandler)
{
// Create the raw buffer
this.SizeOfRawBuffer = sizeOfRawBuffer;
this.RawBuffer = new Byte[this.SizeOfRawBuffer];
// Save the user argument
this.userArg = userArg;
// Set the handler methods
this.messageHandler = messageHandler;
this.closeHandler = closeHandler;
this.errorHandler = errorHandler;
this.connectHandler = connectHandler;
// Set the async socket method handlers
this.callbackReadMethod = new AsyncCallback(ReceiveComplete);
this.callbackWriteMethod = new AsyncCallback(SendComplete);
this.callbackWriteHeadMethod = new AsyncCallback(SendHead);
this.m_Connected = true;
// Init the dispose flag
this.disposed = false;
}
示例2: StartConsumers
static void StartConsumers()
{
var messageHandler = new MessageHandler();
//Start four consumers.
var consumer1 = new Consumer("Consumer1", "group1").Subscribe("SampleTopic").Start(messageHandler);
var consumer2 = new Consumer("Consumer2", "group1").Subscribe("SampleTopic").Start(messageHandler);
var consumer3 = new Consumer("Consumer3", "group1").Subscribe("SampleTopic").Start(messageHandler);
var consumer4 = new Consumer("Consumer4", "group1").Subscribe("SampleTopic").Start(messageHandler);
//Below to wait for consumer balance.
var scheduleService = ObjectContainer.Resolve<IScheduleService>();
var waitHandle = new ManualResetEvent(false);
var taskId = scheduleService.ScheduleTask(() =>
{
var c1AllocatedQueueIds = consumer1.GetCurrentQueues().Select(x => x.QueueId);
var c2AllocatedQueueIds = consumer2.GetCurrentQueues().Select(x => x.QueueId);
var c3AllocatedQueueIds = consumer3.GetCurrentQueues().Select(x => x.QueueId);
var c4AllocatedQueueIds = consumer4.GetCurrentQueues().Select(x => x.QueueId);
if (c1AllocatedQueueIds.Count() == 1 && c2AllocatedQueueIds.Count() == 1 && c3AllocatedQueueIds.Count() == 1 && c4AllocatedQueueIds.Count() == 1)
{
Console.WriteLine(string.Format("Consumer message queue allocation result: c1:{0}, c2:{1}, c3:{2}, c4:{3}",
string.Join(",", c1AllocatedQueueIds),
string.Join(",", c2AllocatedQueueIds),
string.Join(",", c3AllocatedQueueIds),
string.Join(",", c4AllocatedQueueIds)));
waitHandle.Set();
}
}, 1000, 1000);
waitHandle.WaitOne();
scheduleService.ShutdownTask(taskId);
}
示例3: StartConsumers
static void StartConsumers()
{
var messageHandler = new MessageHandler();
//Start four consumers.
var consumerSetting = new ConsumerSetting { HeartbeatBrokerInterval = 1000, UpdateTopicQueueCountInterval = 1000, RebalanceInterval = 1000 };
var consumer1 = new Consumer("Consumer1", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
var consumer2 = new Consumer("Consumer2", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
var consumer3 = new Consumer("Consumer3", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
var consumer4 = new Consumer("Consumer4", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
//Below to wait for consumer balance.
_logger.Info("Start consumer load balance, please wait for a moment.");
var scheduleService = ObjectContainer.Resolve<IScheduleService>();
var waitHandle = new ManualResetEvent(false);
var taskId = scheduleService.ScheduleTask("WaitQueueAllocationComplete", () =>
{
var c1AllocatedQueueIds = consumer1.GetCurrentQueues().Select(x => x.QueueId);
var c2AllocatedQueueIds = consumer2.GetCurrentQueues().Select(x => x.QueueId);
var c3AllocatedQueueIds = consumer3.GetCurrentQueues().Select(x => x.QueueId);
var c4AllocatedQueueIds = consumer4.GetCurrentQueues().Select(x => x.QueueId);
if (c1AllocatedQueueIds.Count() == 1 && c2AllocatedQueueIds.Count() == 1 && c3AllocatedQueueIds.Count() == 1 && c4AllocatedQueueIds.Count() == 1)
{
_logger.Info(string.Format("Consumer load balance finished. Queue allocation result: c1:{0}, c2:{1}, c3:{2}, c4:{3}",
string.Join(",", c1AllocatedQueueIds),
string.Join(",", c2AllocatedQueueIds),
string.Join(",", c3AllocatedQueueIds),
string.Join(",", c4AllocatedQueueIds)));
waitHandle.Set();
}
}, 1000, 1000);
waitHandle.WaitOne();
scheduleService.ShutdownTask(taskId);
}
示例4: Subscribe
public IDisposable Subscribe(MessageHandler messageHandler)
{
lock (_handlers)
{
_handlers.Add(messageHandler);
_handlersSnapshot = _handlers.ToArray();
if (_underlying == null)
{
_underlying = OnRegister(message =>
{
lock (_handlers)
{
foreach (var handler in _handlersSnapshot)
{
handler(message);
}
}
});
}
}
return new AnonymousDisposable(() =>
{
lock (_handlers)
{
_handlers.Remove(messageHandler);
_handlersSnapshot = _handlers.ToArray();
if (_handlers.Count == 0)
{
_underlying.Dispose();
_underlying = null;
}
}
});
}
示例5: App
public App()
: base()
{
// create long-lived objects
handler = new MOCKMessageHandler();
player1Window = new MainWindow();
player1Window.Title = "Player1";
player2Window = new MainWindow();
player2Window.Title = "Player2";
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
// wire up event handler
player1Window.AddIPAddressMenuItemHandler(HandleIPAddressMenuItemForPlayer1);
player2Window.AddIPAddressMenuItemHandler(HandleIPAddressMenuItemForPlayer2);
player1Window.AddNameMenuItemHandler(HandleNameMenuItemForPlayer1);
player2Window.AddNameMenuItemHandler(HandleNameMenuItemForPlayer2);
player1Window.GameBoard.AddMouseHandler(HandleMouseEventForPlayer1);
player2Window.GameBoard.AddMouseHandler(HandleMouseEventForPlayer2);
// show the Views
player1Window.Show();
player2Window.Show();
timer.Start();
}
示例6: AddSessionHandler
public void AddSessionHandler(SocketAsyncEventArgs e,NetInterface netif,MessageHandler handler)
{
long sessionID = Convert.ToInt64(e.UserToken);
SessionHandler sh = new SessionHandler(sessionID,e, netif, handler);
m_dicSessionHandler.Add(sessionID,sh);
PushSessionBuffer(e);
}
示例7: RemoveListener
public static void RemoveListener(MessageHandler handler)
{
lock (s_mutex)
{
Message -= handler;
}
}
示例8: ShellViewModel
public ShellViewModel(IEventAggregator eventAggregator, MessageHandler messageHandler)
{
this.eventAggregator = eventAggregator;
LogMessages = new BindableCollection<LogEntry>();
ViewAttached += OnViewAttachedEventHandler;
}
示例9: App
public App()
: base()
{
handler = new MOCKMessageHandler();
handler.connectTo("127.0.0.1", 50000);
//handler.sendRequest("SET_NAME,BrendanRusso");
Debug.WriteLine(handler.getResponse());
handler.sendRequest("PUT,BrendanRusso,3,1");
Debug.WriteLine(handler.getResponse());
player1Window = new MainWindow();
player2Window = new MainWindow();
player1Window.Title = "Player 1 Window";
player2Window.Title = "Player 2 Window";
player2Window.enableIpSet();
//Wires handlers
wireHandlers(player1Window);
wireHandlers(player2Window);
player1Window.AddSetNameMenuItemHandler(HandleSetNamePlayer1MenuItem);
player2Window.AddSetNameMenuItemHandler(HandleSetNamePlayer2MenuItem);
//player1Window.AddIPAddressMenuItemHandler(HandleIPAddressMenuItem);
//player1Window.GameBoard.AddMouseHandler(HandleMouseEvent);
player1Window.Show();
player2Window.Show();
}
示例10: ConnectionHandler
public ConnectionHandler(Client mainForm)
{
this.mainForm = mainForm;
ServerSocket = new TcpClient();
messageHandler = new MessageHandler();
PacketManager.DefineOpcodeHandlers();
}
示例11: SessionHandler
public SessionHandler(long sessionID, object sessionObject, NetInterface netIF,MessageHandler del)
{
m_sessionID = sessionID;
m_sessionObject = sessionObject;
m_interface = netIF;
m_handler = del;
}
示例12: ConnectorConfig
ConnectorConfig(MessageHandler handler)
{
m_bAutoReConnect = false;
m_iAutoTime = 0;
m_handler = handler;
//m_Connectact = NULL;
}
示例13: AddListener
public static void AddListener(MessageHandler handler)
{
lock (s_mutex)
{
Message += handler;
}
}
示例14: Run_in_test
public void Run_in_test()
{
var streamer = EnvelopeStreamer.CreateDefault(typeof(CreateCustomer), typeof(CustomerCreated));
var builder = new CqrsEngineBuilder(streamer);
var account = new MemoryAccount();
var nuclear = account.CreateNuclear();
var inbox = account.CreateInbox("input");
var sender = account.CreateSimpleSender(streamer, "input");
var handler = new MessageHandler();
handler.WireToLambda<CreateCustomer>(customer => Consume(customer, nuclear, sender));
handler.WireToLambda<CustomerCreated>(m => Console.WriteLine("Created!"));
builder.Handle(inbox, handler.HandleEnvelope);
using (var engine = builder.Build())
{
sender.SendOne(new CreateCustomer
{
CustomerId = 1,
CustomerName = "Rinat Abdullin"
});
engine.RunForever();
}
}
示例15: RegisterTriggerRule
public static void RegisterTriggerRule(MessageHandler c, TestTriggerCondition f)
{
lock (hashMutex)
{
hash.Add(c, f);
}
}