I want to define such a router or Map for my gRPC Server using Enum or similar method
I've a simple Service which named ServerHubService and a Hubs folder which have some classes in it which will be handle every request will be passed by client to my gRPC server
Here is ScreenShot of my Project Project Structure Now as can be seen in the photo The contents of the file are also the image below HubMap.cs
as you can see i want to define a switch case statment to run diffrent classes
Here is my ServiceHubService gRPC class ServerHubService.cs
and finally this my client side call grpc-client.cs
visual studio 2019 ver 16.10
Here is my ServerHub.proto file :
syntax = "proto3";
option csharp_namespace = "NetPlus.Server.Core";
package server;
service ServereHub {
rpc ActionManager (ActionRequest) returns (ActionResult);
}
message ActionRequest {
string ActionType = 1;
}
message ActionResult {
string ActionResultType = 1;
}
my ServerHubService.cs :
using Microsoft.Extensions.Logging;
using NetPlus.Server.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NetPlus.Server.Core.Hubs;
namespace NetPlus.Server.Core
{
public class ServerHubService : ServereHub.ServereHubBase
{
private readonly ILogger<ServerHubService> _logger;
public ServerHubService(ILogger<ServerHubService> logger)
{
_logger = logger;
}
public override Task<ActionResult> ActionManager(ActionRequest request, ServerCallContext context)
{
HubMap map = new HubMap();
HubMap.HubSelector selector;
return Task.FromResult(new ActionResult
{
ActionResultType = map.HubProccessor(selector)
}) ;
}
}
}
and Hubmap.cs
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace NetPlus.Server.Core.Hubs
{
public class HubMap
{
Switcher switcher = new Switcher();
public string HubNameResult { get; set; }
public enum HubSelector
{
SwitchServer_Off = 1
}
public string HubProccessor(HubSelector hName) =>
hName switch
{
HubSelector.SwitchServer_Off => switcher.PutOffline(),
_=> "Error Proccesing Hub"
};
}
}
Question 2:
How to Detect Defined enums in proto file and proccess in HubMap.cs