コード例 #1
0
        public void SystemEventHandler(object sender, StateMachineEventArgs args)
        {
            if (args.EventName == "OnInit" && args.EventType == StateMachineEventType.Command)
            {
                foreach (var dev in DeviceList)
                {
                    try
                    {
                        var initMethod = dev.Value.GetType().GetMethod("OnInit");
                        initMethod.Invoke(dev.Value, new object[] { });
                        RaiseDeviceManagerEvent("DeviceManager -Initialization device", dev.Key);
                    }
                    catch (Exception ex)
                    {
                        RaiseDeviceManagerEvent("DeviceManager -Initialization device exception", dev.Key);
                    }
                }
            }

            if (args.EventType == StateMachineEventType.Command)
            {
                if (args.EventName == "OnInit")
                {
                    return;
                }
                DeviceCommandHandler(this, args);
            }
        }
コード例 #2
0
        /// <summary>
        /// Handler method for state machine commands
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        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 (!DeviceList.Keys.Contains(args.Target))
                {
                    return;
                }
                // Convention device commands and method names must mach!
                var        device       = DeviceList[args.Target];
                MethodInfo deviceMethod = device.GetType().GetMethod(args.EventName);
                deviceMethod.Invoke(device, new object[] { });
                RaiseDeviceManagerEvent("DeviceCommand", "Successful device command: " + args.Target + " - " + args.EventName);
            }
            catch (Exception ex)
            {
                RaiseDeviceManagerEvent("DeviceCommand - Error", ex.ToString());
            }
        }
コード例 #3
0
 /// <summary>
 /// Handler method for state machine commands
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 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 (_viewStates.Contains(args.EventName))
         {
             // Convention: view command event names matches
             // corresponding view state
             _UI.LoadViewState(args.EventName);
             CurrentView = args.EventName;
             RaiseViewManagerEvent("View Manager Command",
                                   $"Successfully loaded view state: {args.EventName}");
         }
         else
         {
             RaiseViewManagerEvent("View Manager Command",
                                   $"View state not found: {args.EventName}");
         }
     }
     catch (Exception ex)
     {
         RaiseViewManagerEvent(
             "View Manager Command - Error", ex.ToString());
     }
 }
コード例 #4
0
        private void RaiseEventManagerEvent(string eventName,
                                            string eventInfo, StateMachineEventType eventType)
        {
            var newArgs = new StateMachineEventArgs(
                eventName, eventInfo, eventType, "Event Manager");

            EventManagerEvent?.Invoke(this, newArgs);
        }
コード例 #5
0
        /// <summary>
        /// Sends a command to another service
        /// </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 newUIargs = new StateMachineEventArgs(
                command, info, StateMachineEventType.Command, source, target);

            ViewManagerEvent?.Invoke(this, newUIargs);
        }
コード例 #6
0
        /// <summary>
        /// Sends a command from device manager to state machine
        /// </summary>
        /// <param name="command"></param>
        /// <param name="info"></param>
        /// <param name="source"></param>
        public void RaiseDeviceManagerNotification(
            string command, string info, string source)
        {
            var newDMArgs = new StateMachineEventArgs(command, info,
                                                      StateMachineEventType.Notification, source, "State Machine");

            // Raise only, if subscribed
            DeviceManagerNotification?.Invoke(this, newDMArgs);
        }
コード例 #7
0
        public void RaiseDeviceManagerNotification(string command, string info, string source)
        {
            var newDMArgs = new StateMachineEventArgs(command, "Device Manager Event" + info, source, "", StateMachineEventType.Notification);

            if (DeviceManagerNotification != null)
            {
                DeviceManagerNotification(this, newDMArgs);
            }
        }
コード例 #8
0
        /// <summary>
        /// Method to raise a device manager event for logging, etc.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="info"></param>
        private void RaiseDeviceManagerEvent(string name, string info)
        {
            var newDMArgs = new StateMachineEventArgs(name,
                                                      $"Device manager event: {info}",
                                                      StateMachineEventType.System, "Device Manager");

            // Raise only, if subscribed
            DeviceManagerEvent?.Invoke(this, newDMArgs);
        }
コード例 #9
0
        protected virtual void StateStatus(StateMachineEventArgs ea)
        {
            StateEventHandler handler = STEvent;

            if (handler != null)
            {
                handler(this, ea);
            }
        }
コード例 #10
0
        public void RaiseDeviceManagerEvent(string p, string name)
        {
            var newDMArgs = new StateMachineEventArgs(name, "Device Manager Event" + name, "Device Manager", "", StateMachineEventType.System);

            if (DeviceManagerEvent != null)
            {
                DeviceManagerEvent(this, newDMArgs);
            }
        }
コード例 #11
0
        /// <summary>
        /// Method to raise a view manager event for logging, etc
        /// </summary>
        /// <param name="name"></param>
        /// <param name="info"></param>
        /// <param name="eventType"></param>
        private void RaiseViewManagerEvent(string name, string info,
                                           StateMachineEventType eventType = StateMachineEventType.System)
        {
            var newVMargs = new StateMachineEventArgs(name,
                                                      $"View manager event: {info}", eventType, "View Manager");

            // Raise event only, if there are subscribers!
            ViewManagerEvent?.Invoke(this, newVMargs);
        }
コード例 #12
0
ファイル: EventManager.cs プロジェクト: hircjusz/StateMachine
        private void RaiseEventManagerEvent(string eventName, string eventInfo, StateMachineEventType eventType)
        {
            var newArgs = new StateMachineEventArgs(eventName, eventInfo, String.Empty, String.Empty, eventType);

            if (EventManagerEvent != null)
            {
                EventManagerEvent(this, newArgs);
            }
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
        /// <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);
            }
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
 public void SystemEventHandler(
     object sender, StateMachineEventArgs args)
 {
     // Initialize
     if (args.EventName == "OnInit")
     {
         _UI.LoadViewState(_defaultViewState);
         CurrentView = _defaultViewState;
     }
 }
コード例 #17
0
        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);
            }
        }
コード例 #18
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);
            }
        }
コード例 #19
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);
            }
        }
コード例 #20
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);
            }
        }
コード例 #21
0
        /// <summary>
        /// Method to raise a device manager event for logging, etc.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="info"></param>
        private void RaiseDeviceManagerEvent(string name, string info)
        {
            var newDMArgs = new StateMachineEventArgs(name, "Device manager event: " + info,
                                                      StateMachineEventType.System, "Device Manager");

            // Raise only, if subscribed
            if (DeviceManagerEvent != null)
            {
                DeviceManagerEvent(this, newDMArgs);
            }
        }
コード例 #22
0
ファイル: LogManager.cs プロジェクト: ristica/state-machine
 /// <summary>
 /// Log infos to debug window
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="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);
     }
     // Log state machine notifications
     else
     {
         Debug.Print(args.TimeStamp + " Notification: " + args.EventName + " - Info: " + args.EventInfo + " - StateMachineArgumentType: " + args.EventType + " - Source: " + args.Source + " - Target: " + args.Target);
     }
 }
コード例 #23
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");
            }
        }
コード例 #24
0
        /// <summary>
        /// Handler method for special system events, e.g. initialization
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void SystemEventHandler(
            object sender, StateMachineEventArgs args)
        {
            // Initialize
            if (args.EventName == "OnInit" &&
                args.EventType == StateMachineEventType.Command)
            {
                foreach (var dev in DeviceList)
                {
                    try
                    {
                        MethodInfo initMethod
                            = dev.Value.GetType().GetMethod("OnInit");
                        initMethod.Invoke(dev.Value, new object[] { });
                        RaiseDeviceManagerEvent(
                            "DeviceCommand - Initialization device", dev.Key);
                    }
                    catch (Exception ex)
                    {
                        RaiseDeviceManagerEvent(
                            "DeviceCommand - Initialization error device " + dev.Key,
                            ex.ToString());
                    }
                }

                // Notification handling
                // 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 as needed!
                if (args.EventType == StateMachineEventType.Command)
                {
                    // Check for right condition
                    if (args.EventName == "OnInit")
                    {
                        return;
                    }
                    if (DeviceList.ContainsKey(args.Target) == false)
                    {
                        return;
                    }

                    // Dispatch command to device
                    DeviceCommandHandler(this, args);
                }
            }
        }
コード例 #25
0
 /// <summary>
 /// Log infos to debug window
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 public void LogEventHandler(object sender, StateMachineEventArgs args)
 {
     if (args.EventType != StateMachineEventType.Notification)
     {
         // Log system events
         //TODO log4net
         Debug.Print("{0} SystemEvent: {1} - Info: {2} - StateMachineArgumentType: {3} - Source: {4} - Target: {5}",
                     args.TimeStamp, args.EventName, args.EventInfo,
                     args.EventType, args.Source, args.Target);
     }
     else
     {
         // Log state machine notifications
         //TODO log4net
         Debug.Print("{0} Notification: {1} - Info: {2} - StateMachineArgumentType: {3} - Source: {4} - Target: {5}",
                     args.TimeStamp, args.EventName, args.EventInfo,
                     args.EventType, args.Source, args.Target);
     }
 }
コード例 #26
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            private void LogAndThrow(
                bool shouldThrow,
                StateMachineEventArgs <PhilisopherState, PhilisopherTrigger> args,
                [CallerMemberName] string methodName = null)
            {
                _log.Add(
                    (shouldThrow ? "THROWING-FROM:" : "") +
                    methodName +
                    "(" +
                    (args.HasFromState ? "from[" + args.FromState + "]" : "") +
                    (args.HasToState ? "to[" + args.ToState + "]" : "") +
                    (args.HasTrigger ? "by[" + args.Trigger + "]" : "") +
                    (args.Context != null ? "with[" + args.Context + "]" : "") +
                    ")");

                if (shouldThrow)
                {
                    throw new TestCodeBehindException(methodName);
                }
            }
コード例 #27
0
        /// <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);
            }
        }
コード例 #28
0
        private void mm_fucntion_STEvent(object sender, StateMachineEventArgs e)
        {
            if (e.CurrentState == STATE.states.initialize)
            {
                if (e.PassOrFail)
                {
                    mm_ready = true;
                    if (tp_ready)
                    {
                        EnableButtonConnect(false);
                        EnableButtonSleep(true);
                        EnableButtonDeepSleep(true);
                    }
                }
            }

            if (e.CurrentState == STATE.states.exit)
            {
                try
                {
                    tp_thread.exit();

                    EnableButtonConnect(true);
                    EnableButtonSleep(false);
                    EnableButtonDeepSleep(false);

                    serialNumberScanned = false;
                    SetTxtBoxSN("");
                }
                catch { }



                mm_fucntion = null;
                mm_thread   = null;
            }
        }
コード例 #29
0
        public void DeviceCommandHandler(object sender, StateMachineEventArgs args)
        {
            if (args.EventType != StateMachineEventType.Command)
            {
                return;
            }

            try
            {
                if (!DeviceList.ContainsKey(args.Target))
                {
                    return;
                }
                var device       = DeviceList[args.Target];
                var deviceMethod = device.GetType().GetMethod(args.EventName);
                deviceMethod.Invoke(device, new object[] {});

                RaiseDeviceManagerEvent("Device Command", args.Target);
            }
            catch (Exception ex)
            {
                RaiseDeviceManagerEvent("Device Command error", ex.ToString());
            }
        }
コード例 #30
0
ファイル: FormMain.cs プロジェクト: fanmuzhi/Cypress
        //#########################################################################//

        #region State Change

        /// <summary>
        /// The StateMachine EVENT of class TP
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tp_function_STEvent(object sender, StateMachineEventArgs e)
        {
            //trackpad thread init
            if (e.CurrentState == STATE.states.initialize)
            {
                if (e.PassOrFail)
                {
                    tp_ready = true;
                    if (mm_ready)
                    {
                        EnableButtonConnect(false);
                        EnableButtonSleep(true);
                        EnableButtonDeepSleep(true);
                    }
                }
            }

            //Trackpad thread exit
            if (e.CurrentState == STATE.states.exit)
            {
                if (mm_ready)
                {
                    try
                    {
                        EnableButtonConnect(true);
                        EnableButtonSleep(false);
                        EnableButtonDeepSleep(false);

                        serialNumberScanned = false;
                        SetTxtBoxSN("");

                        mm_thread.exit();
                    }
                    catch { }
                }


                tp_ready    = false;
                tp_function = null;
                tp_thread   = null;
            }

            //Trackpad Power On
            if (e.CurrentState == STATE.states.TP_PowerOn)
            {
            }

            //Sleep1
            if (e.CurrentState == STATE.states.TP_SendSleep1Command)
            {
                System.Threading.Thread.Sleep(Config.Delay.EnterSleepMode);

                List <STATE.states> MM_STATES = new List <STATE.states>();

                for (int i = 0; i < Config.MEAS_TIMES; i++)
                {
                    MM_STATES.Add(STATE.states.MM_ReadCurr);
                }
                MM_STATES.Add(STATE.states.MM_CalcSleep1Curr);

                mm_thread.en_queue(MM_STATES);
            }

            //Deep Sleep
            if (e.CurrentState == STATE.states.TP_SendDeepSleepCommand)
            {
                System.Threading.Thread.Sleep(Config.Delay.EnterSleepMode);

                List <STATE.states> MM_STATES = new List <STATE.states>();

                for (int i = 0; i < Config.MEAS_TIMES; i++)
                {
                    MM_STATES.Add(STATE.states.MM_ReadCurr);
                }
                MM_STATES.Add(STATE.states.MM_CalcDeepSleepCurr);

                mm_thread.en_queue(MM_STATES);
            }

            //Trackpad Power Off
            if (e.CurrentState == STATE.states.TP_PowerOff)
            {
                //mm_thread.en_queue(STATE.states.idle);
            }
        }