public void SendEvent(GameEvent gameEvent, IEventReceiver receiver) { SingletonFactory.LOG.Log("SendEvent: " + gameEvent.ToString() + (receiver == null ? "" : ", Receiver: " + receiver.ToString()), Logging.LoggerLevel.LOW); SingletonFactory.LOG.Log("EventArgs: " + gameEvent.ArgString); FilterEvent(gameEvent); receiver.OnEvent(gameEvent); }
public EventProcessor(IEventReceiver receiver, ITextSerializer serializer, IEventDispatcher dispatcher) { this.receiver = receiver; this.serializer = serializer; this.dispatcher = dispatcher; }
/// <summary> /// Broadcasts the given GDEvent to all currently registered receivers /// </summary> /// <param name="gameEvent">The event to broadcast</param> public void BroadcastEvent(GDEvent gameEvent) { string eventType = gameEvent.EventType; if (!HasReceiversForEvent(eventType)) { return; } // Flag used to signal whether to clear the list of event receivers after the event is broadcasted bool cleanAfter = false; for (int i = 0; i < eventTypes[eventType].Count; i++) { if (eventTypes[eventType][i].IsAlive) { IEventReceiver receiver = eventTypes[eventType][i].Target as IEventReceiver; if (receiver != null) { receiver.ReceiveEvent(gameEvent); } } else { cleanAfter = true; } } if (cleanAfter) { ClearEmptyEventTypes(eventType); } }
public async Task <TestResult> Invoke(object instance, IEventReceiver eventReceiver) { var result = new TestResult(Owner, this); if (IsIgnored) { result.Ignored(); return(result); } eventReceiver.Handle(new TestMethodStarted(instance, this, result.StartedAtUtc)); try { var maybeTask = _methodInfo.Invoke(instance, null); if (maybeTask is Task t) { await t; } result.Success(); } catch (Exception ex) { result.Failed(ex); } eventReceiver.Handle(new TestMethodFinished(instance, this, result)); return(result); }
/// <summary> /// Publishes the provided <paramref name="command"></paramref> and waits for an event of <typeparamref name="TEvent"/> or exits if the specified timeout is expired. /// </summary> /// <param name="command">The <typeparamref name="TCommand"/> to publish.</param> /// <param name="condition">A delegate to be executed over and over until it returns the <typeparamref name="TEvent"/> that is desired, return null to keep trying.</param> /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param> /// <param name="eventReceiver">If provided, is the <see cref="IEventReceiver{TAuthenticationToken}" /> that the event is expected to be returned on.</param> public TEvent PublishAndWait <TCommand, TEvent>(TCommand command, Func <IEnumerable <IEvent <TAuthenticationToken> >, TEvent> condition, int millisecondsTimeout, IEventReceiver <TAuthenticationToken> eventReceiver = null) where TCommand : ICommand <TAuthenticationToken> { DateTimeOffset startedAt = DateTimeOffset.UtcNow; Stopwatch mainStopWatch = Stopwatch.StartNew(); string responseCode = "200"; bool wasSuccessfull = false; IDictionary <string, string> telemetryProperties = new Dictionary <string, string> { { "Type", "InProcessBus" } }; string telemetryName = string.Format("{0}/{1}", command.GetType().FullName, command.Id); var telemeteredCommand = command as ITelemeteredMessage; if (telemeteredCommand != null) { telemetryName = telemeteredCommand.TelemetryName; } telemetryName = string.Format("Command/{0}", telemetryName); TEvent result; try { if (eventReceiver != null) { throw new NotSupportedException("Specifying a different event receiver is not yet supported."); } RouteHandlerDelegate commandHandler; if (!PrepareAndValidateCommand(command, out commandHandler)) { return((TEvent)(object)null); } result = (TEvent)(object)null; EventWaits.Add(command.CorrelationId, new List <IEvent <TAuthenticationToken> >()); Action <IMessage> handler = commandHandler.Delegate; handler(command); Logger.LogInfo(string.Format("A command was sent of type {0}.", command.GetType().FullName)); wasSuccessfull = true; } finally { mainStopWatch.Stop(); TelemetryHelper.TrackDependency("InProcessBus/CommandBus", "Command", telemetryName, null, startedAt, mainStopWatch.Elapsed, responseCode, wasSuccessfull, telemetryProperties); } SpinWait.SpinUntil(() => { IList <IEvent <TAuthenticationToken> > events = EventWaits[command.CorrelationId]; result = condition(events); return(result != null); }, millisecondsTimeout, SpinWait.DefaultSleepInMilliseconds); TelemetryHelper.TrackDependency("InProcessBus/CommandBus", "Command/AndWait", string.Format("Command/AndWait{0}", telemetryName.Substring(7)), null, startedAt, mainStopWatch.Elapsed, responseCode, wasSuccessfull, telemetryProperties); return(result); }
public void Subscribe(string eventName, IEventReceiver receiver) { if (!eventFilter.ContainsKey(eventName)) { Log(LogLevel.Error, Resources.MissingEventSubError, eventName); return; } if (stateCallbacks.ContainsKey(eventName)) { var ev = stateCallbacks[eventName](); if (ev != null) { receiver.HandleEvent(ev); } } lock (eventFilter[eventName]) { if (!eventFilter[eventName].Contains(receiver)) { eventFilter[eventName].Add(receiver); } } }
public void UnRegistReceiver(int evtid, IEventReceiver receiver) { if (receiver != null) { operQueue.Enqueue(new UnrgistReceiver(evtid, receiver)); } }
/// <summary> /// Sends the provided <paramref name="command"></paramref> and waits for an event of <typeparamref name="TEvent"/> or exits if the specified timeout is expired. /// </summary> /// <param name="command">The <typeparamref name="TCommand"/> to send.</param> /// <param name="condition">A delegate to be executed over and over until it returns the <typeparamref name="TEvent"/> that is desired, return null to keep trying.</param> /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param> /// <param name="eventReceiver">If provided, is the <see cref="IEventReceiver{TAuthenticationToken}" /> that the event is expected to be returned on.</param> public TEvent SendAndWait <TCommand, TEvent>(TCommand command, Func <IEnumerable <IEvent <TAuthenticationToken> >, TEvent> condition, int millisecondsTimeout, IEventReceiver <TAuthenticationToken> eventReceiver = null) where TCommand : ICommand <TAuthenticationToken> { if (eventReceiver != null) { throw new NotSupportedException("Specifying a different event receiver is not yet supported."); } if (!PrepareAndValidateCommand(command)) { return((TEvent)(object)null); } TEvent result = (TEvent)(object)null; EventWaits.Add(command.CorrelationId, new List <IEvent <TAuthenticationToken> >()); ServiceBusPublisher.Send(new BrokeredMessage(MessageSerialiser.SerialiseCommand(command))); Logger.LogInfo(string.Format("A command was sent of type {0}.", command.GetType().FullName)); SpinWait.SpinUntil(() => { IList <IEvent <TAuthenticationToken> > events = EventWaits[command.CorrelationId]; result = condition(events); return(result != null); }, millisecondsTimeout); return(result); }
public BlobQueue(string queueName, string connectionString, IEventFeedback feedback, IEventReceiver receiver) { _queueName = queueName; _connectionString = connectionString; _feedback = feedback; _receiver = receiver; }
public static void Unsubscribe(string eventName, IEventReceiver receiver) { if (eventFilter.ContainsKey(eventName)) { eventFilter[eventName].Remove(receiver); } }
public void RealRegistReceiver(int evtid, IEventReceiver recv) { if (!receivers.ContainsKey(evtid)) { receivers[evtid] = new List <IEventReceiver>(); } receivers[evtid].Add(recv); }
//Dictionary<string, Action<EventAgs>> listofReceveCallback = new Dictionary<string, Action<EventAgs>>(); public void RegisterEvent(EventAgs ags, IEventReceiver receiver) { if (!listofReceiver.ContainsKey(ags.Key)) { listofReceiver.Add(ags.Key, new List <IEventReceiver>()); } listofReceiver[ags.Key].Add(receiver); }
/// <summary> /// Unregisters the given IEventReceiver object from receiving all events it is currently registered on /// </summary> /// <param name="receiver">The event receiver</param> public void UnregisterEventReceiverFromAllEvents(IEventReceiver receiver) { foreach (string key in eventTypes.Keys) { InternalUnregisterEventReceiver(receiver, key, false); } ClearEmptyEventTypes(); }
public AllUpProcessor(IMutator mutator, IPnLConsumer pnLConsumer, ISourcer sourcer, IReducer reducer, IScenarioGenerator scenarioGenerator, IEventReceiver eventReceiver) { this.mutator = mutator; this.pnLConsumer = pnLConsumer; this.sourcer = sourcer; this.reducer = reducer; this.scenarioGenerator = scenarioGenerator; this.eventReceiver = eventReceiver; }
public void RealUnregistEventReceiver(int evtid, IEventReceiver recv) { if (!receivers.ContainsKey(evtid)) { // Error; return; } receivers[evtid].Remove(recv); }
public AkkaEventBus(IBusHelper busHelper, IAuthenticationTokenHelper <TAuthenticationToken> authenticationTokenHelper, ICorrelationIdHelper correlationIdHelper, ILogger logger, IEventPublisher <TAuthenticationToken> eventPublisher, IEventReceiver <TAuthenticationToken> eventReceiver) { BusHelper = busHelper; AuthenticationTokenHelper = authenticationTokenHelper; CorrelationIdHelper = correlationIdHelper; Logger = logger; EventPublisher = eventPublisher; EventReceiver = eventReceiver; }
public void RemoveReceiver(IEventReceiver r) { var w = _targets.FirstOrDefault(x => x.IsAlive && x.Target.Equals(r)); if (w != null) { _targets.Remove(w); } }
public static void UnsubscribeAll(IEventReceiver receiver) { foreach (var item in eventFilter.Values) { if (item.Contains(receiver)) { item.Remove(receiver); } } }
public void Update(UpdateInfo info) { while (m_Events.Count > 0 && m_Events.Peek().Tick <= info.Time) { Event evt = m_Events.Dequeue(); IEventReceiver evtRec = m_Receivers.Values.FirstOrDefault(receiver => receiver.ID == evt.ReceiverID); evtRec.ReceiveEvent(evt); } }
public static void Subscribe(string eventName, IEventReceiver receiver) { if (!eventFilter.ContainsKey(eventName)) { Log(LogLevel.Error, "Got a subscription for missing event \"{0}\"!", eventName); return; } eventFilter[eventName].Add(receiver); }
/// <summary> /// Initializes a new instance of the <see cref="TestExecWindowControl"/> class. /// </summary> public TestExecWindowControl(IMainEvents in_mainEvents, IEventReceiver in_eventReceiver, IExecute in_executor) : this() { m_mainEvents = in_mainEvents; m_evenReceiver = in_eventReceiver; m_executor = in_executor; m_mainEvents.OnSetOutputLevel(Properties.Settings.Default.IdxOutputLevel + 1); m_executor.SetMemLeakCheck(Properties.Settings.Default.CheckForMemoryLeaks); }
/// <summary> /// Publishes the provided <paramref name="command"></paramref> and waits for an event of <typeparamref name="TEvent"/> or exits if the specified timeout is expired. /// </summary> /// <param name="command">The <typeparamref name="TCommand"/> to publish.</param> /// <param name="condition">A delegate to be executed over and over until it returns the <typeparamref name="TEvent"/> that is desired, return null to keep trying.</param> /// <param name="timeout">A <see cref="T:System.TimeSpan"/> that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely.</param> /// <param name="eventReceiver">If provided, is the <see cref="IEventReceiver{TAuthenticationToken}" /> that the event is expected to be returned on.</param> public TEvent PublishAndWait <TCommand, TEvent>(TCommand command, Func <IEnumerable <IEvent <TAuthenticationToken> >, TEvent> condition, TimeSpan timeout, IEventReceiver <TAuthenticationToken> eventReceiver = null) where TCommand : ICommand <TAuthenticationToken> { long num = (long)timeout.TotalMilliseconds; if (num < -1L || num > int.MaxValue) { throw new ArgumentOutOfRangeException("timeout", timeout, "SpinWait_SpinUntil_TimeoutWrong"); } return(PublishAndWait(command, condition, (int)timeout.TotalMilliseconds, eventReceiver)); }
/// [exec data] public Executor(IMainEvents in_mainEvents, IEventReceiver in_eventReceiver) { m_mainEvents = in_mainEvents; m_evenReceiver = in_eventReceiver; boostProcessOutputParser.OnTestSuiteEntered += BoostProcessOutputParser_OnTestSuiteEntered; boostProcessOutputParser.OnTestSuiteLeft += BoostProcessOutputParser_OnTestSuiteLeft; boostProcessOutputParser.OnTestSuiteSkipped += BoostProcessOutputParser_OnTestSuiteSkipped; boostProcessOutputParser.OnTestCaseEntered += BoostProcessOutputParser_OnTestCaseEntered; boostProcessOutputParser.OnTestCaseLeft += BoostProcessOutputParser_OnTestCaseLeft; boostProcessOutputParser.OnTestCaseSkipped += BoostProcessOutputParser_OnTestCaseSkipped; }
/*sub class register or unregister event callback entrance.*/ /// <summary> /// 负责事件接收模块的注册 /// </summary> /// <param name="type">模块类型</param> /// <param name="receiver">模块接口实例</param> public void Register(RoleEventNodeType type, IEventReceiver receiver) { try { if (_receivers != null && !_receivers.ContainsKey(type) && receiver != null) { _receivers.Add(type, receiver); } } catch (Exception e) { Debug.Log(e.Message); } }
/// <summary> /// Registers the given IEventReceiver object to receive events of the given type /// </summary> /// <param name="receiver">The event receiver to register</param> /// <param name="eventType">The event type to notify the receiver of</param> public void RegisterEventReceiver(IEventReceiver receiver, string eventType) { if (IsReceiverRegistered(receiver, eventType)) { return; } List <WeakReference> receivers = GetListForEventType(eventType, true); receivers.Add(new WeakReference(receiver)); }
//public void fireEvent(IEvent evt) //{ // foreach (IEventReceiver iver in receivers) // { // if (iver != null) // iver.ProcessEvent(evt); // } //} public void RealSendEvent(IEvent ievt) { if (receivers.ContainsKey(ievt.evtId)) { List <IEventReceiver> list = receivers[ievt.evtId]; for (int i = 0; i < list.Count; i++) { IEventReceiver r = list[i]; r.ProcessEvent(ievt); } } }
public void UnRegisterEventListener(IEventReceiver newReciever, string eventName) { for (int i = 0; i < eventsList.Count; i++) { if (eventsList [i].eventName == eventName) { RegisterEventListenerToEvent(i, newReciever); //as found a matching event, so register and return. return; } } }
/// <summary> /// Sends the provided <paramref name="command"></paramref> and waits for an event of <typeparamref name="TEvent"/> or exits if the specified timeout is expired. /// </summary> /// <param name="command">The <typeparamref name="TCommand"/> to send.</param> /// <param name="condition">A delegate to be executed over and over until it returns the <typeparamref name="TEvent"/> that is desired, return null to keep trying.</param> /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param> /// <param name="eventReceiver">If provided, is the <see cref="IEventReceiver{TAuthenticationToken}" /> that the event is expected to be returned on.</param> public virtual TEvent SendAndWait <TCommand, TEvent>(TCommand command, Func <IEnumerable <IEvent <TAuthenticationToken> >, TEvent> condition, int millisecondsTimeout, IEventReceiver <TAuthenticationToken> eventReceiver = null) where TCommand : ICommand <TAuthenticationToken> { if (eventReceiver != null) { throw new NotSupportedException("Specifying a different event receiver is not yet supported."); } if (!AzureBusHelper.PrepareAndValidateCommand(command, "Azure-ServiceBus")) { return((TEvent)(object)null); } TEvent result = (TEvent)(object)null; EventWaits.Add(command.CorrelationId, new List <IEvent <TAuthenticationToken> >()); try { var brokeredMessage = new BrokeredMessage(MessageSerialiser.SerialiseCommand(command)) { CorrelationId = CorrelationIdHelper.GetCorrelationId().ToString("N") }; brokeredMessage.Properties.Add("Type", command.GetType().FullName); PrivateServiceBusPublisher.Send(brokeredMessage); } catch (QuotaExceededException exception) { Logger.LogError("The size of the command being sent was too large.", exception: exception, metaData: new Dictionary <string, object> { { "Command", command } }); throw; } catch (Exception exception) { Logger.LogError("An issue occurred while trying to publish a command.", exception: exception, metaData: new Dictionary <string, object> { { "Command", command } }); throw; } Logger.LogInfo(string.Format("A command was sent of type {0}.", command.GetType().FullName)); SpinWait.SpinUntil(() => { IList <IEvent <TAuthenticationToken> > events = EventWaits[command.CorrelationId]; result = condition(events); return(result != null); }, millisecondsTimeout, sleepInMilliseconds: 1000); return(result); }
/// <summary> /// Terminates _clientThread object and any work it was doing /// </summary> /// <param name="status"></param> private void EndClientThread(ClientAPI_Status status) { IEventReceiver parent = FinalizeThread(status); parent?.ConnectionFinished(_apiConnectionStatus); base.Dispose(); if (!(parent is null)) { //reset everything Manager = new Client(); } }
/*sub class register or unregister event callback entrance.*/ /// <summary> /// 负责事件接收模块的注册 /// </summary> /// <param name="type">模块类型</param> /// <param name="receiver">模块接口实例</param> public void Register(RoleEventNodeType type, RoleNumber number, IEventReceiver receiver) { try { _receivers.TryGetValue(number, out var receivers); receivers = receivers ?? (_receivers[number] = new Dictionary <RoleEventNodeType, IEventReceiver>()); if (!receivers.ContainsKey(type)) { receivers.Add(type, receiver); } } catch (Exception e) { Debug.Log(e.Message); } }
public JToken ProcessHandlerMessage(IEventReceiver receiver, string data) { try { var message = JObject.Parse(data); if (!message.ContainsKey("call")) { _logger.Log(LogLevel.Error, Resources.OverlayApiInvalidHandlerCall, receiver.Name + ": " + data); return(null); } var handler = message["call"].ToString(); if (handler == "subscribe") { if (!message.ContainsKey("events")) { _logger.Log(LogLevel.Error, Resources.OverlayApiMissingEventsField, receiver.Name + ": " + data); return(null); } foreach (var name in message["events"].ToList()) { Subscribe(name.ToString(), receiver); _logger.Log(LogLevel.Debug, Resources.OverlayApiSubscribed, receiver.Name, name.ToString()); } return(null); } else if (handler == "unsubscribe") { if (!message.ContainsKey("events")) { _logger.Log(LogLevel.Error, Resources.OverlayApiMissingEventsFieldUnsub, receiver.Name + ": " + data); return(null); } foreach (var name in message["events"].ToList()) { Unsubscribe(name.ToString(), receiver); } return(null); } return(CallHandler(message)); } catch (Exception e) { _logger.Log(LogLevel.Error, Resources.JsHandlerCallException, e); return(null); } }
public void SendEvent(string eventType, object source, Dictionary<string, object> eventArgs, IEventReceiver receiver) { SendEvent(SingletonFactory.GetEventFactory().GetGameEvent(eventType, source, eventArgs), receiver); }
public void SendEvent(string eventType, object source, IEventReceiver receiver) { SendEvent(eventType, source, null, receiver); }
public void AddReceiver(IEventReceiver r) { Contract.IsNotNull(r); // if(!_targets.Any(wr => wr.IsAlive && wr.Target.Equals(r))) _targets.Add(new WeakReference(r)); }
public void SendEvent(GameEvent gameEvent, object source, IEventReceiver receiver) { gameEvent.Source = source; SendEvent(gameEvent, receiver); }
public void RemoveReceiver(IEventReceiver r) { var w = _targets.FirstOrDefault(x => x.IsAlive && x.Target.Equals(r)); if (w != null) _targets.Remove(w); }