public List<string> GetFieldValues(app app, IAppField appField2) { List<string> strValues = new List<string>(); Uri uri = new Uri(url + ":443"); ILocation remoteQlikSenseLocation = Qlik.Engine.Location.FromUri(uri); remoteQlikSenseLocation.AsNtlmUserViaProxy(); IAppIdentifier appidentifier = remoteQlikSenseLocation.AppWithId(app.ID); using (var doc = remoteQlikSenseLocation.App(appidentifier)) { var field = doc.GetAppField(appField2.DimensionInfo.FallbackTitle); var p = new List<NxPage> { new NxPage { Height = 20, Width = 1 } }; var dataPages = field.GetData(p); foreach (var dataPage in dataPages) { var matrix = dataPage.Matrix; foreach (var cellRows in matrix) { foreach (var cellRow in cellRows) { strValues.Add(cellRow.Text); //Console.WriteLine("## " + cellRow.Text + " - " + cellRow.State); } } } } return strValues; }
private IApp GetAppHandle(string appid) { Uri uri = new Uri(url + ":443"); ILocation remoteQlikSenseLocation = Qlik.Engine.Location.FromUri(uri); remoteQlikSenseLocation.AsNtlmUserViaProxy(); IAppIdentifier appidentifier = remoteQlikSenseLocation.AppWithId(appid); return remoteQlikSenseLocation.App(appidentifier); }
private static IApp GetApp(ILocation location, IAppIdentifier appId, bool noData) { try { return(location.App(appId, Session.Random, noData: noData)); } catch { return(null); } }
private void listSheets(string appName) { IAppIdentifier foundAppIdentifier = _location.AppWithNameOrDefault(appName); IApp application = _location.App(foundAppIdentifier); ISheetList sheetList = application.GetSheetList(); foreach (ISheetObjectViewListContainer item in sheetList.Items) { dropDown2.Items.Add(CreateRibbonDropDownItem()); dropDown2.Items.Last().Label = item.Data.Title; } }
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 string[] GetExtensionUsage(ILocation location, IAppIdentifier appId, ICollection <string> extensionNames) { Console.WriteLine($"Scanning app \"{appId.AppName}\" ({appId.AppId})"); using (var app = GetApp(location, appId, true) ?? GetApp(location, appId, false)) { if (app == null) { throw new Exception($"Unable to open app {appId.AppName}."); } var sheets = app.GetSheets(); var objectTypes = sheets.SelectMany(GetObjectTypes); return(objectTypes.Where(extensionNames.Contains).ToArray()); } }
internal QlikAppSession(ILocation location, IAppIdentifier appIdentifier, bool createDefaultSession) { Id = Guid.NewGuid(); if (createDefaultSession) { CurrentApp = location.App(appIdentifier, Session.WithApp(appIdentifier, SessionType.Default), true, false); } else { CurrentApp = location.App(appIdentifier, Session.Random, true, false); } SessionId = location.SessionCookie?.Split('=').ElementAtOrDefault(1) ?? null; Selections = new QlikSelections(CurrentApp); IsFree = false; }
static void cacheObjects(IApp app, ILocation location, IAppIdentifier id) { //get a list of the sheets in the app Print(LogLevel.Info, "{0}: Getting sheets", id.AppName); var sheets = app.GetSheets().ToArray(); //get a list of the objects in the app Print(LogLevel.Info, "{0}: Number of sheets - {1}, getting children", id.AppName, sheets.Count()); IGenericObject[] allObjects = sheets.Concat(sheets.SelectMany(sheet => GetAllChildren(app, sheet))).ToArray(); //draw the layout of all objects so the server calculates the data for them Print(LogLevel.Info, "{0}: Number of objects - {1}, caching all objects", id.AppName, allObjects.Count()); var allLayoutTasks = allObjects.Select(o => o.GetLayoutAsync()).ToArray(); Task.WaitAll(allLayoutTasks); Print(LogLevel.Info, "{0}: Objects cached", id.AppName); }
private void OpenApplication(IAppIdentifier appIdentifier) { if (ActiveApp != null) { ActiveApp.Dispose(); } try { ActiveApp = CurrentLocation.App(appIdentifier, noVersionCheck: true); Session.WithApp(appIdentifier, SessionType.Random); Notify("Open app: " + appIdentifier.AppName); SetModeToOpen(); } catch (MethodInvocationException ex) { Notify("Could not open " + appIdentifier.AppName + ", error " + ex.Message); } }
private void listObjects(string sheetName, string appName) { IAppIdentifier foundAppIdentifier = _location.AppWithNameOrDefault(appName); IApp application = _location.App(foundAppIdentifier); IEnumerable <ISheet> sheets = application.GetSheets(); foreach (ISheet sheet1 in sheets) { if (sheet1.MetaAttributes.Title == sheetName) { foreach (IGenericObject child in sheet1.Children) { dropDown3.Items.Add(CreateRibbonDropDownItem()); dropDown3.Items.Last().Label = child.GetLayout().As <VisualizationBaseLayout>().Title + " <" + child.Info.Type.ToString() + ">"; dropDown3.Items.Last().Tag = child.Info.Id; } } } }
private static async Task ReloadApplicationTask(IAppIdentifier appIdentifier) { using (IApp app = await _qlikSenseServer.AppAsync(appIdentifier, noVersionCheck: true)) { Console.WriteLine("App with name {0} opened", appIdentifier.AppName); AsyncHandle reloadHandle = new AsyncHandle("reloadTask"); // By setting mode parameter on reload you can affect the behaviour check the help for more information. // http://help.qlik.com/sense/2.1/en-US/apis/net%20sdk/html/M_Qlik_Engine_App_DoReload.htm // During the reload task you can cancel the reload by calling app.Session.Hub.CancelReload() you should also need to cancel the "reloadTask" try { var reloadTask = app.DoReloadAsync(reloadHandle, OnReloaded); bool doWork = true; while (doWork) { var progress = await app.Session.Hub.GetProgressAsync(reloadHandle); Console.WriteLine("Progress: " + progress.TransientProgress + " Finished : " + progress.Finished); if (progress.Finished) { doWork = false; } System.Threading.Thread.Sleep(1000); // Give the qlik engine time to work before we check the progress again. } await app.DoSaveAsync(); Console.WriteLine("App with name {0} saved and last reloaded {1}", appIdentifier.AppName, (await app.GetAppLayoutAsync()).LastReloadTime); } catch (TimeoutException e) { // We got a timeout exception from the SDK, handle this should be handled. In this example will just cancel the reload in the engine and igonre it. app.Session.Hub.CancelReload(); } } }
static void LoadApp(ILocation location, IAppIdentifier id) { Print("{0}: Opening app", id.AppName); // Load the app to memory. var app = location.App(id); Print("{0}: App opened, getting sheets", id.AppName); var sheets = app.GetSheets().ToArray(); Print("{0}: Number of sheets - {1}, getting children", id.AppName, sheets.Count()); var allObjects = sheets.Concat(sheets.SelectMany(sheet => GetAllChildren(app, sheet))).ToArray(); Print("{0}: Number of objects - {1}, getting layouts", id.AppName, allObjects.Count()); // Trigger the engine to execute all evaluations required to display all objects included in the app. // The evaluation results are stored in memory so that subsequent identical queries do not need // to be recomputed. var allLayoutTasks = allObjects.Select(o => o.GetLayoutAsync()); Task.WaitAll(allLayoutTasks.ToArray <Task>()); Print("{0}: Completed loading layouts", id.AppName); }
public async Task <IEnumerable <ISheet> > GetSheetsAsync(string appId) { string id = appId; QSConnections qsConn = new QSConnections(); var location = await qsConn.GetLocation(); IAppIdentifier appIdentifier = location.AppWithId(appId); try { IApp app = location.App(appIdentifier, session: Session.Random); var sheets = app.GetSheets(); return(sheets); } catch (NullReferenceException e) { throw e; } catch (Exception e) { throw e; } }
private static void DoWork(Options options) { Uri serverURL; string appname; string appid; bool openSheets; string virtualProxy; QlikSelection mySelection = null; ILocation remoteQlikSenseLocation = null; try { if (options.Debug) { DEBUG_MODE = true; Print(LogLevel.Debug, "Debug logging enabled."); } Print(LogLevel.Debug, "setting parameter values in main"); serverURL = new Uri(options.Server); appname = options.AppName; appid = options.AppID; virtualProxy = !string.IsNullOrEmpty(options.VirtualProxy) ? options.VirtualProxy : ""; openSheets = options.FetchObjects; if (options.SelectionField != null) { mySelection = new QlikSelection(); mySelection.fieldname = options.SelectionField; mySelection.fieldvalues = options.SelectionValues.Split(','); } //TODO need to validate the params ideally Print(LogLevel.Debug, "setting remoteQlikSenseLocation");; ////connect to the server (using windows credentials QlikConnection.Timeout = Int32.MaxValue; var d = DateTime.Now; remoteQlikSenseLocation = Qlik.Engine.Location.FromUri(serverURL); Print(LogLevel.Debug, "validating http(s) and virtual proxy");; if (virtualProxy.Length > 0) { remoteQlikSenseLocation.VirtualProxyPath = virtualProxy; } bool isHTTPs = false; if (serverURL.Scheme == Uri.UriSchemeHttps) { isHTTPs = true; } remoteQlikSenseLocation.AsNtlmUserViaProxy(isHTTPs, null, false); Print(LogLevel.Debug, "starting to cache applications"); ////Start to cache the apps IAppIdentifier appIdentifier = null; if (appid != null) { //Open up and cache one app, based on app ID appIdentifier = remoteQlikSenseLocation.AppWithId(appid); Print(LogLevel.Debug, "got app identifier by ID"); LoadCache(remoteQlikSenseLocation, appIdentifier, openSheets, mySelection); Print(LogLevel.Debug, "finished caching by ID"); } else { if (appname != null) { //Open up and cache one app appIdentifier = remoteQlikSenseLocation.AppWithNameOrDefault(appname); Print(LogLevel.Debug, "got app identifier by name"); LoadCache(remoteQlikSenseLocation, appIdentifier, openSheets, mySelection); Print(LogLevel.Debug, "finished caching by name"); } else { //Get all apps, open them up and cache them remoteQlikSenseLocation.GetAppIdentifiers().ToList().ForEach(id => LoadCache(remoteQlikSenseLocation, id, openSheets, null)); Print(LogLevel.Debug, "finished caching all applications"); } } ////Wrap it up var dt = DateTime.Now - d; Print(LogLevel.Info, "Cache initialization complete. Total time: {0}", dt.ToString()); remoteQlikSenseLocation.Dispose(); Print(LogLevel.Debug, "done"); return; } catch (UriFormatException) { Print(LogLevel.Info, "Invalid server paramater format. Format must be http[s]://host.domain.tld."); return; } catch (WebSocketException webEx) { if (remoteQlikSenseLocation != null) { Print(LogLevel.Info, "Disposing remoteQlikSenseLocation"); remoteQlikSenseLocation.Dispose(); } Print(LogLevel.Info, "Unable to connect to establish WebSocket connection with: " + options.Server); Print(LogLevel.Info, "Error: " + webEx.Message); return; } catch (TimeoutException timeoutEx) { Print(LogLevel.Info, "Timeout Exception - Unable to connect to: " + options.Server); Print(LogLevel.Info, "Error: " + timeoutEx.Message); return; } catch (Exception ex) { if (ex.Message.Trim() == "Websocket closed unexpectedly (EndpointUnavailable):") { Print(LogLevel.Info, "Error: licenses exhausted."); return; } else { Print(LogLevel.Info, "Unexpected error."); Print(LogLevel.Info, "Message: " + ex.Message); return; } } }
public QlikAppSession(ILocation location, IAppIdentifier appIdentifier) : this(location, appIdentifier, false) { }
private void availableApplications_DoubleClick(object sender, EventArgs e) { SelectedApplication = availableApplications.SelectedValue as IAppIdentifier; DialogResult = SelectedApplication != null ? DialogResult.OK : DialogResult.Cancel; }
private void OpenButtonClick(object sender, EventArgs e) { SelectedApplication = availableApplications.SelectedValue as IAppIdentifier; DialogResult = SelectedApplication != null ? DialogResult.OK : DialogResult.Cancel; }
private static void Main(string[] args) { //////Setup var options = new Options(); Uri serverURL; string appname; bool openSheets; QlikSelection mySelection = null; //// process the parameters using the https://commandline.codeplex.com/ if (CommandLine.Parser.Default.ParseArguments(args, options)) { serverURL = new Uri(options.server); appname = options.appname; openSheets = options.fetchobjects; if (options.selectionfield != null) { mySelection = new QlikSelection(); mySelection.fieldname = options.selectionfield; mySelection.fieldvalues = options.selectionvalues.Split(','); } //TODO need to validate the params ideally } else { throw new Exception("Check parameters are correct"); } Print($"{nameof(options.server)}:{options.server}"); Print($"{nameof(options.appname)}:{options.appname}"); Print($"{nameof(options.usingProxy)}:{options.usingProxy}"); Print($"{nameof(options.User)}:{options.User}"); Print($"{ nameof(options.fetchobjects)}:{options.fetchobjects}"); ////connect to the server (using windows credentials QlikConnection.Timeout = int.MaxValue; var d = DateTime.Now; ILocation remoteQlikSenseLocation = Qlik.Engine.Location.FromUri(serverURL); var isHTTPs = serverURL.Scheme == Uri.UriSchemeHttps; if ((!string.IsNullOrWhiteSpace(options.User)) && (!string.IsNullOrWhiteSpace(options.staticHeader))) { remoteQlikSenseLocation.VirtualProxyPath = options.usingProxy; remoteQlikSenseLocation.AsStaticHeaderUserViaProxy(options.User, options.staticHeader, isHTTPs); } else if (!string.IsNullOrWhiteSpace(options.usingProxy)) { remoteQlikSenseLocation.VirtualProxyPath = options.usingProxy; remoteQlikSenseLocation.AsNtlmUserViaProxy(isHTTPs); } else if ((!string.IsNullOrWhiteSpace(options.User)) && !string.IsNullOrWhiteSpace(options.Directory) && options.directConnection) { remoteQlikSenseLocation.AsDirectConnection(options.Directory, options.User); } else { remoteQlikSenseLocation.AsNtlmUserViaProxy(isHTTPs); } ////Start to cache the apps if (appname != null) { //Open up and cache one app IAppIdentifier appidentifier = remoteQlikSenseLocation.AppWithNameOrDefault(appname, false); LoadCache(remoteQlikSenseLocation, appidentifier, openSheets, mySelection); } else { //Get all apps, open them up and cache them remoteQlikSenseLocation.GetAppIdentifiers(true) .ToList() .ForEach(id => LoadCache(remoteQlikSenseLocation, id, openSheets, null)); } ////Wrap it up var dt = DateTime.Now - d; Print("Cache initialization complete. Total time: {0}", dt.ToString()); //Console.ReadKey(); }
static void Main(string[] args) { //////Setup Options options = new Options(); Uri serverURL; string appname; bool openSheets; string virtualProxy; QlikSelection mySelection = null; //// process the parameters using the https://commandline.codeplex.com/ if (CommandLine.Parser.Default.ParseArguments(args, options)) { serverURL = new Uri(options.server); appname = options.appname; virtualProxy = !string.IsNullOrEmpty(options.virtualProxy) ? options.virtualProxy : ""; openSheets = options.fetchobjects; if (options.selectionfield != null) { mySelection = new QlikSelection(); mySelection.fieldname = options.selectionfield; mySelection.fieldvalues = options.selectionvalues.Split(','); } //TODO need to validate the params ideally } else { throw new Exception("Check parameters are correct"); } ////connect to the server (using windows credentials QlikConnection.Timeout = Int32.MaxValue; var d = DateTime.Now; ILocation remoteQlikSenseLocation = Qlik.Engine.Location.FromUri(serverURL); if (virtualProxy.Length > 0) { remoteQlikSenseLocation.VirtualProxyPath = virtualProxy; } bool isHTTPs = false; if (serverURL.Scheme == Uri.UriSchemeHttps) { isHTTPs = true; } remoteQlikSenseLocation.AsNtlmUserViaProxy(isHTTPs, null, false); ////Start to cache the apps if (appname != null) { //Open up and cache one app IAppIdentifier appidentifier = remoteQlikSenseLocation.AppWithNameOrDefault(appname); LoadCache(remoteQlikSenseLocation, appidentifier, openSheets, mySelection); } else { //Get all apps, open them up and cache them remoteQlikSenseLocation.GetAppIdentifiers().ToList().ForEach(id => LoadCache(remoteQlikSenseLocation, id, openSheets, null)); } ////Wrap it up var dt = DateTime.Now - d; Print("Cache initialization complete. Total time: {0}", dt.ToString()); }