Ejemplo n.º 1
0
        private static void Paging(IApp theApp)
        {
            var theObject = CreateCustomObject(theApp);

            // Create a hypercube with sales per YearMonth.
            var salesPerYearMonthHc = new HyperCubeDef();

            AddInlineDimension(salesPerYearMonthHc, "YearMonth");
            AddInlineMeasure(salesPerYearMonthHc, "Sum([Sales Amount])");
            SetHyperCube(theObject, salesPerYearMonthHc);

            // Get the hypercube pager
            var pager = theObject.GetHyperCubePager("/qHyperCubeDef");

            // Get data for a page with width 2 and height 5:
            var firstPage = new[] { new NxPage {
                                        Top = 0, Left = 0, Width = 2, Height = 5
                                    } };
            var firstData = pager.GetData(firstPage).Single();

            PrintPage("First page:", firstData, row => String.Format("YearMonth: {0}, Sales: {1}", row[0].Text, row[1].Text));

            // Print all other pages:
            var pageNr = 1;

            while (!pager.OutsideEdge.Single())
            {
                var nextData = pager.GetNextPage().Single();
                PrintPage("Page nr: " + pageNr, nextData, row => String.Format("YearMonth: {0}, Sales: {1}", row[0].Text, row[1].Text));
                pageNr++;
            }

            // Iterate across all pages:
            pageNr    = 0;
            firstPage = new[] { new NxPage {
                                    Top = 0, Left = 0, Width = 2, Height = 5
                                } };
            foreach (var page in pager.IteratePages(firstPage, Pager.Next))
            {
                PrintPage("Page nr: " + pageNr, page.First(), row => String.Format("YearMonth: {0}, Sales: {1}", row[0].Text, row[1].Text));
                pageNr++;
            }

            // Accessing pager for client object hypercubes:
            var theSheet = GetOrCreateSheet(theApp, "mySheet");
            var barChart = theSheet.CreateBarchart();

            // Set hypercube to sales per year and month
            using (barChart.SuspendedLayout)
            {
                barChart.Properties.HyperCubeDef = salesPerYearMonthHc.CloneAs <VisualizationHyperCubeDef>();
            }
            // Print first page of bar chart data:
            var firstBarchartData = barChart.HyperCubePager.GetData();

            PrintPage("First page of bar chart:", firstBarchartData.Single(),
                      row => String.Format("YearMonth: {0}", row[0].Text)
                      );
        }
 private static void SetHyperCube(IGenericObject theObject, HyperCubeDef hyperCube)
 {
     using (theObject.SuspendedLayout)
     {
         // A property with the name "qHyperCubeDef" will be interpreted by the engine as being of type HyperCubeDef
         // and evaluated accordingly.
         theObject.Properties.Set("qHyperCubeDef", hyperCube);
     }
 }
        // Measures can be predefined in the library and thereby reused in in multiple hypercubes. The alternative
        // is to define the measure directly in the hypercube.
        private static void AddLibraryMeasure(HyperCubeDef theHyperCube, string measureId)
        {
            // A library measure is referred to by the id used when creating it.
            var measure = new NxMeasure {
                LibraryId = measureId
            };

            theHyperCube.Measures = theHyperCube.Measures.Concat(new[] { measure });
        }
        private static void Paging(IApp theApp)
        {
            var theObject = CreateCustomObject(theApp);

            // Create a hypercube with sales per YearMonth.
            var salesPerYearMonthHc = new HyperCubeDef();

            AddInlineDimension(salesPerYearMonthHc, "YearMonth");
            AddInlineMeasure(salesPerYearMonthHc, "Sum([Sales Amount])");
            SetHyperCube(theObject, salesPerYearMonthHc);

            // Get the hypercube pager
            var pager = theObject.GetHyperCubePager("/qHyperCubeDef");

            // Get data for a page with width 2 and height 5:
            var firstPage = new[] { new NxPage {
                                        Top = 0, Left = 0, Width = 2, Height = 5
                                    } };
            var firstData = pager.GetData(firstPage).Single();

            Console.WriteLine("*** First page");
            foreach (var row in firstData.Matrix)
            {
                Console.WriteLine("YearMonth: {0}, Sales: {1}", row[0].Text, row[1].Text);
            }

            // Print all other pages:
            var pageNr = 1;

            while (!pager.OutsideEdge.Single())
            {
                var nextData = pager.GetNextPage().Single();
                Console.WriteLine("*** Page nr: " + pageNr);
                foreach (var row in nextData.Matrix)
                {
                    Console.WriteLine("YearMonth: {0}, Sales: {1}", row[0].Text, row[1].Text);
                }
                pageNr++;
            }

            // Iterate across all pages:
            pageNr    = 0;
            firstPage = new[] { new NxPage {
                                    Top = 0, Left = 0, Width = 2, Height = 5
                                } };
            foreach (var page in pager.IteratePages(firstPage, Pager.Next))
            {
                Console.WriteLine("*** Page nr: " + pageNr);
                foreach (var row in page.Single().Matrix)
                {
                    Console.WriteLine("YearMonth: {0}, Sales: {1}", row[0].Text, row[1].Text);
                }
                pageNr++;
            }
        }
Ejemplo n.º 5
0
        private static void MultipleHyperCubesExamples(IApp theApp)
        {
            var theObject = CreateCustomObject(theApp);
            // Create two hypercubes with the same measure, but different dimensions.
            var salesPerMonthHc = new HyperCubeDef();

            AddInlineDimension(salesPerMonthHc, "Month");
            AddInlineMeasure(salesPerMonthHc, "Sum([Sales Amount])");
            var salesPerYearHc = new HyperCubeDef();

            AddInlineDimension(salesPerYearHc, "Year");
            AddInlineMeasure(salesPerYearHc, "Sum([Sales Amount])");

            // Add the hypercubes to containers. The containers are used to separate the two
            // qHyperCubeDef properties in the property tree of the object.
            var hcContainer0 = new DynamicStructure();

            hcContainer0.Set("qHyperCubeDef", salesPerMonthHc);
            var hcContainer1 = new DynamicStructure();

            hcContainer1.Set("qHyperCubeDef", salesPerYearHc);

            // Add containers to object.
            using (theObject.SuspendedLayout)
            {
                theObject.Properties.Set("container0", hcContainer0);
                theObject.Properties.Set("container1", hcContainer1);
            }

            // Print data for first hypercube
            PrintData("Sales per Month", theObject,
                      row => String.Format("Month: {0}, Sales: {1}", row[0].Text, row[1].Text),
                      // Path to hypercube 0. (Name of container property followed by hypercube property.)
                      "/container0/qHyperCubeDef");

            // Print data for second hypercube
            PrintData("Sales per Year", theObject,
                      row => String.Format("Year: {0}, Sales: {1}", row[0].Num, row[1].Text),
                      // Path to hypercube 1. (Name of container property followed by hypercube property.)
                      "/container1/qHyperCubeDef");

            // Get pager for cube in container 1:
            var thePager = theObject.GetAllHyperCubePagers().First(pager => pager.Path.Contains("container0"));

            // Get Last five rows for that hypercube:
            thePager.CurrentPages = new [] { new NxPage {
                                                 Width = 2, Height = 5
                                             } };
            var theLastFiveRows = thePager.GetLastPage().First();

            PrintPage("The last five rows of hypercube in container0:", theLastFiveRows,
                      row => String.Format("Month: {0}, Sales: {1}", row[0].Text, row[1].Text)
                      );
        }
        // An inline dimension is a dimension that is directly defined in the HyperCubeDef structure.
        // The alternative is to use dimensions predefined in the library.
        private static void AddInlineDimension(HyperCubeDef theHyperCube, string field)
        {
            var inlineDimension = new NxInlineDimensionDef {
                FieldDefs = new[] { field }
            };
            // A dimension directly defined in the hypercube definition. The alternative would be to
            // refer to a predefined library dimension in which case the property LibraryId would be used instead.
            var dimension = new NxDimension {
                Def = inlineDimension
            };

            theHyperCube.Dimensions = theHyperCube.Dimensions.Concat(new[] { dimension });
        }
        private static void AddInlineMeasure(HyperCubeDef theHyperCube, string expression)
        {
            var inlineMeasure = new NxInlineMeasureDef {
                Def = expression
            };
            // Analogous to AddInlineDimension. This NxMeasure represents a measure directly defined in the hyper
            // cube definition. The alternative would be to refer to a predefined library dimension in which case
            // the property LibraryId would be used instead.
            var measure = new NxMeasure {
                Def = inlineMeasure
            };

            theHyperCube.Measures = theHyperCube.Measures.Concat(new[] { measure });
        }