80 lines
3.0 KiB
C#
80 lines
3.0 KiB
C#
|
using System;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using Aurora.Services;
|
||
|
using Aurora.Proto.Events;
|
||
|
using Aurora.Proto.General;
|
||
|
|
||
|
namespace Aurora.RemoteImpl
|
||
|
{
|
||
|
public class RemoteEventServiceImpl : RemoteEventService.RemoteEventServiceBase
|
||
|
{
|
||
|
public RemoteEventServiceImpl()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// RPC for getting event stream for a particular client.
|
||
|
/// </summary>
|
||
|
/// <param name="request">Empty</param>
|
||
|
/// <param name="responseStream">The response stream</param>
|
||
|
/// <param name="context">gRPC client context</param>
|
||
|
/// <returns></returns>
|
||
|
public async override Task GetEvents(Empty request, Grpc.Core.IServerStreamWriter<BaseEvent> responseStream, Grpc.Core.ServerCallContext context)
|
||
|
{
|
||
|
while (EventManager.Instance.GetSubscriptionCount(context.Peer) > 0)
|
||
|
{
|
||
|
List<BaseEvent> events = EventManager.Instance.GetSessionEvents(context.Peer);
|
||
|
foreach (BaseEvent currentEvent in events)
|
||
|
{
|
||
|
await responseStream.WriteAsync(currentEvent);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// RPC for subscribing to remote events
|
||
|
/// </summary>
|
||
|
/// <param name="request">SubscribeRequest</param>
|
||
|
/// <param name="context">gRPC client context</param>
|
||
|
/// <returns></returns>
|
||
|
public override Task<SubscriptionResponse> SubscribeToEvents(SubscribeRequest request, Grpc.Core.ServerCallContext context)
|
||
|
{
|
||
|
EventManager.Instance.AddSubscriptionList(context.Peer, request.EventTypes.ToList());
|
||
|
|
||
|
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// RPC for unsubscibing from events
|
||
|
/// </summary>
|
||
|
/// <param name="request">UnsubscribeRequest</param>
|
||
|
/// <param name="context">gRPC client context</param>
|
||
|
/// <returns></returns>
|
||
|
public override Task<SubscriptionResponse> UnsubscribeFromEvents(UnsubscribeRequest request, Grpc.Core.ServerCallContext context)
|
||
|
{
|
||
|
EventType[] eventTypes = null;
|
||
|
request.EventTypes.CopyTo(eventTypes, 0);
|
||
|
|
||
|
EventManager.Instance.RemoveSubscriptionList(context.Peer, eventTypes.ToList());
|
||
|
|
||
|
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// RPC for unsubscribing from all events
|
||
|
/// </summary>
|
||
|
/// <param name="request">UnsubscribeAllRequest</param>
|
||
|
/// <param name="context">gRPC client context</param>
|
||
|
/// <returns></returns>
|
||
|
public override Task<SubscriptionResponse> UnsubscribeFromAll(UnsubscribeAllRequest request, Grpc.Core.ServerCallContext context)
|
||
|
{
|
||
|
EventManager.Instance.RemoveAllSubscriptions(context.Peer);
|
||
|
|
||
|
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|