This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Test() | |
| { | |
| var notification = new NotificationManager(); | |
| var handler = new ChatMessageHandler<WhisperMessage>(); | |
| handler.Register((msg, sub) => | |
| { | |
| if (msg.Content == null) | |
| { | |
| sub.Unsubscribe(notification); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class ChatMessageHandler<TMessage> : INotificationHandler<TMessage> where TMessage : ChatMessage | |
| { | |
| /// <summary> | |
| /// The callbacks invoked when the handler processes the messages. | |
| /// </summary> | |
| private Action<TMessage, ISubscription> callback; | |
| /// <summary> | |
| /// The conditions that must be met in order to fire the callbacks. | |
| /// </summary> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class ChatMessage : MessageBase<string> | |
| { | |
| /// <summary> | |
| /// Initializes a new instance of the <see cref="ChatMessage"/> class. | |
| /// </summary> | |
| /// <param name="message">The message.</param> | |
| public ChatMessage(string message) | |
| { | |
| this.Message = message; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private ConcurrentDictionary<Type, ConcurrentBag<ISubscription>> listeners = | |
| new ConcurrentDictionary<Type, ConcurrentBag<ISubscription>>(); | |
| public void Publish<T>(T message) where T : class, IMessage | |
| { | |
| if (!listeners.ContainsKey(typeof(T))) | |
| { | |
| return; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Publish_invokes_callbacks() | |
| { | |
| bool callbackCalled = false; | |
| string messageContent = "Test"; | |
| var notificationCenter = new NotificationManager(); | |
| notificationCenter.Subscribe<ShoutMessage>((msg, sub) => | |
| { | |
| if (msg.Content == messageContent) | |
| { | |
| callbackCalled = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Connect() | |
| { | |
| Thread t = new Thread(DoConnect); | |
| t.IsBackground = true; | |
| t.Start(); | |
| } | |
| private void DoConnect() | |
| { | |
| irc = new TcpClient(_server, _port); | |
| stream = irc.GetStream(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var buffer = new byte[1024]; | |
| this.networkStream.BeginRead( | |
| buffer, | |
| 0, | |
| 1024, | |
| new AsyncCallback(ReceivedMessage), | |
| buffer); | |
| private void ReceivedMessage(IAsyncResult ar) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class ClientCommunicator : IClientCommunicator | |
| { | |
| private NetworkStream networkStream; | |
| public ClientCommunicator(NetworkStream stream) | |
| { | |
| this.networkStream = stream; | |
| } | |
| public async Task Listen() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Listen() | |
| { | |
| // BARF O_0 | |
| Task.Run(() => | |
| { | |
| this.isListening = true; | |
| while (this.isListening) | |
| { | |
| var buffer = new byte[1024]; | |
| this.networkStream.ReadAsync(buffer, 0, 1024); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| StreamWriter singlePlayerOutputStream = null; | |
| if (singlePlayer) { | |
| Console.WriteLine (" midparse singlePlayer OK "); | |
| // setup an additional file for the singlePlayerAnalytics | |
| string singlePlayeroutputFileName = fileName + "." + map + "_"+singlePlayerID+".csv"; | |
| singlePlayerOutputStream = new StreamWriter (singlePlayeroutputFileName); | |
| //And write a header so you know what is what in the resulting file | |
| singlePlayeroutputStream.WriteLine (GenerateSinglePlayerCSVHeader ()); | |
| } |