private void buttonConnectToEngine_Click(object sender, RibbonControlEventArgs e) { // Single Qlik Sense Desktop with no special settings QlikSenseLocation(); // Defining the location as a direct connection to Qlik Sense Personal _location.AsDirectConnectionToPersonalEdition(); using (IHub hub = _location.Hub()) { editBox1.Text = hub.ProductVersion(); } bindingSource1.DataSource = _location.GetAppIdentifiers(); foreach (IAppIdentifier appIdentifier in _location.GetAppIdentifiers()) { dropDown1.Items.Add(CreateRibbonDropDownItem()); dropDown1.Items.Last().Label = appIdentifier.AppName; } }
private static IEnumerable <IApp> OpenAllApps(ILocation location) { try { return(location.GetAppIdentifiers().Select(x => location.App(x))); } catch (CommunicationErrorException e) { Console.WriteLine("Communication error exception, no Qlik Sense instance found! " + e.Message); return(new IApp[] { }); } }
public OpenApplicationDialog(ILocation currentLocation) { InitializeComponent(); try { availableApplications.DataSource = currentLocation.GetAppIdentifiers(noVersionCheck: true).ToArray(); availableApplications.DisplayMember = "AppName"; availableApplications.ClearSelected(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private static void ListApps(ILocation location) { foreach (var appIdentifier in location.GetAppIdentifiers()) { try { using (var app = location.App(appIdentifier)) { Traversing.Traverse(app); } } catch (MethodInvocationException e) { TextHelper.WriteLine("Could not open app: " + appIdentifier.AppName + Environment.NewLine + TextHelper.Indent() + e.InvocationError.Message); } catch (TimeoutException e) { TextHelper.WriteLine("Timeout for: " + appIdentifier.AppName + Environment.NewLine + TextHelper.Indent() + e.Message); } } }
private static void listApps(ILocation loc) { ILocation location = loc; foreach (var appIdentifier in location.GetAppIdentifiers()) { try { using (var app = location.App(appIdentifier))// Location specified in Accessing { var layout = app.GetAppLayout(); Console.Write(layout.Title + " [" + app.Type + "]"); } } catch (MethodInvocationException e) { Console.WriteLine("Could not open app: " + appIdentifier.AppName + Environment.NewLine + e.InvocationError.Message); } catch (TimeoutException e) { Console.WriteLine("Timeout for: " + appIdentifier.AppName + Environment.NewLine + e.Message); } } }
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; } } }
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()); }
public List <SenseApplication> GetAppList() { return(location.GetAppIdentifiers().Select(a => new SenseApplication { AppName = a.AppName, AppId = a.AppId }).ToList()); }
static void Main(string[] args) { #if DEBUG string currentExeName = "OpenWithSense.exe"; #else string currentExeName = System.AppDomain.CurrentDomain.FriendlyName; #endif IHub hub; ILocation location = Qlik.Engine.Location.FromUri("ws://127.0.0.1:4848"); location.AsDirectConnectionToPersonalEdition(); string version = ""; string welcome = "Enter the needed number or enter 0 to exit in any menu"; // New app name prefix string tempAppPrefix = "Temp App - "; string userName = System.Environment.UserName; string sensePath = @"C:\Users\" + userName + @"\AppData\Local\Programs\Qlik\Sense\QlikSense.exe"; string currentFolder = System.AppDomain.CurrentDomain.BaseDirectory; string keyPath = "Software\\Classes\\*\\Shell\\OpenInSense"; // Possible file extensions List <string> fileExtensions = new List <string>(); fileExtensions.Add(".csv"); fileExtensions.Add(".qvd"); fileExtensions.Add(".qvf"); //var enviromentPath1 = System.Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User); // Check if Sense is running before everything else. If not - exit try { using (hub = location.Hub()) { version = hub.ProductVersion(); if (version.Substring(0, 3) != "3.2") { Console.WriteLine("I'm sory but only QS version 3.2.x is supported at the moment. Press Enter to close."); Console.ReadLine(); Environment.Exit(0); } } } catch (Exception ex) { Console.Clear(); Console.WriteLine("Qlik Sense Desktop is not running. Please start it and try again."); Console.WriteLine("Bye!"); Environment.Exit(0); } // Check if the app is started from the right click or directly from command line if (args.Length > 0) { string loadedExtension = Path.GetExtension(args[0]).ToLower(); string loadedFileName = Path.GetFileName(args[0]); bool possible = false; for (var i = 0; i < fileExtensions.Count; i++) { if (fileExtensions[i] == loadedExtension) { possible = true; } } // if the selected extension is in the list - csv, qvd and qvf if (possible == true) { using (hub = location.Hub()) { // if its data file - csv or qvd if (loadedExtension != ".qvf") { // Create new app with prefix name and timestamp // Open the app; GetSript; Add the new script; Reload the app; add summary sheet; save the app and open the app inside browser on the summary sheet in edit mode //Console.WriteLine(hub.ProductVersion()); string currentTime = DateTime.Now.ToString("yyyyMMddHHmmssffff"); string appName = tempAppPrefix + "" + currentTime; Qlik.Engine.CreateAppResult appResult = hub.CreateApp(appName); Console.WriteLine("App is created --> '" + appName + "'"); IApp app = hub.OpenApp(appName); Console.WriteLine("App is open ..."); string script = app.GetScript(); string addScript = "TempTable:" + Environment.NewLine + "Load" + Environment.NewLine + " *" + Environment.NewLine + "FROM" + Environment.NewLine + @" [" + args[0] + "] (txt)" + Environment.NewLine + "; " + Environment.NewLine; app.SetScript(script + Environment.NewLine + Environment.NewLine + addScript); Console.WriteLine("New script is added ..."); Console.WriteLine("Reload started..."); app.DoReload(); Console.WriteLine("App is reloaded ..."); ISheet mySheet = app.CreateSheet("Summary"); using (mySheet.SuspendedLayout) { mySheet.Properties.MetaDef.Title = "Summary"; mySheet.Properties.Rank = 0; } Console.WriteLine("New sheet is added ..."); Console.WriteLine("App is saving ..."); app.DoSave(); Console.WriteLine("App is saved."); Console.WriteLine("All is done!"); Process.Start("http://localhost:4848/sense/app/" + WebUtility.UrlEncode(appResult.AppId).Replace("+", "%20") + "/sheet/Summary/state/edit"); Console.Clear(); Console.WriteLine("Bye!"); Environment.Exit(0); } // if its qvf else { string destinationPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Qlik\\Sense\\Apps\\" + loadedFileName; // check if the file already exists in QS Apps folder // if not - copy it // if yes - ask the user to confirm if its ok to overwrite if (!File.Exists(destinationPath)) { CopyQVF(args[0], destinationPath, false); } else { Console.Write("The app already exists. Overwrite? (y/n) "); string result = Console.ReadLine().ToLower(); if (result == "y") { CopyQVF(args[0], destinationPath, true); } else { Console.Clear(); Console.WriteLine("Nothing to do then"); Console.WriteLine("Bye!"); Environment.Exit(0); } } } } } else { Console.Clear(); Console.WriteLine("I'm sorry but at the moment only qvf, qvd and csv files are supported (Press Enter to exit)"); Console.ReadLine(); } } else { //Print the possible options var options = PrintOptions(welcome + "", new string[] { "1. Clear all temporary apps", "2. Add action on right click", "3. Remove the right click action", "4. View documentation (in GitHub)", "0. Exit" }, true); switch (options) { // Exit case 0: { Console.Clear(); Console.WriteLine("Bye!"); Environment.Exit(0); break; } // Get all apps and filter only the ones that have app name prefix in it. // List all the prefixed ones and ask the user ro confirm deletion of all. // If no apps were found - exit case 1: using (hub = location.Hub()) { int tempAppsCount = 0; List <string> tempAppNames = new List <string>(); List <string> tempAppIds = new List <string>(); foreach (IAppIdentifier appIdentifier in location.GetAppIdentifiers()) { if (appIdentifier.AppName.IndexOf(tempAppPrefix) > -1) { tempAppsCount++; tempAppNames.Add(appIdentifier.AppName); tempAppIds.Add(appIdentifier.AppId); } } if (tempAppsCount > 0) { Console.Clear(); Console.WriteLine(tempAppsCount + " temp apps found"); Console.WriteLine("---------------------------------"); for (int i = 0; i < tempAppNames.Count; i++) { Console.WriteLine(tempAppNames[i]); } Console.WriteLine("---------------------------------"); Console.WriteLine(); Console.Write("Delete all? (y/n)"); string response = Console.ReadLine(); if (response.ToLower() == "y") { for (int i = 0; i < tempAppIds.Count; i++) { hub.DestroyApp(tempAppIds[i]); } Console.Clear(); Console.WriteLine(tempAppsCount + " app(s) deleted."); Console.WriteLine("Bye!"); Environment.Exit(0); } else { Console.Clear(); Console.WriteLine("Bye!"); Environment.Exit(0); } } else { Console.Clear(); Console.WriteLine("0 Temp apps found"); Console.WriteLine("Bye!"); Environment.Exit(0); } } break; // Write to registry the values and keys needed for the context menu // Also the folder is added to PATH variable so the app is accessible from everywhere // This is madatory step after the app is started for the first time case 2: { Console.Clear(); Microsoft.Win32.RegistryKey key; key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(keyPath); key.SetValue("", "Load in Qlik Sense"); key.SetValue("Icon", sensePath); key.Close(); key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(keyPath + "\\command"); key.SetValue("", currentFolder + currentExeName + " %1"); var enviromentPath = System.Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User); System.Environment.SetEnvironmentVariable("PATH", enviromentPath + ";" + currentFolder, EnvironmentVariableTarget.User); Console.WriteLine("Right click option is added"); Console.WriteLine("Folder is added to Path variable - just type 'OpenWithSense' in command prompth to see the options again"); Console.WriteLine("Bye!"); Environment.Exit(0); break; } // Delete the registry and the portion of PATH value // Kinda uninstall option case 3: { Console.Clear(); Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser; key.DeleteSubKeyTree(keyPath, false); key.Close(); var enviromentPath = System.Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User); enviromentPath = enviromentPath.Replace(currentFolder, ""); System.Environment.SetEnvironmentVariable("PATH", enviromentPath, EnvironmentVariableTarget.User); Console.WriteLine("Right click option is removed"); Console.WriteLine("Path variable is changed and the base folder is removed from it"); Console.WriteLine("Bye!"); Environment.Exit(0); break; } // Opens the browser to the GitHub page of this app repo case 4: { Console.Clear(); Process.Start("https://github.com/countnazgul/open-with-sense/blob/master/README.md"); Environment.Exit(0); break; } // Exit at any non valid selection default: { Console.Clear(); Console.WriteLine("Invalid selection."); Console.WriteLine("Bye!"); Environment.Exit(0); break; } } } }