Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SWA
Botolution
Platform
Commits
844e098e
Commit
844e098e
authored
Feb 11, 2022
by
Antonio Sarcevic
🌻
Browse files
Merge branch 'master' into e2e-ci
parents
01765d20
b0dd6180
Changes
187
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
844e098e
...
...
@@ -104,11 +104,9 @@ publish-services-dev:
variables
:
IMAGE_TAG
:
latest-dev
script
:
-
docker buildx build -t $IMAGE_PREFIX/matchmaker:$IMAGE_TAG -f MatchMaker/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/matchmanager:$IMAGE_TAG -f MatchManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/gamemanager:$IMAGE_TAG -f GameManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/botmanager:$IMAGE_TAG -f BotManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/refereemanager:$IMAGE_TAG -f RefereeManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/usermanager:$IMAGE_TAG -f UserManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/tournamentsystemmanager:$IMAGE_TAG -f TournamentSystemManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/tournamentmanager:$IMAGE_TAG -f TournamentManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
...
...
@@ -122,7 +120,7 @@ publish-connectors-dev:
variables
:
IMAGE_TAG
:
latest-dev
script
:
-
docker buildx build -t $IMAGE_PREFIX/signalr
hub
:$IMAGE_TAG -f Signal
RHub
/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/signalr
bot
:$IMAGE_TAG -f
Bot
Signal/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/signalrgui:$IMAGE_TAG -f GuiSignal/Dockerfile --platform linux/arm64,linux/amd64 --push .
only
:
-
master
...
...
@@ -143,11 +141,9 @@ publish-services-release:
variables
:
IMAGE_TAG
:
latest
script
:
-
docker buildx build -t $IMAGE_PREFIX/matchmaker:$IMAGE_TAG -f MatchMaker/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/matchmanager:$IMAGE_TAG -f MatchManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/gamemanager:$IMAGE_TAG -f GameManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/botmanager:$IMAGE_TAG -f BotManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/refereemanager:$IMAGE_TAG -f RefereeManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/usermanager:$IMAGE_TAG -f UserManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/tournamentsystemmanager:$IMAGE_TAG -f TournamentSystemManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/tournamentmanager:$IMAGE_TAG -f TournamentManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
...
...
@@ -161,7 +157,7 @@ publish-connecters-release:
variables
:
IMAGE_TAG
:
latest
script
:
-
docker buildx build -t $IMAGE_PREFIX/signal
rhub
:$IMAGE_TAG -f Signal
RHub
/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/signal
bot
:$IMAGE_TAG -f
Bot
Signal/Dockerfile --platform linux/arm64,linux/amd64 --push .
-
docker buildx build -t $IMAGE_PREFIX/signalrgui:$IMAGE_TAG -f GuiSignal/Dockerfile --platform linux/arm64,linux/amd64 --push .
only
:
-
release
...
...
BotManager/BotManager.csproj
View file @
844e098e
...
...
@@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="Botolution.ApiMsgLibrary" Version="
1.1.1
" />
<PackageReference Include="Botolution.ApiMsgLibrary" Version="
2.0.4
" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.11">
...
...
@@ -20,7 +20,7 @@
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.2" />
<PackageReference Include="RabbitMQ.Client.Core.DependencyInjection" Version="4.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.
0.2
" />
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.
1.3
" />
<PackageReference Include="IdentityModel" Version="5.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.11" />
</ItemGroup>
...
...
BotManager/Controller/BotsController.cs
View file @
844e098e
...
...
@@ -15,7 +15,7 @@ namespace BotManager.Controller
{
[
Route
(
"api/v1/bots"
)]
[
ApiController
]
[
Authorize
]
[
Authorize
(
Roles
=
"Student"
)
]
public
class
BotsController
:
ControllerBase
{
private
readonly
IBotManagerService
_botManagerService
;
...
...
BotManager/DB/Repositories/Implementations/BotRepository.cs
View file @
844e098e
...
...
@@ -36,9 +36,9 @@ namespace BotManager.DB.Repositories.Implementations
return
await
dbContext
.
Bots
.
AsNoTracking
().
Where
(
@where
).
ToListAsync
();
}
/* Updates the Status of a bot Online/Offline and the Adress */
public
void
UpdateStatus
(
Bot
bot
)
public
async
Task
UpdateStatus
Async
(
Bot
bot
)
{
using
var
dbContext
=
_contextFactory
.
CreateDbContext
();
await
using
var
dbContext
=
_contextFactory
.
CreateDbContext
();
var
dbBot
=
dbContext
.
Bots
.
AsNoTracking
()
.
FirstOrDefault
(
tmpBot
=>
tmpBot
.
Token
.
Equals
(
bot
.
Token
));
if
(
dbBot
is
not
null
)
//Time to create
...
...
BotManager/DB/Repositories/Interfaces/IBotRepository.cs
View file @
844e098e
...
...
@@ -11,7 +11,7 @@ namespace BotManager.DB.Repositories.Interfaces
Task
<
Bot
>
GetAsync
(
string
botId
);
Task
<
List
<
Bot
>>
GetAllAsync
();
Task
<
List
<
Bot
>>
GetAllAsync
(
Expression
<
Func
<
Bot
,
bool
>>
where
);
void
UpdateStatus
(
Bot
bot
);
Task
UpdateStatus
Async
(
Bot
bot
);
void
InsertBot
(
Bot
bot
);
void
Update
(
Bot
bot
);
public
bool
checkToken
(
Bot
bot
);
...
...
BotManager/MQ/MessageHandler/AbstractMessageHandler.cs
View file @
844e098e
using
AutoMapper
;
using
System.Threading.Tasks
;
using
AutoMapper
;
using
BotManager.Service
;
using
Microsoft.Extensions.Logging
;
using
RabbitMQ.Client.Core.DependencyInjection.MessageHandlers
;
...
...
@@ -6,7 +7,7 @@ using RabbitMQ.Client.Events;
namespace
BotManager.MQ.MessageHandler
{
public
abstract
class
AbstractMessageHandler
:
IMessageHandler
public
abstract
class
AbstractMessageHandler
:
I
Async
MessageHandler
{
protected
readonly
IBotManagerService
BotManagerService
;
protected
readonly
ILogger
Logger
;
...
...
@@ -20,6 +21,6 @@ namespace BotManager.MQ.MessageHandler
Mapper
=
mapper
;
}
public
abstract
void
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
);
public
abstract
Task
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
);
}
}
\ No newline at end of file
BotManager/MQ/MessageHandler/DeregisterBotMessageHandler.cs
View file @
844e098e
using
AutoMapper
;
using
System.Threading.Tasks
;
using
AutoMapper
;
using
BotManager.DB.Model
;
using
BotManager.Service
;
using
Botolution.ApiMsgLibrary.ApiMessages.DeregisterBot
;
...
...
@@ -16,11 +17,11 @@ namespace BotManager.MQ.MessageHandler
{
}
public
override
void
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
)
public
override
async
Task
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
)
{
var
msg
=
JsonConvert
.
DeserializeObject
<
DeregisterBotRequest
>(
eventArgs
.
GetMessage
());
var
bot
=
Mapper
.
Map
<
Bot
>(
msg
.
Bot
);
BotManagerService
.
DeregisterBot
(
bot
);
await
BotManagerService
.
DeregisterBot
Async
(
bot
);
}
}
}
\ No newline at end of file
BotManager/MQ/MessageHandler/RegisterBotMessageHandler.cs
View file @
844e098e
using
AutoMapper
;
using
System.Threading.Tasks
;
using
AutoMapper
;
using
BotManager.DB.Model
;
using
BotManager.Service
;
using
Botolution.ApiMsgLibrary.ApiMessages.RegisterBot
;
...
...
@@ -16,13 +17,12 @@ namespace BotManager.MQ.MessageHandler
{
}
public
override
void
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
)
public
override
async
Task
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
)
{
var
replayAddress
=
eventArgs
.
BasicProperties
.
ReplyTo
;
var
msg
=
JsonConvert
.
DeserializeObject
<
RegisterBotRequest
>(
eventArgs
.
GetMessage
());
var
bot
=
Mapper
.
Map
<
Bot
>(
msg
.
Bot
);
BotManagerService
.
RegisterBot
(
bot
,
replayAddress
);
await
BotManagerService
.
RegisterBot
Async
(
bot
);
}
}
}
\ No newline at end of file
BotManager/MQ/Service/Producing/AbstractProducingService.cs
deleted
100644 → 0
View file @
01765d20
using
System.Text
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json
;
using
RabbitMQ.Client.Core.DependencyInjection.Services
;
namespace
BotManager.MQ.Service.Producing
{
public
class
AbstractProducingService
{
protected
readonly
ILogger
Logger
;
private
IQueueService
_queueService
;
protected
AbstractProducingService
(
ILogger
<
ProducingService
>
logger
)
{
Logger
=
logger
;
}
public
void
SetQueueService
(
IQueueService
queueService
)
{
_queueService
=
queueService
;
}
protected
async
void
Send
<
T
>(
T
@object
,
string
exchangeName
,
string
routingKey
,
string
replayAddress
=
null
,
string
msgType
=
null
)
where
T
:
class
{
var
basicProperties
=
_queueService
.
Channel
.
CreateBasicProperties
();
basicProperties
.
ReplyTo
=
replayAddress
;
basicProperties
.
Type
=
msgType
;
basicProperties
.
Persistent
=
true
;
basicProperties
.
ContentType
=
"application/json"
;
var
json
=
JsonConvert
.
SerializeObject
(
@object
);
var
bytes
=
Encoding
.
UTF8
.
GetBytes
(
json
);
await
_queueService
.
SendAsync
(
bytes
,
basicProperties
,
exchangeName
,
routingKey
);
}
}
}
\ No newline at end of file
BotManager/MQ/Service/Producing/IProducingService.cs
deleted
100644 → 0
View file @
01765d20
namespace
BotManager.MQ.Service.Producing
{
public
interface
IProducingService
{
void
SendRegisterBotResponse
(
string
replayAddress
);
}
}
\ No newline at end of file
BotManager/MQ/Service/Producing/ProducingService.cs
deleted
100644 → 0
View file @
01765d20
using
Botolution.ApiMsgLibrary.ApiMessages.RegisterBot
;
using
Microsoft.Extensions.Logging
;
namespace
BotManager.MQ.Service.Producing
{
public
class
ProducingService
:
AbstractProducingService
,
IProducingService
{
public
ProducingService
(
ILogger
<
ProducingService
>
logger
)
:
base
(
logger
)
{
}
public
void
SendRegisterBotResponse
(
string
replayAddress
)
{
var
msg
=
new
RegisterBotResponse
();
Send
(
msg
,
"amq.topic"
,
$"
{
replayAddress
}
.RegisterBotResponse"
);
}
}
}
\ No newline at end of file
BotManager/Service/BotManagerService.cs
View file @
844e098e
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
BotManager.DB.Model
;
using
BotManager.DB.Repositories.Interfaces
;
using
BotManager.MQ.Service.Producing
;
using
Microsoft.Extensions.Logging
;
namespace
BotManager.Service
...
...
@@ -12,32 +10,27 @@ namespace BotManager.Service
{
private
readonly
IBotRepository
_botRepository
;
private
readonly
ILogger
_logger
;
private
readonly
IProducingService
_producingService
;
public
BotManagerService
(
ILogger
<
BotManagerService
>
logger
,
IBotRepository
botRepository
,
IProducingService
producingService
)
public
BotManagerService
(
ILogger
<
BotManagerService
>
logger
,
IBotRepository
botRepository
)
{
_logger
=
logger
;
_botRepository
=
botRepository
;
_producingService
=
producingService
;
}
public
void
DeregisterBot
(
Bot
bot
)
public
async
Task
DeregisterBot
Async
(
Bot
bot
)
{
_botRepository
.
UpdateStatus
(
bot
);
await
_botRepository
.
UpdateStatus
Async
(
bot
);
}
/* Ändert den Status eines Bots zu Online*/
public
void
RegisterBot
(
Bot
bot
,
string
replayAddress
)
public
async
Task
RegisterBot
Async
(
Bot
bot
)
{
if
(!
_botRepository
.
checkToken
(
bot
))
{
return
;
}
bot
.
Address
=
replayAddress
;
_botRepository
.
UpdateStatus
(
bot
);
_producingService
.
SendRegisterBotResponse
(
replayAddress
);
await
_botRepository
.
UpdateStatusAsync
(
bot
);
}
public
void
NewBot
(
Bot
bot
)
...
...
BotManager/Service/IBotManagerService.cs
View file @
844e098e
...
...
@@ -6,9 +6,9 @@ namespace BotManager.Service
{
public
interface
IBotManagerService
{
void
DeregisterBot
(
Bot
msg
);
Task
DeregisterBot
Async
(
Bot
msg
);
void
RegisterBot
(
Bot
bot
,
string
replayAddress
);
Task
RegisterBot
Async
(
Bot
bot
);
public
void
NewBot
(
Bot
bot
);
...
...
BotManager/Startup.cs
View file @
844e098e
using
BotManager.DB
;
using
BotManager.DB.Model
;
using
BotManager.DB.Repositories.Implementations
;
using
BotManager.DB.Repositories.Interfaces
;
using
BotManager.Mapper
;
using
BotManager.MQ.MessageHandler
;
using
BotManager.MQ.Service.Consuming
;
using
BotManager.MQ.Service.Producing
;
using
BotManager.Service
;
using
IdentityModel
;
using
Microsoft.AspNetCore.Authentication.JwtBearer
;
...
...
@@ -17,8 +15,6 @@ using Microsoft.Extensions.DependencyInjection;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.IdentityModel.Tokens
;
using
RabbitMQ.Client.Core.DependencyInjection
;
using
RabbitMQ.Client.Core.DependencyInjection.Services
;
using
IProducingService
=
BotManager
.
MQ
.
Service
.
Producing
.
IProducingService
;
namespace
BotManager
{
...
...
@@ -47,6 +43,8 @@ namespace BotManager
NameClaimType
=
JwtClaimTypes
.
Name
,
};
});
services
.
AddAuthorization
();
services
.
AddCors
(
options
=>
{
...
...
@@ -63,28 +61,24 @@ namespace BotManager
var
rabbitMqSection
=
_configuration
.
GetSection
(
"RabbitMq"
);
var
exchangeSection
=
_configuration
.
GetSection
(
"RabbitMqExchange"
);
services
.
AddRabbitMqClient
(
rabbitMqSection
)
.
AddExchange
(
"amq.
topic
"
,
true
,
exchangeSection
)
.
AddMessageHandlerSingleton
<
DeregisterBotMessageHandler
>(
"
*.
DeregisterBotRequest"
)
.
AddMessageHandlerSingleton
<
RegisterBotMessageHandler
>(
"
*.
RegisterBotRequest"
);
.
AddExchange
(
"amq.
direct
"
,
true
,
exchangeSection
)
.
Add
Async
MessageHandlerSingleton
<
DeregisterBotMessageHandler
>(
"DeregisterBotRequest"
)
.
Add
Async
MessageHandlerSingleton
<
RegisterBotMessageHandler
>(
"RegisterBotRequest"
);
services
.
AddSingleton
<
IHostedService
,
ConsumingService
>();
services
.
AddControllers
();
services
.
AddMvc
().
AddNewtonsoftJson
();
services
.
AddAutoMapper
(
typeof
(
BotProfile
));
services
.
AddSingleton
<
IBotRepository
,
BotRepository
>();
services
.
AddSingleton
<
IProducingService
,
ProducingService
>();
services
.
AddSingleton
<
IBotManagerService
,
BotManagerService
>();
DbRegistrar
.
RegisterDbContextAsFactory
(
_configuration
,
services
);
}
public
void
Configure
(
IApplicationBuilder
app
,
IWebHostEnvironment
env
,
IQueueService
queueService
,
IProducingService
producingService
,
IDbContextFactory
<
BotManagerContext
>
contextFactory
)
public
void
Configure
(
IApplicationBuilder
app
,
IWebHostEnvironment
env
,
IDbContextFactory
<
BotManagerContext
>
contextFactory
)
{
DbMigrator
.
MigrateDbOnStartup
(
contextFactory
);
(
producingService
as
AbstractProducingService
)?.
SetQueueService
(
queueService
);
if
(
env
.
IsDevelopment
())
{
app
.
UseDeveloperExceptionPage
();
...
...
Signal
RHub
/.vscode/launch.json
→
Bot
Signal/.vscode/launch.json
View file @
844e098e
File moved
Signal
RHub
/.vscode/tasks.json
→
Bot
Signal/.vscode/tasks.json
View file @
844e098e
File moved
Signal
RHub/
Signal
RHub
.csproj
→
Bot
Signal
/Bot
Signal.csproj
View file @
844e098e
...
...
@@ -5,14 +5,16 @@
<UserSecretsId>f0b40b76-b230-4d94-b1d7-8ae0d57bd22e</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<RootNamespace>BotSignal</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Botolution.ApiMsgLibrary" Version="
1.1.1
" />
<PackageReference Include="Botolution.ApiMsgLibrary" Version="
2.0.4
" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="RabbitMQ.Client.Core.DependencyInjection" Version="4.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.1.3" />
</ItemGroup>
<ItemGroup>
...
...
Signal
RHub
/Dockerfile
→
Bot
Signal/Dockerfile
View file @
844e098e
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM
mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim
AS
base
WORKDIR
/app
EXPOSE
80
...
...
@@ -7,17 +5,17 @@ EXPOSE 443
FROM
mcr.microsoft.com/dotnet/sdk:5.0-buster-slim
AS
build
WORKDIR
/src
COPY
["nuget.config", "Signal
RHub
/"]
COPY
["Signal
RHub/
Signal
RHub
.csproj", "Signal
RHub
/"]
RUN
dotnet restore
"Signal
RHub/
Signal
RHub
.csproj"
COPY
["nuget.config", "
Bot
Signal/"]
COPY
["
Bot
Signal
/Bot
Signal.csproj", "
Bot
Signal/"]
RUN
dotnet restore
"
Bot
Signal
/Bot
Signal.csproj"
COPY
. .
WORKDIR
"/src/Signal
RHub
"
RUN
dotnet build
"Signal
RHub
.csproj"
-c
Release
-o
/app/build
WORKDIR
"/src/
Bot
Signal"
RUN
dotnet build
"
Bot
Signal.csproj"
-c
Release
-o
/app/build
FROM
build
AS
publish
RUN
dotnet publish
"Signal
RHub
.csproj"
-c
Release
-o
/app/publish
RUN
dotnet publish
"
Bot
Signal.csproj"
-c
Release
-o
/app/publish
FROM
base
AS
final
WORKDIR
/app
COPY
--from=publish /app/publish .
ENTRYPOINT
["dotnet", "SignalRHub.dll"]
\ No newline at end of file
ENTRYPOINT
["dotnet", "BotSignal.dll"]
\ No newline at end of file
Signal
RHub
/Hubs/BotHub.cs
→
Bot
Signal/Hubs/BotHub.cs
View file @
844e098e
using
System
;
using
System.Threading.Tasks
;
using
Botolution.ApiMsgLibrary.ApiMessages.MakeMove
;
using
Botolution.ApiMsgLibrary.Events
;
using
BotSignal.MQ.Service.Producing
;
using
Microsoft.AspNetCore.SignalR
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json
;
using
Serilog
;
using
SignalRHub.MQ.Service.Producing
;
namespace
Signal
RHub
.Hubs
namespace
Bot
Signal.Hubs
{
public
class
BotHub
:
Hub
{
private
readonly
IProducingService
_producingService
;
private
readonly
ILogger
<
BotHub
>
_logger
;
...
...
@@ -22,58 +19,38 @@ namespace SignalRHub.Hubs
_producingService
=
producingService
;
}
//Bot Calls this Function to connect to SignalRHub with Botname, Game and Address? etc.
// public Task RegisterBot(string name, string game, string address)
// {
// _producingService.SendRegisterBotRequest(name, game, address, "Online", 5000);
// }
// public Task DeregisterBot(string name, string game, string address)
// {
// _producingService.SendDeregisterBotRequest(name, game, address, "Offline");
// }
public
override
async
Task
OnConnectedAsync
()
{
// await Groups.AddToGroupAsync(Context.ConnectionId, "SignalR Users");
string
connectionId
=
Context
.
ConnectionId
;
// string name = Context.User.Identity.Name;
// var dict = Context.Items;
// var game = dict["game"];
// var address = dict["address"];
var
connectionId
=
Context
.
ConnectionId
;
string
bottoken
=
Context
.
GetHttpContext
().
Request
.
Query
[
"bottoken"
];
// await Groups.AddToGroupAsync(connectionId, botname);
// _producingService.SendRegisterBotRequest(name, (String)game, (String)address, "Online", 5000);
_logger
.
LogInformation
(
$"Someone tries to connect to SignalR Hub, ConnectionId:
{
connectionId
}
, Token:
{
bottoken
}
"
);
_producingService
.
SendRegisterBotRequest
(
connectionId
,
"Online"
,
bottoken
,
5000
);
_producingService
.
SendRegisterBotRequest
(
connectionId
,
"Online"
,
bottoken
,
5000
);
await
base
.
OnConnectedAsync
();
}
public
override
async
Task
OnDisconnectedAsync
(
Exception
exception
)
{
// await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users");
string
connectionId
=
Context
.
ConnectionId
;
// string name = Context.UserIdentifier;
// var dict = Context.Items;
// var game = dict["game"];
// var address = dict["address"];
var
connectionId
=
Context
.
ConnectionId
;
string
bottoken
=
Context
.
GetHttpContext
().
Request
.
Query
[
"bottoken"
];
// _producingService.SendDeregisterBotRequest(name, (String)game, (String)address, "Offline");
_logger
.
LogInformation
(
"Someone wants to get lost of SignalR Hub"
);
_producingService
.
SendDeregisterBotRequest
(
connectionId
,
"Offline"
,
bottoken
);
_producingService
.
SendDeregisterBotRequest
(
connectionId
,
"Offline"
,
bottoken
);
await
base
.
OnDisconnectedAsync
(
exception
);
}
public
async
Task
MakeMove
(
string
makeMoveRes
po
n
se
)
public
async
Task
TurnProposed
(
string
turnPro
pose
d
)
{
_logger
.
LogInformation
(
"Received makeMoveResponse: "
+
makeMoveResponse
);
MakeMoveResponse
resp
=
JsonConvert
.
DeserializeObject
<
MakeMoveResponse
>(
makeMoveResponse
);
resp
.
ConnectionId
=
Context
.
ConnectionId
;
_producingService
.
SendMakeMoveResponse
(
resp
);
_logger
.
LogInformation
(
$"Received turnProposed:
{
turnProposed
}
"
);
var
resp
=
JsonConvert
.
DeserializeObject
<
TurnProposed
>(
turnProposed
);
if
(
resp
!=
null
)
{
resp
.
BotAddress
=
Context
.
ConnectionId
;
_producingService
.
SendTurnProposed
(
resp
);
}
}
}
}
\ No newline at end of file
Signal
RHub
/MQ/MessageHandler/AbstractMessageHandler.cs
→
Bot
Signal/MQ/MessageHandler/AbstractMessageHandler.cs
View file @
844e098e
using
Microsoft.AspNetCore.SignalR
;
using
System.Threading.Tasks
;
using
BotSignal.Hubs
;
using
Microsoft.AspNetCore.SignalR
;
using
Microsoft.Extensions.Logging
;
using
RabbitMQ.Client.Core.DependencyInjection.MessageHandlers
;
using
RabbitMQ.Client.Events
;
using
SignalRHub.Hubs
;
namespace
Signal
RHub
.MQ.MessageHandler
namespace
Bot
Signal.MQ.MessageHandler
{
public
abstract
class
AbstractMessageHandler
:
IMessageHandler
public
abstract
class
AbstractMessageHandler
:
I
Async
MessageHandler
{
protected
readonly
ILogger
Logger
;
protected
readonly
IHubContext
<
BotHub
>
Hubcontext
;
...
...
@@ -17,6 +18,6 @@ namespace SignalRHub.MQ.MessageHandler
Hubcontext
=
hubcontext
;
}
public
abstract
void
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
);
public
abstract
Task
Handle
(
BasicDeliverEventArgs
eventArgs
,
string
matchingRoute
);
}
}
\ No newline at end of file
Prev
1
2
3
4
5
…
10
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment