Event manager improvements. Changed to console.writeline instead of diagnostics
This commit is contained in:
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using Aurora.Services;
|
||||
using Aurora.Utils;
|
||||
using System.Linq;
|
||||
using Aurora.Services.EventManager;
|
||||
using Aurora.Proto.Events;
|
||||
@ -27,19 +28,24 @@ namespace Aurora.RemoteImpl
|
||||
Grpc.Core.IServerStreamWriter<BaseEvent> responseStream,
|
||||
Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
string peerId = Combine(new string[] { context.Peer, request.ClientId });
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("SERVER - Events request received from peer: {0}", peerId));
|
||||
string peerId = Misc.Combine(new string[] { context.Peer, request.ClientId });
|
||||
Console.WriteLine(string.Format("SERVER - Events request received from peer: {0}", peerId));
|
||||
|
||||
AutoResetEvent are = new AutoResetEvent(false);
|
||||
Action<BaseEvent> callback = (BaseEvent bEvent) =>
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("SERVER - Event fired for peer: {0}", peerId));
|
||||
Console.WriteLine(string.Format("SERVER - Event fired for peer: {0}", peerId));
|
||||
//TODO need to remove callback if stream no longer exists IE. Client crashed or stopped
|
||||
responseStream.WriteAsync(bEvent);
|
||||
|
||||
};
|
||||
|
||||
EventManager.Instance.AddEventHandler(callback, Combine(new string[] { context.Peer, request.ClientId }));
|
||||
Action cancelled = () =>
|
||||
{
|
||||
are.Set();
|
||||
};
|
||||
|
||||
EventManager.Instance.AddEventHandler(callback, cancelled, Misc.Combine(new string[] { context.Peer, request.ClientId }));
|
||||
are.WaitOne();
|
||||
return Task.FromResult<object>(null);
|
||||
}
|
||||
@ -52,8 +58,8 @@ namespace Aurora.RemoteImpl
|
||||
/// <returns></returns>
|
||||
public override Task<SubscriptionResponse> SubscribeToEvents(SubscribeRequest request, Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("SERVER - Subscription from client with id: {0}", request.ClientId));
|
||||
EventManager.Instance.AddSubscriptionList(Combine(new string[] { context.Peer, request.ClientId }), request.EventTypes.ToList());
|
||||
Console.WriteLine(string.Format("SERVER - Subscription from client with id: {0}", request.ClientId));
|
||||
EventManager.Instance.AddSubscriptionList(Misc.Combine(new string[] { context.Peer, request.ClientId }), request.EventTypes.ToList());
|
||||
|
||||
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||||
}
|
||||
@ -69,7 +75,7 @@ namespace Aurora.RemoteImpl
|
||||
EventType[] eventTypes = null;
|
||||
request.EventTypes.CopyTo(eventTypes, 0);
|
||||
|
||||
EventManager.Instance.RemoveSubscriptionList(Combine(new string[] { context.Peer, request.ClientId }), eventTypes.ToList());
|
||||
EventManager.Instance.RemoveSubscriptionList(Misc.Combine(new string[] { context.Peer, request.ClientId }), eventTypes.ToList());
|
||||
|
||||
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||||
}
|
||||
@ -82,28 +88,10 @@ namespace Aurora.RemoteImpl
|
||||
/// <returns></returns>
|
||||
public override Task<SubscriptionResponse> UnsubscribeFromAll(UnsubscribeAllRequest request, Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
EventManager.Instance.RemoveAllSubscriptions(Combine(new string[] { context.Peer, request.ClientId }));
|
||||
EventManager.Instance.RemoveAllSubscriptions(Misc.Combine(new string[] { context.Peer, request.ClientId }));
|
||||
|
||||
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||||
}
|
||||
|
||||
private string Combine(string[] args)
|
||||
{
|
||||
string outString = "";
|
||||
foreach (string arg in args)
|
||||
{
|
||||
if (arg == args.Last())
|
||||
{
|
||||
outString += arg;
|
||||
}
|
||||
else
|
||||
{
|
||||
outString += arg + ":";
|
||||
}
|
||||
}
|
||||
|
||||
return outString;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,13 +2,12 @@ using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Aurora.Utils;
|
||||
using Aurora.Proto.Party;
|
||||
using Aurora.Proto.Events;
|
||||
using Aurora.Proto.General;
|
||||
using Aurora.Services.EventManager;
|
||||
using Aurora.Services;
|
||||
using Aurora.Models.Media;
|
||||
using System.Collections;
|
||||
|
||||
namespace Aurora.RemoteImpl
|
||||
{
|
||||
@ -40,7 +39,7 @@ namespace Aurora.RemoteImpl
|
||||
IpAddress = context.Host,
|
||||
};
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("SERVER - Client joined party: " + partyMember.Id);
|
||||
Console.WriteLine("SERVER - Client joined party: " + partyMember.Id);
|
||||
|
||||
_partyMembers.Add(partyMember);
|
||||
|
||||
@ -75,6 +74,8 @@ namespace Aurora.RemoteImpl
|
||||
};
|
||||
|
||||
EventManager.Instance.FireEvent(bv);
|
||||
EventManager.Instance.RemoveAllSubscriptions(Misc.Combine(new string[] { context.Peer, request.ClientId }));
|
||||
EventManager.Instance.CancelEventStream(Misc.Combine(new string[] { context.Peer, request.ClientId }));
|
||||
|
||||
LeavePartyResponse response = new LeavePartyResponse() { Status = PartyJoinedStatusEnum.Disconnected };
|
||||
return Task.FromResult(response);
|
||||
@ -128,7 +129,7 @@ namespace Aurora.RemoteImpl
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Error preparing queue: {0}", ex.Message));
|
||||
Console.WriteLine(string.Format("Error preparing queue: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace Aurora.RemoteImpl
|
||||
}
|
||||
|
||||
//Send stream
|
||||
System.Diagnostics.Debug.WriteLine("Begin sending file");
|
||||
Console.WriteLine("Begin sending file");
|
||||
byte[] buffer = new byte[2048]; // read in chunks of 2KB
|
||||
int bytesRead;
|
||||
while ((bytesRead = songCopy.DataStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
@ -41,11 +41,11 @@ namespace Aurora.RemoteImpl
|
||||
Google.Protobuf.ByteString bufferByteString = Google.Protobuf.ByteString.CopyFrom(buffer);
|
||||
await responseStream.WriteAsync(new Chunk { Content = bufferByteString });
|
||||
}
|
||||
System.Diagnostics.Debug.WriteLine("Done sending file");
|
||||
Console.WriteLine("Done sending file");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Exception caught while sending audio file: " + ex.Message);
|
||||
Console.WriteLine("Exception caught while sending audio file: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace Aurora.RemoteImpl
|
||||
ServerTimeTicks = Utils.TimeUtils.GetNetworkTime().DateTime.Ticks
|
||||
};
|
||||
await responseStream.WriteAsync(sync);
|
||||
System.Diagnostics.Debug.WriteLine("Sent Sync");
|
||||
Console.WriteLine("Sent Sync");
|
||||
await Task.Delay(5000);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user