static void LoadCache(ILocation location, IAppIdentifier id, bool opensheets, QlikSelection Selections) { IApp app = null; try { //open up the app Print(LogLevel.Info, "{0}: Opening app", id.AppName); app = location.App(id); Print(LogLevel.Info, "{0}: App open", id.AppName); //see if we are going to open the sheets too if (opensheets) { //see of we are going to make some selections too if (Selections != null) { for (int i = 0; i < Selections.fieldvalues.Length; i++) { //clear any existing selections Print(LogLevel.Info, "{0}: Clearing Selections", id.AppName); app.ClearAll(true); //apply the new selections Print(LogLevel.Info, "{0}: Applying Selection: {1} = {2}", id.AppName, Selections.fieldname, Selections.fieldvalues[i]); app.GetField(Selections.fieldname).Select(Selections.fieldvalues[i]); //cache the results cacheObjects(app, location, id); } } else { //clear any selections Print(LogLevel.Info, "{0}: Clearing Selections", id.AppName); app.ClearAll(true); //cache the results cacheObjects(app, location, id); } } Print(LogLevel.Info, "{0}: App cache completed", id.AppName); app.Dispose(); } catch (Exception ex) { if (app != null) { app.Dispose(); } throw ex; } }
private static void BasicSelection(IApp theApp, IGenericObject theObject) { // Print data for year 2014 only. theApp.GetField("Year").Select("2014"); PrintData("Sales for year 2014 only", theObject, row => String.Format("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text)); var salesRepField = theApp.GetField("Sales Rep Name"); // Print data for year 2014 only, and for sales rep "Amalia Craig" only. salesRepField.Select("Amalia Craig"); PrintData("Sales for year 2014 and sales rep Amalia Craig", theObject, row => String.Format("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text)); // Switch to sales rep "Amanda Honda" salesRepField.Clear(); salesRepField.Select("Amanda Honda"); // Print data for year 2014 only, and for sales rep "Amanda Honda" only. PrintData("Sales for all years", theObject, row => String.Format("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text)); // Clear selections and print data for all years and sales reps. theApp.ClearAll(); PrintData("Sales for all years", theObject, row => String.Format("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text)); }
private static void TakeSnapshots(ISheet sheet, IApp app, out ISnapshot nordicTop5, out ISnapshot nordicQuarterly, out ISnapshot usaTop5, out ISnapshot usaQuarterly, out ISnapshot japanTop5, out ISnapshot japanQuarterly) { // Get the Sales per Region on the sheet var salesPerRegion = GetVisualisationWithTitle(sheet, "Sales per Region"); // Take a snapshot of SalesPerRegion if (salesPerRegion != null) { app.CreateSnapshot("SDK_SalesPerRegion", sheet.Id, salesPerRegion.Id); } // Select a region an take a snapshot of Top5Customers and QuarterlyTrend GetSelectAndCreateSnapshots(app, sheet, "Nordic", out nordicTop5, out nordicQuarterly); app.ClearAll(); GetSelectAndCreateSnapshots(app, sheet, "Usa", out usaTop5, out usaQuarterly); app.ClearAll(); GetSelectAndCreateSnapshots(app, sheet, "Japan", out japanTop5, out japanQuarterly); app.ClearAll(); }
private static void GroupedDimensions(IApp theApp, IGenericObject theObject) { var hyperCube = theObject.Properties.Get <HyperCubeDef>("qHyperCubeDef"); // Make YearMonth, Year and Month stacked dimensions hyperCube.Dimensions = Enumerable.Empty <NxDimension>(); AddInlineDimension(hyperCube, "Year"); var dimension = hyperCube.Dimensions.ToArray()[0]; dimension.Def.FieldDefs = dimension.Def.FieldDefs.Concat(new[] { "Month" }); // The Grouping property indicates that the Dimension is stacked. dimension.Def.Grouping = NxGrpType.GRP_NX_HIEARCHY; dimension.Def.SortCriterias = new[] { new SortCriteria { SortByNumeric = SortDirection.Ascending }, new SortCriteria { SortByNumeric = SortDirection.Ascending } }; SetHyperCube(theObject, hyperCube); // Prints sales per Year PrintGroupedData("Stacked, Sales per Year", theObject); // When selecting a single field of the top dimension of the stack, the hypercube // will use the next dimension of the stack instead. theApp.GetField("Year").Select("2016"); // Prints sales per month for the selected year. PrintGroupedData("Stacked, Sales per Month for selected Year 2016", theObject); // Clear year selection. theApp.ClearAll(); // Set group mode to cyclic and add dimension YearMonth dimension.Def.Grouping = NxGrpType.GRP_NX_COLLECTION; dimension.Def.FieldDefs = dimension.Def.FieldDefs.Concat(new[] { "YearMonth" }); SetHyperCube(theObject, hyperCube); // Print data for Year PrintGroupedData("Cyclic, Sales per Year (group 0)", theObject); // Print data for Month dimension.Def.ActiveField = 1; SetHyperCube(theObject, hyperCube); PrintGroupedData("Cyclic, Sales per Month (group 1)", theObject); // Print data for YearMonth dimension.Def.ActiveField = 2; SetHyperCube(theObject, hyperCube); PrintGroupedData("Cyclic, Sales per YearMonth (group 2)", theObject); }
private static void BasicSelection(IApp theApp, IGenericObject theObject) { // Print data for year 2016 only. theApp.GetField("Year").Select("2016"); Console.WriteLine("*** Sales for year 2016 only"); foreach (var row in GetAllRows(theObject.GetHyperCubePager("/qHyperCubeDef"))) { Console.WriteLine("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text); } var salesRepField = theApp.GetField("Sales Rep Name"); // Print data for year 2016 only, and for sales rep "Amalia Craig" only. salesRepField.Select("Amalia Craig"); Console.WriteLine("*** Sales for year 2016 and sales rep Amalia Craig"); foreach (var row in GetAllRows(theObject.GetHyperCubePager("/qHyperCubeDef"))) { Console.WriteLine("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text); } // Switch to sales rep "Amanda Honda" salesRepField.Clear(); salesRepField.Select("Amanda Honda"); // Print data for year 2016 only, and for sales rep "Amanda Honda" only. Console.WriteLine("*** Sales for year 2016 and sales rep Amanda Honda"); foreach (var row in GetAllRows(theObject.GetHyperCubePager("/qHyperCubeDef"))) { Console.WriteLine("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text); } // Clear selections and print data for all years and sales reps. theApp.ClearAll(); Console.WriteLine("*** Sales for all years"); foreach (var row in GetAllRows(theObject.GetHyperCubePager("/qHyperCubeDef"))) { Console.WriteLine("Year: {0}, Month: {1}, Sales: {2}", row[0].Num, row[1].Text, row[2].Text); } }