Skip to content

Commit

Permalink
Add ClientResultSample (#1703)
Browse files Browse the repository at this point in the history
* Add ClientResultSample

* Move file

* minor update.

* minor update README.

* show server/service ex.message

* Add Broadcast method and update README
  • Loading branch information
JialinXin authored Oct 26, 2022
1 parent 34314d1 commit 5826b42
Show file tree
Hide file tree
Showing 114 changed files with 77,740 additions and 1,239 deletions.
9 changes: 8 additions & 1 deletion AzureSignalR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.Ser
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.Serverless.Protocols.Tests", "test\Microsoft.Azure.SignalR.Serverless.Protocols.Tests\Microsoft.Azure.SignalR.Serverless.Protocols.Tests.csproj", "{82C1FF3D-EC6C-4B21-B6A4-E69E8D75D0D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatSample.Net60", "samples\ChatSample\ChatSample.Net60\ChatSample.Net60.csproj", "{594EC59A-7305-4A36-8BE6-4A928FBFD71B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatSample.Net60", "samples\ChatSample\ChatSample.Net60\ChatSample.Net60.csproj", "{594EC59A-7305-4A36-8BE6-4A928FBFD71B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatSample.Net70", "samples\ChatSample\ChatSample.Net70\ChatSample.Net70.csproj", "{49634EE4-A0F4-4672-A8B3-B994CF81C9AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -190,6 +192,10 @@ Global
{594EC59A-7305-4A36-8BE6-4A928FBFD71B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{594EC59A-7305-4A36-8BE6-4A928FBFD71B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{594EC59A-7305-4A36-8BE6-4A928FBFD71B}.Release|Any CPU.Build.0 = Release|Any CPU
{49634EE4-A0F4-4672-A8B3-B994CF81C9AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49634EE4-A0F4-4672-A8B3-B994CF81C9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49634EE4-A0F4-4672-A8B3-B994CF81C9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49634EE4-A0F4-4672-A8B3-B994CF81C9AB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -223,6 +229,7 @@ Global
{52944A80-44A9-48D4-919D-11AAAD55193E} = {DA69F624-5398-4884-87E4-B816698CDE65}
{82C1FF3D-EC6C-4B21-B6A4-E69E8D75D0D0} = {2429FBD8-1FCE-4C42-AA28-DF32F7249E77}
{594EC59A-7305-4A36-8BE6-4A928FBFD71B} = {C965ED06-6A17-4329-B3C6-811830F4F4ED}
{49634EE4-A0F4-4672-A8B3-B994CF81C9AB} = {C965ED06-6A17-4329-B3C6-811830F4F4ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7945A4E4-ACDB-4F6E-95CA-6AC6E7C2CD59}
Expand Down
13 changes: 13 additions & 0 deletions samples/ChatSample/ChatSample.Net70/ChatSample.Net70.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.Azure.SignalR\Microsoft.Azure.SignalR.csproj" />
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions samples/ChatSample/ChatSample.Net70/ClientResultHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.SignalR;

namespace ClientResultSample
{
public class ClientResultHub : Hub
{
public override Task OnConnectedAsync()
{
return Clients.All.SendAsync("Connect", $"Connection '{Context.ConnectionId}' is connected.");
}

public async Task<string> GetMessage(string ID)
{
try
{
var res = await Clients.Client(ID).InvokeAsync<string>("GetMessage", default);
return $"From {ID}: {res}";
}
catch (Exception ex)
{
return $"[Error] Failed invoke connection {ID}]: {ex.Message}";
}
}

public async Task Broadcast(string message)
{
await Clients.All.SendAsync("Broadcast", $"Broadcast from '{Context.ConnectionId}': {message}");
}

public override Task OnDisconnectedAsync(Exception? exception)
{
return Clients.All.SendAsync("Connect", $"Connection '{Context.ConnectionId}' is disconnected.");
}
}
}
39 changes: 39 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Chats.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@page
@using Microsoft.AspNetCore.Http.Extensions;
<div class="container">
<div class="row">&nbsp;</div>
<div class="row">
<div class="col-2">ID</div>
<div class="col-4"><input type="text" id="IDInput" /></div>
</div>
<div class="row">&nbsp;</div>
<div class="row">
<div class="col-6">
<input type="button" id="getButton" value="Get Message" />
</div>
</div>
<div class="row">&nbsp;</div>
<div class="row">
<div class="col-2">Message</div>
<div class="col-4"><input type="text" id="messageInput" /></div>
</div>
<div class="row">&nbsp;</div>
<div class="row">
<div class="col-6">
<input type="button" id="broadcastButton" value="Broadcast" />
<input type="button" id="sendButton" value="Ack Message" />
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<hr />
</div>
</div>
<div class="row">
<div class="col-6">
<ul id="messagesList"></ul>
</div>
</div>
<script src="~/js/signalr/signalr.js"></script>
<script src="~/js/chat.js"></script>
20 changes: 20 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Chats.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ClientResultSample.Pages
{
public class ChatsModel : PageModel
{
private readonly ILogger<ChatsModel> _logger;

public ChatsModel(ILogger<ChatsModel> logger)
{
_logger = logger;
}

public void OnGet()
{

}
}
}
26 changes: 26 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
27 changes: 27 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace ClientResultSample.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
17 changes: 17 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@page
<div class="row">
<div class="col-6">
<div class="row">
<div class="col-2"><input type="button" value="Enter" onclick="document.getElementById('leftChat').src = document.getElementById('leftPage').value"/></div>
<div class="col-6"><input type="text" id="leftPage" value="@Request.Scheme://@Request.Host/chats" /></div>
</div>
<iframe src="@Request.Scheme://@Request.Host/chats" id="leftChat"></iframe>
</div>
<div class="col-6">
<div class="row">
<div class="col-2"><input type="button" value="Enter" onclick="document.getElementById('rightChat').src = document.getElementById('rightPage').value" /></div>
<div class="col-6"><input type="text" id="rightPage" value="@Request.Scheme://@Request.Host/chats" /></div>
</div>
<iframe src="@Request.Scheme://@Request.Host/chats" id="rightChat"></iframe>
</div>
</div>
20 changes: 20 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ClientResultSample.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;

public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}

public void OnGet()
{

}
}
}
8 changes: 8 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
19 changes: 19 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ClientResultSample.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
}
}
}
50 changes: 50 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - ClientResultSample</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/ClientResultSample.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">ClientResultSample</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2022 - ClientResultSample - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */

a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}

a {
color: #0077cc;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
font-size: 1rem;
line-height: inherit;
}

.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
3 changes: 3 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using ClientResultSample
@namespace ClientResultSample.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions samples/ChatSample/ChatSample.Net70/Pages/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = (Context.Request.Path.Value == "/") ? "_Layout" : null;
}
Loading

0 comments on commit 5826b42

Please sign in to comment.