示例#1
0
        public TableHelper GetTableInfosFromApp(string tableName, ScriptCode script, IDoc app)
        {
            try
            {
                var resultTable = new ResultTable()
                {
                    Name = tableName,
                };

                var fields = new List <ResultHeader>();
                var rows   = new List <ResultRow>();
                var size   = new Size();

                if (app == null)
                {
                    throw new Exception("No App session.");
                }

                var tableObject = app.GetObjectAsync(script.ObjectId).Result;
                if (tableObject == null)
                {
                    throw new Exception("No Table object found.");
                }
                logger.Debug($"TableObject objectId: {script.ObjectId} - objectType {tableObject.qGenericType}");

                dynamic   hyperCubeLayout = tableObject.GetLayoutAsync <JObject>().Result;
                HyperCube hyperCube       = hyperCubeLayout.qHyperCube.ToObject <HyperCube>();
                var       columnOrder     = hyperCube.qColumnOrder.ToList();
                size = hyperCube.qSize;
                fields.AddRange(GetHyperCubeFields(hyperCube.qDimensionInfo, hyperCube.qMeasureInfo, script));

                if (columnOrder == null || columnOrder.Count == 0)
                {
                    columnOrder = new List <int>();
                    for (int i = 0; i < fields.Count; i++)
                    {
                        columnOrder.Add(i);
                    }
                }

                var preview = new PreviewResponse()
                {
                    MaxCount = 15,
                };

                if (script != null)
                {
                    var allPages = new List <IEnumerable <NxDataPage> >();
                    if (script.Full)
                    {
                        //DataLoad
                        preview.MaxCount = 0;
                        var pageHeight = Math.Min(size.qcy * size.qcx, 5000) / size.qcx;
                        logger.Debug($"read data - column count: {size.qcx}");
                        var counter = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(size.qcy) / Convert.ToDouble(pageHeight)));
                        allPages = new List <IEnumerable <NxDataPage> >(counter);
                        var options = new ParallelOptions()
                        {
                            MaxDegreeOfParallelism = Environment.ProcessorCount
                        };
                        Parallel.For(0, counter, options, i =>
                        {
                            var initalPage = new NxPage {
                                qTop = 0, qLeft = 0, qWidth = size.qcx, qHeight = pageHeight
                            };
                            initalPage.qTop = i * pageHeight;
                            var pages       = tableObject.GetHyperCubeDataAsync("/qHyperCubeDef", new List <NxPage>()
                            {
                                initalPage
                            }).Result;
                            allPages.Add(pages);
                        });
                    }
                    else
                    {
                        //Preview
                        var initalPage = new NxPage {
                            qTop = 0, qLeft = 0, qWidth = size.qcx, qHeight = preview.MaxCount
                        };
                        var pages = tableObject.GetHyperCubeDataAsync("/qHyperCubeDef", new List <NxPage>()
                        {
                            initalPage
                        }).Result;
                        allPages.Add(pages);
                    }
                    if (allPages == null)
                    {
                        throw new Exception($"no dimension in table {script.ObjectId} exits.");
                    }
                    logger.Debug($"read pages - count {allPages.Count}");

                    var hrow = new PreviewRow();
                    preview.qPreview.Add(hrow);

                    foreach (var page in allPages)
                    {
                        var allMatrix = page?.SelectMany(p => p.qMatrix);
                        foreach (var matrix in allMatrix)
                        {
                            var drow = new PreviewRow();
                            preview.qPreview.Add(drow);

                            foreach (var order in columnOrder)
                            {
                                if (order < fields.Count)
                                {
                                    var row   = new ResultRow();
                                    var field = fields[order];
                                    row.Value  = matrix[order].qText;
                                    row.Num    = matrix[order]?.qNum ?? Double.NaN;
                                    row.Header = field.Name;

                                    if (order == 0)
                                    {
                                        row.IsFirstRow = true;
                                    }

                                    if (order == fields.Count - 1)
                                    {
                                        row.IsLastRow = true;
                                    }

                                    rows.Add(row);

                                    if (!preview.qPreview.Any(s => s.qValues.Contains(field.Name)))
                                    {
                                        hrow.qValues.Add(field.Name);
                                    }
                                    if (preview.qPreview.Count <= preview.MaxCount)
                                    {
                                        drow.qValues.Add(matrix[order].qText);
                                    }
                                }
                            }
                        }
                    }
                }

                resultTable.Headers.AddRange(fields);
                resultTable.Rows.AddRange(rows);
                logger.Debug($"return table {resultTable.Name}");
                return(new TableHelper(resultTable, preview));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "can´t read table infos.");
                return(null);
            }
        }
示例#2
0
 public TableHelper(ResultTable table, IPreviewResponse preview)
 {
     QvxTable = table;
     Preview  = preview;
 }