Example #1
0
        public async Task <bool> TryShowRowForUrn(SessionDetails sessionDetails, string systemName, string referenceVariableName, string urnValue, List <string> variableNames, TextWriter outputWriter)
        {
            FastStatsSystemService fastStatsSystemService = new FastStatsSystemService(connectorFactory, dataViewName);
            Variable referenceVariable = await fastStatsSystemService.GetVariable(sessionDetails, systemName, referenceVariableName);

            if (referenceVariable == null)
            {
                throw new Exception($"The variable {referenceVariableName} wasn't found in the system {systemName}");
            }

            Query query = BuildQueryForUrn(referenceVariable, urnValue);

            variableNames.Insert(0, referenceVariableName);
            List <Column> columns = BuildExportColumns(variableNames);

            ExportsService exportsService = new ExportsService(connectorFactory, dataViewName);
            List <string>  rows           = await exportsService.ExportData(systemName, sessionDetails, query, columns, 1, TimeSpan.FromMinutes(5));

            if (rows == null)
            {
                return(false);
            }

            foreach (string row in rows)
            {
                outputWriter.WriteLine(row);
            }

            return(true);
        }
Example #2
0
        public async Task <bool> TryShowRowsForQuery(SessionDetails sessionDetails, string systemName, string queryFilePath, List <string> variableNames, int topNRows, TextWriter outputWriter)
        {
            QueriesService queriesService = new QueriesService(connectorFactory, dataViewName);
            Query          query          = await queriesService.GetQueryDefinitionFromFile(systemName, sessionDetails, queryFilePath, TimeSpan.FromMinutes(5));

            if (query == null)
            {
                return(false);
            }

            if (query?.Selection?.TableName == null)
            {
                throw new Exception($"The query {queryFilePath} must have at least a selection with a table name");
            }

            FastStatsSystemService fastStatsSystemService = new FastStatsSystemService(connectorFactory, dataViewName);
            Variable referenceVariable = await fastStatsSystemService.GetReferenceVariableForTable(sessionDetails, systemName, query.Selection.TableName);

            if (referenceVariable != null)
            {
                variableNames.Insert(0, referenceVariable.Name);
            }

            List <Column> columns = BuildExportColumns(variableNames);

            ExportsService exportsService = new ExportsService(connectorFactory, dataViewName);
            List <string>  rows           = await exportsService.ExportData(systemName, sessionDetails, query, columns, topNRows, TimeSpan.FromMinutes(5));

            if (rows == null)
            {
                return(false);
            }

            foreach (string row in rows)
            {
                outputWriter.WriteLine(row);
            }

            return(true);
        }