Пример #1
0
        /*
         * Event Handler Methods
         */
        protected void messageReceived(ConnectionEventArgs a)
        {
            PUC.Communication.Message msg = a.GetMessage();

            if (msg is ServerInformation)
            {
                // Globals.GetDefaultLog().AddLogLine( msg.GetXML() );
                initUIMenu((ServerInformation)msg);
                Globals.GetDefaultLog().AddLogLine("Server information updated for " + _name);
            }
        }
Пример #2
0
        protected void messageReceived(ConnectionEventArgs a)
        {
            PUC.Communication.Message msg = a.GetMessage();

            if (msg is DeviceSpec)
            {
                DeviceSpec dmsg = (DeviceSpec)msg;

                Appliance appl = new Appliance(this);

#if POCKETPC
                Globals.AddFrameMapping(appl, PUCFrame.DEFAULT_FRAME);
#endif
#if SMARTPHONE
                Globals.AddFrameMapping(appl, PhonePUC.PUCFrame.DEFAULT_FRAME);
#endif
#if DESKTOP && !DEBUGSVR
                // TODO: Make DesktopPUC use multiple windows, like Debug Server
                Globals.AddFrameMapping(appl, DesktopPUC.PUCFrame.DEFAULT_FRAME);
#endif

                try
                {
                    SpecParser.Parse(new StringReader(dmsg.GetSpec()), appl);

                    MenuItem mi = new MenuItem();
                    mi.Text = appl.Name;
                    appl.SetMenuItem(mi);

                    _server.ActivateAppliance(this, appl);

                    Cursor.Current = Cursors.Default;

                    _connection.MessageReceivedEvent    -= new Connection.MessageReceivedHandler(this.messageReceived);
                    _connection.ConnectionRegainedEvent -= new Connection.ConnectionRegainedHandler(this.connectionRegained);
                    _connection.ConnectionLostEvent     += new Connection.ConnectionLostHandler(appl.ConnectionLost);
                    _connection.MessageReceivedEvent    += new Connection.MessageReceivedHandler(appl.MessageReceived);
                    _connection.ConnectionRegainedEvent += new Connection.ConnectionRegainedHandler(appl.ConnectionRegained);

                    FullStateRequest fsrMsg = new FullStateRequest();
                    _connection.Send(fsrMsg);
                }
                catch (Exception e)
                {
                    Globals.GetFrame(appl).AddLogLine(e.ToString());
                    Cursor.Current = Cursors.Default;
                }
            }
        }
Пример #3
0
        public void SendAll(PUC.Communication.Message msg)
        {
            IEnumerator e = _connections.GetEnumerator();

            while (e.MoveNext())
            {
                try
                {
                    ((Connection)e.Current).Send(msg);
                }
                catch (Exception)
                {
                }
            }
        }
Пример #4
0
        public void MessageReceived(ConnectionEventArgs a)
        {
            PUC.Communication.Message msg = a.GetMessage();

            if (msg is StateChangeNotification)
            {
                _varTable.HandleStateChangeNotification((StateChangeNotification)msg);
            }
            else if (msg is BinaryStateChangeNotification)
            {
                _varTable.HandleBinaryStateChangeNotification((BinaryStateChangeNotification)msg);
            }
            else if (msg is AlertInformation)
            {
                MessageBox.Show(this.Name, ((AlertInformation)msg).GetAlertMessage());
            }
        }
Пример #5
0
 public override void Send(PUC.Communication.Message msg)
 {
     ((IDevice2)_frame).HandleMessage(this, msg);
     Globals.AddEventCallback(new MessageDispatcher(this, msg));
 }
Пример #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.");
            }
        }