Code runs

This commit is contained in:
watsonb8 2019-11-02 15:47:41 -04:00
parent a3937e78da
commit 9a34e31f9c
7 changed files with 471 additions and 196 deletions

View File

@ -1,26 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1" /> <dllmap
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1" /> os="linux"
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1" /> dll="opengl32.dll"
<dllmap os="linux" dll="alut.dll" target="libalut.so.0" /> target="libGL.so.1"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so" /> <dllmap
<dllmap os="linux" dll="libX11" target="libX11.so.6" /> os="linux"
<dllmap os="linux" dll="libXi" target="libXi.so.6" /> dll="glu32.dll"
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0" /> target="libGLU.so.1"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL" /> <dllmap
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" /> os="linux"
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" /> dll="openal32.dll"
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> target="libopenal.so.1"/>
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> <dllmap
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> os="linux"
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL" /> dll="alut.dll"
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib" /> target="libalut.so.0"/>
<!-- XQuartz compatibility (X11 on Mac) --> <dllmap
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib" /> os="linux"
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib" /> dll="opencl.dll"
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib" /> target="libOpenCL.so"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib" /> <dllmap
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib" /> os="linux"
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib" /> dll="libX11"
target="libX11.so.6"/>
<dllmap
os="linux"
dll="libXi"
target="libXi.so.6"/>
<dllmap
os="linux"
dll="SDL2.dll"
target="libSDL2-2.0.so.0"/>
<dllmap
os="osx"
dll="opengl32.dll"
target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap
os="osx"
dll="openal32.dll"
target="/System/Library/Frameworks/OpenAL.framework/OpenAL"/>
<dllmap
os="osx"
dll="alut.dll"
target="/System/Library/Frameworks/OpenAL.framework/OpenAL"/>
<dllmap
os="osx"
dll="libGLES.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="libGLESv1_CM.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="libGLESv2.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="opencl.dll"
target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap
os="osx"
dll="SDL2.dll"
target="libSDL2.dylib"/><!-- XQuartz compatibility (X11 on Mac) -->
<dllmap
os="osx"
dll="libGL.so.1"
target="/usr/X11/lib/libGL.dylib"/>
<dllmap
os="osx"
dll="libX11"
target="/usr/X11R6/lib/libX11.dylib"/>
<dllmap
os="osx"
dll="libXcursor.so.1"
target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap
os="osx"
dll="libXi"
target="/usr/X11/lib/libXi.dylib"/>
<dllmap
os="osx"
dll="libXinerama"
target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap
os="osx"
dll="libXrandr.so.2"
target="/usr/X11/lib/libXrandr.dylib"/>
</configuration> </configuration>

View File

@ -1,26 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1" /> <dllmap
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1" /> os="linux"
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1" /> dll="opengl32.dll"
<dllmap os="linux" dll="alut.dll" target="libalut.so.0" /> target="libGL.so.1"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so" /> <dllmap
<dllmap os="linux" dll="libX11" target="libX11.so.6" /> os="linux"
<dllmap os="linux" dll="libXi" target="libXi.so.6" /> dll="glu32.dll"
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0" /> target="libGLU.so.1"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL" /> <dllmap
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" /> os="linux"
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" /> dll="openal32.dll"
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> target="libopenal.so.1"/>
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> <dllmap
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> os="linux"
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL" /> dll="alut.dll"
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib" /> target="libalut.so.0"/>
<!-- XQuartz compatibility (X11 on Mac) --> <dllmap
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib" /> os="linux"
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib" /> dll="opencl.dll"
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib" /> target="libOpenCL.so"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib" /> <dllmap
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib" /> os="linux"
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib" /> dll="libX11"
target="libX11.so.6"/>
<dllmap
os="linux"
dll="libXi"
target="libXi.so.6"/>
<dllmap
os="linux"
dll="SDL2.dll"
target="libSDL2-2.0.so.0"/>
<dllmap
os="osx"
dll="opengl32.dll"
target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap
os="osx"
dll="openal32.dll"
target="/System/Library/Frameworks/OpenAL.framework/OpenAL"/>
<dllmap
os="osx"
dll="alut.dll"
target="/System/Library/Frameworks/OpenAL.framework/OpenAL"/>
<dllmap
os="osx"
dll="libGLES.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="libGLESv1_CM.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="libGLESv2.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="opencl.dll"
target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap
os="osx"
dll="SDL2.dll"
target="libSDL2.dylib"/><!-- XQuartz compatibility (X11 on Mac) -->
<dllmap
os="osx"
dll="libGL.so.1"
target="/usr/X11/lib/libGL.dylib"/>
<dllmap
os="osx"
dll="libX11"
target="/usr/X11R6/lib/libX11.dylib"/>
<dllmap
os="osx"
dll="libXcursor.so.1"
target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap
os="osx"
dll="libXi"
target="/usr/X11/lib/libXi.dylib"/>
<dllmap
os="osx"
dll="libXinerama"
target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap
os="osx"
dll="libXrandr.so.2"
target="/usr/X11/lib/libXrandr.dylib"/>
</configuration> </configuration>

View File

@ -1,26 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1" /> <dllmap
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1" /> os="linux"
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1" /> dll="opengl32.dll"
<dllmap os="linux" dll="alut.dll" target="libalut.so.0" /> target="libGL.so.1"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so" /> <dllmap
<dllmap os="linux" dll="libX11" target="libX11.so.6" /> os="linux"
<dllmap os="linux" dll="libXi" target="libXi.so.6" /> dll="glu32.dll"
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0" /> target="libGLU.so.1"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL" /> <dllmap
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" /> os="linux"
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" /> dll="openal32.dll"
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> target="libopenal.so.1"/>
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> <dllmap
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" /> os="linux"
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL" /> dll="alut.dll"
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib" /> target="libalut.so.0"/>
<!-- XQuartz compatibility (X11 on Mac) --> <dllmap
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib" /> os="linux"
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib" /> dll="opencl.dll"
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib" /> target="libOpenCL.so"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib" /> <dllmap
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib" /> os="linux"
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib" /> dll="libX11"
target="libX11.so.6"/>
<dllmap
os="linux"
dll="libXi"
target="libXi.so.6"/>
<dllmap
os="linux"
dll="SDL2.dll"
target="libSDL2-2.0.so.0"/>
<dllmap
os="osx"
dll="opengl32.dll"
target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap
os="osx"
dll="openal32.dll"
target="/System/Library/Frameworks/OpenAL.framework/OpenAL"/>
<dllmap
os="osx"
dll="alut.dll"
target="/System/Library/Frameworks/OpenAL.framework/OpenAL"/>
<dllmap
os="osx"
dll="libGLES.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="libGLESv1_CM.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="libGLESv2.dll"
target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES"/>
<dllmap
os="osx"
dll="opencl.dll"
target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap
os="osx"
dll="SDL2.dll"
target="libSDL2.dylib"/><!-- XQuartz compatibility (X11 on Mac) -->
<dllmap
os="osx"
dll="libGL.so.1"
target="/usr/X11/lib/libGL.dylib"/>
<dllmap
os="osx"
dll="libX11"
target="/usr/X11R6/lib/libX11.dylib"/>
<dllmap
os="osx"
dll="libXcursor.so.1"
target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap
os="osx"
dll="libXi"
target="/usr/X11/lib/libXi.dylib"/>
<dllmap
os="osx"
dll="libXinerama"
target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap
os="osx"
dll="libXrandr.so.2"
target="/usr/X11/lib/libXrandr.dylib"/>
</configuration> </configuration>

View File

@ -1,7 +1,7 @@
using System; using System;
namespace Aurora.Design.Views.Albums namespace Aurora.Design.Views.Albums
{ {
public class AlbumsViewModel public class AlbumsViewModel : BaseViewModel
{ {
public AlbumsViewModel() public AlbumsViewModel()
{ {

View File

@ -10,6 +10,7 @@ using Aurora.Proto.General;
using Aurora.Proto.Party; using Aurora.Proto.Party;
using Aurora.Proto.Playback; using Aurora.Proto.Playback;
using Aurora.Proto.Events; using Aurora.Proto.Events;
using Aurora.Services.ClientService;
namespace Aurora.Design.Views.Party namespace Aurora.Design.Views.Party
{ {
@ -26,14 +27,6 @@ namespace Aurora.Design.Views.Party
private string _hostname; private string _hostname;
private ObservableCollection<PartyMember> _members; private ObservableCollection<PartyMember> _members;
//Client fields
private Channel _channel;
private RemotePartyService.RemotePartyServiceClient _remotePartyClient;
private RemotePlaybackService.RemotePlaybackServiceClient _remotePlaybackClient;
private RemoteEventService.RemoteEventServiceClient _remoteEventsClient;
CancellationTokenSource _eventCancellationTokenSource;
public PartyViewModel() public PartyViewModel()
{ {
this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute); this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute);
@ -42,11 +35,14 @@ namespace Aurora.Design.Views.Party
_members = new ObservableCollection<PartyMember>(); _members = new ObservableCollection<PartyMember>();
SetState(PartyState.SelectingHost); SetState(PartyState.SelectingHost);
//Hook up event handler
ClientService.Instance.EventReceived += this.OnEventReceived;
} }
~PartyViewModel() ~PartyViewModel()
{ {
Task.Run(ServerService.Instance.Stop); //Task.Run(ServerService.Instance.Stop);
} }
#region Properties #region Properties
@ -84,11 +80,55 @@ namespace Aurora.Design.Views.Party
#endregion Properties #endregion Properties
#region Commands #region Events
private void OnJoinExecute() /// <summary>
/// An event handler for the client receiving update events
/// </summary>
/// <param name="sender">The object that sent the event</param>
/// <param name="eventArgs">The event arguments</param>
public void OnEventReceived(object sender, EventReceivedEventArgs eventArgs)
{ {
InitializeClients(Hostname, SettingsService.Instance.DefaultPort.ToString()); switch (eventArgs.BaseEvent.DerivedEventCase)
JoinParty(); {
case BaseEvent.DerivedEventOneofCase.None:
{
throw new InvalidOperationException();
}
case BaseEvent.DerivedEventOneofCase.PartyMemberJoinedEvent:
{
PartyMemberJoinedEvent derivedEvent = eventArgs.BaseEvent.PartyMemberJoinedEvent;
PartyMember member = new PartyMember
{
UserName = derivedEvent.Member.UserName,
Id = derivedEvent.Member.Id,
IpAddress = derivedEvent.Member.IpAddress,
Port = derivedEvent.Member.Port
};
AddMember(member);
break;
}
case BaseEvent.DerivedEventOneofCase.PartyMemberLeftEvent:
{
PartyMemberJoinedEvent derivedEvent = eventArgs.BaseEvent.PartyMemberJoinedEvent;
var found = Members.Where(x => x.Id == derivedEvent.Member.Id);
foreach (PartyMember member in found)
{
_members.Remove(member);
}
break;
}
}
}
#endregion Events
#region Commands
private async void OnJoinExecute()
{
ClientService.Instance.Start(Hostname, SettingsService.Instance.DefaultPort.ToString());
await JoinParty();
SetState(PartyState.Connecting); SetState(PartyState.Connecting);
} }
@ -98,12 +138,14 @@ namespace Aurora.Design.Views.Party
return true; return true;
} }
private void OnHostExecute() private async void OnHostExecute()
{ {
ServerService.Instance.Start(); ServerService.Instance.Start();
string localHost = ServerService.GetLocalIPAddress(); string localHost = ServerService.GetLocalIPAddress();
InitializeClients(localHost, SettingsService.Instance.DefaultPort.ToString()); ClientService.Instance.Start(localHost, SettingsService.Instance.DefaultPort.ToString());
JoinParty(); await JoinParty();
ClientService.Instance.GetEvents();
//Change state //Change state
SetState(PartyState.Connecting); SetState(PartyState.Connecting);
@ -118,55 +160,40 @@ namespace Aurora.Design.Views.Party
#endregion Commands #endregion Commands
#region Private Methods #region Private Methods
private void InitializeClients(string hostname, string port)
{
_channel = new Channel(string.Format("{0}:{1}", hostname, port), ChannelCredentials.Insecure);
_remotePartyClient = new RemotePartyService.RemotePartyServiceClient(_channel);
_remotePlaybackClient = new RemotePlaybackService.RemotePlaybackServiceClient(_channel);
_remoteEventsClient = new RemoteEventService.RemoteEventServiceClient(_channel);
//Assign but don't start task
_eventCancellationTokenSource = new CancellationTokenSource();
}
/// <summary> /// <summary>
/// Join the remote party. /// Join the remote party.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private async void JoinParty() private async Task JoinParty()
{ {
JoinPartyResponse resp = await _remotePartyClient.JoinPartyAsync(new JoinPartyRequest
{
UserName = SettingsService.Instance.Username,
});
SettingsService.Instance.ClientId = resp.ClientId;
RefreshMembers();
//Subscribe to events
SubscribeRequest req = new SubscribeRequest();
req.EventTypes.Add(EventType.PartyMemberJoined);
req.EventTypes.Add(EventType.PartyMemberLeft);
if (!string.IsNullOrWhiteSpace(SettingsService.Instance.ClientId))
{
req.ClientId = SettingsService.Instance.ClientId;
}
try try
{ {
JoinPartyResponse resp = await ClientService.Instance.RemotePartyClient.JoinPartyAsync(new JoinPartyRequest
{
UserName = SettingsService.Instance.Username,
});
SettingsService.Instance.ClientId = resp.ClientId;
RefreshMembers();
//Subscribe to events
SubscribeRequest req = new SubscribeRequest();
req.EventTypes.Add(EventType.PartyMemberJoined);
req.EventTypes.Add(EventType.PartyMemberLeft);
if (!string.IsNullOrWhiteSpace(SettingsService.Instance.ClientId))
{
req.ClientId = SettingsService.Instance.ClientId;
}
Console.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));
_remoteEventsClient.SubscribeToEvents(req); ClientService.Instance.RemoteEventClient.SubscribeToEvents(req);
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("Error subscribing to events: " + ex.Message); Console.WriteLine("Error subscribing to events: " + ex.Message);
} }
GetEvents();
} }
/// <summary> /// <summary>
@ -174,21 +201,12 @@ namespace Aurora.Design.Views.Party
/// </summary> /// </summary>
private void RefreshMembers() private void RefreshMembers()
{ {
MembersResponse response = _remotePartyClient.GetPartyMembers(new Empty()); MembersResponse response = ClientService.Instance.RemotePartyClient.GetPartyMembers(new Empty());
//Add members //Add members
foreach (PartyMember member in response.Members) foreach (PartyMember member in response.Members)
{ {
Members.Add(member); Members.Add(member);
} }
//Remove out of date members
// foreach (PartyMember member in Members)
// {
// if (!response.Members.Contains(member))
// {
// Members.Remove(member);
// }
// }
} }
private void SetState(PartyState state) private void SetState(PartyState state)
@ -203,70 +221,6 @@ namespace Aurora.Design.Views.Party
Members.Add(member); Members.Add(member);
} }
/// <summary>
/// Asynchronous function for processing events off of the event stream.
/// </summary>
/// <returns></returns>
private async void GetEvents()
{
Console.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", SettingsService.Instance.ClientId));
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient
.GetEvents(new EventsRequest { ClientId = SettingsService.Instance.ClientId }))
{
while (!_eventCancellationTokenSource.Token.IsCancellationRequested &&
await eventStream.ResponseStream.MoveNext(_eventCancellationTokenSource.Token))
{
Console.WriteLine(string.Format("CLIENT {0} - Event received for client with id", SettingsService.Instance.ClientId));
try
{
//Convert derived event type
BaseEvent e = new BaseEvent(eventStream.ResponseStream.Current);
switch (e.DerivedEventCase)
{
case BaseEvent.DerivedEventOneofCase.None:
{
throw new InvalidOperationException();
}
case BaseEvent.DerivedEventOneofCase.PartyMemberJoinedEvent:
{
PartyMemberJoinedEvent derivedEvent = e.PartyMemberJoinedEvent;
PartyMember member = new PartyMember
{
UserName = derivedEvent.Member.UserName,
Id = derivedEvent.Member.Id,
IpAddress = derivedEvent.Member.IpAddress,
Port = derivedEvent.Member.Port
};
AddMember(member);
break;
}
case BaseEvent.DerivedEventOneofCase.PartyMemberLeftEvent:
{
PartyMemberJoinedEvent derivedEvent = e.PartyMemberJoinedEvent;
var found = Members.Where(x => x.Id == derivedEvent.Member.Id);
foreach (PartyMember member in found)
{
_members.Remove(member);
}
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("EXCEPTION --- " + ex.Message));
}
OnPropertyChanged("Members");
}
}
}
#endregion Private Methods #endregion Private Methods
} }
} }

View File

@ -0,0 +1,110 @@
using System;
using System.Threading.Tasks;
using System.Threading;
using Grpc.Core;
using Aurora.Proto.Events;
using Aurora.Proto.Party;
using Aurora.Proto.Playback;
using Aurora.Services.ClientService;
namespace Aurora.Services.ClientService
{
public class ClientService : BaseService<ClientService>
{
private RemotePartyService.RemotePartyServiceClient _remotePartyClient;
private RemotePlaybackService.RemotePlaybackServiceClient _remotePlaybackClient;
private RemoteEventService.RemoteEventServiceClient _remoteEventsClient;
private Channel _channel;
CancellationTokenSource _eventCancellationTokenSource;
public ClientService()
{
}
public EventReceivedEventHandler EventReceived;
public RemotePartyService.RemotePartyServiceClient RemotePartyClient
{
get
{
return _remotePartyClient;
}
}
public RemotePlaybackService.RemotePlaybackServiceClient RemotePlaybackServiceClient
{
get
{
return _remotePlaybackClient;
}
}
public RemoteEventService.RemoteEventServiceClient RemoteEventClient
{
get { return _remoteEventsClient; }
}
public bool IsStarted
{
get
{
return _remoteEventsClient != null &&
_remotePartyClient != null &&
_remotePlaybackClient != null;
}
}
public void Start(string hostname, string port)
{
_channel = new Channel(string.Format("{0}:{1}", hostname, port), ChannelCredentials.Insecure);
_remotePartyClient = new RemotePartyService.RemotePartyServiceClient(_channel);
_remotePlaybackClient = new RemotePlaybackService.RemotePlaybackServiceClient(_channel);
_remoteEventsClient = new RemoteEventService.RemoteEventServiceClient(_channel);
//Assign but don't start task
_eventCancellationTokenSource = new CancellationTokenSource();
}
public async void Close()
{
_eventCancellationTokenSource.Cancel();
await _channel.ShutdownAsync();
_remotePartyClient = null;
_remotePlaybackClient = null;
_remoteEventsClient = null;
}
/// <summary>
/// Asynchronous function for processing events off of the event stream.
/// </summary>
/// <returns></returns>
public async Task GetEvents()
{
string clientId = SettingsService.Instance.ClientId;
Console.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", clientId));
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient
.GetEvents(new EventsRequest { ClientId = SettingsService.Instance.ClientId }))
{
try
{
while (!_eventCancellationTokenSource.Token.IsCancellationRequested &&
await eventStream.ResponseStream.MoveNext(_eventCancellationTokenSource.Token))
{
BaseEvent e = new BaseEvent(eventStream.ResponseStream.Current);
if (this.EventReceived != null)
{
this.EventReceived.Invoke(this, new EventReceivedEventArgs(e));
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("EXCEPTION --- " + ex.Message));
}
}
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using Aurora.Proto.Events;
namespace Aurora.Services.ClientService
{
public delegate void EventReceivedEventHandler(object sender, EventReceivedEventArgs e);
public class EventReceivedEventArgs
{
public BaseEvent BaseEvent { get; private set; }
public EventReceivedEventArgs(BaseEvent e)
{
BaseEvent = e;
}
}
}