Exemplo n.º 1
0
 /// <summary>
 /// Deserializes workflow markup into an QvxReply object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output QvxReply object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out QvxReply obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(QvxReply);
     try {
         obj = Deserialize(xml);
         return(true);
     }
     catch (System.Exception ex) {
         exception = ex;
         return(false);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Deserializes xml markup from file into an QvxReply object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output QvxReply object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out QvxReply obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(QvxReply);
     try {
         obj = LoadFromFile(fileName);
         return(true);
     }
     catch (System.Exception ex) {
         exception = ex;
         return(false);
     }
 }
Exemplo n.º 3
0
 public QvxReply HandleQvxRequest(QvxRequest request)
 {
     lock (lockSendQvxRequest)
     {
         // TODO better request and response handling + async
         this.reply   = null;
         this.request = request;
         while (reply == null)
         {
             Thread.Sleep(10);
         }
         return(reply);
     }
 }
Exemplo n.º 4
0
        public QvxReply HandleRequest(QvxGenericCommands command)
        {
            var result = new QvxReply()
            {
                Result = QvxResult.QVX_OK
            };

            switch (command)
            {
            case QvxGenericCommands.HaveStarField:
                if (HaveStarField.HasValue)
                {
                    result.OutputValues.Add(HaveStarField.Value.ToString());
                }
                break;

            case QvxGenericCommands.IsConnected:
                if (IsConnected.HasValue)
                {
                    result.OutputValues.Add(IsConnected.Value.ToString());
                }
                break;

            case QvxGenericCommands.DisableQlikViewSelectButton:
                if (DisableQlikViewSelectButton.HasValue)
                {
                    result.OutputValues.Add(DisableQlikViewSelectButton.Value.ToString());
                }
                break;

            case QvxGenericCommands.GetCustomCaption:
                if (GetCustomCaption != null)
                {
                    result.OutputValues.Add(GetCustomCaption);
                }
                break;
            }

            if (result.OutputValues.Count == 0)
            {
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
            }
            return(result);
        }
Exemplo n.º 5
0
 public static bool Deserialize(string xml, out QvxReply obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }
Exemplo n.º 6
0
        private void QvxCommandWorker()
        {
            try
            {
                if (pipeName == null) return;

                object state = new object();
                object connection = null;

                using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut))
                {
                    var buf = new byte[4];
                    var buf2 = new byte[4];
                    Int32 count = 0;
                    Int32 datalength = 0;
                    pipeClient.Connect(1000);
                    while (pipeClient.IsConnected)
                    {
                        try
                        {
                            #region Get QvxRequest
                            var iar = pipeClient.BeginRead(buf, 0, 4, null, state);
                            while (!iar.IsCompleted) Thread.Sleep(1);
                            count = pipeClient.EndRead(iar);
                            if (count != 4) throw new Exception("Invalid Count Length");
                            buf2[0] = buf[3];
                            buf2[1] = buf[2];
                            buf2[2] = buf[1];
                            buf2[3] = buf[0];
                            datalength = BitConverter.ToInt32(buf2, 0);
                            var data = new byte[datalength];
                            count = pipeClient.Read(data, 0, datalength);
                            if (count != datalength) throw new Exception("Invalid Data Length");

                            var sdata = ASCIIEncoding.ASCII.GetString(data);
                            sdata = sdata.Replace("\0", "");
                            QvxRequest request;
                            try
                            {
                                request = QvxRequest.Deserialize(sdata);

                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex);
                                throw ex;
                            }
                            request.QVWindow = QVWindow;
                            request.Connection = connection;
                            #endregion

                            #region Handle QvxRequets
                            QvxReply result = null;
                            if (HandleQvxRequest != null)
                                result = HandleQvxRequest(request);

                            if (result == null)
                                result = new QvxReply() { Result = QvxResult.QVX_UNKNOWN_ERROR };
                            #endregion

                            #region Send QvxReply
                            sdata = "    " + result.Serialize() + "\0";
                            datalength = sdata.Length - 4;
                            buf2 = ASCIIEncoding.ASCII.GetBytes(sdata);
                            buf = BitConverter.GetBytes(datalength);
                            buf2[0] = buf[3];
                            buf2[1] = buf[2];
                            buf2[2] = buf[1];
                            buf2[3] = buf[0];
                            pipeClient.Write(buf2, 0, buf2.Length);
                            pipeClient.WaitForPipeDrain();
                            #endregion

                            #region Handle result States
                            if (result.Terminate)
                                close = true;
                            if (result.Connection != null)
                                connection = result.Connection;
                            if (result.SetConnectionNULL)
                                connection = null;
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex);
                            Thread.Sleep(500);
                            close = true;
                        }

                        if (close)
                        {
                            close = false;
                            pipeClient.Close();
                        }

                        Thread.Sleep(5);
                    }
                }
                running = false;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Exemplo n.º 7
0
        public QvxReply HandleRequest(QvxRequest request)
        {
            logger.Debug("HandleRequest Command:", request.Command);
            var result = new QvxReply() { Result = QvxResult.QVX_OK };
            try
            {
                switch (request.Command)
                {
                    #region QVX_CONNECT
                    case QvxCommand.QVX_CONNECT:
                        if (request.Parameters.Count != 1)
                        {
                            result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                            logger.Warn("QvxCommand.QVX_CONNECT: request.Parameters.Count expected 1 found:" + request.Parameters.Count.ToString());
                        }
                        else
                            if (QvxConnectHandler == null)
                                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                            else
                            {
                                // TODO: Parse User & Password, Config Options

                                //QlikView uses extra quotation around UserID and Password value if a) a value contains a
                                //semicolon or b) a value starts with a double quote. The Connectors that use such values have
                                //to modify QVX_CONNECT and QVX_EDIT_CONNECT command handling by removing
                                //or adding the extra quotation when it is relevant.
                                result = QvxConnectHandler(request.Parameters[0]);
                            }
                        break;
                    #endregion

                    #region QVX_EXECUTE
                    case QvxCommand.QVX_EXECUTE:
                        if (!((request.Parameters.Count == 2) | (request.Parameters.Count == 3)))
                            result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                        else
                        {
                            QvxExecuteCommands cmd;
                            if (!Enum.TryParse<QvxExecuteCommands>(request.Parameters[0], out cmd))
                                cmd = QvxExecuteCommands.SQL;

                            if (QvxExecuteHandler == null)
                                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                            else
                            {
                                List<string> list = new List<string>();
                                if (request.Parameters.Count == 3)
                                    list = request.Parameters[2].Split(new char[1] { ';' }).ToList();

                                result = QvxExecuteHandler(cmd, request.Parameters[0], new QvxDataClient(request.Parameters[1]), list);
                            }
                        }
                        break;
                    #endregion

                    #region QVX_EDIT_CONNECT
                    case QvxCommand.QVX_EDIT_CONNECT:
                        if (request.Parameters.Count != 1)
                            result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                        else
                            if (QvxEditConnectHandler == null)
                                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                            else
                                result = QvxEditConnectHandler(request.Parameters[0], request.QVWindow);
                        break;
                    #endregion

                    #region QVX_EDIT_SELECT
                    case QvxCommand.QVX_EDIT_SELECT:
                        if (request.Parameters.Count != 2)
                            result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                        else
                            if (QvxEditSelectHandler == null)
                                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                            else
                                result = QvxEditSelectHandler(request.Parameters[0], request.Parameters[1], request.QVWindow);
                        break;
                    #endregion

                    #region QVX_GENERIC_COMMAND
                    case QvxCommand.QVX_GENERIC_COMMAND:
                        if (!(request.Parameters.Count > 0))
                            result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                        else
                        {
                            string command = request.Parameters[0];
                            QvxGenericCommands cmd;
                            bool validCmd = Enum.TryParse<QvxGenericCommands>(command, out cmd);
                            if ((QvxGenericCommandHandler == null) | (!validCmd))
                                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                            else
                                result = QvxGenericCommandHandler(cmd);
                        }
                        break;
                    #endregion

                    #region QVX_DISCONNECT
                    case QvxCommand.QVX_DISCONNECT:
                        if (QvxDisconnectHandler == null)
                            result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                        else
                            result = QvxDisconnectHandler();
                        result.SetConnectionNULL = true;
                        break;
                    #endregion

                    #region QVX_TERMINATE
                    case QvxCommand.QVX_TERMINATE:
                        if (QvxTerminateHandler != null)
                            QvxTerminateHandler();
                        result.Result = QvxResult.QVX_OK;
                        result.Terminate = true;
                        break;
                    #endregion

                    #region QVX_GET_EXECUTE_ERROR
                    case QvxCommand.QVX_GET_EXECUTE_ERROR:
                        result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                        if (QvxExecuteErrorHandler != null)
                            result = QvxExecuteErrorHandler();
                        break;
                    #endregion

                    #region QVX_ABORT & QVX_PROGRESS
                    case QvxCommand.QVX_ABORT:
                    case QvxCommand.QVX_PROGRESS:
                        result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                        break;
                    #endregion

                    #region Default
                    default:
                        result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                        break;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                result.Result = QvxResult.QVX_UNKNOWN_ERROR;
            }
            return result;
        }
Exemplo n.º 8
0
        private void QvxCommandServerWorker()
        {
            using (NamedPipeServerStream pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1))
            {
                pipeServer.WaitForConnection();

                var    buf   = new byte[4];
                var    buf2  = new byte[4];
                object state = new object();
                while (running)
                {
                    if (request != null)
                    {
                        #region Send Request
                        byte[] bRequest = null;
                        try
                        {
                            bRequest = ASCIIEncoding.ASCII.GetBytes(request.Serialize() + "\0");
                            request  = null;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex);
                            throw ex;
                        }

                        buf     = BitConverter.GetBytes((Int32)bRequest.Length);
                        buf2[0] = buf[3];
                        buf2[1] = buf[2];
                        buf2[2] = buf[1];
                        buf2[3] = buf[0];
                        pipeServer.Write(buf2, 0, 4);
                        pipeServer.Write(bRequest, 0, bRequest.Length);
                        pipeServer.WaitForPipeDrain();
                        #endregion

                        #region Receive Response
                        var iar = pipeServer.BeginRead(buf, 0, 4, null, state);
                        while (!iar.IsCompleted)
                        {
                            Thread.Sleep(1);                        // TODO: add Timeout possibility
                        }
                        var count = pipeServer.EndRead(iar);
                        if (count != 4)
                        {
                            throw new Exception("Invalid Count Length");
                        }
                        buf2[0] = buf[3];
                        buf2[1] = buf[2];
                        buf2[2] = buf[1];
                        buf2[3] = buf[0];
                        var datalength = BitConverter.ToInt32(buf2, 0);
                        var data       = new byte[datalength];
                        count = pipeServer.Read(data, 0, datalength);
                        if (count != datalength)
                        {
                            throw new Exception("Invalid Data Length");
                        }

                        var sdata = ASCIIEncoding.ASCII.GetString(data);
                        sdata = sdata.Replace("\0", "");
                        try
                        {
                            reply = QvxReply.Deserialize(sdata);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex);
                            reply = new QvxReply()
                            {
                                Result = QvxResult.QVX_PIPE_ERROR, ErrorMessage = ex.Message
                            };
                            throw ex;
                        }
                        #endregion
                    }
                }
            }
        }
Exemplo n.º 9
0
        public QvxReply HandleRequest(QvxRequest request)
        {
            logger.Debug("HandleRequest Command:" + request.Command.ToString());
            var result = new QvxReply()
            {
                Result = QvxResult.QVX_OK
            };

            try
            {
                switch (request.Command)
                {
                    #region QVX_CONNECT
                case QvxCommand.QVX_CONNECT:
                    if (request.Parameters.Count != 1)
                    {
                        result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                        logger.Warn("QvxCommand.QVX_CONNECT: request.Parameters.Count expected 1 found:" + request.Parameters.Count.ToString());
                    }
                    else
                    if (QvxConnectHandler == null)
                    {
                        result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    }
                    else
                    {
                        // TODO: Parse User & Password, Config Options

                        //QlikView uses extra quotation around UserID and Password value if a) a value contains a
                        //semicolon or b) a value starts with a double quote. The Connectors that use such values have
                        //to modify QVX_CONNECT and QVX_EDIT_CONNECT command handling by removing
                        //or adding the extra quotation when it is relevant.
                        result = QvxConnectHandler(request.Parameters[0]);
                    }
                    break;
                    #endregion

                    #region QVX_EXECUTE
                case QvxCommand.QVX_EXECUTE:
                    if (!((request.Parameters.Count == 2) | (request.Parameters.Count == 3)))
                    {
                        result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                    }
                    else
                    if (QvxRequestRawExecuteHandler != null)
                    {
                        result = QvxRequestRawExecuteHandler(request);
                    }
                    else
                    {
                        QvxExecuteCommands cmd;
                        if (!Enum.TryParse <QvxExecuteCommands>(request.Parameters[0], out cmd))
                        {
                            cmd = QvxExecuteCommands.SQL;
                        }

                        if (QvxExecuteHandler == null)
                        {
                            result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                        }
                        else
                        {
                            List <string> list = new List <string>();
                            if (request.Parameters.Count == 3)
                            {
                                list = request.Parameters[2].Split(new char[1] {
                                    ';'
                                }).ToList();
                            }

                            result = QvxExecuteHandler(cmd, request.Parameters[0], new QvxDataClient(request.Parameters[1]), list);
                        }
                    }
                    break;
                    #endregion

                    #region QVX_EDIT_CONNECT
                case QvxCommand.QVX_EDIT_CONNECT:
                    if (request.Parameters.Count != 1)
                    {
                        result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                    }
                    else
                    if (QvxEditConnectHandler == null)
                    {
                        result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    }
                    else
                    {
                        result = QvxEditConnectHandler(request.Parameters[0], request.QVWindow);
                    }
                    break;
                    #endregion

                    #region QVX_EDIT_SELECT
                case QvxCommand.QVX_EDIT_SELECT:
                    if (request.Parameters.Count != 2)
                    {
                        result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                    }
                    else
                    if (QvxEditSelectHandler == null)
                    {
                        result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    }
                    else
                    {
                        result = QvxEditSelectHandler(request.Parameters[0], request.Parameters[1], request.QVWindow);
                    }
                    break;
                    #endregion

                    #region QVX_GENERIC_COMMAND
                case QvxCommand.QVX_GENERIC_COMMAND:
                    if (!(request.Parameters.Count > 0))
                    {
                        result.Result = QvxResult.QVX_UNKNOWN_ERROR;
                    }
                    else
                    {
                        string             command = request.Parameters[0];
                        QvxGenericCommands cmd;
                        bool validCmd = Enum.TryParse <QvxGenericCommands>(command, out cmd);
                        if ((QvxGenericCommandHandler == null) | (!validCmd))
                        {
                            result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                        }
                        else
                        {
                            result = QvxGenericCommandHandler(cmd);
                        }
                    }
                    break;
                    #endregion

                    #region QVX_DISCONNECT
                case QvxCommand.QVX_DISCONNECT:
                    if (QvxDisconnectHandler == null)
                    {
                        result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    }
                    else
                    {
                        result = QvxDisconnectHandler();
                    }
                    result.SetConnectionNULL = true;
                    break;
                    #endregion

                    #region QVX_TERMINATE
                case QvxCommand.QVX_TERMINATE:
                    if (QvxTerminateHandler != null)
                    {
                        QvxTerminateHandler();
                    }
                    result.Result    = QvxResult.QVX_OK;
                    result.Terminate = true;
                    break;
                    #endregion

                    #region QVX_GET_EXECUTE_ERROR
                case QvxCommand.QVX_GET_EXECUTE_ERROR:
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    if (QvxExecuteErrorHandler != null)
                    {
                        result = QvxExecuteErrorHandler();
                    }
                    break;
                    #endregion

                    #region QVX_ABORT & QVX_PROGRESS
                case QvxCommand.QVX_ABORT:
                case QvxCommand.QVX_PROGRESS:
                    // TODO !!
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    break;
                    #endregion

                    #region Default
                default:
                    result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
                    break;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                result.Result = QvxResult.QVX_UNKNOWN_ERROR;
            }
            return(result);
        }
Exemplo n.º 10
0
 public static bool LoadFromFile(string fileName, out QvxReply obj) {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Deserializes xml markup from file into an QvxReply object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output QvxReply object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out QvxReply obj, out System.Exception exception) {
     exception = null;
     obj = default(QvxReply);
     try {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
Exemplo n.º 12
0
 public static bool Deserialize(string xml, out QvxReply obj) {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Deserializes workflow markup into an QvxReply object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output QvxReply object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out QvxReply obj, out System.Exception exception) {
     exception = null;
     obj = default(QvxReply);
     try {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
Exemplo n.º 14
0
 public static bool LoadFromFile(string fileName, out QvxReply obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
Exemplo n.º 15
0
        public QvxReply HandleRequest(QvxGenericCommands command)
        {
            var result = new QvxReply() { Result = QvxResult.QVX_OK };

            switch (command)
            {
                case QvxGenericCommands.HaveStarField:
                    if (HaveStarField.HasValue)
                        result.OutputValues.Add(HaveStarField.Value.ToString());
                    break;
                case QvxGenericCommands.IsConnected:
                    if (IsConnected.HasValue)
                        result.OutputValues.Add(IsConnected.Value.ToString());
                    break;
                case QvxGenericCommands.DisableQlikViewSelectButton:
                    if (DisableQlikViewSelectButton.HasValue)
                        result.OutputValues.Add(DisableQlikViewSelectButton.Value.ToString());
                    break;
                case QvxGenericCommands.GetCustomCaption:
                    if (GetCustomCaption != null)
                        result.OutputValues.Add(GetCustomCaption);
                    break;
            }

            if (result.OutputValues.Count == 0)
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
            return result;
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
0
        public QvxReply HandleRequest(QvxGenericCommands command)
        {
            var result = new QvxReply()
            {
                Result = QvxResult.QVX_OK
            };

            switch (command)
            {
            case QvxGenericCommands.HaveStarField:
                if (HaveStarField.HasValue)
                {
                    result.OutputValues.Add(HaveStarField.Value.ToString());
                }
                break;

            case QvxGenericCommands.IsConnected:
                if (IsConnected.HasValue)
                {
                    result.OutputValues.Add(IsConnected.Value.ToString());
                }
                break;

            case QvxGenericCommands.DisableQlikViewSelectButton:
                if (DisableQlikViewSelectButton.HasValue)
                {
                    result.OutputValues.Add(DisableQlikViewSelectButton.Value.ToString());
                }
                break;

            case QvxGenericCommands.GetCustomCaption:
                if (GetCustomCaption != null)
                {
                    result.OutputValues.Add(GetCustomCaption);
                }
                break;

            case QvxGenericCommands.JsonRequest:

                // TODO: handle new JSON Requests

                //               string method = request.Parameters[1];
                //this.SetupMParametersFromJsonRequest(request);
                //string[] userParams = request.Parameters.Skip<string>(5).Take<string>((request.Parameters.Length - 1)).ToArray<string>();
                //JsonResponse = this.HandleJsonRequest(method, userParams, this._mConnection);

                //            if (JsonRequest != null)
                //string connectString = request.Parameters[2].Replace("CUSTOM CONNECT TO", null).Replace("\"", null).Trim();
                //string parsableConnectionString = connectString + ";UserId=" + request.Parameters[3] + ";Password="******";";
                //this._mConnection.MParameters = QvxConnection.ParseConnectionString(parsableConnectionString);


                break;
            }

            if (result.OutputValues.Count == 0)
            {
                result.Result = QvxResult.QVX_UNSUPPORTED_COMMAND;
            }
            return(result);
        }
Exemplo n.º 19
0
        private void QvxCommandWorker()
        {
            try
            {
                if (pipeName == null)
                {
                    return;
                }

                object state      = new object();
                object connection = null;

                using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut))
                {
                    var   buf        = new byte[4];
                    var   buf2       = new byte[4];
                    Int32 count      = 0;
                    Int32 datalength = 0;
                    pipeClient.Connect(1000);
                    while (pipeClient.IsConnected)
                    {
                        try
                        {
                            #region Get QvxRequest
                            var iar = pipeClient.BeginRead(buf, 0, 4, null, state);
                            while (!iar.IsCompleted)
                            {
                                Thread.Sleep(1);
                            }
                            count = pipeClient.EndRead(iar);
                            if (count != 4)
                            {
                                throw new Exception("Invalid Count Length");
                            }
                            buf2[0]    = buf[3];
                            buf2[1]    = buf[2];
                            buf2[2]    = buf[1];
                            buf2[3]    = buf[0];
                            datalength = BitConverter.ToInt32(buf2, 0);
                            var data = new byte[datalength];
                            count = pipeClient.Read(data, 0, datalength);
                            if (count != datalength)
                            {
                                throw new Exception("Invalid Data Length");
                            }

                            var sdata = ASCIIEncoding.ASCII.GetString(data);
                            sdata = sdata.Replace("\0", "");
                            QvxRequest request;
                            try
                            {
                                request = QvxRequest.Deserialize(sdata);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex);
                                throw ex;
                            }
                            request.QVWindow   = QVWindow;
                            request.Connection = connection;
                            #endregion

                            #region Handle QvxRequets
                            QvxReply result = null;
                            if (HandleQvxRequest != null)
                            {
                                result = HandleQvxRequest(request);
                            }

                            if (result == null)
                            {
                                result = new QvxReply()
                                {
                                    Result = QvxResult.QVX_UNKNOWN_ERROR
                                }
                            }
                            ;
                            #endregion

                            #region Send QvxReply
                            sdata      = "    " + result.Serialize() + "\0";
                            datalength = sdata.Length - 4;
                            buf2       = ASCIIEncoding.ASCII.GetBytes(sdata);
                            buf        = BitConverter.GetBytes(datalength);
                            buf2[0]    = buf[3];
                            buf2[1]    = buf[2];
                            buf2[2]    = buf[1];
                            buf2[3]    = buf[0];
                            pipeClient.Write(buf2, 0, buf2.Length);
                            pipeClient.WaitForPipeDrain();
                            #endregion

                            #region Handle result States
                            if (result.Terminate)
                            {
                                close = true;
                            }
                            if (result.Connection != null)
                            {
                                connection = result.Connection;
                            }
                            if (result.SetConnectionNULL)
                            {
                                connection = null;
                            }
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex);
                            Thread.Sleep(500);
                            close = true;
                        }

                        if (close)
                        {
                            close = false;
                            pipeClient.Close();
                        }

                        Thread.Sleep(5);
                    }
                }
                running = false;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }