2019-06-03 14:57:05 +00:00
|
|
|
using System;
|
2019-07-05 21:37:10 +00:00
|
|
|
using System.Collections.ObjectModel;
|
2019-07-06 19:52:28 +00:00
|
|
|
using Grpc.Core;
|
|
|
|
using Aurora.Proto;
|
2019-07-05 21:37:10 +00:00
|
|
|
using Aurora.Models;
|
2019-07-06 19:52:28 +00:00
|
|
|
using Aurora.Services;
|
2019-07-05 18:17:09 +00:00
|
|
|
namespace Aurora.Executors
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-05 15:37:44 +00:00
|
|
|
public class ClientExecutor : BaseExecutor
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
private Channel _channel;
|
|
|
|
private RemotePartyService.RemotePartyServiceClient _remotePartyClient;
|
|
|
|
private RemotePlaybackService.RemotePlaybackServiceClient _remotePlaybackClient;
|
|
|
|
|
|
|
|
private ObservableCollection<PartyMember> _partyMembers;
|
|
|
|
|
2019-07-05 15:37:44 +00:00
|
|
|
public ClientExecutor()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
_partyMembers = new ObservableCollection<PartyMember>();
|
2019-06-03 14:57:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 21:37:10 +00:00
|
|
|
#region Properties
|
|
|
|
public override ObservableCollection<PartyMember> PartyMembers
|
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
get { return _partyMembers; }
|
2019-07-05 21:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion Properties
|
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
public override void Connect(string hostname)
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
_channel = new Channel(string.Format("{0}:{1}", hostname, SettingsService.Instance.DefaultPort), ChannelCredentials.Insecure);
|
|
|
|
|
|
|
|
_remotePartyClient = new RemotePartyService.RemotePartyServiceClient(_channel);
|
|
|
|
_remotePlaybackClient = new RemotePlaybackService.RemotePlaybackServiceClient(_channel);
|
|
|
|
|
|
|
|
JoinParty();
|
2019-06-03 14:57:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
public override async void Close()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
await _channel.ShutdownAsync();
|
2019-06-03 14:57:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
public override void AddToQueue()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
public override ObservableCollection<PartyMember> GetMembers()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
public override void GetQueue()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void RemoveFromQueue()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
private async void JoinParty()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
await _remotePartyClient.JoinPartyAsync(new JoinPartyRequest
|
|
|
|
{
|
|
|
|
UserName = SettingsService.Instance.Username,
|
|
|
|
});
|
|
|
|
|
|
|
|
MembersResponse resposne = _remotePartyClient.GetPartyMembers(new Empty());
|
|
|
|
//Add members
|
|
|
|
foreach (PartyMember member in resposne.Members)
|
|
|
|
{
|
|
|
|
_partyMembers.Add(member);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Remove out of date members
|
|
|
|
foreach (PartyMember member in _partyMembers)
|
|
|
|
{
|
|
|
|
if (!resposne.Members.Contains(member))
|
|
|
|
{
|
|
|
|
_partyMembers.Remove(member);
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 14:57:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|