aurora/aurora-sharp-desktop/Aurora/Services/Server/Controllers/EventSubscriptionController.cs
2021-03-05 23:10:12 -05:00

66 lines
2.6 KiB
C#

using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Aurora.Proto.Party;
using Aurora.Proto.General;
using Aurora.Utils;
namespace Aurora.Services.Server.Controllers
{
public partial class RemotePartyController : RemotePartyService.RemotePartyServiceBase
{
public override Task<ListEventSubscriptionsResponse> ListEventSubscriptions(
ListEventSubscriptionsRequest request,
Grpc.Core.ServerCallContext context)
{
throw new NotImplementedException();
}
public override Task<EventSubscription> CreateEventSubscription(
CreateEventSubscriptionRequest request,
Grpc.Core.ServerCallContext context)
{
Console.WriteLine(string.Format("SERVER - Subscription from client with id: {0}", request.Parent));
this._eventManager.AddSubscription(Misc.Combine(new string[] { context.Peer, request.Parent }), request.EventSubscription.Type);
return Task.FromResult(request.EventSubscription);
}
public override Task<CreateEventSubscriptionListResponse> CreateEventSubscriptionList(
CreateEventSubscriptionListRequest request,
Grpc.Core.ServerCallContext context)
{
Console.WriteLine(string.Format("SERVER - Subscription from client with id: {0}", request.Parent));
List<EventType> eventTypes = new List<EventType>();
foreach (EventSubscription subscription in request.EventSubscriptions)
{
eventTypes.Add(subscription.Type);
}
this._eventManager.AddSubscriptionList(Misc.Combine(new string[] { context.Peer, request.Parent }), eventTypes);
CreateEventSubscriptionListResponse resp = new CreateEventSubscriptionListResponse();
resp.EventSubscriptions.AddRange(request.EventSubscriptions);
return Task.FromResult(resp);
}
public override Task<Empty> DeleteEventSubscription(
DeleteEventSubscriptionRequest request,
Grpc.Core.ServerCallContext context)
{
this._eventManager.RemoveSubscription(Misc.Combine(new string[] { context.Peer, request.Parent }), request.Type);
return Task.FromResult(new Empty());
}
public override Task<Empty> DeleteAllEventSubscriptions(
DeleteAllEventSubscriptionsRequest request,
Grpc.Core.ServerCallContext context)
{
this._eventManager.RemoveAllSubscriptions(Misc.Combine(new string[] { context.Peer, request.Parent }));
return Task.FromResult(new Empty());
}
}
}