Event manager improvements. Changed to console.writeline instead of diagnostics
This commit is contained in:
@ -95,7 +95,7 @@ namespace Aurora.Services.ClientService
|
||||
{
|
||||
_eventCancellationTokenSource = new CancellationTokenSource();
|
||||
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
|
||||
.GetEvents(new EventsRequest { ClientId = SettingsService.Instance.ClientId }))
|
||||
{
|
||||
@ -126,14 +126,14 @@ namespace Aurora.Services.ClientService
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Exception while parsing event ---" + ex.Message);
|
||||
Console.WriteLine("Exception while parsing event ---" + ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
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>
|
||||
{
|
||||
#region Fields
|
||||
private Dictionary<string, List<EventType>> _subscriptionList;
|
||||
private Dictionary<string, Action<BaseEvent>> _actionList;
|
||||
private Dictionary<string, EventAction> _actionList;
|
||||
|
||||
#endregion Fields
|
||||
public EventManager()
|
||||
{
|
||||
_subscriptionList = new Dictionary<string, List<EventType>>();
|
||||
_actionList = new Dictionary<string, Action<BaseEvent>>();
|
||||
_actionList = new Dictionary<string, EventAction>();
|
||||
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
_actionList.Add(sessionId, action);
|
||||
_actionList.Add(sessionId, new EventAction(action, cancel));
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,13 +171,21 @@ namespace Aurora.Services.EventManager
|
||||
_actionList.Remove(sessionId);
|
||||
}
|
||||
|
||||
public void CancelEventStream(string sessionId)
|
||||
{
|
||||
_actionList.TryGetValue(sessionId, out EventAction value);
|
||||
value.Cancel();
|
||||
|
||||
RemoveEventHandler(sessionId);
|
||||
}
|
||||
|
||||
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
|
||||
lock (_actionList)
|
||||
{
|
||||
foreach (KeyValuePair<string, Action<BaseEvent>> pair in _actionList)
|
||||
foreach (KeyValuePair<string, EventAction> pair in _actionList)
|
||||
{
|
||||
actionsCopy.Add(pair.Key, pair.Value);
|
||||
}
|
||||
@ -180,14 +199,14 @@ namespace Aurora.Services.EventManager
|
||||
//If action list contains an action for id, invoke
|
||||
if (actionsCopy.ContainsKey(pair.Key))
|
||||
{
|
||||
actionsCopy.TryGetValue(pair.Key, out Action<BaseEvent> action);
|
||||
Task executionTask = new Task(() => action(bEvent));
|
||||
actionsCopy.TryGetValue(pair.Key, out EventAction action);
|
||||
Task executionTask = new Task(() => action.Callback(bEvent));
|
||||
|
||||
//Execute task with exception handler
|
||||
executionTask.ContinueWith((Task task) =>
|
||||
{
|
||||
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);
|
||||
},
|
||||
TaskContinuationOptions.OnlyOnFaulted);
|
||||
|
@ -145,21 +145,21 @@ namespace Aurora.Services.PlayerService
|
||||
newPosition - oldPosition < -0.001)
|
||||
{
|
||||
_mediaPlayer.Position = newPosition;
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("**Audio synced**"));
|
||||
// System.Diagnostics.Debug.WriteLine(string.Format("Remote Server Time {0}", new DateTime(sync.ServerTimeTicks).ToLongTimeString()));
|
||||
// System.Diagnostics.Debug.WriteLine(string.Format("Remote Track Time: {0}", sync.TrackPosition));
|
||||
// System.Diagnostics.Debug.WriteLine(string.Format("Local Server Time: {0}", time.DateTime.ToLongTimeString()));
|
||||
// System.Diagnostics.Debug.WriteLine(string.Format("Local Track Time: {0}", _mediaPlayer.Position));
|
||||
// System.Diagnostics.Debug.WriteLine(string.Format("Offset: {0}", offset));
|
||||
// System.Diagnostics.Debug.WriteLine(string.Format("Old Position: {0}", oldPosition));
|
||||
// System.Diagnostics.Debug.WriteLine(string.Format("New Position: {0}", newPosition));
|
||||
Console.WriteLine(string.Format("**Audio synced**"));
|
||||
// Console.WriteLine(string.Format("Remote Server Time {0}", new DateTime(sync.ServerTimeTicks).ToLongTimeString()));
|
||||
// Console.WriteLine(string.Format("Remote Track Time: {0}", sync.TrackPosition));
|
||||
// Console.WriteLine(string.Format("Local Server Time: {0}", time.DateTime.ToLongTimeString()));
|
||||
// Console.WriteLine(string.Format("Local Track Time: {0}", _mediaPlayer.Position));
|
||||
// Console.WriteLine(string.Format("Offset: {0}", offset));
|
||||
// Console.WriteLine(string.Format("Old Position: {0}", oldPosition));
|
||||
// Console.WriteLine(string.Format("New Position: {0}", newPosition));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
@ -93,7 +93,7 @@ namespace Aurora.Services
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user