/// <inheritdoc/> internal override void TryCreateMonitor(Type type) { // Check if monitors are enabled in production. if (!this.Configuration.IsMonitoringEnabledInInProduction) { return; } lock (this.Monitors) { if (this.Monitors.Any(m => m.GetType() == type)) { // Idempotence: only one monitor per type can exist. return; } } this.Assert(type.IsSubclassOf(typeof(Monitor)), "Type '{0}' is not a subclass of Monitor.", type.FullName); Monitor monitor = (Monitor)Activator.CreateInstance(type); monitor.Initialize(this); monitor.InitializeStateInformation(); lock (this.Monitors) { this.Monitors.Add(monitor); } this.LogWriter.LogCreateMonitor(type.FullName); monitor.GotoStartState(); }
/// <inheritdoc/> internal override void TryCreateMonitor(Type type) { if (this.Monitors.Any(m => m.GetType() == type)) { // Idempotence: only one monitor per type can exist. return; } this.Assert(type.IsSubclassOf(typeof(Monitor)), "Type '{0}' is not a subclass of Monitor.", type.FullName); Monitor monitor = Activator.CreateInstance(type) as Monitor; monitor.Initialize(this); monitor.InitializeStateInformation(); this.LogWriter.LogCreateMonitor(type.FullName); if (this.Configuration.ReportActivityCoverage) { this.ReportActivityCoverageOfMonitor(monitor); } this.Monitors.Add(monitor); monitor.GotoStartState(); }
/// <summary> /// Reports coverage for the specified monitor. /// </summary> private void ReportActivityCoverageOfMonitor(Monitor monitor) { var monitorName = monitor.GetType().FullName; if (this.CoverageInfo.IsMachineDeclared(monitorName)) { return; } // Fetch states. var states = monitor.GetAllStates(); foreach (var state in states) { this.CoverageInfo.DeclareMachineState(monitorName, state); } // Fetch registered events. var pairs = monitor.GetAllStateEventPairs(); foreach (var tup in pairs) { this.CoverageInfo.DeclareStateEvent(monitorName, tup.Item1, tup.Item2); } }
/// <summary> /// Invokes the specified <see cref="Specifications.Monitor"/> with the specified <see cref="Event"/>. /// </summary> internal virtual void Monitor(Type type, Event e, string senderName, string senderType, string senderState) { // Check if monitors are enabled in production. if (!this.Configuration.IsMonitoringEnabledInInProduction) { return; } Monitor monitor = null; lock (this.Monitors) { foreach (var m in this.Monitors) { if (m.GetType() == type) { monitor = m; break; } } } if (monitor != null) { lock (monitor) { monitor.MonitorEvent(e, senderName, senderType, senderState); } } }
/// <inheritdoc/> internal override void NotifyRaisedEvent(Monitor monitor, Event e) { string monitorState = monitor.CurrentStateName; this.LogWriter.LogMonitorRaiseEvent(monitor.GetType().FullName, monitorState, e); }
/// <inheritdoc/> internal override void NotifyInvokedAction(Monitor monitor, MethodInfo action, string stateName, Event receivedEvent) { this.LogWriter.LogMonitorExecuteAction(monitor.GetType().FullName, stateName, action.Name); }
/// <inheritdoc/> internal override void NotifyExitedState(Monitor monitor) { this.LogWriter.LogMonitorStateTransition(monitor.GetType().FullName, monitor.CurrentStateName, false, monitor.GetHotState()); }
/// <inheritdoc/> internal override void NotifyEnteredState(Monitor monitor) { string monitorState = monitor.CurrentStateName; this.LogWriter.LogMonitorStateTransition(monitor.GetType().FullName, monitorState, true, monitor.GetHotState()); }