예제 #1
0
        /// <summary>
        /// Executes a query.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="cql">The CQL.</param>
        /// <param name="logger">The logger.</param>
        /// <returns>
        /// A CqlDataReader that can be used to access the query results
        /// </returns>
        private async Task <CqlDataReader> ExecQuery(Connection connection, string cql, Logger logger)
        {
            logger.LogVerbose("Excuting query {0} on {1}", cql, connection);

            var query  = new QueryFrame(cql, CqlConsistency.One);
            var result = (ResultFrame)await connection.SendRequestAsync(query, logger).ConfigureAwait(false);

            var reader = new CqlDataReader(result);

            logger.LogVerbose("Query {0} returned {1} results", cql, reader.Count);

            return(reader);
        }
예제 #2
0
        /// <summary>
        /// Executes the query async on the given connection
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="state">The state.</param>
        /// <param name="logger">The logger.</param>
        /// <returns></returns>
        /// <exception cref="CqlException">Unexpected frame received</exception>
        private async Task <ResultFrame> ExecuteInternalAsync(Connection connection, QueryExecutionState state, Logger logger)
        {
            Frame query;

            if (_prepared)
            {
                ResultFrame prepareResult = await PrepareInternalAsync(connection, state, logger).ConfigureAwait(false);

                query = new ExecuteFrame(prepareResult.PreparedQueryId, _level, state.Values);
                logger.LogVerbose("Sending execute {0} using {1}", _cql, connection);
            }
            else
            {
                query = new QueryFrame(_cql, _level);
                logger.LogVerbose("Sending query {0} using {1}", _cql, connection);
            }

            //update frame with tracing option if requested
            if (state.TracingEnabled)
            {
                query.Flags |= FrameFlags.Tracing;
            }

            Frame response = await connection.SendRequestAsync(query, logger, state.Load).ConfigureAwait(false);

            var result = response as ResultFrame;

            if (result != null)
            {
                //read all the data into a buffer, if requested
                if (state.UseBuffering)
                {
                    logger.LogVerbose("Buffering used, reading all data");
                    await result.BufferDataAsync().ConfigureAwait(false);
                }

                return(result);
            }

            throw new CqlException("Unexpected frame received " + response.OpCode);
        }
예제 #3
0
 private void panel1_Load(object sender, EventArgs e)
 {
     //  checkf = new Checkframe();
     managementf = new ManagementFrame();
     queryf      = new QueryFrame();
 }
예제 #4
0
        IEnumerator <ITask> QueryFrameHandler(QueryFrame query)
        {
            if (_state.Image == null)
            {
                query.ResponsePort.Post(new QueryFrameResponse());
                yield break;
            }

            if (query.Body.Format == Guid.Empty)
            {
                // raw image requested;
                BitmapData raw = null;
                try
                {
                    raw = _state.Image.LockBits(new Rectangle(Point.Empty, _state.Size),
                                                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

                    int size = raw.Height * raw.Stride;

                    QueryFrameResponse response = new QueryFrameResponse();

                    response.TimeStamp = _state.TimeStamp;
                    response.Frame     = new byte[size];
                    response.Size      = new Size(raw.Width, raw.Height);
                    response.Format    = Guid.Empty;

                    System.Runtime.InteropServices.Marshal.Copy(raw.Scan0, response.Frame, 0, size);

                    query.ResponsePort.Post(response);
                }
                finally
                {
                    if (raw != null)
                    {
                        _state.Image.UnlockBits(raw);
                    }
                }
            }
            else
            {
                ImageFormat format = new ImageFormat(query.Body.Format);

                using (MemoryStream stream = new MemoryStream())
                {
                    Size size = query.Body.Size;
                    if (size == _state.Image.Size ||
                        size.Width == 0 ||
                        size.Height == 0 ||
                        size.Width >= _state.Image.Width ||
                        size.Height >= _state.Image.Height)
                    {
                        size = _state.Image.Size;
                        _state.Image.Save(stream, format);
                    }
                    else
                    {
                        using (Bitmap temp = new Bitmap(
                                   _state.Image, query.Body.Size))
                        {
                            temp.Save(stream, format);
                        }
                    }


                    QueryFrameResponse response = new QueryFrameResponse();
                    response.TimeStamp = _state.TimeStamp;
                    response.Frame     = new byte[(int)stream.Length];
                    response.Size      = size;
                    response.Format    = format.Guid;

                    stream.Position = 0;
                    stream.Read(response.Frame, 0, response.Frame.Length);

                    query.ResponsePort.Post(response);
                }
            }
            yield break;
        }