public void DeviceCommandHandler(object sender, StateMachineEventArgs args)
        {
            // Listen to command events only
            if (args.EventType != StateMachineEventType.Command)
            {
                return;
            }

            // Get device and execute command action method
            try
            {
                if (!this.DeviceList.Keys.Contains(args.Target))
                {
                    return;
                }

                // Convention device commands and method names must match!
                var device = this.DeviceList[args.Target];
                MethodInfo deviceMethod = device.GetType().GetMethod(args.EventName);
                deviceMethod.Invoke(device, new object[] { });
                this.RaiseDeviceManagerEvent("DeviceCommand", "Successful device command: " + args.Target + " - " + args.EventInfo);
            }
            catch (Exception ex)
            {
                this.RaiseDeviceManagerEvent("DeviceCommand - Error", ex.ToString());
                throw;
            }
        }
 public void RaiseDeviceManagerNotification(string command, string info, string source)
 {
     var devManagerNotification = this.DeviceManagerNotification;
     if (devManagerNotification != null)
     {
         var newDMArgs = new StateMachineEventArgs(command, info, StateMachineEventType.Notification, source, "State Machine");
         devManagerNotification(this, newDMArgs);
     }
 }
 private void RaiseDeviceEvent(string target, string command)
 {
     var devEvent = this.TelephoneDeviceEvent;
     if (devEvent != null)
     {
         var telArgs = new StateMachineEventArgs(command, "Device command", StateMachineEventType.Command, "State machine action", target);
         devEvent(this, telArgs);
     }
 }
Exemplo n.º 4
0
 private void RaiseEventManagerEvent(string eventName, string eventInfo, StateMachineEventType eventType)
 {
     var evtMgrEvt = this.EventManagerEvent;
     if (evtMgrEvt != null)
     {
         var newArgs = new StateMachineEventArgs(eventName, eventInfo, eventType, "Event Manager");
         evtMgrEvt(this, newArgs);
     }
 }
Exemplo n.º 5
0
		public void SystemEventHandler(object sender, StateMachineEventArgs args)
		{
			// Initialize
			if (args.EventName == "OnInit")
			{
				this._UI.LoadViewState(this.DefaultViewState);
				this.CurrentView = this.DefaultViewState;
			}

            // Catastrophic error handling
            if (args.EventName == "CompleteFailure")
            {
                this._UI.LoadViewState("CompleteFailure");
            }
		}
Exemplo n.º 6
0
 /// <summary>
 /// Log infos to dubug window
 /// </summary>
 /// <param name="sender">"sender"</param>
 /// <param name="args">"args"</param>
 public void LogEventHandler(object sender, StateMachineEventArgs args)
 {
     // Log system events
     if (args.EventType != StateMachineEventType.Notification)
     {
         Debug.Print(args.TimeStamp + 
             " SystemEvent: " + args.EventName + 
             " - Info: " + args.EventInfo + 
             " - StateMachineArgumentType: " + args.EventType + 
             " - Source: " + args.Source + 
             " - Target: " + args.Target); ;
     }
     else
     {
         // Log state machine notifications
         Debug.Print(args.TimeStamp + 
             " Notification: " + args.EventName + 
             " - Info: " + args.EventInfo + 
             " - StateMachineArgumentType: " + args.EventType + 
             " - Source: " + args.Source + 
             " - Target: " + args.Target); ;
     }
 }
Exemplo n.º 7
0
		public void ViewCommandHandler(object sender, StateMachineEventArgs args)
		{
			// This approach assumes that there is a dedicated view state for every state machine UI command
			try
			{
				if (this.viewStates.Contains(args.EventName))
				{
					// Convention: view command event names matches corresponding view state
					this._UI.LoadViewState(args.EventName);
					this.CurrentView = args.EventName;
					this.RaiseViewManagerEvent("View Manager Command", "Successfully loaded viewStates state: " + args.EventName);

				}
				else
				{
					this.RaiseViewManagerEvent("View Manager Command", "View state not found!");
				}
			}
			catch (Exception ex)
			{

				this.RaiseViewManagerEvent("View Manager Command - Error", ex.ToString());
			}
		}
        /// <summary>
        /// Handler method for special system evnts, e.g. initialization
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="args">args</param>
        public void SystemEventHandler(object sender, StateMachineEventArgs args)
        {
            // Initialize
            if (args.EventName == "OnInit" && args.EventType == StateMachineEventType.Command)
            {
                foreach (var dev in this.DeviceList)
                {
                    try
                    {
                        MethodInfo initMethod = dev.Value.GetType().GetMethod("OnInit");
                        initMethod.Invoke(dev.Value, new object[] { });
                        this.RaiseDeviceManagerEvent("DeviceCommand - Initialization device", dev.Key);
                    }
                    catch (Exception ex)
                    {
                        this.RaiseDeviceManagerEvent("DeviceCommand - Initialization error device" + dev.Key, ex.ToString());
                    }
                }
            }

            // Notification Handler
            // because we use UI to trigger transitions devices would trigger normally themselves.
            // Nevertheless, this is common, if SW user interfaces control devices
            // View and device managers communicate on system event bus and use notifications to trigger state machine
            if (args.EventType == StateMachineEventType.Command)
            {
                // check for right condition
                if (args.EventName == "OnInit") return;
                if (!this.DeviceList.ContainsKey(args.Target)) return;

                //Dispatch commmand to device
                this.DeviceCommandHandler(this, args);
                //this.RaiseDeviceManagerNotification(args.EventName, "routed through device manager: " + args.EventInfo, args.Source);
            }
        }
 private void RaiseDeviceManagerEvent(string name, string info)
 {
     var devManagerEvent = this.DeviceManagerEvent;
     if (devManagerEvent != null)
     {
         var newDMArgs = new StateMachineEventArgs(name, "Device manager event: " + info, StateMachineEventType.System, "Device Manager");
         devManagerEvent(this, newDMArgs);
     }
 }
 public void InternalNotificationHandler(object sender, StateMachineEventArgs intArgs)
 {
     // Catastrophic error
     if (intArgs.EventName == "CompleteFailure")
     {
         this.RaiseStateMachineSystemCommand("CompleteFailure", intArgs.EventInfo + " Device : " + intArgs.Source);
         // stop state machine to avoid any damage
         this.Stop();
     }
     // Normal operation
     else
     {                
         this.EnterTrigger(intArgs.EventName);
     }
     
 }
Exemplo n.º 11
0
		/// <summary>
		/// Method to raise a view manager event for logging, etc.
		/// </summary>
		/// <param name="name">"name"</param>
		/// <param name="info">"info"</param>
		/// <param name="eventType">"eventType"</param>
		private void RaiseViewManagerEvent(string name, string info, StateMachineEventType eventType = StateMachineEventType.System)
		{            
			var vmEventHandler = this.ViewManagerEvent;
			if (vmEventHandler != null)
			{
				var newVMargs = new StateMachineEventArgs(name, "View manager event: " + info, eventType, "View manager");
				vmEventHandler(this, newVMargs);
			}
		}
Exemplo n.º 12
0
		/// <summary>
		/// Sends a command to 
		/// </summary>
		/// <param name="command"></param>
		/// <param name="info"></param>
		/// <param name="source"></param>
		/// <param name="target"></param>
		public void RaiseUICommand(string command, string info, string source, string target)
		{
			var uiNotificationEvent = this.UINotification;
			if (uiNotificationEvent != null)
			{
				var newUIargs = new StateMachineEventArgs(command, info, StateMachineEventType.Command, source, target);
				uiNotificationEvent(this, newUIargs);
			}
		}
 /// <summary>
 /// Helper to raise the telphone UI event
 /// </summary>
 /// <param name="command"></param>
 private void RaiseTelephoneUiEvent(string command)
 {
     var uiEvent = this.TelephoneUiEvent;
     if (uiEvent != null)
     {
         var telArgs = new StateMachineEventArgs(command, "UI command", StateMachineEventType.Command, "State machine action", "View Manager");
         uiEvent(this, telArgs);
     }
 }