MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run...

18
ASP.NET MVC http://nbende.wordpress.com

Transcript of MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run...

Page 1: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

ASP.NET MVChttp://nbende.wordpress.com

Page 2: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

Agenda

• Getting started with SignalR

• Using SignalR for Dual Communication modes

Page 3: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN
Page 4: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

What is ASP.NET SignalR

Page 5: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

Real-time web" functionality ?

Page 6: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

Why use SignalR?

Page 7: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN
Page 8: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

SignalR Hosts

Host agnostic – run in asp.net or stand alone

with self-host on OWIN

Page 9: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

What to include?

Page 10: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

Hubs and Connections

Connections – LOW LEVEL

Raw strings up and down

Broadcast to all clients, groups or individuals

Connection, reconnection and disconnection semantics

Hubs – Bit higher level

Client-server and server-client

Automatic client proxy generation

Page 11: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

Getting started with SignalR

Page 12: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

To Start

Page 13: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

<body>

<div class="container">

<input type="text" id="message" />

<input type="button" id="sendmessage" value="Send" />

<input type="hidden" id="displayname" />

<ul id="discussion">

</ul>

</div>

<!--Script references. -->

<script src="Scripts/jquery-1.6.4.min.js" ></script>

<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>

<script src="signalr/hubs"></script>

<!--Add script to update the page and send messages.-->

<script type="text/javascript">

$(function () {

// Declare a proxy to reference the hub.

var chat = $.connection.chatHub;

// Create a function that the hub can call to broadcast messages.

chat.client.broadcastMessage = function (name, message) {

Page 14: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

To Start ( VS 2013 )

Page 15: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

<div class="container"><input type="text" id="message" /><input type="button" id="sendmessage" value="Send" /><input type="hidden" id="displayname" /><ul id="discussion"></ul>

</div>

@section scripts {

Page 16: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

@section scripts {<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>

<!--Reference the autogenerated SignalR hub script. --><script src="~/signalr/hubs"></script><!--SignalR script to update the chat page and send messages.--><script>

$(function () {// Reference the auto-generated proxy for the hub.var chat = $.connection.chatHub;// Create a function that the hub can call back to display messages.chat.client.addNewMessageToPage = function (name, message) {

// Add the message to the page.$('#discussion').append('<li><strong>' + htmlEncode(name)

+ '</strong>: ' + htmlEncode(message) + '</li>');};// Get the user name and store it to prepend to messages.$('#displayname').val(prompt('Enter your name:', ''));// Set initial focus to message input box.$('#message').focus();// Start the connection.$.connection.hub.start().done(function () {

$('#sendmessage').click(function () {// Call the Send method on the hub.chat.server.send($('#displayname').val(), $('#message').val());// Clear text box and reset focus for next comment.$('#message').val('').focus();

});});

});// This optional function html-encodes messages for display in the page.function htmlEncode(value) {

var encodedValue = $('<div />').text(value).html();return encodedValue;

}</script>

}

Page 17: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN
Page 18: MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... fileSignalR Hosts Host agnostic –run in asp.net or stand alone with self-host on OWIN

Questions?