Esempio n. 1
0
 /// <summary>
 /// Deserializes xml markup from file into an QvxRequest object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output QvxRequest 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 QvxRequest obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(QvxRequest);
     try {
         obj = LoadFromFile(fileName);
         return(true);
     }
     catch (System.Exception ex) {
         exception = ex;
         return(false);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Deserializes workflow markup into an QvxRequest object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output QvxRequest 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 QvxRequest obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(QvxRequest);
     try {
         obj = Deserialize(xml);
         return(true);
     }
     catch (System.Exception ex) {
         exception = ex;
         return(false);
     }
 }
Esempio 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);
     }
 }
Esempio n. 4
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);
        }
Esempio n. 5
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;
        }
Esempio n. 6
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
                    }
                }
            }
        }
Esempio n. 7
0
 public static bool LoadFromFile(string fileName, out QvxRequest obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
Esempio n. 8
0
 public static bool Deserialize(string xml, out QvxRequest obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }
Esempio n. 9
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);
            }
        }