Refactored to only having one executor per platform

This commit is contained in:
watsonb8
2019-07-05 11:37:44 -04:00
parent 0cb0546741
commit a01d399a1f
18 changed files with 226 additions and 170 deletions

View File

@ -6,22 +6,47 @@ namespace Aurora.Backend.Executors
{
public abstract class BaseExecutor
{
public BaseExecutor()
protected BaseExecutor()
{
}
public ExecutorType ExecutorType { get; protected set; }
public Type ExecutorType { get; protected set; }
public static BaseExecutor CreateExecutor<T>(ExecutorType executorType) where T : BaseExecutor
public static BaseExecutor CreateExecutor<T>()
{
MethodInfo method = typeof(T).GetMethod("Create");
if (method == null)
BaseExecutor executor = null;
if (typeof(T) == typeof(HostExecutor))
{
throw new InvalidOperationException("Executor must include a 'create' method.");
executor = new HostExecutor();
executor.ExecutorType = typeof(HostExecutor);
}
else if (typeof(T) == typeof(ClientExecutor))
{
executor = new ClientExecutor();
executor.ExecutorType = typeof(ClientExecutor);
}
else
{
throw new InvalidOperationException("Cannot create an executor of type: " + nameof(T));
}
return method.Invoke(null, new object[] { executorType }) as BaseExecutor;
return executor;
}
public abstract void Initialize();
public abstract void Run();
public abstract void Close();
public abstract void GetMembers();
public abstract void GetQueue();
public abstract void AddToQueue();
public abstract void RemoveFromQueue();
}
public enum ExecutorType

View File

@ -1,51 +0,0 @@
using System;
using Aurora.Backend.Server.Party;
using Aurora.Backend.Client.Party;
namespace Aurora.Backend.Executors
{
public abstract class BasePartyExecutor : BaseExecutor
{
public BasePartyExecutor()
{
}
public static BasePartyExecutor Create(ExecutorType type)
{
BasePartyExecutor executor = null;
switch (type)
{
case ExecutorType.Client:
{
executor = new ClientPartyExecutor();
executor.ExecutorType = type;
break;
}
case ExecutorType.Server:
{
executor = new HostPartyExecutor();
executor.ExecutorType = type;
break;
}
}
return executor;
}
public abstract void Initialize();
public abstract void Run();
public abstract void Close();
public abstract void GetMembers();
public abstract void GetQueue();
public abstract void AddToQueue();
public abstract void RemoveFromQueue();
}
}

View File

@ -0,0 +1,48 @@
using System;
using Aurora.Backend.Executors;
namespace Aurora.Backend.Executors
{
public class ClientExecutor : BaseExecutor
{
public ClientExecutor()
{
}
public override void AddToQueue()
{
throw new NotImplementedException();
}
public override void Close()
{
throw new NotImplementedException();
}
public override void GetMembers()
{
throw new NotImplementedException();
}
public override void GetQueue()
{
throw new NotImplementedException();
}
public override void Initialize()
{
throw new NotImplementedException();
}
public override void RemoveFromQueue()
{
throw new NotImplementedException();
}
public override void Run()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Threading.Tasks;
using Aurora.Backend.Executors;
using Aurora.Backend.Services;
using Aurora.Backend.Proto;
using Aurora.Backend.RemoteImpl;
namespace Aurora.Backend.Executors
{
public class HostExecutor : BaseExecutor
{
RemotePartyServiceImpl _remoteServiceImpl;
RemotePlaybackServiceImpl _remotePlaybackImpl;
public HostExecutor()
{
_remoteServiceImpl = new RemotePartyServiceImpl();
}
public override void Initialize()
{
//Register grpc RemoteService with singleton server service
ServerService.Instance.RegisterService(RemotePartyService.BindService(_remoteServiceImpl));
ServerService.Instance.RegisterService(RemotePlaybackService.BindService(_remotePlaybackImpl));
}
public override async void Close()
{
await ServerService.Instance.Stop();
}
public override void AddToQueue()
{
throw new NotImplementedException();
}
public override void GetMembers()
{
throw new NotImplementedException();
}
public override void GetQueue()
{
throw new NotImplementedException();
}
public override void RemoveFromQueue()
{
throw new NotImplementedException();
}
public override void Run()
{
throw new NotImplementedException();
}
}
}