Skip to content

Instantly share code, notes, and snippets.

public void Test()
{
var notification = new NotificationManager();
var handler = new ChatMessageHandler<WhisperMessage>();
handler.Register((msg, sub) =>
{
if (msg.Content == null)
{
sub.Unsubscribe(notification);
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>
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;
}
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;
}
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;
public void Connect()
{
Thread t = new Thread(DoConnect);
t.IsBackground = true;
t.Start();
}
private void DoConnect()
{
irc = new TcpClient(_server, _port);
stream = irc.GetStream();
var buffer = new byte[1024];
this.networkStream.BeginRead(
buffer,
0,
1024,
new AsyncCallback(ReceivedMessage),
buffer);
private void ReceivedMessage(IAsyncResult ar)
{
internal class ClientCommunicator : IClientCommunicator
{
private NetworkStream networkStream;
public ClientCommunicator(NetworkStream stream)
{
this.networkStream = stream;
}
public async Task Listen()
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);
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 ());
}