Code refactoring for cleaner view model design
This commit is contained in:
@ -6,9 +6,12 @@ using Aurora.Proto.Events;
|
||||
using Aurora.Proto.Party;
|
||||
using Aurora.Proto.Playback;
|
||||
using Aurora.Proto.Sync;
|
||||
using Aurora.Services.ClientService.Events;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Aurora.Services.ClientService
|
||||
{
|
||||
|
||||
public class ClientService : BaseService<ClientService>
|
||||
{
|
||||
private RemotePartyService.RemotePartyServiceClient _remotePartyClient;
|
||||
@ -23,7 +26,11 @@ namespace Aurora.Services.ClientService
|
||||
{
|
||||
}
|
||||
|
||||
public EventReceivedEventHandler EventReceived;
|
||||
public MediaPausedEventHandler OnMediaPaused;
|
||||
public NewMediaPlayingEventHandler OnNewMediaPlaying;
|
||||
public PartyMemberJoinedEventHandler OnPartyMemberJoined;
|
||||
public PartyMemberLeftEventHandler OnPartyMemberLeft;
|
||||
public MediaResumedEventHandler OnMediaResumed;
|
||||
|
||||
public RemotePartyService.RemotePartyServiceClient RemotePartyClient
|
||||
{
|
||||
@ -99,16 +106,36 @@ namespace Aurora.Services.ClientService
|
||||
while (!_eventCancellationTokenSource.Token.IsCancellationRequested &&
|
||||
await eventStream.ResponseStream.MoveNext(_eventCancellationTokenSource.Token))
|
||||
{
|
||||
BaseEvent e = new BaseEvent(eventStream.ResponseStream.Current);
|
||||
if (this.EventReceived != null)
|
||||
try
|
||||
{
|
||||
this.EventReceived.Invoke(this, new EventReceivedEventArgs(e));
|
||||
BaseEvent e = new BaseEvent(eventStream.ResponseStream.Current);
|
||||
|
||||
Dictionary<BaseEvent.DerivedEventOneofCase, EventInfo> events = new Dictionary<BaseEvent.DerivedEventOneofCase, EventInfo>()
|
||||
{
|
||||
{BaseEvent.DerivedEventOneofCase.MediaPausedEvent, new EventInfo(this.OnMediaPaused, typeof(MediaPausedEventArgs))},
|
||||
{BaseEvent.DerivedEventOneofCase.MediaResumedEvent, new EventInfo(this.OnMediaResumed, typeof(MediaResumedEventArgs))},
|
||||
{BaseEvent.DerivedEventOneofCase.NewMediaPlayingEvent, new EventInfo(this.OnNewMediaPlaying, typeof(NewMediaPlayingEventArgs))},
|
||||
{BaseEvent.DerivedEventOneofCase.PartyMemberJoinedEvent, new EventInfo(this.OnPartyMemberJoined, typeof(PartyMemberJoinedEventArgs))},
|
||||
{BaseEvent.DerivedEventOneofCase.PartyMemberLeftEvent, new EventInfo(this.OnPartyMemberLeft, typeof(PartyMemberLeftEventArgs))}
|
||||
};
|
||||
|
||||
events.TryGetValue(e.DerivedEventCase, out EventInfo eventInfo);
|
||||
|
||||
if (eventInfo != null && eventInfo.Handler != null)
|
||||
{
|
||||
eventInfo.Handler.DynamicInvoke(new object[] { this, Activator.CreateInstance(eventInfo.ArgsType, new object[] { e }) });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Exception while parsing event ---" + ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(string.Format("EXCEPTION --- " + ex.Message));
|
||||
Console.WriteLine(string.Format("EXCEPTION while parsing events --- " + ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user