Skip to content

Commit

Permalink
Merge pull request #30 from JaimeStill/demo
Browse files Browse the repository at this point in the history
Demo
  • Loading branch information
JaimeStill authored Mar 7, 2023
2 parents 90f233f + c6c09a0 commit db0ccc3
Show file tree
Hide file tree
Showing 34 changed files with 11,328 additions and 11 deletions.
18 changes: 18 additions & 0 deletions src/Arma.Demo.Core/Sync/SyncGroupProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Arma.Demo.Core.Sync;
public class SyncGroupProvider
{
public SyncGroup ListenerGroup { get; private set; }
public SyncGroup ServiceGroup { get; private set; }
public List<SyncGroup> SyncGroups { get; private set; }

Expand All @@ -11,6 +12,23 @@ public SyncGroupProvider()
SyncGroups = new();
}

public async Task<Guid> InitializeListener(Guid key, string connectionId, IGroupManager groups)
{
if (ListenerGroup is null)
{
ListenerGroup = new(key, new() { connectionId });
}
else
{
if (!ListenerGroup.Connections.Contains(connectionId))
ListenerGroup.Connections.Add(connectionId);
}

await groups.AddToGroupAsync(connectionId, ListenerGroup.Key.ToString());

return ListenerGroup.Key;
}

public async Task<Guid> InitializeService(Guid key, string connectionId, IGroupManager groups)
{
if (ServiceGroup is null)
Expand Down
51 changes: 45 additions & 6 deletions src/Arma.Demo.Core/Sync/SyncHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public override async Task OnDisconnectedAsync(Exception ex)
await base.OnDisconnectedAsync(ex);
}

public async Task RegisterListener(Guid key)
{
Console.WriteLine($"Registering listener with provided key {key}");
key = await groups.InitializeListener(key, Context.ConnectionId, Groups);
Console.WriteLine($"Listener registered at {key}");
await Clients.Caller.Registered(key);
}

public async Task RegisterService(Guid key)
{
Console.WriteLine($"Registering service with provided key {key}");
Expand Down Expand Up @@ -52,11 +60,18 @@ public async Task SendPush(SyncMessage<T> message)
Console.WriteLine($"Service Group: {groups.ServiceGroup.Key}");

await Clients
.Groups(
message.Key.ToString(),
groups.ServiceGroup.Key.ToString()
)
.OthersInGroup(message.Key.ToString())
.Push(message);

if (groups.ServiceGroup?.Key is not null)
await Clients
.Groups(groups.ServiceGroup.Key.ToString())
.Push(message);

if (groups.ListenerGroup?.Key is not null)
await Clients
.Groups(groups.ListenerGroup.Key.ToString())
.Push(message);
}

public async Task SendNotify(SyncMessage<T> message)
Expand All @@ -67,6 +82,11 @@ public async Task SendNotify(SyncMessage<T> message)
await Clients
.OthersInGroup(message.Key.ToString())
.Notify(message);

if (groups.ListenerGroup?.Key is not null)
await Clients
.Groups(groups.ListenerGroup.Key.ToString())
.Notify(message);
}

public async Task SendComplete(SyncMessage<T> message)
Expand All @@ -77,15 +97,34 @@ public async Task SendComplete(SyncMessage<T> message)
await Clients
.OthersInGroup(message.Key.ToString())
.Complete(message);

if (groups.ListenerGroup?.Key is not null)
await Clients
.Groups(groups.ListenerGroup.Key.ToString())
.Complete(message);
}

public async Task SendReturn(SyncMessage<T> message) =>
public async Task SendReturn(SyncMessage<T> message)
{
await Clients
.OthersInGroup(message.Key.ToString())
.Return(message);

public async Task SendReject(SyncMessage<T> message) =>
if (groups.ListenerGroup?.Key is not null)
await Clients
.Groups(groups.ListenerGroup.Key.ToString())
.Return(message);
}

public async Task SendReject(SyncMessage<T> message)
{
await Clients
.OthersInGroup(message.Key.ToString())
.Reject(message);

if (groups.ListenerGroup?.Key is not null)
await Clients
.Groups(groups.ListenerGroup.Key.ToString())
.Reject(message);
}
}
20 changes: 16 additions & 4 deletions tests/cross-service-signalr/apis/sync-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@

var builder = WebApplication.CreateBuilder(args);

string[] origins = builder
.Configuration
.GetSection("CorsOrigins")
.Get<string[]>()
?? new string[] {
"http://localhost:4200",
"http://localhost:5000",
"http://localhost:5001"
};

// Add services to the container.
builder.Services.AddCors(options =>
options.AddDefaultPolicy(policy =>
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
policy
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
.WithOrigins(origins)
)
);

Expand All @@ -21,4 +33,4 @@
app.UseCors();
app.MapHubs();

app.Run();
app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"CorsOrigins": [
"http://localhost:4200",
"http://localhost:5000",
"http://localhost:5001"
]
}
23 changes: 23 additions & 0 deletions tests/cross-service-signalr/app/spa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db
4 changes: 4 additions & 0 deletions tests/cross-service-signalr/app/spa/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["angular.ng-template"]
}
13 changes: 13 additions & 0 deletions tests/cross-service-signalr/app/spa/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "pwa-chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
}
]
}
24 changes: 24 additions & 0 deletions tests/cross-service-signalr/app/spa/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
}
]
}
27 changes: 27 additions & 0 deletions tests/cross-service-signalr/app/spa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Processor

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.2.1.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.

## Code scaffolding

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
109 changes: 109 additions & 0 deletions tests/cross-service-signalr/app/spa/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"processor": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"inlineTemplate": true,
"inlineStyle": true,
"style": "scss",
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:guard": {
"skipTests": true
},
"@schematics/angular:interceptor": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:resolver": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/processor",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "processor:build:production"
},
"development": {
"browserTarget": "processor:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "processor:build"
}
}
}
}
}
}
Loading

0 comments on commit db0ccc3

Please sign in to comment.