1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Linq ;
44using System . Threading . Tasks ;
77using Qlik . Sense . Client ;
88
99// Title: Qlik Sense Cache Initializer
10- // Date: Feb 2015
11- // Version: 0.1
12- // Author: Joe Bickley
10+ // Date: 19.08.2016
11+ // Version: 0.11
12+ // Author: Joe Bickley,Roland Vecera
1313// Summary: This tool will "warm" the cache of a Qlik Sense server so that when using large apps the users get good performance right away.
1414// You can use it to load all apps, a single app, and you can get it to just open the app to RAM or cycle through all the objects
1515// so that it will pre calculate expressions so users get rapid performance. You can also pass in selections too.
16- // Credits: Thanks to Oysein Kolsrud for helping with the Qlik Sense .net SDK steps
16+ // Credits: Thanks to Øystein Kolsrud for helping with the Qlik Sense .net SDK steps
1717// Uses the commandline.codeplex.com for processing parameters
1818
1919
20- // Usage: cacheinitiazer.exe -s https://server.domain.com [-a appname] [-o] [-f fieldname] [-v "value 1,value 2"]
20+ // Usage: cacheinitiazer.exe -s https://server.domain.com [-a appname] [-o] [-f fieldname] [-v "value 1,value 2"] [-p virtualproxyprefix]
2121// Notes: This projects use the Qlik Sense .net SDK, you must use the right version of the SDK to match the server you are connecting too.
2222// To swap version simply replace the .net SDK files in the BIN directory of this project, if you dont match them, it wont work!
2323
@@ -27,73 +27,78 @@ namespace CacheInitializer
2727 class Program
2828 {
2929
30- static void Main ( string [ ] args )
30+ static void Main ( string [ ] args )
3131 {
3232
3333 //////Setup
34- Options options = new Options ( ) ;
35- Uri serverURL ;
36- string appname ;
37- bool openSheets ;
38- QlikSelection mySelection = null ;
34+ Options options = new Options ( ) ;
35+ Uri serverURL ;
36+ string appname ;
37+ bool openSheets ;
38+ string virtualProxy ;
39+ QlikSelection mySelection = null ;
3940
4041 //// process the parameters using the https://commandline.codeplex.com/
41- if ( CommandLine . Parser . Default . ParseArguments ( args , options ) )
42- {
43- serverURL = new Uri ( options . server ) ;
44- appname = options . appname ;
45- openSheets = options . fetchobjects ;
46- if ( options . selectionfield != null )
47- {
48- mySelection = new QlikSelection ( ) ;
49- mySelection . fieldname = options . selectionfield ;
50- mySelection . fieldvalues = options . selectionvalues . Split ( ',' ) ;
51- }
52- //TODO need to validate the params ideally
53- }
54- else
42+ if ( CommandLine . Parser . Default . ParseArguments ( args , options ) )
43+ {
44+ serverURL = new Uri ( options . server ) ;
45+ appname = options . appname ;
46+ virtualProxy = ! string . IsNullOrEmpty ( options . virtualProxy ) ? options . virtualProxy : "" ;
47+ openSheets = options . fetchobjects ;
48+ if ( options . selectionfield != null )
5549 {
56- throw new Exception ( "Check parameters are correct" ) ;
50+ mySelection = new QlikSelection ( ) ;
51+ mySelection . fieldname = options . selectionfield ;
52+ mySelection . fieldvalues = options . selectionvalues . Split ( ',' ) ;
5753 }
54+ //TODO need to validate the params ideally
55+ }
56+ else
57+ {
58+ throw new Exception ( "Check parameters are correct" ) ;
59+ }
5860
5961
6062 ////connect to the server (using windows credentials
61- QlikConnection . Timeout = Int32 . MaxValue ;
62- var d = DateTime . Now ;
63- ILocation remoteQlikSenseLocation = Qlik . Engine . Location . FromUri ( serverURL ) ;
64- bool isHTTPs = false ;
65- if ( serverURL . Scheme == Uri . UriSchemeHttps ) isHTTPs = true ;
66- remoteQlikSenseLocation . AsNtlmUserViaProxy ( isHTTPs ) ;
63+ QlikConnection . Timeout = Int32 . MaxValue ;
64+ var d = DateTime . Now ;
65+ ILocation remoteQlikSenseLocation = Qlik . Engine . Location . FromUri ( serverURL ) ;
66+ if ( virtualProxy . Length > 0 )
67+ {
68+ remoteQlikSenseLocation . VirtualProxyPath = virtualProxy ;
69+ }
70+ bool isHTTPs = false ;
71+ if ( serverURL . Scheme == Uri . UriSchemeHttps ) isHTTPs = true ;
72+ remoteQlikSenseLocation . AsNtlmUserViaProxy ( isHTTPs , null , false ) ;
6773
6874
6975 ////Start to cache the apps
70- if ( appname != null )
71- {
72- //Open up and cache one app
73- IAppIdentifier appidentifier = remoteQlikSenseLocation . AppWithNameOrDefault ( appname ) ;
76+ if ( appname != null )
77+ {
78+ //Open up and cache one app
79+ IAppIdentifier appidentifier = remoteQlikSenseLocation . AppWithNameOrDefault ( appname ) ;
7480
75- LoadCache ( remoteQlikSenseLocation , appidentifier , openSheets , mySelection ) ;
76- }
77- else
78- {
79- //Get all apps, open them up and cache them
80- remoteQlikSenseLocation . GetAppIdentifiers ( ) . ToList ( ) . ForEach ( id => LoadCache ( remoteQlikSenseLocation , id , openSheets , null ) ) ;
81- }
81+ LoadCache ( remoteQlikSenseLocation , appidentifier , openSheets , mySelection ) ;
82+ }
83+ else
84+ {
85+ //Get all apps, open them up and cache them
86+ remoteQlikSenseLocation . GetAppIdentifiers ( ) . ToList ( ) . ForEach ( id => LoadCache ( remoteQlikSenseLocation , id , openSheets , null ) ) ;
87+ }
8288
8389 ////Wrap it up
84- var dt = DateTime . Now - d ;
85- Print ( "Cache initialization complete. Total time: {0}" , dt . ToString ( ) ) ;
90+ var dt = DateTime . Now - d ;
91+ Print ( "Cache initialization complete. Total time: {0}" , dt . ToString ( ) ) ;
8692
87- Console . ReadKey ( ) ;
8893
8994 }
9095
91- static void LoadCache ( ILocation location , IAppIdentifier id , bool opensheets , QlikSelection Selections )
96+ static void LoadCache ( ILocation location , IAppIdentifier id , bool opensheets , QlikSelection Selections )
9297 {
9398 //open up the app
94- Print ( "{0}: Opening app" , id . AppName ) ;
95- IApp app = location . App ( id ) ;
96- Print ( "{0}: App open" , id . AppName ) ;
99+ Print ( "{0}: Opening app" , id . AppName ) ;
100+ IApp app = location . App ( id ) ;
101+ Print ( "{0}: App open" , id . AppName ) ;
97102
98103 //see if we are going to open the sheets too
99104 if ( opensheets )
@@ -162,10 +167,10 @@ private static void Print(string txt, params object[] os)
162167
163168 }
164169
165- class QlikSelection
166- {
167- public string fieldname { get ; set ; }
168- public string [ ] fieldvalues { get ; set ; }
169- }
170+ class QlikSelection
171+ {
172+ public string fieldname { get ; set ; }
173+ public string [ ] fieldvalues { get ; set ; }
174+ }
170175
171176}
0 commit comments