protected void processMessage(IncomingAggreGateCommand cmd, OutgoingAggreGateCommand ans)
        {
            var messageCode = cmd.getMessageCode();

            if (messageCode.Length > 1)
            {
                throw new SyntaxErrorException(Cres.get().getString("clInvalidMsgCode") + messageCode);
            }

            var code = messageCode[0];

            if ((code != AggreGateCommand.MESSAGE_CODE_START) && (!startMessageReceived))
            {
                Logger.getLogger(Log.CLIENTS).debug("Can't process message: start message was not received yet");
                ans.constructReply(cmd.getId(), AggreGateCommand.REPLY_CODE_DENIED);
                return;
            }

            switch (code)
            {
            case AggreGateCommand.MESSAGE_CODE_START:
                processMessageStart(cmd, ans);
                break;

            case AggreGateCommand.MESSAGE_CODE_OPERATION:
                processMessageOperation(cmd, ans);
                break;

            default:
                throw new SyntaxErrorException(Cres.get().getString("clUnknownMsgCode") + messageCode[0]);
            }
        }
        public void processMessageStart(IncomingAggreGateCommand cmd, OutgoingAggreGateCommand ans)
        {
            var version = Int32.Parse(cmd.getParameter(AggreGateCommand.INDEX_PROTOCOL_VERSION));

            Logger.getLogger(Log.CLIENTS).debug("Processing start command, client protocol version: " + version);

            if (version == ClientCommandUtils.CLIENT_PROTOCOL_VERSION)
            {
                ans.constructReply(cmd.getId(), AggreGateCommand.REPLY_CODE_OK);
                startMessageReceived = true;
            }
            else
            {
                ans.constructReply(cmd.getId(), AggreGateCommand.REPLY_CODE_DENIED);
            }
        }
        public OutgoingAggreGateCommand processCommand(IncomingAggreGateCommand cmd)
        {
            var ans = new OutgoingAggreGateCommand();

            try
            {
                var commandCode = cmd.getParameter(AggreGateCommand.INDEX_COMMAND_CODE);

                if (commandCode.Length > 1)
                {
                    throw new AggreGateException(Cres.get().getString("clInvalidCmdCode") + commandCode);
                }

                switch (commandCode[0])
                {
                case AggreGateCommand.COMMAND_CODE_MESSAGE:
                    processMessage(cmd, ans);
                    break;

                default:
                    throw new AggreGateException(Cres.get().getString("clUnknownCmdCode") + commandCode[0]);
                }
            }
            catch (ContextSecurityException ex)
            {
                Logger.getLogger(Log.CLIENTS).info("Access denied while processing command '" + cmd + "': ", ex);
                ans.constructReply(cmd.getId(), AggreGateCommand.REPLY_CODE_DENIED);
            }
            catch (Exception ex)
            {
                Logger.getLogger(Log.CLIENTS).info("Error processing command '" + cmd + "': ", ex);
                ans.constructReply(cmd.getId(), AggreGateCommand.REPLY_CODE_ERROR, ex.Message ?? ex.ToString(),
                                   getErrorDetails(ex));
            }
            return(ans);
        }
        protected virtual void processMessageOperation(IncomingAggreGateCommand cmd, OutgoingAggreGateCommand ans)
        {
            var operation = cmd.getParameter(AggreGateCommand.INDEX_OPERATION_CODE);
            var context   = cmd.getParameter(AggreGateCommand.INDEX_OPERATION_CONTEXT);
            var target    = cmd.getParameter(AggreGateCommand.INDEX_OPERATION_TARGET);

            if (operation.Length > 1)
            {
                throw new SyntaxErrorException(Cres.get().getString("clInvalidOpcode") + operation);
            }

            Logger.getLogger(Log.CLIENTS).debug("Processing message, context '" + context + "', target '" + target +
                                                "', operation '" + operation + "'");

            switch (operation[0])
            {
            case AggreGateCommand.COMMAND_OPERATION_ADD_EVENT_LISTENER:
                var listenerStr = cmd.getParameter(AggreGateCommand.INDEX_OPERATION_LISTENER);
                var listener    = listenerStr.Length > 0 ? (Int32?)Int32.Parse(listenerStr) : null;
                processOperationAddEventListener(cmd.getId(), context, target, listener, ans);
                return;

            case AggreGateCommand.COMMAND_OPERATION_REMOVE_EVENT_LISTENER:
                listenerStr = cmd.getParameter(AggreGateCommand.INDEX_OPERATION_LISTENER);
                listener    = listenerStr.Length > 0 ? (Int32?)Int32.Parse(listenerStr) : null;
                processOperationRemoveEventListener(cmd.getId(), context, target, listener, ans);
                return;
            }

            var con = contextManager.get(context, callerController);

            if (con == null)
            {
                throw new ContextException(Cres.get().getString("conNotAvail") + context);
            }

            if (addNormalListener(con.getPath(), AbstractContext.E_DESTROYED, defaultEventListener))
            {
                addNormalListener(con.getPath(), AbstractContext.E_CHILD_ADDED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_CHILD_REMOVED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_VARIABLE_ADDED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_VARIABLE_REMOVED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_FUNCTION_ADDED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_FUNCTION_REMOVED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_EVENT_ADDED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_EVENT_REMOVED, defaultEventListener);
                addNormalListener(con.getPath(), AbstractContext.E_INFO_CHANGED, defaultEventListener);

                addCustomListeners(con);
            }

            switch (operation[0])
            {
            case AggreGateCommand.COMMAND_OPERATION_GET_VAR:
                processOperationGetVar(cmd.getId(), con, target, ans);
                break;

            case AggreGateCommand.COMMAND_OPERATION_SET_VAR:
                processOperationSetVar(cmd.getId(), con, target, cmd.getEncodedDataTableFromOperationMessage(), ans);
                break;

            case AggreGateCommand.COMMAND_OPERATION_CALL_FUNCTION:
                processOperationCallFunction(cmd.getId(), con, target, cmd.getEncodedDataTableFromOperationMessage(),
                                             ans);
                break;

            default:
                throw new SyntaxErrorException(Cres.get().getString("clUnknownOpcode") + operation[0]);
            }
        }