Updated most samples to RC1
- Use 2.1 template - Make wwwroot folders consistent - Fixed broken samples
This commit is contained in:
Родитель
f28a9a0680
Коммит
869866a0c1
|
@ -5,8 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace SignalRChatSample
|
||||
namespace ChatSample.Hubs
|
||||
{
|
||||
public class ChatHub : Hub
|
||||
{
|
|
@ -1,25 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SignalRChatSample
|
||||
namespace ChatSample
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ChatSample.Hubs;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace SignalRChatSample
|
||||
namespace ChatSample
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
|
|
|
@ -15,12 +15,11 @@
|
|||
<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. -->
|
||||
<!--Reference the SignalR library. -->
|
||||
<script type="text/javascript" src="scripts/signalr.js"></script>
|
||||
<script type="text/javascript" src="lib/signalr.min.js"></script>
|
||||
<!--Add script to update the page and send messages.-->
|
||||
<script type="text/javascript">
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
@ -33,7 +32,9 @@
|
|||
messageInput.focus();
|
||||
|
||||
// Start the connection.
|
||||
var connection = new signalR.HubConnection(url);
|
||||
var connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl('/chat')
|
||||
.build();
|
||||
|
||||
// Create a function that the hub can call to broadcast messages.
|
||||
connection.on('broadcastMessage', function (name, message) {
|
||||
|
@ -48,7 +49,7 @@
|
|||
|
||||
// Transport fallback functionality is now built into start.
|
||||
connection.start()
|
||||
.then(function (connection) {
|
||||
.then(function () {
|
||||
console.log('connection started');
|
||||
document.getElementById('sendmessage').addEventListener('click', function (event) {
|
||||
// Call the Send method on the hub.
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace MoveShape.Hubs
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MoveShape
|
||||
{
|
||||
|
@ -14,13 +7,11 @@ namespace MoveShape
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.Build();
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script type="text/javascript" src="lib/signalr.js"></script>
|
||||
<script type="text/javascript" src="lib/signalr.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.js"
|
||||
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
|
||||
crossorigin="anonymous"></script>
|
||||
|
@ -23,7 +23,9 @@
|
|||
<div id="shape"></div>
|
||||
<script>
|
||||
$shape = $("#shape");
|
||||
var connection = new signalR.HubConnection('/shapeHub');
|
||||
var connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl('/shapeHub')
|
||||
.build();
|
||||
|
||||
connection.on('shapeMoved', function(x, y) {
|
||||
$shape.css({ left: x, top: y });
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -2,11 +2,14 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="1.0.0-alpha2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="1.0.0-rc1-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="1.0.0-rc1-final" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.0-rc1-final" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -3,24 +3,22 @@ using System.Collections.Generic;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CsharpClient
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Task.Run(Run).Wait();
|
||||
}
|
||||
|
||||
static async Task Run()
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
var connection = new HubConnectionBuilder()
|
||||
.WithUrl("http://localhost:5000/stocks")
|
||||
.WithConsoleLogger()
|
||||
.WithMessagePackProtocol()
|
||||
.WithTransport(TransportType.WebSockets)
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
logging.AddConsole();
|
||||
})
|
||||
.AddMessagePackProtocol()
|
||||
.Build();
|
||||
|
||||
await connection.StartAsync();
|
||||
|
@ -41,33 +39,28 @@ namespace CsharpClient
|
|||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
connection.On("marketOpened", async () =>
|
||||
|
||||
connection.On("marketOpened", () =>
|
||||
{
|
||||
await StartStreaming();
|
||||
Console.WriteLine("Market opened");
|
||||
});
|
||||
|
||||
// Do an initial check to see if we can start streaming the stocks
|
||||
var state = await connection.InvokeAsync<string>("GetMarketState");
|
||||
if (string.Equals(state, "Open"))
|
||||
connection.On("marketClosed", () =>
|
||||
{
|
||||
await StartStreaming();
|
||||
}
|
||||
Console.WriteLine("Market closed");
|
||||
});
|
||||
|
||||
// Keep client running until cancel requested.
|
||||
while (!cts.IsCancellationRequested)
|
||||
connection.On("marketReset", () =>
|
||||
{
|
||||
await Task.Delay(250);
|
||||
}
|
||||
// We don't care if the market rest
|
||||
});
|
||||
|
||||
async Task StartStreaming()
|
||||
var channel = await connection.StreamAsChannelAsync<Stock>("StreamStocks", CancellationToken.None);
|
||||
while (await channel.WaitToReadAsync() && !cts.IsCancellationRequested)
|
||||
{
|
||||
var channel = await connection.StreamAsync<Stock>("StreamStocks", CancellationToken.None);
|
||||
while (await channel.WaitToReadAsync() && !cts.IsCancellationRequested)
|
||||
while (channel.TryRead(out var stock))
|
||||
{
|
||||
while (channel.TryRead(out var stock))
|
||||
{
|
||||
Console.WriteLine($"{stock.Symbol} {stock.Price}");
|
||||
}
|
||||
Console.WriteLine($"{stock.Symbol} {stock.Price}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
const signalR = require("@aspnet/signalr");
|
||||
|
||||
XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
||||
WebSocket = require("websocket").w3cwebsocket;
|
||||
|
||||
var hubConnection = new signalR.HubConnectionBuilder()
|
||||
.withUrl("http://localhost:5000/stocks")
|
||||
.build();
|
||||
|
||||
hubConnection.start()
|
||||
.then(() => {
|
||||
hubConnection.stream("StreamStocks").subscribe({
|
||||
next: (stock) => {
|
||||
console.log(stock);
|
||||
// console.log(stock.Symbol + " " + stock.Price);
|
||||
},
|
||||
error: (err) => { },
|
||||
complete: () => { }
|
||||
});
|
||||
});
|
|
@ -0,0 +1,105 @@
|
|||
{
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"@aspnet/signalr": {
|
||||
"version": "1.0.0-rc1-update1",
|
||||
"resolved": "https://registry.npmjs.org/@aspnet/signalr/-/signalr-1.0.0-rc1-update1.tgz",
|
||||
"integrity": "sha512-6GBJTho/CZfv1ZHninq7ckBGhm6DPK5wGuzc5IZq6v1Rj6Ua9htvVAVXxAbTaIHzu+iEXJI+Ms4EP8DVcGeQYg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "8.10.14",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.14.tgz",
|
||||
"integrity": "sha512-TKQqQIaYNO+8MrOsFgobkt3fbMzkfXhBFKcg20Nip5Omptw1HOY/IEvYiFtMwIbr7Me/Y2H/JO+TgNUMJ9NGjA==",
|
||||
"dev": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"eventsource": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.0.5.tgz",
|
||||
"integrity": "sha512-IzjLaND9GBK3+fBPhmvG/Yq3FhSDGHnucJCDWhNsneLlN+HX5jeaSpl3Folr2PipGmyUsd/T2Vrua+s6I2aTgQ==",
|
||||
"requires": {
|
||||
"original": "1.0.0"
|
||||
}
|
||||
},
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"nan": {
|
||||
"version": "2.10.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
|
||||
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA=="
|
||||
},
|
||||
"original": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/original/-/original-1.0.0.tgz",
|
||||
"integrity": "sha1-kUf5P6FpbQS+YeAb1QuurKZWvTs=",
|
||||
"requires": {
|
||||
"url-parse": "1.0.5"
|
||||
}
|
||||
},
|
||||
"querystringify": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-0.0.4.tgz",
|
||||
"integrity": "sha1-DPf4T5Rj/wrlHExLFC2VvjdyTZw="
|
||||
},
|
||||
"requires-port": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
|
||||
},
|
||||
"typedarray-to-buffer": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
|
||||
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
|
||||
"requires": {
|
||||
"is-typedarray": "1.0.0"
|
||||
}
|
||||
},
|
||||
"url-parse": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.0.5.tgz",
|
||||
"integrity": "sha1-CFSGBCKv3P7+tsllxmLUgAFpkns=",
|
||||
"requires": {
|
||||
"querystringify": "0.0.4",
|
||||
"requires-port": "1.0.0"
|
||||
}
|
||||
},
|
||||
"websocket": {
|
||||
"version": "1.0.26",
|
||||
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.26.tgz",
|
||||
"integrity": "sha512-fjcrYDPIQxpTnqFQ9JjxUQcdvR89MFAOjPBlF+vjOt49w/XW4fJknUoMz/mDIn2eK1AdslVojcaOxOqyZZV8rw==",
|
||||
"requires": {
|
||||
"debug": "2.6.9",
|
||||
"nan": "2.10.0",
|
||||
"typedarray-to-buffer": "3.1.5",
|
||||
"yaeti": "0.0.6"
|
||||
}
|
||||
},
|
||||
"xmlhttprequest": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",
|
||||
"integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw="
|
||||
},
|
||||
"yaeti": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
|
||||
"integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"atob": "^2.0.3",
|
||||
"btoa": "^1.1.2",
|
||||
"eventsource": "^1.0.5",
|
||||
"msgpack5": "^3.5.1",
|
||||
"websocket": "^1.0.24",
|
||||
"xmlhttprequest": "^1.8.0"
|
||||
},
|
||||
|
@ -11,7 +8,7 @@
|
|||
"src/**/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@aspnet/signalr-client": "^1.0.0-alpha2-final",
|
||||
"@aspnet/signalr": "^1.0.0-rc1-final",
|
||||
"@types/node": "^8.0.32"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const signalR = require("@aspnet/signalr-client");
|
||||
const EventSource = require("eventsource");
|
||||
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
||||
global.WebSocket = require("websocket").w3cwebsocket;
|
||||
global.EventSource = EventSource;
|
||||
global.btoa = require("btoa");
|
||||
global.atob = require("atob");
|
||||
const hubConnection = new signalR.HubConnection("http://localhost:5000/stocks");
|
||||
hubConnection.start().then(() => {
|
||||
hubConnection.invoke("GetMarketState").then(function (state) {
|
||||
if (state === "Open") {
|
||||
streamStocks();
|
||||
}
|
||||
else {
|
||||
hubConnection.invoke("OpenMarket");
|
||||
}
|
||||
});
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
hubConnection.on("marketOpened", function () {
|
||||
streamStocks();
|
||||
});
|
||||
function streamStocks() {
|
||||
hubConnection.stream("StreamStocks").subscribe({
|
||||
next: (stock) => {
|
||||
console.log(stock);
|
||||
// console.log(stock.Symbol + " " + stock.Price);
|
||||
},
|
||||
error: () => { },
|
||||
complete: () => { }
|
||||
});
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
import * as signalR from "@aspnet/signalr-client";
|
||||
import * as EventSource from "eventsource";
|
||||
|
||||
(<any>global).XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
||||
(<any>global).WebSocket = require("websocket").w3cwebsocket;
|
||||
(<any>global).EventSource = EventSource;
|
||||
(<any>global).btoa = require("btoa");
|
||||
(<any>global).atob = require("atob");
|
||||
|
||||
const hubConnection : signalR.HubConnection = new signalR.HubConnection("http://localhost:5000/stocks");
|
||||
|
||||
hubConnection.start().then(() => {
|
||||
hubConnection.invoke("GetMarketState").then(function (state : string): void {
|
||||
if (state === "Open") {
|
||||
streamStocks();
|
||||
} else {
|
||||
hubConnection.invoke("OpenMarket");
|
||||
}
|
||||
});
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
hubConnection.on("marketOpened", function(): void {
|
||||
streamStocks();
|
||||
});
|
||||
|
||||
function streamStocks (): void {
|
||||
hubConnection.stream("StreamStocks").subscribe({
|
||||
next: (stock : any) => {
|
||||
console.log(stock);
|
||||
// console.log(stock.Symbol + " " + stock.Price);
|
||||
},
|
||||
error: () => {},
|
||||
complete: () => {}
|
||||
});
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs"
|
||||
},
|
||||
"include": [
|
||||
"src/main.ts"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockTickR", "StockTickRApp\StockTickR.csproj", "{6139B392-E328-46E5-BC60-BCFA3BB42E67}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsharpClient", "CsharpClient\CsharpClient.csproj", "{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Release|x64.Build.0 = Release|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{6139B392-E328-46E5-BC60-BCFA3BB42E67}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E4E0DC98-E0C1-41AE-9337-34508BFFCA87}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace SignalR.StockTicker
|
||||
namespace StockTickR.Hubs
|
||||
{
|
||||
public class StockTickerHub : Hub
|
||||
{
|
||||
|
@ -19,9 +20,9 @@ namespace SignalR.StockTicker
|
|||
return _stockTicker.GetAllStocks();
|
||||
}
|
||||
|
||||
public IObservable<Stock> StreamStocks()
|
||||
public ChannelReader<Stock> StreamStocks()
|
||||
{
|
||||
return _stockTicker.StreamStocks();
|
||||
return _stockTicker.StreamStocks().AsChannelReader(10);
|
||||
}
|
||||
|
||||
public string GetMarketState()
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Threading.Channels;
|
||||
|
||||
namespace System
|
||||
{
|
||||
public static class ObservableExtensions
|
||||
{
|
||||
public static ChannelReader<T> AsChannelReader<T>(this IObservable<T> observable, int? maxBufferSize = null)
|
||||
{
|
||||
// This sample shows adapting an observable to a ChannelReader without
|
||||
// back pressure, if the connection is slower than the producer, memory will
|
||||
// start to increase.
|
||||
|
||||
// If the channel is bounded, TryWrite will return false and effectively
|
||||
// drop items.
|
||||
|
||||
// The other alternative is to use a bounded channel, and when the limit is reached
|
||||
// block on WaitToWriteAsync. This will block a thread pool thread and isn't recommended and isn't shown here.
|
||||
var channel = maxBufferSize != null ? Channel.CreateBounded<T>(maxBufferSize.Value) : Channel.CreateUnbounded<T>();
|
||||
|
||||
var disposable = observable.Subscribe(
|
||||
value => channel.Writer.TryWrite(value),
|
||||
error => channel.Writer.TryComplete(error),
|
||||
() => channel.Writer.TryComplete());
|
||||
|
||||
// Complete the subscription on the reader completing
|
||||
channel.Reader.Completion.ContinueWith(task => disposable.Dispose());
|
||||
|
||||
return channel.Reader;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +1,20 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SignalR.StockTicker
|
||||
namespace StockTickR
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseSetting(WebHostDefaults.PreventHostingStartupKey, "true")
|
||||
.ConfigureLogging((context, factory) =>
|
||||
{
|
||||
factory.AddConfiguration(context.Configuration.GetSection("Logging"));
|
||||
factory.AddConsole();
|
||||
factory.AddDebug();
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StockTickR.Hubs;
|
||||
|
||||
namespace SignalR.StockTicker
|
||||
namespace StockTickR
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSignalR();
|
||||
services.AddSignalR()
|
||||
.AddMessagePackProtocol();
|
||||
|
||||
services.AddScoped<StockTickerHub>();
|
||||
services.AddSingleton<StockTicker>();
|
||||
}
|
||||
|
||||
|
@ -21,7 +22,7 @@ namespace SignalR.StockTicker
|
|||
|
||||
app.UseSignalR(routes =>
|
||||
{
|
||||
routes.MapHub<StockTickerHub>("stocks");
|
||||
routes.MapHub<StockTickerHub>("/stocks");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
|
||||
namespace SignalR.StockTicker
|
||||
namespace StockTickR
|
||||
{
|
||||
public class Stock
|
||||
{
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\index.html" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="1.0.0-rc1-final" />
|
||||
<PackageReference Include="System.Reactive.Linq" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-alpha2-final" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -2,12 +2,13 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Channels;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using StockTickR.Hubs;
|
||||
|
||||
namespace SignalR.StockTicker
|
||||
namespace StockTickR
|
||||
{
|
||||
public class StockTicker
|
||||
{
|
||||
|
@ -16,6 +17,8 @@ namespace SignalR.StockTicker
|
|||
|
||||
private readonly ConcurrentDictionary<string, Stock> _stocks = new ConcurrentDictionary<string, Stock>();
|
||||
|
||||
private readonly Subject<Stock> _subject = new Subject<Stock>();
|
||||
|
||||
// Stock can go up or down by a percentage of this factor on each change
|
||||
private readonly double _rangePercent = 0.002;
|
||||
|
||||
|
@ -51,18 +54,7 @@ namespace SignalR.StockTicker
|
|||
|
||||
public IObservable<Stock> StreamStocks()
|
||||
{
|
||||
return Observable.Create(
|
||||
async (IObserver<Stock> observer) =>
|
||||
{
|
||||
while (MarketState == MarketState.Open)
|
||||
{
|
||||
foreach (var stock in _stocks.Values)
|
||||
{
|
||||
observer.OnNext(stock);
|
||||
}
|
||||
await Task.Delay(_updateInterval);
|
||||
}
|
||||
});
|
||||
return _subject;
|
||||
}
|
||||
|
||||
public async Task OpenMarket()
|
||||
|
@ -154,6 +146,8 @@ namespace SignalR.StockTicker
|
|||
foreach (var stock in _stocks.Values)
|
||||
{
|
||||
TryUpdateStockPrice(stock);
|
||||
|
||||
_subject.OnNext(stock);
|
||||
}
|
||||
|
||||
_updatingStockPrices = false;
|
||||
|
@ -190,10 +184,10 @@ namespace SignalR.StockTicker
|
|||
switch (marketState)
|
||||
{
|
||||
case MarketState.Open:
|
||||
await Hub.Clients.All.InvokeAsync("marketOpened");
|
||||
await Hub.Clients.All.SendAsync("marketOpened");
|
||||
break;
|
||||
case MarketState.Closed:
|
||||
await Hub.Clients.All.InvokeAsync("marketClosed");
|
||||
await Hub.Clients.All.SendAsync("marketClosed");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -202,12 +196,7 @@ namespace SignalR.StockTicker
|
|||
|
||||
private async Task BroadcastMarketReset()
|
||||
{
|
||||
await Hub.Clients.All.InvokeAsync("marketReset");
|
||||
}
|
||||
|
||||
private async Task BroadcastStockPrice(Stock stock)
|
||||
{
|
||||
await Hub.Clients.All.InvokeAsync("updateStockPrice", stock);
|
||||
await Hub.Clients.All.SendAsync("marketReset");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,14 +30,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
if (typeof Promise === 'undefined') {
|
||||
document.write('<script type="text/javascript" src="scripts/signalr-clientES5-1.0.0-alpha2-final.min.js"><\/script>');
|
||||
}
|
||||
else {
|
||||
document.write('<script type="text/javascript" src="scripts/signalr-client-1.0.0-alpha2-final.min.js"><\/script>');
|
||||
}
|
||||
</script>
|
||||
<script src="scripts/SignalR.StockTicker.js"></script>
|
||||
<script src="lib/signalr.min.js"></script>
|
||||
<script src="lib/stockTicker.js"></script>
|
||||
</body>
|
||||
</html>
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -12,14 +12,17 @@ if (!String.prototype.supplant) {
|
|||
|
||||
var stockTable = document.getElementById('stockTable');
|
||||
var stockTableBody = stockTable.getElementsByTagName('tbody')[0];
|
||||
var rowTemplate = '<td>{symbol}</td><td>{price}</td><td>{DayOpen}</td><td>{DayHigh}</td><td>{dayLow}</td><td class="changeValue"><span class="dir {directionClass}">{direction}</span> {change}</td><td>{percentChange}</td>';
|
||||
var tickerTemplate = '<span class="symbol">{symbol}</span> <span class="price">{price}</span> <span class="changeValue"><span class="dir {directionClass}">{direction}</span> {Change} ({percentChange})</span>';
|
||||
var rowTemplate = '<td>{symbol}</td><td>{price}</td><td>{dayOpen}</td><td>{dayHigh}</td><td>{dayLow}</td><td class="changeValue"><span class="dir {directionClass}">{direction}</span> {change}</td><td>{percentChange}</td>';
|
||||
var tickerTemplate = '<span class="symbol">{symbol}</span> <span class="price">{price}</span> <span class="changeValue"><span class="dir {directionClass}">{direction}</span> {change} ({percentChange})</span>';
|
||||
var stockTicker = document.getElementById('stockTicker');
|
||||
var stockTickerBody = stockTicker.getElementsByTagName('ul')[0];
|
||||
var up = '▲';
|
||||
var down = '▼';
|
||||
|
||||
let connection = new signalR.HubConnection("/stocks");
|
||||
let connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl("/stocks")
|
||||
.build();
|
||||
|
||||
connection.start().then(function () {
|
||||
connection.invoke("GetAllStocks").then(function (stocks) {
|
||||
for (let i = 0; i < stocks.length; i++) {
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -1,12 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace WhiteBoard
|
||||
{
|
||||
|
@ -14,12 +7,11 @@ namespace WhiteBoard
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-preview2-final" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script type="text/javascript" src="scripts/signalr.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.js"
|
||||
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"
|
||||
integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30="
|
||||
crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="lib/signalr.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30="
|
||||
crossorigin="anonymous"></script>
|
||||
<title>WhiteBoard</title>
|
||||
<style>
|
||||
canvas {
|
||||
|
@ -17,6 +15,7 @@
|
|||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<canvas id="canvas" width="800" height="500" onmouseout="clearMousePositions()"></canvas>
|
||||
<select id="color">
|
||||
|
@ -75,7 +74,10 @@
|
|||
});
|
||||
|
||||
var mouse_down = false;
|
||||
var connection = new signalR.HubConnection('/draw');
|
||||
var connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl('/draw')
|
||||
.build();
|
||||
|
||||
connection.on('draw', function (prev_x, prev_y, x, y, clr) {
|
||||
console.log("X: " + x + " Y: " + y);
|
||||
drawCanvas(prev_x, prev_y, x, y, clr);
|
||||
|
@ -89,4 +91,5 @@
|
|||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Загрузка…
Ссылка в новой задаче