From 40f9117e69c23bccc7b7e22325aa86a29e89bc41 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Sun, 5 May 2024 07:54:33 -0500 Subject: [PATCH] full reformatting (#29) --- Directory.Build.props | 32 +- .../Server/Actors/PaintInstanceActor.cs | 167 ++- .../Server/Actors/PaintInstanceManager.cs | 35 +- .../Server/Actors/UserInstanceActor.cs | 26 +- src/DrawTogether.UI/Server/App.razor | 4 +- .../Server/Components/Circle.razor | 26 +- .../Server/Components/ColorPicker.razor | 8 +- .../Server/Components/CursorPicker.razor | 8 +- .../Server/Components/Curve.razor | 25 +- .../Server/DrawTogether.UI.Server.csproj | 28 +- src/DrawTogether.UI/Server/Hubs/DrawHub.cs | 88 +- .../Server/Pages/Counter.razor | 2 +- src/DrawTogether.UI/Server/Pages/Error.cshtml | 50 +- .../Server/Pages/Error.cshtml.cs | 42 +- src/DrawTogether.UI/Server/Pages/Paint.razor | 21 +- src/DrawTogether.UI/Server/Pages/_Host.cshtml | 14 +- .../Server/Pages/_Host.cshtml.cs | 10 +- src/DrawTogether.UI/Server/Program.cs | 31 +- .../Server/Properties/launchSettings.json | 48 +- .../Server/Services/AkkaService.cs | 34 +- .../Server/Services/IDrawHubHandler.cs | 106 +- .../Server/Services/IDrawSessionHandler.cs | 41 +- .../Server/Services/IPaintSessionGenerator.cs | 29 +- .../Services/Users/RandomNameService.cs | 35 +- .../Services/Users/UserNamingService.cs | 49 +- .../Server/Shared/MainLayout.razor | 4 +- .../Server/Shared/MainLayout.razor.css | 16 +- .../Server/Shared/NavMenu.razor | 3 +- .../Server/Shared/NavMenu.razor.css | 34 +- src/DrawTogether.UI/Server/Startup.cs | 101 +- src/DrawTogether.UI/Server/_Imports.razor | 2 +- .../Server/_ViewImports.cshtml | 2 +- src/DrawTogether.UI/Server/appsettings.json | 2 +- .../Server/wwwroot/css/app.css | 12 +- .../Server/wwwroot/css/open-iconic/README.md | 23 +- .../open-iconic/font/fonts/open-iconic.svg | 1059 +++++++++-------- src/DrawTogether.UI/Server/wwwroot/index.html | 26 +- src/DrawTogether.UI/Shared/ConnectedStroke.cs | 23 +- .../Connectivity/PaintSessionProtocol.cs | 131 +- .../Shared/DrawHubConstants.cs | 9 +- .../Shared/DrawTogether.UI.Shared.csproj | 22 +- src/DrawTogether.UI/Shared/Point.cs | 22 +- 42 files changed, 1167 insertions(+), 1283 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3b5632d..813f476 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,18 +1,18 @@ - - Copyright © 2015-2024 Petabridge - Petabridge - 0.2.2 - Added footer that displays assembly version on Pricing UI - - - - - - - $(NoWarn);CS1591 - - - net8.0 - + + Copyright © 2015-2024 Petabridge + Petabridge + 0.2.2 + Added footer that displays assembly version on Pricing UI + + + + + + + $(NoWarn);CS1591 + + + net8.0 + \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Actors/PaintInstanceActor.cs b/src/DrawTogether.UI/Server/Actors/PaintInstanceActor.cs index 5a61dad..cda3ea9 100644 --- a/src/DrawTogether.UI/Server/Actors/PaintInstanceActor.cs +++ b/src/DrawTogether.UI/Server/Actors/PaintInstanceActor.cs @@ -1,115 +1,110 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Akka.Actor; +using Akka.Actor; using Akka.Event; using Akka.Streams; using Akka.Streams.Dsl; using Akka.Util.Internal; -using DrawTogether.UI.Server.Hubs; using DrawTogether.UI.Server.Services; using DrawTogether.UI.Shared; -using DrawTogether.UI.Shared.Connectivity; -using Microsoft.AspNetCore.SignalR; using static DrawTogether.UI.Shared.Connectivity.PaintSessionProtocol; -namespace DrawTogether.UI.Server.Actors +namespace DrawTogether.UI.Server.Actors; + +/// +/// Holds all stroke data in memory for a single drawing instance. +/// +public class PaintInstanceActor : UntypedActor { - /// - /// Holds all stroke data in memory for a single drawing instance. - /// - public class PaintInstanceActor : UntypedActor - { - // Handle to the Akka.NET asynchronous logging system - private readonly ILoggingAdapter _log = Context.GetLogger(); + private readonly List _connectedStrokes = new(); + private readonly IDrawHubHandler _hubHandler; - private readonly List _connectedStrokes = new(); - private readonly List _users = new(); - private readonly IDrawHubHandler _hubHandler; - private readonly string _sessionId; - private readonly TimeSpan _idleTimeout = TimeSpan.FromMinutes(20); - private IActorRef _streamsDebouncer; + private readonly TimeSpan _idleTimeout = TimeSpan.FromMinutes(20); - public PaintInstanceActor(string sessionId, IDrawHubHandler hubHandler) - { - _sessionId = sessionId; - _hubHandler = hubHandler; - } + // Handle to the Akka.NET asynchronous logging system + private readonly ILoggingAdapter _log = Context.GetLogger(); + private readonly string _sessionId; + private readonly List _users = new(); + private IActorRef _streamsDebouncer; - protected override void OnReceive(object message) + public PaintInstanceActor(string sessionId, IDrawHubHandler hubHandler) + { + _sessionId = sessionId; + _hubHandler = hubHandler; + } + + protected override void OnReceive(object message) + { + switch (message) { - switch (message) + case JoinPaintSession join: { - case JoinPaintSession join: - { - _log.Debug("User [{0}] joined [{1}]", join.ConnectionId, join.InstanceId); - // need to make immutable copy of stroke data and pass it along - var strokeCopy = _connectedStrokes.ToArray(); - - // sync a single user. - _hubHandler.PushConnectedStrokes(join.ConnectionId, _sessionId, strokeCopy); - _hubHandler.AddUsers(join.ConnectionId, _users.ToArray()); - - // let all users know about the new user - _users.Add(join.UserId); - _hubHandler.AddUser(_sessionId, join.UserId); - break; - } - case AddPointToConnectedStroke or CreateConnectedStroke: - { - _streamsDebouncer.Tell(message); - break; - } - case ReceiveTimeout _: - { - _log.Info("Terminated Painting Session [{0}] after [{1}]", _sessionId, _idleTimeout); - Context.Stop(Self); - break; - } - default: - Unhandled(message); - break; + _log.Debug("User [{0}] joined [{1}]", join.ConnectionId, join.InstanceId); + // need to make immutable copy of stroke data and pass it along + var strokeCopy = _connectedStrokes.ToArray(); + + // sync a single user. + _hubHandler.PushConnectedStrokes(join.ConnectionId, _sessionId, strokeCopy); + _hubHandler.AddUsers(join.ConnectionId, _users.ToArray()); + + // let all users know about the new user + _users.Add(join.UserId); + _hubHandler.AddUser(_sessionId, join.UserId); + break; } + case AddPointToConnectedStroke or CreateConnectedStroke: + { + _streamsDebouncer.Tell(message); + break; + } + case ReceiveTimeout _: + { + _log.Info("Terminated Painting Session [{0}] after [{1}]", _sessionId, _idleTimeout); + Context.Stop(Self); + break; + } + default: + Unhandled(message); + break; } + } - protected override void PreStart() - { - _log.Info("Started drawing session [{0}]", _sessionId); + protected override void PreStart() + { + _log.Info("Started drawing session [{0}]", _sessionId); - var materializer = Context.Materializer(); - var (sourceRef, source) = Source.ActorRef(1000, OverflowStrategy.DropHead) - .PreMaterialize(materializer); + var materializer = Context.Materializer(); + var (sourceRef, source) = Source.ActorRef(1000, OverflowStrategy.DropHead) + .PreMaterialize(materializer); - _streamsDebouncer = sourceRef; - source.GroupedWithin(10, TimeSpan.FromMilliseconds(75)).RunForeach(TransmitActions, materializer); + _streamsDebouncer = sourceRef; + source.GroupedWithin(10, TimeSpan.FromMilliseconds(75)).RunForeach(TransmitActions, materializer); - // idle timeout all drawings after 20 minutes - Context.SetReceiveTimeout(_idleTimeout); - } + // idle timeout all drawings after 20 minutes + Context.SetReceiveTimeout(_idleTimeout); + } - private void TransmitActions(IEnumerable actions) - { - var createActions = actions.Where(a => a is CreateConnectedStroke).Select(a => ((CreateConnectedStroke)a).ConnectedStroke); + private void TransmitActions(IEnumerable actions) + { + var createActions = actions.Where(a => a is CreateConnectedStroke) + .Select(a => ((CreateConnectedStroke)a).ConnectedStroke); - var addActions = actions.Where(a => a is AddPointToConnectedStroke).Select(a => (AddPointToConnectedStroke)a); + var addActions = actions.Where(a => a is AddPointToConnectedStroke).Select(a => (AddPointToConnectedStroke)a); - _log.Info("BATCHED {0} create actions and {1} add actions", createActions.Count(), addActions.Count()); + _log.Info("BATCHED {0} create actions and {1} add actions", createActions.Count(), addActions.Count()); - createActions.ForEach(c => { c.Points = addActions.Where(a => a.Id == c.Id).Select(a => a.Point).ToList(); }); + createActions.ForEach(c => { c.Points = addActions.Where(a => a.Id == c.Id).Select(a => a.Point).ToList(); }); - addActions = addActions.Where(a => !createActions.Any(c => a.Id == c.Id)); + addActions = addActions.Where(a => !createActions.Any(c => a.Id == c.Id)); - _hubHandler.PushConnectedStrokes(_sessionId, createActions.ToArray()); - _connectedStrokes.AddRange(createActions); + _hubHandler.PushConnectedStrokes(_sessionId, createActions.ToArray()); + _connectedStrokes.AddRange(createActions); - addActions.GroupBy(a => a.Id).ForEach(add => { - _connectedStrokes.Where(c => c.Id == add.Key).First().Points.AddRange(add.Select(a => a.Point)); + addActions.GroupBy(a => a.Id).ForEach(add => + { + _connectedStrokes.Where(c => c.Id == add.Key).First().Points.AddRange(add.Select(a => a.Point)); - // sync ALL users - // TODO: look into zero-copy for this - _hubHandler.AddPointsToConnectedStroke(_sessionId, add.Key, add.Select(a => a.Point).ToArray()); - }); - } + // sync ALL users + // TODO: look into zero-copy for this + _hubHandler.AddPointsToConnectedStroke(_sessionId, add.Key, add.Select(a => a.Point).ToArray()); + }); } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Actors/PaintInstanceManager.cs b/src/DrawTogether.UI/Server/Actors/PaintInstanceManager.cs index a65db76..0078348 100644 --- a/src/DrawTogether.UI/Server/Actors/PaintInstanceManager.cs +++ b/src/DrawTogether.UI/Server/Actors/PaintInstanceManager.cs @@ -8,30 +8,29 @@ using Akka.DependencyInjection; using DrawTogether.UI.Shared.Connectivity; -namespace DrawTogether.UI.Server.Actors +namespace DrawTogether.UI.Server.Actors; + +public sealed class PaintInstanceManager : UntypedActor { - public sealed class PaintInstanceManager : UntypedActor + protected override void OnReceive(object message) { - protected override void OnReceive(object message) + switch (message) { - switch (message) + case PaintSessionProtocol.IPaintSessionMessage m: { - case PaintSessionProtocol.IPaintSessionMessage m: - { - // need to create or get child that corresponds to sessionId - var child = Context.Child(m.InstanceId) - .GetOrElse(() => - Context.ActorOf( - DependencyResolver.For(Context.System).Props(m.InstanceId), - m.InstanceId)); + // need to create or get child that corresponds to sessionId + var child = Context.Child(m.InstanceId) + .GetOrElse(() => + Context.ActorOf( + DependencyResolver.For(Context.System).Props(m.InstanceId), + m.InstanceId)); - child.Forward(m); - break; - } - default: - Unhandled(message); - break; + child.Forward(m); + break; } + default: + Unhandled(message); + break; } } } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Actors/UserInstanceActor.cs b/src/DrawTogether.UI/Server/Actors/UserInstanceActor.cs index f999442..210cdeb 100644 --- a/src/DrawTogether.UI/Server/Actors/UserInstanceActor.cs +++ b/src/DrawTogether.UI/Server/Actors/UserInstanceActor.cs @@ -1,20 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Akka.Actor; +using Akka.Actor; -namespace DrawTogether.UI.Server.Actors +namespace DrawTogether.UI.Server.Actors; + +/// +/// Gives a user a randomly-assigned name and associates that +/// with their session on DrawTogether +/// +public class UserInstanceActor : UntypedActor { - /// - /// Gives a user a randomly-assigned name and associates that - /// with their session on DrawTogether - /// - public class UserInstanceActor : UntypedActor + protected override void OnReceive(object message) { - protected override void OnReceive(object message) - { - - } } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/App.razor b/src/DrawTogether.UI/Server/App.razor index 3a2af53..e5d542c 100644 --- a/src/DrawTogether.UI/Server/App.razor +++ b/src/DrawTogether.UI/Server/App.razor @@ -1,10 +1,10 @@ - +

Sorry, there's nothing at this address.

-
+ \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Components/Circle.razor b/src/DrawTogether.UI/Server/Components/Circle.razor index fee0219..133ca5c 100644 --- a/src/DrawTogether.UI/Server/Components/Circle.razor +++ b/src/DrawTogether.UI/Server/Components/Circle.razor @@ -1,26 +1,20 @@ - + @code { - [Parameter] - public int radius { get; set; } = 10; + [Parameter] public int radius { get; set; } = 10; - [Parameter] - public string borderColor { get; set; } = "#eee"; + [Parameter] public string borderColor { get; set; } = "#eee"; - [Parameter] - public string fillColor { get; set; } = "#eee"; + [Parameter] public string fillColor { get; set; } = "#eee"; - [Parameter] - public string cursorId { get; set; } + [Parameter] public string cursorId { get; set; } - [Parameter] - public double cX { get; set; } + [Parameter] public double cX { get; set; } - [Parameter] - public double cY { get; set; } + [Parameter] public double cY { get; set; } } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Components/ColorPicker.razor b/src/DrawTogether.UI/Server/Components/ColorPicker.razor index 2927c25..a88a2c5 100644 --- a/src/DrawTogether.UI/Server/Components/ColorPicker.razor +++ b/src/DrawTogether.UI/Server/Components/ColorPicker.razor @@ -4,14 +4,12 @@ Color - + @code { - [Parameter] - public string CurrentColor { get; set; } = "#ff0000"; + [Parameter] public string CurrentColor { get; set; } = "#ff0000"; - [Parameter] - public EventCallback ColorValueChanged { get; set; } + [Parameter] public EventCallback ColorValueChanged { get; set; } } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Components/CursorPicker.razor b/src/DrawTogether.UI/Server/Components/CursorPicker.razor index 86761fb..6f2cbb9 100644 --- a/src/DrawTogether.UI/Server/Components/CursorPicker.razor +++ b/src/DrawTogether.UI/Server/Components/CursorPicker.razor @@ -6,15 +6,13 @@ Cursor Size (px) - + @code { - [Parameter] - public string CursorSize { get; set; } = "8"; + [Parameter] public string CursorSize { get; set; } = "8"; - [Parameter] - public EventCallback CursorSizeChanged { get; set; } + [Parameter] public EventCallback CursorSizeChanged { get; set; } } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Components/Curve.razor b/src/DrawTogether.UI/Server/Components/Curve.razor index b53efc0..d00eea8 100644 --- a/src/DrawTogether.UI/Server/Components/Curve.razor +++ b/src/DrawTogether.UI/Server/Components/Curve.razor @@ -4,14 +4,11 @@ @code { private Point[] _points { get; set; } = new Point[0]; - [Parameter] - public List Points { get; set; } = new List(); + [Parameter] public List Points { get; set; } = new(); - [Parameter] - public int StrokeWidth { get; set; } = 8; + [Parameter] public int StrokeWidth { get; set; } = 8; - [Parameter] - public string Stroke { get; set; } = "#ff0000"; + [Parameter] public string Stroke { get; set; } = "#ff0000"; protected override bool ShouldRender() { @@ -20,24 +17,28 @@ _points = Points.ToArray(); return true; } + return false; } protected static string PathData(Point[] Points) { - // Parameter for smoothness of path in interval [0, 0.5] - double smoothness = 1.0 / 3.0; + // Parameter for smoothness of path in interval [0, 0.5] + var smoothness = 1.0 / 3.0; var result = ""; if (Points.Length >= 2) { - result = $"M {Points[0].x} {Points[0].y} "; - for (int i = 1; i < Points.Length - 1; i++) + result = $"M {Points[0].X} {Points[0].Y} "; + for (var i = 1; i < Points.Length - 1; i++) { - result += $"S {Points[i - 1].x * smoothness / 2 + Points[i].x - Points[i + 1].x * smoothness / 2} {Points[i - 1].y * smoothness / 2 + Points[i].y - Points[i + 1].y * smoothness / 2} {Points[i].x} {Points[i].y} "; + result += $"S {Points[i - 1].X * smoothness / 2 + Points[i].X - Points[i + 1].X * smoothness / 2} {Points[i - 1].Y * smoothness / 2 + Points[i].Y - Points[i + 1].Y * smoothness / 2} {Points[i].X} {Points[i].Y} "; } - result += $"S {Points[^2].x * smoothness + Points[^1].x * (1 - smoothness)} {Points[^2].y * smoothness + Points[^1].y * (1 - smoothness)} {Points[^1].x} {Points[^1].y} "; + + result += $"S {Points[^2].X * smoothness + Points[^1].X * (1 - smoothness)} {Points[^2].Y * smoothness + Points[^1].Y * (1 - smoothness)} {Points[^1].X} {Points[^1].Y} "; } + return result; } + } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/DrawTogether.UI.Server.csproj b/src/DrawTogether.UI/Server/DrawTogether.UI.Server.csproj index 8a40268..0626cea 100644 --- a/src/DrawTogether.UI/Server/DrawTogether.UI.Server.csproj +++ b/src/DrawTogether.UI/Server/DrawTogether.UI.Server.csproj @@ -1,23 +1,19 @@ - - $(NetVersion) - enable - enable - + + $(NetVersion) + enable + enable + - - - - + + + + - - - - - - - + + + diff --git a/src/DrawTogether.UI/Server/Hubs/DrawHub.cs b/src/DrawTogether.UI/Server/Hubs/DrawHub.cs index 65f3ccb..52f6939 100644 --- a/src/DrawTogether.UI/Server/Hubs/DrawHub.cs +++ b/src/DrawTogether.UI/Server/Hubs/DrawHub.cs @@ -1,55 +1,47 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using DrawTogether.UI.Server.Services; -using DrawTogether.UI.Server.Services.Users; +using DrawTogether.UI.Server.Services; using DrawTogether.UI.Shared; using DrawTogether.UI.Shared.Connectivity; using Microsoft.AspNetCore.SignalR; -using Microsoft.Extensions.Logging; -namespace DrawTogether.UI.Server.Hubs +namespace DrawTogether.UI.Server.Hubs; + +public sealed class DrawHub : Hub { - public sealed class DrawHub : Hub + private readonly ILogger _log; + private readonly IDrawSessionHandler _sessionHandler; + + public DrawHub(IDrawSessionHandler sessionHandler, ILogger log) + { + _sessionHandler = sessionHandler; + _log = log; + } + + /// + /// Connects this SignalR User to a paint session in progress. + /// + /// The unique id of a specific paint session. + public async Task JoinSession(string sessionId) + { + await Groups.AddToGroupAsync(Context.ConnectionId, sessionId); + + // need to have some sort of service handle here for sending / retrieving state + _sessionHandler.Handle(new PaintSessionProtocol.JoinPaintSession(sessionId, Context.ConnectionId, + Context.UserIdentifier ?? "BadUser")); + } + + public void CreateConnectedStroke(string sessionId, ConnectedStroke connectedStroke) + { + _sessionHandler.Handle(new PaintSessionProtocol.CreateConnectedStroke(sessionId, connectedStroke)); + } + + public void AddPointToConnectedStroke(string sessionId, Guid id, Point point) + { + _sessionHandler.Handle(new PaintSessionProtocol.AddPointToConnectedStroke(sessionId, id, point)); + } + + public override Task OnConnectedAsync() { - private readonly IDrawSessionHandler _sessionHandler; - private readonly ILogger _log; - - public DrawHub(IDrawSessionHandler sessionHandler, ILogger log) - { - _sessionHandler = sessionHandler; - _log = log; - } - - /// - /// Connects this SignalR User to a paint session in progress. - /// - /// The unique id of a specific paint session. - public async Task JoinSession(string sessionId) - { - - await Groups.AddToGroupAsync(Context.ConnectionId, sessionId); - - // need to have some sort of service handle here for sending / retrieving state - _sessionHandler.Handle(new PaintSessionProtocol.JoinPaintSession(sessionId, Context.ConnectionId, Context.UserIdentifier ?? "BadUser")); - } - - public void CreateConnectedStroke(string sessionId, ConnectedStroke connectedStroke) - { - _sessionHandler.Handle(new PaintSessionProtocol.CreateConnectedStroke(sessionId, connectedStroke)); - } - - public void AddPointToConnectedStroke(string sessionId, Guid id, Point point) - { - _sessionHandler.Handle(new PaintSessionProtocol.AddPointToConnectedStroke(sessionId, id, point)); - } - - public override Task OnConnectedAsync() - { - _log.LogInformation("Received connection from [{0}->{1}]", Context.ConnectionId, Context.UserIdentifier); - return base.OnConnectedAsync(); - } + _log.LogInformation("Received connection from [{0}->{1}]", Context.ConnectionId, Context.UserIdentifier); + return base.OnConnectedAsync(); } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Pages/Counter.razor b/src/DrawTogether.UI/Server/Pages/Counter.razor index 0ff5d87..ff95da7 100644 --- a/src/DrawTogether.UI/Server/Pages/Counter.razor +++ b/src/DrawTogether.UI/Server/Pages/Counter.razor @@ -17,4 +17,4 @@ navigationManager.NavigateTo($"/paint/{sessionId}"); } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Pages/Error.cshtml b/src/DrawTogether.UI/Server/Pages/Error.cshtml index c565485..ce49ae4 100644 --- a/src/DrawTogether.UI/Server/Pages/Error.cshtml +++ b/src/DrawTogether.UI/Server/Pages/Error.cshtml @@ -5,38 +5,38 @@ - - + + Error - - + + -
-
-

Error.

-

An error occurred while processing your request.

+
+
+

Error.

+

An error occurred while processing your request.

- @if (Model.ShowRequestId) - { -

- Request ID: @Model.RequestId -

- } - -

Development Mode

-

- Swapping to the Development environment displays detailed information about the error that occurred. -

+ @if (Model.ShowRequestId) + {

- The Development environment shouldn't be enabled for deployed applications. - It can result in displaying sensitive information from exceptions to end users. - For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development - and restarting the app. + Request ID: @Model.RequestId

-
+ } + +

Development Mode

+

+ Swapping to the Development environment displays detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+
- + \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Pages/Error.cshtml.cs b/src/DrawTogether.UI/Server/Pages/Error.cshtml.cs index fcfa080..08456a9 100644 --- a/src/DrawTogether.UI/Server/Pages/Error.cshtml.cs +++ b/src/DrawTogether.UI/Server/Pages/Error.cshtml.cs @@ -1,32 +1,26 @@ -using Microsoft.AspNetCore.Mvc; +using System.Diagnostics; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; -namespace DrawTogether.UI.Server.Pages +namespace DrawTogether.UI.Server.Pages; + +[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] +[IgnoreAntiforgeryToken] +public class ErrorModel : PageModel { - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - [IgnoreAntiforgeryToken] - public class ErrorModel : PageModel - { - public string RequestId { get; set; } + private readonly ILogger _logger; - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + public ErrorModel(ILogger logger) + { + _logger = logger; + } - private readonly ILogger _logger; + public string RequestId { get; set; } - public ErrorModel(ILogger logger) - { - _logger = logger; - } + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - public void OnGet() - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; - } + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Pages/Paint.razor b/src/DrawTogether.UI/Server/Pages/Paint.razor index 46d1d3f..ba52253 100644 --- a/src/DrawTogether.UI/Server/Pages/Paint.razor +++ b/src/DrawTogether.UI/Server/Pages/Paint.razor @@ -1,8 +1,8 @@ @page "/paint/{sessionId}" -@using DrawTogether.UI.Server.Components; -@using DrawTogether.UI.Shared; -@using Microsoft.AspNetCore.SignalR.Client @inject NavigationManager navigationManager; +@using DrawTogether.UI.Server.Components +@using DrawTogether.UI.Shared +@using Microsoft.AspNetCore.SignalR.Client @implements IDisposable;

Paint!

@@ -38,19 +38,18 @@ @code { - [Parameter] - public string SessionId { get; set; } + [Parameter] public string SessionId { get; set; } - Dictionary RenderStrokes = new(); + readonly Dictionary RenderStrokes = new(); - HashSet Users = new HashSet(); + readonly HashSet Users = new(); private string _hubUrl; private HubConnection _hubConnection; protected override async Task OnInitializedAsync() { - // Create the chat client + // Create the chat client var baseUrl = navigationManager.BaseUri; _hubUrl = navigationManager.BaseUri.TrimEnd('/') + DrawHubConstants.HubUri; @@ -118,7 +117,7 @@ private void CursorDown(MouseEventArgs e) { CurrentStrokeId = Guid.NewGuid(); - var newStroke = new ConnectedStroke() {Id = CurrentStrokeId, Stroke = Color, StrokeWidth = CursorSize}; + var newStroke = new ConnectedStroke { Id = CurrentStrokeId, Stroke = Color, StrokeWidth = CursorSize }; _hubConnection.SendAsync("CreateConnectedStroke", SessionId, newStroke); if (e.Buttons == 1) { @@ -128,7 +127,7 @@ private void CursorMove(MouseEventArgs e) { - //mousePointerMessage = $"Mouse coordinates: {e.ScreenX}:{e.ScreenY}"; + //mousePointerMessage = $"Mouse coordinates: {e.ScreenX}:{e.ScreenY}"; cX = e.OffsetX; cY = e.OffsetY; mousePointerMessage = $"Moving circle to {e.OffsetX},{e.OffsetY} [button pressed? {e.Buttons}]"; @@ -158,7 +157,7 @@ private void ResetScreen() { - //strokes.Clear(); + //strokes.Clear(); } public void Dispose() diff --git a/src/DrawTogether.UI/Server/Pages/_Host.cshtml b/src/DrawTogether.UI/Server/Pages/_Host.cshtml index 98b1e19..769957c 100644 --- a/src/DrawTogether.UI/Server/Pages/_Host.cshtml +++ b/src/DrawTogether.UI/Server/Pages/_Host.cshtml @@ -8,16 +8,16 @@ - - + + TestBlazor - - - - + + + + - +
diff --git a/src/DrawTogether.UI/Server/Pages/_Host.cshtml.cs b/src/DrawTogether.UI/Server/Pages/_Host.cshtml.cs index 9c1374a..d97204b 100644 --- a/src/DrawTogether.UI/Server/Pages/_Host.cshtml.cs +++ b/src/DrawTogether.UI/Server/Pages/_Host.cshtml.cs @@ -1,12 +1,10 @@ using Microsoft.AspNetCore.Mvc.RazorPages; -namespace DefaultNamespace +namespace DefaultNamespace; + +public class _Host : PageModel { - public class _Host : PageModel + public void OnGet() { - public void OnGet() - { - - } } } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Program.cs b/src/DrawTogether.UI/Server/Program.cs index db9cb4e..5d123da 100644 --- a/src/DrawTogether.UI/Server/Program.cs +++ b/src/DrawTogether.UI/Server/Program.cs @@ -1,26 +1,15 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +namespace DrawTogether.UI.Server; -namespace DrawTogether.UI.Server +public class Program { - public class Program + public static void Main(string[] args) { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } + CreateHostBuilder(args).Build().Run(); + } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + public static IHostBuilder CreateHostBuilder(string[] args) + { + return Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Properties/launchSettings.json b/src/DrawTogether.UI/Server/Properties/launchSettings.json index e2fd888..a5c9a0d 100644 --- a/src/DrawTogether.UI/Server/Properties/launchSettings.json +++ b/src/DrawTogether.UI/Server/Properties/launchSettings.json @@ -1,30 +1,30 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:25141", - "sslPort": 44337 + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:25141", + "sslPort": 44337 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "DrawTogether.UI.Server": { - "commandName": "Project", - "dotnetRunMessages": "true", - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:5001;http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "DrawTogether.UI.Server": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" } } } +} diff --git a/src/DrawTogether.UI/Server/Services/AkkaService.cs b/src/DrawTogether.UI/Server/Services/AkkaService.cs index 46bc5eb..d3ee599 100644 --- a/src/DrawTogether.UI/Server/Services/AkkaService.cs +++ b/src/DrawTogether.UI/Server/Services/AkkaService.cs @@ -4,35 +4,27 @@ // // ----------------------------------------------------------------------- -using System; -using System.Threading; -using System.Threading.Tasks; using Akka.Actor; -using Akka.DependencyInjection; using Akka.Hosting; using DrawTogether.UI.Server.Actors; -using DrawTogether.UI.Shared.Connectivity; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -namespace DrawTogether.UI.Server.Services +namespace DrawTogether.UI.Server.Services; + +/// +/// INTERNAL API +/// +public static class AkkaExtensions { - /// - /// INTERNAL API - /// - public static class AkkaExtensions + public static void AddDrawTogetherAkka(this IServiceCollection services) { - public static void AddDrawTogetherAkka(this IServiceCollection services) + // creates an instance of the ISignalRProcessor that can be handled by SignalR + services.AddAkka("DrawTogether", (builder, sp) => { - // creates an instance of the ISignalRProcessor that can be handled by SignalR - services.AddAkka("DrawTogether", (builder, sp) => + builder.WithActors((system, registry, resolver) => { - builder.WithActors((system, registry, resolver) => - { - var paintActor = system.ActorOf(Props.Create(() => new PaintInstanceManager()), "paint"); - registry.Register(paintActor); - }); + var paintActor = system.ActorOf(Props.Create(() => new PaintInstanceManager()), "paint"); + registry.Register(paintActor); }); - } + }); } } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Services/IDrawHubHandler.cs b/src/DrawTogether.UI/Server/Services/IDrawHubHandler.cs index 0a9a30f..8f2ce5c 100644 --- a/src/DrawTogether.UI/Server/Services/IDrawHubHandler.cs +++ b/src/DrawTogether.UI/Server/Services/IDrawHubHandler.cs @@ -4,73 +4,71 @@ // // ----------------------------------------------------------------------- -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using DrawTogether.UI.Server.Hubs; using DrawTogether.UI.Shared; using Microsoft.AspNetCore.SignalR; -namespace DrawTogether.UI.Server.Services +namespace DrawTogether.UI.Server.Services; + +/// +/// Used for Akka.NET --> SignalR interop +/// +public interface IDrawHubHandler +{ + Task AddPointsToConnectedStroke(string sessionId, Guid Id, Point[] points); + + Task AddPointsToConnectedStroke(string connectionId, string sessionId, Guid Id, Point[] points); + + Task PushConnectedStrokes(string sessionId, ConnectedStroke[] connectedStrokes); + + Task PushConnectedStrokes(string connectionId, string sessionId, ConnectedStroke[] connectedStrokes); + + Task AddUser(string sessionId, string userName); + + Task AddUsers(string connectionId, IEnumerable userNames); +} + +internal sealed class DrawHubHandler : IDrawHubHandler { - /// - /// Used for Akka.NET --> SignalR interop - /// - public interface IDrawHubHandler + private readonly IHubContext _drawHub; + + public DrawHubHandler(IHubContext drawHub) { - Task AddPointsToConnectedStroke(string sessionId, Guid Id, Point[] points); + _drawHub = drawHub; + } - Task AddPointsToConnectedStroke(string connectionId, string sessionId, Guid Id, Point[] points); + public async Task AddPointsToConnectedStroke(string sessionId, Guid Id, Point[] points) + { + await _drawHub.Clients.Group(sessionId).SendAsync("AddPointsToConnectedStroke", Id, points) + .ConfigureAwait(false); + } - Task PushConnectedStrokes(string sessionId, ConnectedStroke[] connectedStrokes); + public async Task AddPointsToConnectedStroke(string connectionId, string sessionId, Guid Id, Point[] points) + { + await _drawHub.Clients.Client(connectionId).SendAsync("AddPointsToConnectedStroke", Id, points) + .ConfigureAwait(false); + } - Task PushConnectedStrokes(string connectionId, string sessionId, ConnectedStroke[] connectedStrokes); + public async Task PushConnectedStrokes(string sessionId, ConnectedStroke[] connectedStrokes) + { + await _drawHub.Clients.Group(sessionId).SendAsync("AddConnectedStrokes", connectedStrokes) + .ConfigureAwait(false); + } - Task AddUser(string sessionId, string userName); + public async Task PushConnectedStrokes(string connectionId, string sessionId, ConnectedStroke[] connectedStrokes) + { + await _drawHub.Clients.Client(connectionId).SendAsync("AddConnectedStrokes", connectedStrokes) + .ConfigureAwait(false); + } - Task AddUsers(string connectionId, IEnumerable userNames); + public async Task AddUser(string sessionId, string userName) + { + await _drawHub.Clients.Group(sessionId).SendAsync("AddUser", userName).ConfigureAwait(false); } - internal sealed class DrawHubHandler : IDrawHubHandler + public async Task AddUsers(string connectionId, IEnumerable userNames) { - private readonly IHubContext _drawHub; - - public DrawHubHandler(IHubContext drawHub) - { - _drawHub = drawHub; - } - - public async Task AddPointsToConnectedStroke(string sessionId, Guid Id, Point[] points) - { - await _drawHub.Clients.Group(sessionId).SendAsync("AddPointsToConnectedStroke", Id, points).ConfigureAwait(false); - } - - public async Task AddPointsToConnectedStroke(string connectionId, string sessionId, Guid Id, Point[] points) - { - await _drawHub.Clients.Client(connectionId).SendAsync("AddPointsToConnectedStroke", Id, points).ConfigureAwait(false); - } - - public async Task PushConnectedStrokes(string sessionId, ConnectedStroke[] connectedStrokes) - { - await _drawHub.Clients.Group(sessionId).SendAsync("AddConnectedStrokes", connectedStrokes).ConfigureAwait(false); - } - - public async Task PushConnectedStrokes(string connectionId, string sessionId, ConnectedStroke[] connectedStrokes) - { - await _drawHub.Clients.Client(connectionId).SendAsync("AddConnectedStrokes", connectedStrokes).ConfigureAwait(false); - } - - public async Task AddUser(string sessionId, string userName) - { - await _drawHub.Clients.Group(sessionId).SendAsync("AddUser", userName).ConfigureAwait(false); - } - - public async Task AddUsers(string connectionId, IEnumerable userNames) - { - foreach (var u in userNames) - { - await _drawHub.Clients.Client(connectionId).SendAsync("AddUser", u).ConfigureAwait(false); - } - } + foreach (var u in userNames) + await _drawHub.Clients.Client(connectionId).SendAsync("AddUser", u).ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Services/IDrawSessionHandler.cs b/src/DrawTogether.UI/Server/Services/IDrawSessionHandler.cs index b0c949d..79d267e 100644 --- a/src/DrawTogether.UI/Server/Services/IDrawSessionHandler.cs +++ b/src/DrawTogether.UI/Server/Services/IDrawSessionHandler.cs @@ -1,32 +1,29 @@ -using System.Collections.Generic; -using System.Linq; -using Akka.Actor; +using Akka.Actor; using Akka.Hosting; using DrawTogether.UI.Server.Actors; using static DrawTogether.UI.Shared.Connectivity.PaintSessionProtocol; -namespace DrawTogether.UI.Server.Services +namespace DrawTogether.UI.Server.Services; + +/// +/// Used by SignalR to message our shared drawing system. +/// +public interface IDrawSessionHandler +{ + void Handle(IPaintSessionMessage msg); +} + +public sealed class DrawSessionHandler : IDrawSessionHandler { - /// - /// Used by SignalR to message our shared drawing system. - /// - public interface IDrawSessionHandler + private readonly IActorRef _paintInstanceManager; + + public DrawSessionHandler(IRequiredActor paintInstanceManager) { - void Handle(IPaintSessionMessage msg); + _paintInstanceManager = paintInstanceManager.GetAsync().Result; } - public sealed class DrawSessionHandler : IDrawSessionHandler + public void Handle(IPaintSessionMessage msg) { - private readonly IActorRef _paintInstanceManager; - - public DrawSessionHandler(IRequiredActor paintInstanceManager) - { - _paintInstanceManager = paintInstanceManager.GetAsync().Result; - } - - public void Handle(IPaintSessionMessage msg) - { - _paintInstanceManager.Tell(msg); - } + _paintInstanceManager.Tell(msg); } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Services/IPaintSessionGenerator.cs b/src/DrawTogether.UI/Server/Services/IPaintSessionGenerator.cs index ab9d389..b20fbba 100644 --- a/src/DrawTogether.UI/Server/Services/IPaintSessionGenerator.cs +++ b/src/DrawTogether.UI/Server/Services/IPaintSessionGenerator.cs @@ -1,21 +1,18 @@ -using System; +namespace DrawTogether.UI.Server.Services; -namespace DrawTogether.UI.Server.Services +public interface IPaintSessionGenerator { - public interface IPaintSessionGenerator - { - /// - /// Create a randomly named new drawing session. - /// - string CreateNewSession(); - } + /// + /// Create a randomly named new drawing session. + /// + string CreateNewSession(); +} - internal class GuidPaintSessionGenerator : IPaintSessionGenerator +internal class GuidPaintSessionGenerator : IPaintSessionGenerator +{ + public string CreateNewSession() { - public string CreateNewSession() - { - // return a base64 encoded GUID - return Convert.ToBase64String(Guid.NewGuid().ToByteArray()); - } + // return a base64 encoded GUID + return Convert.ToBase64String(Guid.NewGuid().ToByteArray()); } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Services/Users/RandomNameService.cs b/src/DrawTogether.UI/Server/Services/Users/RandomNameService.cs index 7a9d8c3..05e5743 100644 --- a/src/DrawTogether.UI/Server/Services/Users/RandomNameService.cs +++ b/src/DrawTogether.UI/Server/Services/Users/RandomNameService.cs @@ -1,28 +1,21 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; +using System.Collections.Concurrent; using Microsoft.AspNetCore.SignalR; -namespace DrawTogether.UI.Server.Services.Users +namespace DrawTogether.UI.Server.Services.Users; + +public sealed class RandomNameService : IUserIdProvider { - public sealed class RandomNameService : IUserIdProvider - { - // DO NOT DO THIS IN PRODUCTION - private readonly ConcurrentDictionary _connectionIdToNames = - new ConcurrentDictionary(); + // DO NOT DO THIS IN PRODUCTION + private readonly ConcurrentDictionary _connectionIdToNames = new(); - public string? GetUserId(HubConnectionContext connection) + public string? GetUserId(HubConnectionContext connection) + { + if (_connectionIdToNames.ContainsKey(connection.ConnectionId)) { - if (_connectionIdToNames.ContainsKey(connection.ConnectionId)) - return _connectionIdToNames[connection.ConnectionId]; - else - { - var name = _connectionIdToNames[connection.ConnectionId] = UserNamingService.GenerateRandomName(); - return name; - } + return _connectionIdToNames[connection.ConnectionId]; } + + var name = _connectionIdToNames[connection.ConnectionId] = UserNamingService.GenerateRandomName(); + return name; } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Services/Users/UserNamingService.cs b/src/DrawTogether.UI/Server/Services/Users/UserNamingService.cs index 54169c7..a88d5d0 100644 --- a/src/DrawTogether.UI/Server/Services/Users/UserNamingService.cs +++ b/src/DrawTogether.UI/Server/Services/Users/UserNamingService.cs @@ -1,33 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Akka.Util; +using Akka.Util; -namespace DrawTogether.UI.Server.Services.Users +namespace DrawTogether.UI.Server.Services.Users; + +public static class UserNamingService { - public static class UserNamingService + public static readonly string[] SeedNames1 = { - public static readonly string[] SeedNames1 = new[] - { - "Icarus", "H3", "himij", "Ruk", "Kristoffer", "Stan", - "Cheeseburger", "Farmaggedon", "Inflation", "Oracle", - "Apple", "Dollar", "Big", "Sloppy", "Angry" - }; + "Icarus", "H3", "himij", "Ruk", "Kristoffer", "Stan", + "Cheeseburger", "Farmaggedon", "Inflation", "Oracle", + "Apple", "Dollar", "Big", "Sloppy", "Angry" + }; - public static readonly string[] SeedNames2 = new[] - { - "Ardbeg", "Pappy", "Weller", "TrashCan", "Foo", - "Bar", "Fuber", "DotNetDrama", "Bulleit", "TheGreat", - "Pinn", "Swede", "German", "'Merican", "Canadian", "Dane" - }; + public static readonly string[] SeedNames2 = + { + "Ardbeg", "Pappy", "Weller", "TrashCan", "Foo", + "Bar", "Fuber", "DotNetDrama", "Bulleit", "TheGreat", + "Pinn", "Swede", "German", "'Merican", "Canadian", "Dane" + }; - public static string GenerateRandomName() - { - var r1 = SeedNames1[ThreadLocalRandom.Current.Next(0, SeedNames1.Length - 1)]; - var r2 = SeedNames2[ThreadLocalRandom.Current.Next(0, SeedNames2.Length - 1)]; - var r3 = ThreadLocalRandom.Current.Next(0, 10000); - return $"{r1}{r2}{r3}"; - } + public static string GenerateRandomName() + { + var r1 = SeedNames1[ThreadLocalRandom.Current.Next(0, SeedNames1.Length - 1)]; + var r2 = SeedNames2[ThreadLocalRandom.Current.Next(0, SeedNames2.Length - 1)]; + var r3 = ThreadLocalRandom.Current.Next(0, 10000); + return $"{r1}{r2}{r3}"; } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Shared/MainLayout.razor b/src/DrawTogether.UI/Server/Shared/MainLayout.razor index b416cb9..a31ba9d 100644 --- a/src/DrawTogether.UI/Server/Shared/MainLayout.razor +++ b/src/DrawTogether.UI/Server/Shared/MainLayout.razor @@ -2,7 +2,7 @@
@@ -14,4 +14,4 @@ @Body
-
+
\ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Shared/MainLayout.razor.css b/src/DrawTogether.UI/Server/Shared/MainLayout.razor.css index 43c355a..7b3e22f 100644 --- a/src/DrawTogether.UI/Server/Shared/MainLayout.razor.css +++ b/src/DrawTogether.UI/Server/Shared/MainLayout.razor.css @@ -21,15 +21,15 @@ align-items: center; } - .top-row ::deep a, .top-row .btn-link { - white-space: nowrap; - margin-left: 1.5rem; - } +.top-row ::deep a, .top-row .btn-link { + white-space: nowrap; + margin-left: 1.5rem; +} - .top-row a:first-child { - overflow: hidden; - text-overflow: ellipsis; - } +.top-row a:first-child { + overflow: hidden; + text-overflow: ellipsis; +} @media (max-width: 640.98px) { .top-row:not(.auth) { diff --git a/src/DrawTogether.UI/Server/Shared/NavMenu.razor b/src/DrawTogether.UI/Server/Shared/NavMenu.razor index ca75d86..e0d62ec 100644 --- a/src/DrawTogether.UI/Server/Shared/NavMenu.razor +++ b/src/DrawTogether.UI/Server/Shared/NavMenu.razor @@ -29,4 +29,5 @@ { collapseNavMenu = !collapseNavMenu; } -} + +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/Shared/NavMenu.razor.css b/src/DrawTogether.UI/Server/Shared/NavMenu.razor.css index acc5f9f..5f415c8 100644 --- a/src/DrawTogether.UI/Server/Shared/NavMenu.razor.css +++ b/src/DrawTogether.UI/Server/Shared/NavMenu.razor.css @@ -4,7 +4,7 @@ .top-row { height: 3.5rem; - background-color: rgba(0,0,0,0.4); + background-color: rgba(0, 0, 0, 0.4); } .navbar-brand { @@ -23,30 +23,30 @@ padding-bottom: 0.5rem; } - .nav-item:first-of-type { - padding-top: 1rem; - } +.nav-item:first-of-type { + padding-top: 1rem; +} - .nav-item:last-of-type { - padding-bottom: 1rem; - } +.nav-item:last-of-type { + padding-bottom: 1rem; +} - .nav-item ::deep a { - color: #d7d7d7; - border-radius: 4px; - height: 3rem; - display: flex; - align-items: center; - line-height: 3rem; - } +.nav-item ::deep a { + color: #d7d7d7; + border-radius: 4px; + height: 3rem; + display: flex; + align-items: center; + line-height: 3rem; +} .nav-item ::deep a.active { - background-color: rgba(255,255,255,0.25); + background-color: rgba(255, 255, 255, 0.25); color: white; } .nav-item ::deep a:hover { - background-color: rgba(255,255,255,0.1); + background-color: rgba(255, 255, 255, 0.1); color: white; } diff --git a/src/DrawTogether.UI/Server/Startup.cs b/src/DrawTogether.UI/Server/Startup.cs index e0ff4f2..13a2531 100644 --- a/src/DrawTogether.UI/Server/Startup.cs +++ b/src/DrawTogether.UI/Server/Startup.cs @@ -1,72 +1,63 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.ResponseCompression; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using System.Linq; using DrawTogether.UI.Server.Hubs; using DrawTogether.UI.Server.Services; using DrawTogether.UI.Server.Services.Users; using DrawTogether.UI.Shared; using Microsoft.AspNetCore.SignalR; -namespace DrawTogether.UI.Server +namespace DrawTogether.UI.Server; + +public class Startup { - public class Startup + public Startup(IConfiguration configuration) { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } + Configuration = configuration; + } + + public IConfiguration Configuration { get; } - public IConfiguration Configuration { get; } + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + services.AddDrawTogetherAkka(); + services.AddTransient(); + services.AddSingleton(); + services.AddSignalR(); + services.AddServerSideBlazor(); + services.AddControllersWithViews(); + services.AddRazorPages(); + } - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) { - services.AddSingleton(); - services.AddSingleton(); - services.AddDrawTogetherAkka(); - services.AddTransient(); - services.AddSingleton(); - services.AddSignalR(); - services.AddServerSideBlazor(); - services.AddControllersWithViews(); - services.AddRazorPages(); + app.UseDeveloperExceptionPage(); } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + else { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); + } - app.UseHttpsRedirection(); - app.UseStaticFiles(); + app.UseHttpsRedirection(); + app.UseStaticFiles(); - app.UseRouting(); - app.UseAuthentication(); - app.UseAuthorization(); + app.UseRouting(); + app.UseAuthentication(); + app.UseAuthorization(); - app.UseEndpoints(endpoints => - { - endpoints.MapBlazorHub(); - endpoints.MapHub(DrawHubConstants.HubUri); - endpoints.MapRazorPages(); - endpoints.MapControllers(); - endpoints.MapFallbackToPage("/_Host"); - }); - } + app.UseEndpoints(endpoints => + { + endpoints.MapBlazorHub(); + endpoints.MapHub(DrawHubConstants.HubUri); + endpoints.MapRazorPages(); + endpoints.MapControllers(); + endpoints.MapFallbackToPage("/_Host"); + }); } -} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/_Imports.razor b/src/DrawTogether.UI/Server/_Imports.razor index 6d9fdea..63559be 100644 --- a/src/DrawTogether.UI/Server/_Imports.razor +++ b/src/DrawTogether.UI/Server/_Imports.razor @@ -6,4 +6,4 @@ @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.JSInterop @using DrawTogether.UI.Server -@using DrawTogether.UI.Server.Shared +@using DrawTogether.UI.Server.Shared \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/_ViewImports.cshtml b/src/DrawTogether.UI/Server/_ViewImports.cshtml index 9df1023..3f10073 100644 --- a/src/DrawTogether.UI/Server/_ViewImports.cshtml +++ b/src/DrawTogether.UI/Server/_ViewImports.cshtml @@ -2,4 +2,4 @@ DrawTogether.UI.Server.Pages -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/src/DrawTogether.UI/Server/appsettings.json b/src/DrawTogether.UI/Server/appsettings.json index 3c37399..d9d9a9b 100644 --- a/src/DrawTogether.UI/Server/appsettings.json +++ b/src/DrawTogether.UI/Server/appsettings.json @@ -6,5 +6,5 @@ "Microsoft.Hosting.Lifetime": "Information" } }, -"AllowedHosts": "*" + "AllowedHosts": "*" } diff --git a/src/DrawTogether.UI/Server/wwwroot/css/app.css b/src/DrawTogether.UI/Server/wwwroot/css/app.css index 82fc22a..8a24f76 100644 --- a/src/DrawTogether.UI/Server/wwwroot/css/app.css +++ b/src/DrawTogether.UI/Server/wwwroot/css/app.css @@ -42,9 +42,9 @@ a, .btn-link { z-index: 1000; } - #blazor-error-ui .dismiss { - cursor: pointer; - position: absolute; - right: 0.75rem; - top: 0.5rem; - } +#blazor-error-ui .dismiss { + cursor: pointer; + position: absolute; + right: 0.75rem; + top: 0.5rem; +} diff --git a/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/README.md b/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/README.md index 6b810e4..45f384e 100644 --- a/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/README.md +++ b/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/README.md @@ -3,18 +3,15 @@ ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons) - - ## What's in Open Iconic? * 223 icons designed to be legible down to 8 pixels -* Super-light SVG files - 61.8 for the entire set +* Super-light SVG files - 61.8 for the entire set * SVG sprite—the modern replacement for icon fonts * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. - ## Getting Started #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections. @@ -23,7 +20,8 @@ #### Using Open Iconic's SVGs -We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). +We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest +you display them like you would any other image (don't forget the `alt` attribute). ``` icon name @@ -31,9 +29,12 @@ We like SVGs and we think they're the way to display icons on the web. Since Ope #### Using Open Iconic's SVG Sprite -Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. +Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's +like an icon font, without being a hack. -Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* +Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: +To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for +each different icon in the* `` *tag.* ``` @@ -41,7 +42,8 @@ Adding an icon from an SVG sprite is a little different than what you're used to ``` -Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. +Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width +and height dimensions. ``` .icon { @@ -62,17 +64,14 @@ To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.c #### Using Open Iconic's Icon Font... - ##### …with Bootstrap You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` - ``` ``` - ``` ``` @@ -85,7 +84,6 @@ You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css ``` - ``` ``` @@ -102,7 +100,6 @@ You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, ``` - ## License ### Icons diff --git a/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/font/fonts/open-iconic.svg b/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/font/fonts/open-iconic.svg index 32b2c4e..9d1833e 100644 --- a/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/font/fonts/open-iconic.svg +++ b/src/DrawTogether.UI/Server/wwwroot/css/open-iconic/font/fonts/open-iconic.svg @@ -4,540 +4,541 @@ 2014-7-1: Created. --> - -Created by FontForge 20120731 at Tue Jul 1 20:39:22 2014 - By P.J. Onori -Created by P.J. Onori with FontForge 2.0 (http://fontforge.sf.net) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +s22 50 50 50zM650 200c28 0 50 -22 50 -50s-22 -50 -50 -50s-50 22 -50 50s22 50 50 50zM400 100c28 0 50 -22 50 -50s-22 -50 -50 -50s-50 22 -50 50s22 50 50 50z"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/DrawTogether.UI/Server/wwwroot/index.html b/src/DrawTogether.UI/Server/wwwroot/index.html index d5ceb0e..f1f27b5 100644 --- a/src/DrawTogether.UI/Server/wwwroot/index.html +++ b/src/DrawTogether.UI/Server/wwwroot/index.html @@ -2,24 +2,24 @@ - - + + DrawTogether.UI - - - - + + + + -
Loading...
+
Loading...
-
- An unhandled error has occurred. - Reload - 🗙 -
- +
+ An unhandled error has occurred. + Reload + 🗙 +
+ diff --git a/src/DrawTogether.UI/Shared/ConnectedStroke.cs b/src/DrawTogether.UI/Shared/ConnectedStroke.cs index 43bb386..500eb1f 100644 --- a/src/DrawTogether.UI/Shared/ConnectedStroke.cs +++ b/src/DrawTogether.UI/Shared/ConnectedStroke.cs @@ -1,19 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace DrawTogether.UI.Shared; -namespace DrawTogether.UI.Shared +public class ConnectedStroke { - public class ConnectedStroke - { - public Guid Id { get; set; } + public Guid Id { get; set; } - public List Points { get; set; } = new (); - - public string Stroke { get; set; } + public List Points { get; set; } = new(); - public int StrokeWidth { get; set; } - } -} + public string Stroke { get; set; } + + public int StrokeWidth { get; set; } +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Shared/Connectivity/PaintSessionProtocol.cs b/src/DrawTogether.UI/Shared/Connectivity/PaintSessionProtocol.cs index 990d1da..2761d9a 100644 --- a/src/DrawTogether.UI/Shared/Connectivity/PaintSessionProtocol.cs +++ b/src/DrawTogether.UI/Shared/Connectivity/PaintSessionProtocol.cs @@ -1,91 +1,86 @@ -using System; -using System.Collections.Generic; -using Akka.Actor; +namespace DrawTogether.UI.Shared.Connectivity; -namespace DrawTogether.UI.Shared.Connectivity +public static class PaintSessionProtocol { - public static class PaintSessionProtocol + public interface IPaintSessionMessage { - public interface IPaintSessionMessage - { - /// - /// Refers to a unique painting instance. - /// - string InstanceId { get; } - } + /// + /// Refers to a unique painting instance. + /// + string InstanceId { get; } + } - public sealed class JoinPaintSession : IPaintSessionMessage + public sealed class JoinPaintSession : IPaintSessionMessage + { + public JoinPaintSession(string instanceId, string connectionId, string userId) { - public JoinPaintSession(string instanceId, string connectionId, string userId) - { - InstanceId = instanceId; - ConnectionId = connectionId; - UserId = userId; - } + InstanceId = instanceId; + ConnectionId = connectionId; + UserId = userId; + } - public string InstanceId { get; } + /// + /// The unique connection id for this websocket in SignalR + /// + public string ConnectionId { get; } - /// - /// The unique connection id for this websocket in SignalR - /// - public string ConnectionId { get; } + public string UserId { get; } - public string UserId { get; } - } + public string InstanceId { get; } + } - public sealed class AddPointToConnectedStroke : IPaintSessionMessage + public sealed class AddPointToConnectedStroke : IPaintSessionMessage + { + public AddPointToConnectedStroke(string instanceId, Guid id, Point point) { - public AddPointToConnectedStroke(string instanceId, Guid id, Point point) - { - InstanceId = instanceId; - Id = id; - Point = point; - } + InstanceId = instanceId; + Id = id; + Point = point; + } - public string InstanceId { get; } + public Guid Id { get; } - public Guid Id { get; } + public Point Point { get; } - public Point Point { get; } - } + public string InstanceId { get; } + } - public sealed class CreateConnectedStroke : IPaintSessionMessage + public sealed class CreateConnectedStroke : IPaintSessionMessage + { + public CreateConnectedStroke(string instanceId, ConnectedStroke connectedStroke) { - public CreateConnectedStroke(string instanceId, ConnectedStroke connectedStroke) - { - InstanceId = instanceId; - ConnectedStroke = connectedStroke; - } + InstanceId = instanceId; + ConnectedStroke = connectedStroke; + } - public string InstanceId { get; } + public ConnectedStroke ConnectedStroke { get; set; } - public ConnectedStroke ConnectedStroke { get; set; } - } + public string InstanceId { get; } + } - //public sealed class SubscribeToSession : IPaintSessionMessage - //{ - // public SubscribeToSession(string instanceId, IActorRef subscriber) - // { - // InstanceId = instanceId; - // Subscriber = subscriber; - // } + //public sealed class SubscribeToSession : IPaintSessionMessage + //{ + // public SubscribeToSession(string instanceId, IActorRef subscriber) + // { + // InstanceId = instanceId; + // Subscriber = subscriber; + // } - // public string InstanceId { get; } + // public string InstanceId { get; } - // public IActorRef Subscriber { get; } - //} + // public IActorRef Subscriber { get; } + //} - //public sealed class UnsubscribeFromSession : IPaintSessionMessage - //{ - // public UnsubscribeFromSession(string instanceId, IActorRef subscriber) - // { - // InstanceId = instanceId; - // Subscriber = subscriber; - // } + //public sealed class UnsubscribeFromSession : IPaintSessionMessage + //{ + // public UnsubscribeFromSession(string instanceId, IActorRef subscriber) + // { + // InstanceId = instanceId; + // Subscriber = subscriber; + // } - // public string InstanceId { get; } + // public string InstanceId { get; } - // public IActorRef Subscriber { get; } - //} - } -} + // public IActorRef Subscriber { get; } + //} +} \ No newline at end of file diff --git a/src/DrawTogether.UI/Shared/DrawHubConstants.cs b/src/DrawTogether.UI/Shared/DrawHubConstants.cs index 43b211a..ef7d737 100644 --- a/src/DrawTogether.UI/Shared/DrawHubConstants.cs +++ b/src/DrawTogether.UI/Shared/DrawHubConstants.cs @@ -4,10 +4,9 @@ // // ----------------------------------------------------------------------- -namespace DrawTogether.UI.Shared +namespace DrawTogether.UI.Shared; + +public sealed class DrawHubConstants { - public sealed class DrawHubConstants - { - public const string HubUri = "/draw"; - } + public const string HubUri = "/draw"; } \ No newline at end of file diff --git a/src/DrawTogether.UI/Shared/DrawTogether.UI.Shared.csproj b/src/DrawTogether.UI/Shared/DrawTogether.UI.Shared.csproj index af3304b..0db82a6 100644 --- a/src/DrawTogether.UI/Shared/DrawTogether.UI.Shared.csproj +++ b/src/DrawTogether.UI/Shared/DrawTogether.UI.Shared.csproj @@ -1,16 +1,16 @@ - - $(NetVersion) - enable - enable - + + $(NetVersion) + enable + enable + - - - + + + - - - + + + diff --git a/src/DrawTogether.UI/Shared/Point.cs b/src/DrawTogether.UI/Shared/Point.cs index eb2c884..7f31e78 100644 --- a/src/DrawTogether.UI/Shared/Point.cs +++ b/src/DrawTogether.UI/Shared/Point.cs @@ -1,19 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace DrawTogether.UI.Shared; -namespace DrawTogether.UI.Shared +public readonly struct Point(double x, double y) { - public struct Point - { - public Point(double x, double y) - { - this.x = x; - this.y = y; - } - public double x { get; set; } - public double y { get; set; } - } -} + public double X { get; } = x; + public double Y { get; } = y; +} \ No newline at end of file