Exemplo n.º 1
0
        private void Run(string query, string format, int rowCountLimit, int colCountLimit, DateTime asOfDate, IHttpResponse response)
        {
            IXTable pipeline = null;

            try
            {
                XDatabaseContext context = _xDatabaseContext;

                // Build for another moment in time if requested
                if (asOfDate != _xDatabaseContext.RequestedAsOfDateTime)
                {
                    context = new XDatabaseContext(_xDatabaseContext)
                    {
                        RequestedAsOfDateTime = asOfDate
                    };
                }

                // Build a Pipeline for the Query
                pipeline = context.Query(query);

                // If there was no query, return an empty result
                if (pipeline == null)
                {
                    return;
                }

                // Restrict the row and column count if requested
                if (rowCountLimit >= 0 || colCountLimit > 0)
                {
                    pipeline = new Verbs.Limit(pipeline, rowCountLimit, colCountLimit);
                }

                // Build a writer for the desired format
                pipeline = new TabularFileWriter(pipeline, WriterForFormat(format, response));

                // Run the query and return the output
                pipeline.RunWithoutDispose();
            }
            catch (ColumnDataNotFoundException ex)
            {
                // If column data is missing, delete the table to try to spur re-creating it
                // NOTE: This logic will likely need to be updated when columns are downloaded remotely; multi-threaded scenarios will be complex.
                string tablePath = Path.Combine(ex.ColumnPath, @"..\..\..");
                TableMetadataSerializer.Delete(_xDatabaseContext.StreamProvider, tablePath);
            }
            finally
            {
                if (pipeline != null)
                {
                    pipeline.Dispose();
                    pipeline = null;
                }
            }
        }
Exemplo n.º 2
0
        private void Run(string query, string format, int rowCountLimit, int colCountLimit, DateTime asOfDate, IHttpResponse response)
        {
            IXTable pipeline = null;

            try
            {
                XDatabaseContext context = _xDatabaseContext;

                // Build for another moment in time if requested
                if (asOfDate != _xDatabaseContext.RequestedAsOfDateTime)
                {
                    context = new XDatabaseContext(_xDatabaseContext)
                    {
                        RequestedAsOfDateTime = asOfDate
                    };
                }

                // Build a Pipeline for the Query
                pipeline = context.Query(query);

                // Restrict the row and column count if requested
                if (rowCountLimit >= 0 || colCountLimit > 0)
                {
                    pipeline = new Verbs.Limit(pipeline, rowCountLimit, colCountLimit);
                }

                // Build a writer for the desired format
                using (ITabularWriter writer = WriterForFormat(format, response))
                {
                    // Run the query and return the output
                    pipeline = new TabularFileWriter(pipeline, writer);
                    pipeline.RunAndDispose();
                }
            }
            finally
            {
                if (pipeline != null)
                {
                    pipeline.Dispose();
                    pipeline = null;
                }
            }
        }