Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public async Task <bool> TryShowCubeForVariables(SessionDetails sessionDetails, string systemName, string queryFilePath, List <string> variableNames, 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);

            foreach (string variableName in variableNames)
            {
                Variable variable = await fastStatsSystemService.GetVariable(sessionDetails, systemName, variableName);

                if (variable == null)
                {
                    throw new Exception($"Couldn't find a variable with the name {variableName} in the system {systemName}");
                }

                if (variable.Type != Variable.TypeEnum.Selector)
                {
                    throw new Exception($"The DataAggregator can only build cubes with selector variables, but {variable.Description} is of type {variable.Type}");
                }
            }

            List <Dimension> dimensions = BuildDimensions(variableNames);
            List <Measure>   measures   = BuildMeasures(query.Selection.TableName);

            CubesService  cubesService = new CubesService(connectorFactory, dataViewName);
            List <string> rows         = await cubesService.CalculateCube(systemName, sessionDetails, query, dimensions, measures, TimeSpan.FromMinutes(5));

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

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

            return(true);
        }