Skip to content

Commit

Permalink
Add signalR thing
Browse files Browse the repository at this point in the history
  • Loading branch information
wtgodbe committed Mar 12, 2020
1 parent ce5e02e commit 82f9604
Show file tree
Hide file tree
Showing 36 changed files with 1,572 additions and 0 deletions.
37 changes: 37 additions & 0 deletions SigRBlazor/BlazorSignalRApp/BlazorSignalRApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorSignalRApp.Server", "BlazorSignalRApp\Server\BlazorSignalRApp.Server.csproj", "{C46146B2-2322-40B7-9C44-6C71412E385B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorSignalRApp.Client", "BlazorSignalRApp\Client\BlazorSignalRApp.Client.csproj", "{0BCEAB93-535B-4E1F-8F5F-20D44878DB93}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorSignalRApp.Shared", "BlazorSignalRApp\Shared\BlazorSignalRApp.Shared.csproj", "{E796F28C-EC0E-4413-902B-4D3E17749B63}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C46146B2-2322-40B7-9C44-6C71412E385B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C46146B2-2322-40B7-9C44-6C71412E385B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C46146B2-2322-40B7-9C44-6C71412E385B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C46146B2-2322-40B7-9C44-6C71412E385B}.Release|Any CPU.Build.0 = Release|Any CPU
{0BCEAB93-535B-4E1F-8F5F-20D44878DB93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BCEAB93-535B-4E1F-8F5F-20D44878DB93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BCEAB93-535B-4E1F-8F5F-20D44878DB93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BCEAB93-535B-4E1F-8F5F-20D44878DB93}.Release|Any CPU.Build.0 = Release|Any CPU
{E796F28C-EC0E-4413-902B-4D3E17749B63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E796F28C-EC0E-4413-902B-4D3E17749B63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E796F28C-EC0E-4413-902B-4D3E17749B63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E796F28C-EC0E-4413-902B-4D3E17749B63}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AB814721-1BFA-4B8B-B74E-58D5E416C901}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions SigRBlazor/BlazorSignalRApp/BlazorSignalRApp/Client/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\BlazorSignalRApp.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@page "/fetchdata"
@using BlazorSignalRApp.Shared
@inject HttpClient Http

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}

@code {
private WeatherForecast[] forecasts;

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("WeatherForecast");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@page "/"
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager NavigationManager

<div class="form-group">
<label>
User:
<input @bind="_userInput" />
</label>
</div>
<div class="form-group">
<label>
Message:
<input @bind="_messageInput" size="50" />
</label>
</div>
<button @onclick="Send" disabled="@(!IsConnected)">Send</button>

<hr>

<ul id="messagesList">
@foreach (var message in _messages)
{
<li>@message</li>
}
</ul>

@code {
private HubConnection _hubConnection;
private List<string> _messages = new List<string>();
private string _userInput;
private string _messageInput;

async Task<string> AccessTokenProvider()
{
var myToken = "MyGreatToken";
return myToken;
}

protected override async Task OnInitializedAsync()
{
_hubConnection = new HubConnectionBuilder()
.WithUrl(NavigationManager.ToAbsoluteUri("/chatHub"), options =>
{
options.AccessTokenProvider = AccessTokenProvider;
})
.Build();

_hubConnection.On<string, string>("ReceiveMessage", (user, message) =>
{
var encodedMsg = $"{user}: {message}";
_messages.Add(encodedMsg);
StateHasChanged();
});

await _hubConnection.StartAsync();
}

Task Send() =>
_hubConnection.SendAsync("SendMessage", _userInput, _messageInput);

public bool IsConnected =>
_hubConnection.State == HubConnectionState.Connected;
}
22 changes: 22 additions & 0 deletions SigRBlazor/BlazorSignalRApp/BlazorSignalRApp/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace BlazorSignalRApp.Client
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");

builder.Services.AddBaseAddressHttpClient();

await builder.Build().RunAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63196",
"sslPort": 44304
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BlazorSignalRApp": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@inherits LayoutComponentBase

<div class="sidebar">
<NavMenu />
</div>

<div class="main">
<div class="top-row px-4">
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
</div>

<div class="content px-4">
@Body
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="top-row pl-4 navbar navbar-dark">
<a class="navbar-brand" href="">BlazorSignalRApp</a>
<button class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<ul class="nav flex-column">
<li class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</li>
</ul>
</div>

@code {
private bool collapseNavMenu = true;

private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="alert alert-secondary mt-4" role="alert">
<span class="oi oi-pencil mr-2" aria-hidden="true"></span>
<strong>@Title</strong>

<span class="text-nowrap">
Please take our
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2121313">brief survey</a>
</span>
and tell us what you think.
</div>

@code {
// Demonstrates how a parent component can supply parameters
[Parameter]
public string Title { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using BlazorSignalRApp.Client
@using BlazorSignalRApp.Client.Shared

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 82f9604

Please sign in to comment.