예제 #1
0
        protected async Task StateChanged(PipelineModuleStatus newState)
        {
            if (newState == Status)
            {
                return;
            }

            PEMBus.InstanceLogger.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.StateChange, $"StatusChange: {GetType().Name} from {Status} to {newState}.", "statusChange",
                                                 new KeyValuePair <string, string>("oldState", Status.ToString()),
                                                 new KeyValuePair <string, string>("newState", newState.ToString()),
                                                 new KeyValuePair <string, string>("pipelineModuleId", Id));

            var stateChangeNotification = new StateChangeNotification()
            {
                OldState = EntityHeader <PipelineModuleStatus> .Create(Status),
                NewState = EntityHeader <PipelineModuleStatus> .Create(newState),
            };

            var msg = new Notification()
            {
                Payload     = JsonConvert.SerializeObject(stateChangeNotification),
                PayloadType = typeof(StateChangeNotification).Name,
                Channel     = EntityHeader <Services.Channels> .Create(Services.Channels.PipelineModule),
                ChannelId   = Id,
                Text        = $"Status Change from {stateChangeNotification.OldState.Text} to {stateChangeNotification.NewState.Text}"
            };
            await PEMBus.NotificationPublisher.PublishAsync(Targets.WebSocket, msg);

            StateChangeTimeStamp = DateTime.Now.ToJSONString();

            Status = newState;
        }
예제 #2
0
        public void HandleStateChangeNotification(StateChangeNotification scn)
        {
            if (scn.IsListData())
            {
                // store list data, and update list groups
                scn.Data.ApplyData(this);

                this.UpdateStates();
            }
            else
            {
                // deal with a single state change
                ApplianceState state;

                if (scn.Defined)
                {
                    try
                    {
                        state = storeValue(scn.State, scn.Value);
                        state.ValueChanged();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Couldn't set value of state " + scn.State +
                                          " to " + scn.Value);
                    }
                }
                else
                {
                    state = (ApplianceState)this[scn.State];
                    state.Undefine();
                }
            }
        }
예제 #3
0
        /*
         * Registers a notification event handler with the FSM.
         */
        public void registerNotification(string StateName, InternalEventHandler ieHandler,
                                         string EventName, string SourceName)
        {
            StateChangeNotification n = new StateChangeNotification();

            n._state   = StateName;
            n._handler = ieHandler;
            n._event   = EventName;
            n._source  = SourceName;

            notifications.Add(n);
        }
예제 #4
0
파일: UndefineDlg.cs 프로젝트: jwnichls/puc
        private void undefButton_Click(object sender, System.EventArgs e)
        {
            Appliance a = _frame.GetAppliance();

            IEnumerator en = _boxes.GetEnumerator();

            while (en.MoveNext())
            {
                CheckBox chbx = (CheckBox)en.Current;
                if (chbx.Checked)
                {
                    // ((ApplianceState)objs[ chbx.Text ]).Undefine();
                    StateChangeNotification msg = new StateChangeNotification(chbx.Text);
                    _frame.SendAll(msg);
                }
            }

            this.Close();
        }
예제 #5
0
        /*
        * Registers a notification event handler with the FSM.
        */
        public void registerNotification( string StateName, InternalEventHandler ieHandler, 
            string EventName, string SourceName)
        {
            StateChangeNotification n = new StateChangeNotification();
            n._state = StateName;
            n._handler = ieHandler;
            n._event = EventName;
            n._source = SourceName;

            notifications.Add( n );
        }
예제 #6
0
        void PUC.IDevice2.HandleMessage(Connection c, PUC.Communication.Message m)
        {
            Globals.GetFrame(_appliance).AddLogLine(m.ToString());
            PUC.Communication.Message newmsg;

            if (m is SpecRequest)
            {
                newmsg = new PUC.Communication.DeviceSpec(_specification);
                c.Send(newmsg);
            }
            else if (m is FullStateRequest)
            {
                IEnumerator states = _appliance.VariableTable.GetObjectEnumerator();;
                while (states.MoveNext())
                {
                    if (!((ApplianceObject)states.Current).State)
                    {
                        continue;
                    }

                    ApplianceState state = (ApplianceState)states.Current;

                    if (state.Defined)
                    {
                        newmsg = new StateChangeNotification(state.FullName, state.Value.ToString());
                    }
                    else
                    {
                        newmsg = new StateChangeNotification(state.FullName);
                    }

                    c.Send(newmsg);
                }
            }
            else if (m is StateChangeRequest)
            {
                StateChangeRequest smsg = (StateChangeRequest)m;

                try
                {
                    ApplianceState state =
                        (ApplianceState)_appliance.VariableTable[smsg.GetState()];

                    if (state != null)
                    {
                        string val =
                            state.Type.ValueSpace.Validate(smsg.Value).ToString();
                        newmsg = new StateChangeNotification(smsg.GetState(), val);

                        SendAll(newmsg);
                    }
                }
                catch (Exception)
                {
                }
            }
            else if (m is CommandInvokeRequest)
            {
                this.AddLogLine("Command " + ((CommandInvokeRequest)m).GetCommand() + " requested to be invoked.");
            }
        }