Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
signalr / SignalR Programming in Microsoft ASP.NET.pdf
Скачиваний:
65
Добавлен:
25.05.2015
Размер:
19.23 Mб
Скачать

if (points[x][y]) {

setPoint(x, y, points[x][y]);

}

}

}

};

// Voila! $.connection.hub.start()

.done(function () { connected = true;

});

});

Implementation on the server side

Hub (DrawingBoard.cs)

public class DrawingBoard : Hub

{

private const int BoardWidth = 300; private const int BoardHeight = 300;

private static int[,] _buffer = GetEmptyBuffer(); public Task BroadcastPoint(int x, int y)

{

if (x < 0) x = 0;

if (x >= BoardWidth) x = BoardWidth-1; if (y < 0) y = 0;

if (y >= BoardHeight) y = BoardHeight - 1;

int color = 0; int.TryParse(Clients.Caller.color, out color); _buffer[x, y] = color;

return Clients.Others.DrawPoint(x, y, Clients.Caller.color);

}

public Task BroadcastClear()

{

_buffer = GetEmptyBuffer(); return Clients.Others.Clear();

}

public override Task OnConnected()

{

return Clients.Caller.Update(_buffer);

}

private static int[,] GetEmptyBuffer()

{

var buffer = new int[BoardWidth, BoardHeight]; return buffer;

}

}

100 Chapter 5Hubs

www.it-ebooks.info

Startup code (Startup.cs)

public class Startup

{

public void Configuration(IAppBuilder app)

{

app.MapSignalR();

}

}

HubsChapter 5

101

www.it-ebooks.info

www.it-ebooks.info

Соседние файлы в папке signalr