Exemple #1
0
        public QvxReply HandleRequest(QvxExecuteCommands command, string cmd, QvxDataClient dataclient, List <string> param)
        {
            var result = new QvxReply()
            {
                Result = QvxResult.QVX_OK
            };

            switch (command)
            {
                #region SQL
            case QvxExecuteCommands.SQL:
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                if (QvxExecuteRequestSelectHandler != null)
                {
                    var tmpResult = QvxExecuteRequestSelectHandler(cmd, param);
                    if (tmpResult != null)
                    {
                        result.Result = tmpResult.Item1;
                        dataclient.DataClientDeliverData = tmpResult.Item2;
                    }
                }
                break;
                #endregion

                #region TYPES
            case QvxExecuteCommands.TYPES:
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                if (QvxExecuteRequestTypesHandler != null)
                {
                    var res = QvxExecuteRequestTypesHandler();
                    if (res != null)
                    {
                        result.Result = QvxResult.QVX_OK;

                        Type type = res.GetType().GetInterface(typeof(IEnumerable <>).Name).GetGenericArguments()[0];

                        var serializer = new QvxSerializer(type);
                        serializer.Serialize(res, new BinaryWriter(dataclient));
                    }
                    else
                    {
                        result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                    }
                }
                break;
                #endregion

                #region COLUMNS
            case QvxExecuteCommands.COLUMNS:
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                if (QvxExecuteRequestColumnsHandler != null)
                {
                    string tablename = null;

                    result.Result = QvxResult.QVX_OK;

                    if ((param != null) && (param.Count > 0) && param[0].StartsWith("TABLE_NAME="))
                    {
                        tablename = param[0].Substring(11);
                    }

                    dataclient.DataClientDeliverData = (dc) =>
                    {
                        var res = QvxExecuteRequestColumnsHandler(tablename);
                        if (res != null)
                        {
                            QvxColumsRow.Serialize(res, new BinaryWriter(dataclient));
                        }
                    };
                }
                break;
                #endregion

                #region TABLES
            case QvxExecuteCommands.TABLES:
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                if (QvxExecuteRequestColumnsHandler != null)
                {
                    result.Result = QvxResult.QVX_OK;
                    dataclient.DataClientDeliverData = (dc) =>
                    {
                        var res = QvxExecuteRequestTablesHandler();
                        if (res != null)
                        {
                            QvxTablesRow.Serialize(res, new BinaryWriter(dc));
                        }
                    };
                }
                break;
                #endregion

                #region Default
            default:
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                break;
                #endregion
            }

            if (result.Result == QvxResult.QVX_OK)
            {
                dataclient.StartThread();
            }
            return(result);
        }
Exemple #2
0
        public QvxReply HandleRequest(QvxExecuteCommands command, string cmd, QvxDataClient dataclient, List<string> param)
        {
            var result = new QvxReply() { Result = QvxResult.QVX_OK };
            switch (command)
            {
                #region SQL
                case QvxExecuteCommands.SQL:
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    if (QvxExecuteRequestSelectHandler != null)
                    {
                        var tmpResult = QvxExecuteRequestSelectHandler(cmd, param);
                        if (tmpResult != null)
                        {
                            result.Result = tmpResult.Item1;
                            dataclient.DataClientDeliverData = tmpResult.Item2;
                        }
                    }
                    break;
                #endregion

                #region TYPES
                case QvxExecuteCommands.TYPES:
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    if (QvxExecuteRequestTypesHandler != null)
                    {
                        var res = QvxExecuteRequestTypesHandler();
                        if (res != null)
                        {
                            result.Result = QvxResult.QVX_OK;

                            Type type = res.GetType().GetInterface(typeof(IEnumerable<>).Name).GetGenericArguments()[0];

                            var serializer = new QvxSerializer(type);
                            serializer.Serialize(res, new BinaryWriter(dataclient));
                        }
                        else
                            result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                    }
                    break;
                #endregion

                #region COLUMNS
                case QvxExecuteCommands.COLUMNS:
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    if (QvxExecuteRequestColumnsHandler != null)
                    {
                        string tablename = null;

                        result.Result = QvxResult.QVX_OK;

                        if ((param != null) && (param.Count > 0) && param[0].StartsWith("TABLE_NAME="))
                        {
                            tablename = param[0].Substring(11);
                        }

                        dataclient.DataClientDeliverData = (dc) =>
                            {
                                var res = QvxExecuteRequestColumnsHandler(tablename);
                                if (res != null)
                                    QvxColumsRow.Serialize(res, new BinaryWriter(dataclient));
                            };
                    }
                    break;
                #endregion

                #region TABLES
                case QvxExecuteCommands.TABLES:
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    if (QvxExecuteRequestColumnsHandler != null)
                    {
                        result.Result = QvxResult.QVX_OK;
                        dataclient.DataClientDeliverData = (dc) =>
                            {
                                var res = QvxExecuteRequestTablesHandler();
                                if (res != null)
                                    QvxTablesRow.Serialize(res, new BinaryWriter(dc));
                            };
                    }
                    break;
                #endregion

                #region Default
                default:
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    break;
                #endregion
            }

            if (result.Result == QvxResult.QVX_OK)
            {
                dataclient.StartThread();
            }
            return result;
        }