static void Instance_ListenerAcceptMessage(object sender, MessageListenerEventArgs e) { ChangeConsoleOut(); #if (PrivateUse) string ip = e.Listener.FromIP; if (ip.StartsWith("192.168.") || ip.StartsWith("127.0.0.1")) //测试,仅限于局域网使用 { ip = string.Empty; } else { Console.WriteLine("错误,{0}", UseDescrition); return; } #endif //下面整个处理过程应该放到一个动态实例对象的方法中,否则,多线程问题难以避免 SubscriberInfo subInfo = new SubscriberInfo(e.Listener); MessageProcesser processer = new MessageProcesser(subInfo, e.Listener.FromMessage); processer.ServiceErrorEvent += new EventHandler <ServiceErrorEventArgs>(Processer_ServiceErrorEvent); //Console.WriteLine("process message begin."); try { processer.Process(); } catch (Exception ex) { Processer_ServiceErrorEvent(processer, new ServiceErrorEventArgs(ex)); } //Console.WriteLine("process message end."); }
static void Instance_ListenerEventMessage(object sender, MessageListenerEventArgs e) { string text = string.Format("[{0}]监听器事件--From: {1}:{2}\r\n[{3}]", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), e.Listener.FromIP, e.Listener.FromPort, e.MessageText); ConsoleWriteSubText(text, 1000); WriteLogFile("ListenerEvent.txt", text); }
public void InvokeProcessMessage(MessageListenerEventArgs mle) { if (MessageHasPairedValues(mle)) { var auctionEvent = AuctionEvent.From(mle.Message.Body); switch (auctionEvent.Type) { case "CLOSE": _auctionEventListener.AuctionClosed(); break; case "PRICE": _auctionEventListener.CurrentPrice(auctionEvent.CurrentPrice, auctionEvent.Increment, auctionEvent.IsFrom(_sniperId)); break; default: string messageDetail = $"Message type: {auctionEvent.Type} not handled, from message {mle.Message.Body}"; throw new Exception(messageDetail); } } else { if (mle.Message.Body.Contains(SharedConstants.STATUS_JOINING)) { _auctionEventListener.JoiningAuction(); } } }
public void InvokeProcessMessage(MessageListenerEventArgs mle) { IMessageListenerEventHandler handler = ProcessMessage; if (handler != null) { handler(this, mle); } }
public void NotifiesAuctionClosedWhenCloseMessageReceived() { var message = new Message(_unusedChat) { Body = "SOLVersion: 1.1; Event: CLOSE;" }; var mlea = new MessageListenerEventArgs(message); _translator.InvokeProcessMessage(mlea); }
public void NotifiesAuctionClosedWhenCloseMessageReceived() { _mockListener.AuctionClosed(); _mocks.ReplayAll(); var message = new Message(UNUSED_CHAT) { Body = "SOLVersion: 1.1; Event: CLOSE;" }; var mlea = new MessageListenerEventArgs(message); _translator.InvokeProcessMessage(mlea); }
public void NotifiesBidDetailsWhenCurrentPriceMessageReceivedFromOtherBidder() { _mockListener.CurrentPrice(192, 7, Enums.PriceSource.FromOtherBidder); _mocks.ReplayAll(); var message = new Message(UNUSED_CHAT) { Body = "SOLVersion: 1.1; Event: PRICE; CurrentPrice: 192; Increment: 7; Bidder: Someone else;" }; var mlea = new MessageListenerEventArgs(message); _translator.InvokeProcessMessage(mlea); }
public void NotifiesBidDetailsWhenCurrentPriceMessageReceivedFromSniper() { _mockListener.CurrentPrice(234, 5, Enums.PriceSource.FromSniper); _mocks.ReplayAll(); var message = new Message(UNUSED_CHAT) { Body = string.Format( "SOLVersion: 1.1; Event: PRICE; CurrentPrice: 234; Increment: 5; Bidder: {0};", SNIPER_ID) }; var mlea = new MessageListenerEventArgs(message); _translator.InvokeProcessMessage(mlea); }
static void Instance_ListenerAdded(object sender, MessageListenerEventArgs e) { Console.WriteLine("[{0}]订阅消息-- From: {1}:{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), e.Listener.FromIP, e.Listener.FromPort); }
private void MessageListenerProcessMessage(object sender, MessageListenerEventArgs mle) { var messageListener = (IMessageListener)sender; messageListener.Message = mle.Message; }
private bool MessageHasPairedValues(MessageListenerEventArgs mle) { return(mle.Message.Body.Contains(";")); }