Event manager improvements. Changed to console.writeline instead of diagnostics
This commit is contained in:
parent
43c6a5a2c6
commit
e796bf2f35
@ -2,7 +2,6 @@
|
|||||||
<ContentView
|
<ContentView
|
||||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:hl="clr-namespace:Aurora.Design.Components.HorizontalList"
|
|
||||||
xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
|
xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
|
||||||
x:Class="Aurora.Design.Components.MemberList.MemberList">
|
x:Class="Aurora.Design.Components.MemberList.MemberList">
|
||||||
<ContentView.Resources>
|
<ContentView.Resources>
|
||||||
@ -14,7 +13,6 @@
|
|||||||
x:Name="MembersList"
|
x:Name="MembersList"
|
||||||
FlowColumnMinWidth="150"
|
FlowColumnMinWidth="150"
|
||||||
RowHeight="150"
|
RowHeight="150"
|
||||||
VerticalOptions="FillAndExpand"
|
|
||||||
SeparatorVisibility="None"
|
SeparatorVisibility="None"
|
||||||
BackgroundColor="#181818"
|
BackgroundColor="#181818"
|
||||||
HasUnevenRows="false">
|
HasUnevenRows="false">
|
||||||
|
@ -25,7 +25,7 @@ namespace Aurora.Design.Extensions
|
|||||||
|
|
||||||
foreach (var res in gtkAsm.GetManifestResourceNames())
|
foreach (var res in gtkAsm.GetManifestResourceNames())
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("found resource: " + res);
|
Console.WriteLine("found resource: " + res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gtkAsm == null && gtkAsm is Assembly)
|
if (gtkAsm == null && gtkAsm is Assembly)
|
||||||
|
@ -146,7 +146,6 @@ namespace Aurora.Design.Views.Main
|
|||||||
vm.OnActive();
|
vm.OnActive();
|
||||||
|
|
||||||
_viewContent.Content = view;
|
_viewContent.Content = view;
|
||||||
MasterPage.ListView.SelectedItem = firstNavItem;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,3 +6,32 @@ Label {
|
|||||||
height: 100;
|
height: 100;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#LeaveButton {
|
||||||
|
margin-top: 20;
|
||||||
|
margin-bottom: 20;
|
||||||
|
vertical-align: bottom;
|
||||||
|
align-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#MembersList {
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
}
|
||||||
|
|
||||||
|
#MembersList Grid {
|
||||||
|
margin-left: 20;
|
||||||
|
margin-right: 20;
|
||||||
|
margin-top: 20;
|
||||||
|
margin-bottom: 20;
|
||||||
|
width: 150;
|
||||||
|
border-radius: 25;
|
||||||
|
background-color: #626363;
|
||||||
|
}
|
||||||
|
|
||||||
|
#MembersList Label {
|
||||||
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
color: white;
|
||||||
|
font-size: 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -22,13 +22,31 @@
|
|||||||
HeaderBackgroundColor="#181818"
|
HeaderBackgroundColor="#181818"
|
||||||
x:Name="TabView">
|
x:Name="TabView">
|
||||||
<tabView:TabViewControl.ItemSource>
|
<tabView:TabViewControl.ItemSource>
|
||||||
|
<!-- Members Tab -->
|
||||||
<tabView:TabItem
|
<tabView:TabItem
|
||||||
HeaderText="Members">
|
HeaderText="Members">
|
||||||
<ml:MemberList
|
<Grid
|
||||||
x:Name="MembersList"
|
HorizontalOptions="FillAndExpand"
|
||||||
VerticalOptions="FillAndExpand"
|
VerticalOptions="FillAndExpand">
|
||||||
Members="{Binding Members}"/>
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition
|
||||||
|
Height="*"/>
|
||||||
|
<RowDefinition
|
||||||
|
Height="30"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<ml:MemberList
|
||||||
|
x:Name="MembersList"
|
||||||
|
Grid.Row="0"
|
||||||
|
VerticalOptions="FillAndExpand"
|
||||||
|
Members="{Binding Members}"/>
|
||||||
|
<!-- Leave Party Button -->
|
||||||
|
<Button
|
||||||
|
Grid.Row="1"
|
||||||
|
Text="Leave Party"
|
||||||
|
Command="{Binding LeavePartyCommand}"/>
|
||||||
|
</Grid>
|
||||||
</tabView:TabItem>
|
</tabView:TabItem>
|
||||||
|
<!-- Library Tab -->
|
||||||
<tabView:TabItem
|
<tabView:TabItem
|
||||||
HeaderText="Queue">
|
HeaderText="Queue">
|
||||||
<library:Library
|
<library:Library
|
||||||
|
@ -45,6 +45,8 @@ namespace Aurora.Design.Views.Party
|
|||||||
|
|
||||||
PlayCommand = new Command(OnDoubleClickExecute, CanDoubleClickExecute);
|
PlayCommand = new Command(OnDoubleClickExecute, CanDoubleClickExecute);
|
||||||
|
|
||||||
|
LeavePartyCommand = new Command(OnLeavePartyExecute, CanLeaveParty);
|
||||||
|
|
||||||
_client = ClientService.Instance;
|
_client = ClientService.Instance;
|
||||||
|
|
||||||
_client.OnMediaPaused += this.OnMediaPaused;
|
_client.OnMediaPaused += this.OnMediaPaused;
|
||||||
@ -52,6 +54,7 @@ namespace Aurora.Design.Views.Party
|
|||||||
_client.OnNewMediaPlaying += this.OnNewMediaPlaying;
|
_client.OnNewMediaPlaying += this.OnNewMediaPlaying;
|
||||||
_client.OnPartyMemberJoined += this.OnPartyMemberJoined;
|
_client.OnPartyMemberJoined += this.OnPartyMemberJoined;
|
||||||
_client.OnPartyMemberLeft += this.OnPartyMemberLeft;
|
_client.OnPartyMemberLeft += this.OnPartyMemberLeft;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~PartyViewModel()
|
~PartyViewModel()
|
||||||
@ -118,6 +121,8 @@ namespace Aurora.Design.Views.Party
|
|||||||
/// <value></value>
|
/// <value></value>
|
||||||
public Command PlayCommand { get; private set; }
|
public Command PlayCommand { get; private set; }
|
||||||
|
|
||||||
|
public Command LeavePartyCommand { get; private set; }
|
||||||
|
|
||||||
#endregion Properties
|
#endregion Properties
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
@ -251,7 +256,7 @@ namespace Aurora.Design.Views.Party
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("Exception occurred while receiviing events: ", ex.Message);
|
Console.WriteLine("Exception occurred while receiviing events: ", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +284,7 @@ namespace Aurora.Design.Views.Party
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("Exception occurred while receiviing events: ", ex.Message);
|
Console.WriteLine("Exception occurred while receiviing events: ", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,6 +293,16 @@ namespace Aurora.Design.Views.Party
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void OnLeavePartyExecute()
|
||||||
|
{
|
||||||
|
await _client.RemotePartyClient.LeavePartyAsync(new LeavePartyRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanLeaveParty()
|
||||||
|
{
|
||||||
|
return (this._state == PartyState.InParty || this._state == PartyState.Hosting) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnPlayButtonExecute()
|
public override void OnPlayButtonExecute()
|
||||||
{
|
{
|
||||||
if (base.IsPlaying())
|
if (base.IsPlaying())
|
||||||
@ -408,7 +423,7 @@ namespace Aurora.Design.Views.Party
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("Error subscribing to events: " + ex.Message);
|
Console.WriteLine("Error subscribing to events: " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +453,7 @@ namespace Aurora.Design.Views.Party
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", SettingsService.Instance.ClientId));
|
Console.WriteLine(string.Format("CLIENT {0} - SubscribeToEvents called from client with id", SettingsService.Instance.ClientId));
|
||||||
await _client.RemoteEventClient.SubscribeToEventsAsync(req);
|
await _client.RemoteEventClient.SubscribeToEventsAsync(req);
|
||||||
}
|
}
|
||||||
private async Task UnsubscribeFromEvents()
|
private async Task UnsubscribeFromEvents()
|
||||||
|
@ -69,11 +69,11 @@ namespace Aurora.Models.Media
|
|||||||
|
|
||||||
await this.DataStream.WriteAsync(buffer, 0, buffer.Length);
|
await this.DataStream.WriteAsync(buffer, 0, buffer.Length);
|
||||||
}
|
}
|
||||||
System.Diagnostics.Debug.WriteLine("Done receiving stream");
|
Console.WriteLine("Done receiving stream");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("Exception caught while loading remote audio:" + ex.Message);
|
Console.WriteLine("Exception caught while loading remote audio:" + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await base.Load();
|
await base.Load();
|
||||||
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Aurora.Services;
|
using Aurora.Services;
|
||||||
|
using Aurora.Utils;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Aurora.Services.EventManager;
|
using Aurora.Services.EventManager;
|
||||||
using Aurora.Proto.Events;
|
using Aurora.Proto.Events;
|
||||||
@ -27,19 +28,24 @@ namespace Aurora.RemoteImpl
|
|||||||
Grpc.Core.IServerStreamWriter<BaseEvent> responseStream,
|
Grpc.Core.IServerStreamWriter<BaseEvent> responseStream,
|
||||||
Grpc.Core.ServerCallContext context)
|
Grpc.Core.ServerCallContext context)
|
||||||
{
|
{
|
||||||
string peerId = Combine(new string[] { context.Peer, request.ClientId });
|
string peerId = Misc.Combine(new string[] { context.Peer, request.ClientId });
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("SERVER - Events request received from peer: {0}", peerId));
|
Console.WriteLine(string.Format("SERVER - Events request received from peer: {0}", peerId));
|
||||||
|
|
||||||
AutoResetEvent are = new AutoResetEvent(false);
|
AutoResetEvent are = new AutoResetEvent(false);
|
||||||
Action<BaseEvent> callback = (BaseEvent bEvent) =>
|
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
|
//TODO need to remove callback if stream no longer exists IE. Client crashed or stopped
|
||||||
responseStream.WriteAsync(bEvent);
|
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();
|
are.WaitOne();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
@ -52,8 +58,8 @@ namespace Aurora.RemoteImpl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Task<SubscriptionResponse> SubscribeToEvents(SubscribeRequest request, Grpc.Core.ServerCallContext context)
|
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));
|
Console.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());
|
EventManager.Instance.AddSubscriptionList(Misc.Combine(new string[] { context.Peer, request.ClientId }), request.EventTypes.ToList());
|
||||||
|
|
||||||
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||||||
}
|
}
|
||||||
@ -69,7 +75,7 @@ namespace Aurora.RemoteImpl
|
|||||||
EventType[] eventTypes = null;
|
EventType[] eventTypes = null;
|
||||||
request.EventTypes.CopyTo(eventTypes, 0);
|
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 });
|
return Task.FromResult(new SubscriptionResponse { Successful = true });
|
||||||
}
|
}
|
||||||
@ -82,28 +88,10 @@ namespace Aurora.RemoteImpl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Task<SubscriptionResponse> UnsubscribeFromAll(UnsubscribeAllRequest request, Grpc.Core.ServerCallContext context)
|
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 });
|
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.Threading.Tasks;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Aurora.Utils;
|
||||||
using Aurora.Proto.Party;
|
using Aurora.Proto.Party;
|
||||||
using Aurora.Proto.Events;
|
using Aurora.Proto.Events;
|
||||||
using Aurora.Proto.General;
|
|
||||||
using Aurora.Services.EventManager;
|
using Aurora.Services.EventManager;
|
||||||
using Aurora.Services;
|
using Aurora.Services;
|
||||||
using Aurora.Models.Media;
|
using Aurora.Models.Media;
|
||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace Aurora.RemoteImpl
|
namespace Aurora.RemoteImpl
|
||||||
{
|
{
|
||||||
@ -40,7 +39,7 @@ namespace Aurora.RemoteImpl
|
|||||||
IpAddress = context.Host,
|
IpAddress = context.Host,
|
||||||
};
|
};
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine("SERVER - Client joined party: " + partyMember.Id);
|
Console.WriteLine("SERVER - Client joined party: " + partyMember.Id);
|
||||||
|
|
||||||
_partyMembers.Add(partyMember);
|
_partyMembers.Add(partyMember);
|
||||||
|
|
||||||
@ -75,6 +74,8 @@ namespace Aurora.RemoteImpl
|
|||||||
};
|
};
|
||||||
|
|
||||||
EventManager.Instance.FireEvent(bv);
|
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 };
|
LeavePartyResponse response = new LeavePartyResponse() { Status = PartyJoinedStatusEnum.Disconnected };
|
||||||
return Task.FromResult(response);
|
return Task.FromResult(response);
|
||||||
@ -128,7 +129,7 @@ namespace Aurora.RemoteImpl
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
//Send stream
|
||||||
System.Diagnostics.Debug.WriteLine("Begin sending file");
|
Console.WriteLine("Begin sending file");
|
||||||
byte[] buffer = new byte[2048]; // read in chunks of 2KB
|
byte[] buffer = new byte[2048]; // read in chunks of 2KB
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
while ((bytesRead = songCopy.DataStream.Read(buffer, 0, buffer.Length)) > 0)
|
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);
|
Google.Protobuf.ByteString bufferByteString = Google.Protobuf.ByteString.CopyFrom(buffer);
|
||||||
await responseStream.WriteAsync(new Chunk { Content = bufferByteString });
|
await responseStream.WriteAsync(new Chunk { Content = bufferByteString });
|
||||||
}
|
}
|
||||||
System.Diagnostics.Debug.WriteLine("Done sending file");
|
Console.WriteLine("Done sending file");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
ServerTimeTicks = Utils.TimeUtils.GetNetworkTime().DateTime.Ticks
|
||||||
};
|
};
|
||||||
await responseStream.WriteAsync(sync);
|
await responseStream.WriteAsync(sync);
|
||||||
System.Diagnostics.Debug.WriteLine("Sent Sync");
|
Console.WriteLine("Sent Sync");
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ namespace Aurora.Services.ClientService
|
|||||||
{
|
{
|
||||||
_eventCancellationTokenSource = new CancellationTokenSource();
|
_eventCancellationTokenSource = new CancellationTokenSource();
|
||||||
string clientId = SettingsService.Instance.ClientId;
|
string clientId = SettingsService.Instance.ClientId;
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", clientId));
|
Console.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", clientId));
|
||||||
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient
|
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient
|
||||||
.GetEvents(new EventsRequest { ClientId = SettingsService.Instance.ClientId }))
|
.GetEvents(new EventsRequest { ClientId = SettingsService.Instance.ClientId }))
|
||||||
{
|
{
|
||||||
@ -126,14 +126,14 @@ namespace Aurora.Services.ClientService
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("Exception while parsing event ---" + ex.Message);
|
Console.WriteLine("Exception while parsing event ---" + ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("EXCEPTION while parsing events --- " + ex.Message));
|
Console.WriteLine(string.Format("EXCEPTION while parsing events --- " + ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,28 @@ using Aurora.Proto.Events;
|
|||||||
|
|
||||||
namespace Aurora.Services.EventManager
|
namespace Aurora.Services.EventManager
|
||||||
{
|
{
|
||||||
|
public class EventAction
|
||||||
|
{
|
||||||
|
public EventAction(Action<BaseEvent> callback, Action cancel)
|
||||||
|
{
|
||||||
|
Callback = callback;
|
||||||
|
Cancel = cancel;
|
||||||
|
}
|
||||||
|
public Action<BaseEvent> Callback { get; set; }
|
||||||
|
public Action Cancel { get; set; }
|
||||||
|
}
|
||||||
public class EventManager : BaseService<EventManager>
|
public class EventManager : BaseService<EventManager>
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private Dictionary<string, List<EventType>> _subscriptionList;
|
private Dictionary<string, List<EventType>> _subscriptionList;
|
||||||
private Dictionary<string, Action<BaseEvent>> _actionList;
|
private Dictionary<string, EventAction> _actionList;
|
||||||
|
|
||||||
#endregion Fields
|
#endregion Fields
|
||||||
public EventManager()
|
public EventManager()
|
||||||
{
|
{
|
||||||
_subscriptionList = new Dictionary<string, List<EventType>>();
|
_subscriptionList = new Dictionary<string, List<EventType>>();
|
||||||
_actionList = new Dictionary<string, Action<BaseEvent>>();
|
_actionList = new Dictionary<string, EventAction>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
@ -147,11 +158,11 @@ namespace Aurora.Services.EventManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddEventHandler(Action<BaseEvent> action, string sessionId)
|
public void AddEventHandler(Action<BaseEvent> action, Action cancel, string sessionId)
|
||||||
{
|
{
|
||||||
lock (_actionList)
|
lock (_actionList)
|
||||||
{
|
{
|
||||||
_actionList.Add(sessionId, action);
|
_actionList.Add(sessionId, new EventAction(action, cancel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,13 +171,21 @@ namespace Aurora.Services.EventManager
|
|||||||
_actionList.Remove(sessionId);
|
_actionList.Remove(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CancelEventStream(string sessionId)
|
||||||
|
{
|
||||||
|
_actionList.TryGetValue(sessionId, out EventAction value);
|
||||||
|
value.Cancel();
|
||||||
|
|
||||||
|
RemoveEventHandler(sessionId);
|
||||||
|
}
|
||||||
|
|
||||||
public void FireEvent(BaseEvent bEvent)
|
public void FireEvent(BaseEvent bEvent)
|
||||||
{
|
{
|
||||||
Dictionary<string, Action<BaseEvent>> actionsCopy = new Dictionary<string, Action<BaseEvent>>();
|
Dictionary<string, EventAction> actionsCopy = new Dictionary<string, EventAction>();
|
||||||
//Copy actions list
|
//Copy actions list
|
||||||
lock (_actionList)
|
lock (_actionList)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, Action<BaseEvent>> pair in _actionList)
|
foreach (KeyValuePair<string, EventAction> pair in _actionList)
|
||||||
{
|
{
|
||||||
actionsCopy.Add(pair.Key, pair.Value);
|
actionsCopy.Add(pair.Key, pair.Value);
|
||||||
}
|
}
|
||||||
@ -180,14 +199,14 @@ namespace Aurora.Services.EventManager
|
|||||||
//If action list contains an action for id, invoke
|
//If action list contains an action for id, invoke
|
||||||
if (actionsCopy.ContainsKey(pair.Key))
|
if (actionsCopy.ContainsKey(pair.Key))
|
||||||
{
|
{
|
||||||
actionsCopy.TryGetValue(pair.Key, out Action<BaseEvent> action);
|
actionsCopy.TryGetValue(pair.Key, out EventAction action);
|
||||||
Task executionTask = new Task(() => action(bEvent));
|
Task executionTask = new Task(() => action.Callback(bEvent));
|
||||||
|
|
||||||
//Execute task with exception handler
|
//Execute task with exception handler
|
||||||
executionTask.ContinueWith((Task task) =>
|
executionTask.ContinueWith((Task task) =>
|
||||||
{
|
{
|
||||||
var exception = executionTask.Exception;
|
var exception = executionTask.Exception;
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("SERVER --- Exception occurred firing event"));
|
Console.WriteLine(string.Format("SERVER --- Exception occurred firing event"));
|
||||||
this._actionList.Remove(pair.Key);
|
this._actionList.Remove(pair.Key);
|
||||||
},
|
},
|
||||||
TaskContinuationOptions.OnlyOnFaulted);
|
TaskContinuationOptions.OnlyOnFaulted);
|
||||||
|
@ -145,21 +145,21 @@ namespace Aurora.Services.PlayerService
|
|||||||
newPosition - oldPosition < -0.001)
|
newPosition - oldPosition < -0.001)
|
||||||
{
|
{
|
||||||
_mediaPlayer.Position = newPosition;
|
_mediaPlayer.Position = newPosition;
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("**Audio synced**"));
|
Console.WriteLine(string.Format("**Audio synced**"));
|
||||||
// System.Diagnostics.Debug.WriteLine(string.Format("Remote Server Time {0}", new DateTime(sync.ServerTimeTicks).ToLongTimeString()));
|
// Console.WriteLine(string.Format("Remote Server Time {0}", new DateTime(sync.ServerTimeTicks).ToLongTimeString()));
|
||||||
// System.Diagnostics.Debug.WriteLine(string.Format("Remote Track Time: {0}", sync.TrackPosition));
|
// Console.WriteLine(string.Format("Remote Track Time: {0}", sync.TrackPosition));
|
||||||
// System.Diagnostics.Debug.WriteLine(string.Format("Local Server Time: {0}", time.DateTime.ToLongTimeString()));
|
// Console.WriteLine(string.Format("Local Server Time: {0}", time.DateTime.ToLongTimeString()));
|
||||||
// System.Diagnostics.Debug.WriteLine(string.Format("Local Track Time: {0}", _mediaPlayer.Position));
|
// Console.WriteLine(string.Format("Local Track Time: {0}", _mediaPlayer.Position));
|
||||||
// System.Diagnostics.Debug.WriteLine(string.Format("Offset: {0}", offset));
|
// Console.WriteLine(string.Format("Offset: {0}", offset));
|
||||||
// System.Diagnostics.Debug.WriteLine(string.Format("Old Position: {0}", oldPosition));
|
// Console.WriteLine(string.Format("Old Position: {0}", oldPosition));
|
||||||
// System.Diagnostics.Debug.WriteLine(string.Format("New Position: {0}", newPosition));
|
// Console.WriteLine(string.Format("New Position: {0}", newPosition));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("Exception caught while attempting to sync: " + ex.Message);
|
Console.WriteLine("Exception caught while attempting to sync: " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -73,7 +73,7 @@ namespace Aurora.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("Starting gRPC server at hostname: {0}, port: {1}", _hostname, _port));
|
Console.WriteLine(string.Format("Starting gRPC server at hostname: {0}, port: {1}", _hostname, _port));
|
||||||
|
|
||||||
if (!Initialized)
|
if (!Initialized)
|
||||||
{
|
{
|
||||||
@ -93,7 +93,7 @@ namespace Aurora.Services
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine(string.Format("Error starting gRPC server: {0}", ex.Message));
|
Console.WriteLine(string.Format("Error starting gRPC server: {0}", ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
Aurora/Utils/Combine.cs
Normal file
25
Aurora/Utils/Combine.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Aurora.Utils
|
||||||
|
{
|
||||||
|
public static class Misc
|
||||||
|
{
|
||||||
|
public static string Combine(string[] args)
|
||||||
|
{
|
||||||
|
string outString = "";
|
||||||
|
foreach (string arg in args)
|
||||||
|
{
|
||||||
|
if (arg == args.Last())
|
||||||
|
{
|
||||||
|
outString += arg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outString += arg + ":";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -73,7 +73,7 @@ namespace Aurora.Utils
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine($"{ex.GetType()} {ex.Message}\n{ex.StackTrace}");
|
Console.WriteLine($"{ex.GetType()} {ex.Message}\n{ex.StackTrace}");
|
||||||
ex = ex.InnerException;
|
ex = ex.InnerException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user