Exemple #1
0
        void ProcessMessage(GetVariablesMessage m)
        {
            foreach (Variable v in variables)
            {
                SendVariable(v);
                DebugPrint("Sent Variable " + v.Name);
#if MF_FRAMEWORK_VERSION_V4_3
                Thread.Sleep(10);                  // Throttle
#endif
            }
        }
Exemple #2
0
        void Run()
        {
            // Preallocate messages (not thread-safe)
            var header = new Header();
            var getVariablesMessage     = new GetVariablesMessage();
            var setVariableValueMessage = new SetVariableValueMessage();
            var getCommandsMessage      = new GetCommandsMessage();
            var executeCommandMessage   = new ExecuteCommandMessage();

            for (; ;)
            {
                try {
                    ReadHeader(header);

                    DebugPrint("Received header: " + header.ToString());

                    switch (header.Operation)
                    {
                    case ControlOp.GetVariables:
                        ReadMessage(getVariablesMessage);
                        ProcessMessage(getVariablesMessage);
                        break;

                    case ControlOp.SetVariableValue:
                        ReadMessage(setVariableValueMessage);
                        ProcessMessage(setVariableValueMessage);
                        break;

                    case ControlOp.GetCommands:
                        ReadMessage(getCommandsMessage);
                        ProcessMessage(getCommandsMessage);
                        break;

                    case ControlOp.ExecuteCommand:
                        ReadMessage(executeCommandMessage);
                        ProcessMessage(executeCommandMessage);
                        break;

                    default:
                        // Unrecognized operation
                        UnknownMessage unknownMessage = new UnknownMessage();
                        ReadMessage(unknownMessage);
                        break;
                    }
                }
                catch (Exception ex) {
                    DebugPrint("!! " + ex + "\n");
                    throw;
                }
            }
        }