Esempio n. 1
0
        private static void PrintQlikSenseVersionNumber()
        {
            try
            {
                var              uri      = new Uri("https://myQlikSenseServer.myDomain.com");
                ILocation        location = Qlik.Engine.Location.FromUri(uri);
                X509Certificate2 x509     = new X509Certificate2();
                //Create X509Certificate2 object from .cert file.
                byte[] rawData = ReadFile("PathToMyCertFile.pfx");
                x509.Import(rawData, "PasswordToMyCert", X509KeyStorageFlags.UserKeySet);
                X509Certificate2Collection certificateCollection = new X509Certificate2Collection(x509);
                // Defining the location as a direct connection to Qlik Sense Server
                location.AsDirectConnection("domain", "user", certificateCollection: certificateCollection);

                using (IHub hub = location.Hub(noVersionCheck: true))
                {
                    Console.WriteLine(hub.EngineVersion().ComponentVersion);
                }
            }
            catch (CommunicationErrorException cex)
            {
                Console.WriteLine("Can not connect to Qlik Sense instance, check that Qlik Sense is running." + Environment.NewLine + cex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("General error." + Environment.NewLine + ex.Message);
            }
            Console.ReadLine();
        }
Esempio n. 2
0
        private static void GetEngineObjects(string centralNodeHostname, TelemetryMetadata metadata, int engineRequestTimeoutMS)
        {
            TelemetryDashboardMain.Logger.Log(string.Format("Engine request timeout set to: {0} ms (default is: 30000 ms)", engineRequestTimeoutMS.ToString()), LogLevel.Info);

            Qlik.Sense.JsonRpc.RpcConnection.Timeout = engineRequestTimeoutMS;

            string    wssPath  = "https://" + centralNodeHostname + ":4747";
            ILocation location = Location.FromUri(new Uri(wssPath));

            X509Certificate2Collection certificateCollection = new X509Certificate2Collection(CertificateConfigHelpers.Certificate);

            // Defining the location as a direct connection to Qlik Sense Server
            location.AsDirectConnection("INTERNAL", "sa_api", certificateCollection: certificateCollection);

            int totalApps  = metadata.Apps.Count;
            int currentApp = 0;

            TelemetryDashboardMain.Logger.Log("Will start to fetch all app objects from the engine.", LogLevel.Info);

            foreach (KeyValuePair <Guid, QRSApp> appTuple in metadata.Apps)
            {
                currentApp++;
                TelemetryDashboardMain.Logger.Log(string.Format("App {0} of {1} - Checking to see if visualaizations fetch is needed for app '{2}' with ID '{3}' ", currentApp, totalApps, appTuple.Value.Name, appTuple.Key.ToString()), LogLevel.Debug);

                if (appTuple.Value.VisualizationUpdateNeeded)
                {
                    TelemetryDashboardMain.Logger.Log(string.Format("Getting visualizations for app '{0}' with ID '{1}' ", appTuple.Value.Name, appTuple.Key.ToString()), LogLevel.Info);
                    try
                    {
                        IAppIdentifier appIdentifier = new AppIdentifier()
                        {
                            AppId = appTuple.Key.ToString()
                        };
                        using (IApp app = location.App(appIdentifier, null, true))
                        {
                            IEnumerable <ISheet> sheetList = app.GetSheets();
                            foreach (ISheet sheet in sheetList)
                            {
                                ISheetLayout          sheetObject = (SheetLayout)sheet.GetLayout();
                                IList <Visualization> vizs        = new List <Visualization>();
                                sheetObject.Cells.ToList().ForEach(c => vizs.Add(new Visualization(c.Name, c.Type)));
                                metadata.Apps[appTuple.Key].Sheets.FirstOrDefault(s => s.Value.EngineObjectID == sheetObject.Info.Id).Value.SetSheetsList(vizs);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        TelemetryDashboardMain.Logger.Log("Failed to get engine objects from App: " + appTuple.Key.ToString() + ". Message: " + e.Message, LogLevel.Error);
                        TelemetryDashboardMain.Logger.Log("Skipping app: " + appTuple.Key.ToString(), LogLevel.Error);
                    }
                }
            }
            TelemetryDashboardMain.Logger.Log("Done getting all app objects from the engine.", LogLevel.Info);
        }
Esempio n. 3
0
        private static ILocation SetupConnection(Uri uri)
        {
            // Qlik Sense Server on a local machine.
            // Note 1. The uri must match the host name that the server certificate was issued to when installing Qlik Sense. If not, the certificate validation will fail.
            // Note 2. The account executing this program must the same as the one running the Qlik Sense services.
            ILocation location = Qlik.Engine.Location.FromUri(uri);

            // Defines the location as a direct connection. userDirectory contains the name of the domain / user directory (AD). userId contains the user. extendedSecurityEnvironment defines whether there is an extended security environment (default is false).
            location.AsDirectConnection(userDirectory: "myDomain", userId: "myUser", extendedSecurityEnvironment: false);

            return(location);
        }
Esempio n. 4
0
        // Connects to the Qlik Sense server with the UserID and UserDirectory provided (Qlik Sense users)
        public void QSConnectServerHeader(string UserId, string HeaderAuthName, string VirtualProxyPath = "",
                                          Boolean UseSSL = false, Boolean CheckSDKVersion = true)
        {
            QSIsConnected = false;
            string strUri = qsServer;
            Uri    uri    = new Uri(strUri);

            qsLocation = Qlik.Engine.Location.FromUri(uri);
            if (VirtualProxyPath.Trim() != "")
            {
                qsLocation.VirtualProxyPath = VirtualProxyPath;
            }

            //qsLocation.AsStaticHeaderUserViaProxy(UserId, HeaderAuthName, UseSSL, false);
            //qsLocation.AsDirectConnection("qlikdbs2", UserId, certificateValidation: false);
            //qsLocation.AsNtlmUserViaProxy(true, new System.Net.NetworkCredential { Domain = "qlikdbs2", Password = "******", UserName = "******" }, false);

            X509Certificate2 x509 = new X509Certificate2();

            //Create X509Certificate2 object from .cert file.
            byte[] rawData = ReadFile("client.pfx");
            x509.Import(rawData, "test@123", X509KeyStorageFlags.UserKeySet);
            X509Certificate2Collection certificateCollection = new X509Certificate2Collection(x509);

            // Defining the location as a direct connection to Qlik Sense Server
            qsLocation.AsDirectConnection("qlikdbs2", "usera", certificateCollection: certificateCollection, certificateValidation: false);

            qsLocation.IsVersionCheckActive = CheckSDKVersion;
            IHub MyHub = qsLocation.Hub();

            QSUserId         = UserId;
            QSHeaderAuthName = HeaderAuthName;

            QSIsConnected = true;

            Console.WriteLine("QSEasy connected to Qlik Sense version: " + MyHub.ProductVersion());
            Console.WriteLine("UserID: " + UserId + " - VirtualProxy: " + VirtualProxyPath);
        }
Esempio n. 5
0
        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();
        }