Beispiel #1
0
        private bool PollSingleTask(IQMS client, Guid execId, int pollInterval, int timeout)
        {
            EDXStatus result = null;

            do
            {
                //depurar aca
                try
                {
                    result = client.GetEDXTaskStatus(Guid.Empty, execId);
                } catch
                {
                    return(false);
                }
                Thread.Sleep(pollInterval * 1000);
                if (result.TaskStatus == TaskStatusValue.Completed || result.TaskStatus == TaskStatusValue.Failed)
                {
                    break;
                }
            } while (1 == 1);

            if (result.TaskStatus == TaskStatusValue.Failed)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public short TriggerAndMonitorTask(string sApp, string sServer, string sVarName, string[] sVarValue, Form1 Principal)
        {
            string applicationTask;
            Uri    _qms    = new Uri("http://" + sServer + ":4799/QMS/Service");
            IQMS   client  = CreateQMSAPIClient(_qms, Principal);
            bool   bResult = false;
            TriggerEDXTaskResult triggerResult;

            byte serverType = getServerType(client);

            applicationTask = sApp;
            if (serverType == 1)
            {
                applicationTask = applicationTask.Replace(".qvw", "");
                if (applicationTask.LastIndexOf('\\') > 0)
                {
                    applicationTask = applicationTask.Substring(applicationTask.LastIndexOf('\\') + 1);
                }
                Console.WriteLine(applicationTask);
            }

            if (client != null)
            {
                try
                {
                    triggerResult = client.TriggerEDXTask(Guid.Empty, applicationTask, string.Empty, sVarName, sVarValue);
                    if (triggerResult.EDXTaskStartResult == EDXTaskStartResult.TaskIsAlreadyRunning)
                    {
                        return(5);
                    }
                }
                catch (Exception ex)
                {
                    Principal.setEstadoRecarga(System.Security.Principal.WindowsIdentity.GetCurrent().Name + " " + ex.Message);
                    return(1); //error de permisos
                }
                if (triggerResult.EDXTaskStartResult == EDXTaskStartResult.Success)
                {
                    bResult = PollSingleTask(client, triggerResult.ExecId, _pollIntervall, _timeout);
                }
                else
                {
                    return(2); //error de recarga no se pudo iniciar la recarga o tarea no existe
                }
            }
            else
            {
                return(3); //error de conexion
            }
            if (bResult == true)
            {
                sendF5();
                return(0);
            }
            return(4); //error de recarga(Codigo) o se la cancelo de consola
        }
Beispiel #3
0
        private static ServiceInfo FindService(IQMS client, ServiceTypes serviceType, string serviceName)
        {
            List <ServiceInfo> service = client.GetServices(serviceType);

            if (service != null && service.Count > 0)
            {
                return(service.FirstOrDefault(x => x.Name.Equals(serviceName)));
            }
            return(null);
        }
Beispiel #4
0
 private byte getServerType(IQMS client)
 {
     if (isPublisher(client))
     {
         return(1);
     }
     else
     {
         return(2);
     }
 }
        public QlikQvExport(string[] args, CommunicationSupport commSup, IQMS qmsClient)
        {
            client      = qmsClient;
            commSupport = commSup;

            try
            {
                foreach (var arg in args)
                {
                    string parameter      = arg.Substring(0, arg.IndexOf('='));
                    string parameterValue = arg.Substring(arg.LastIndexOf('=') + 1);

                    switch (parameter.ToLower())
                    {
                    case "-space":
                        space = parameterValue;
                        break;

                    case "-protocol":
                        protocol = parameterValue;
                        break;

                    case "-qvscluster":
                        qvsCluster = parameterValue;
                        break;

                    case "-qvwsmachine":
                        qvwsMachine = parameterValue;
                        break;

                    case "-category":
                        category = parameterValue;
                        break;

                    case "-filename":
                        csvFileName = parameterValue;
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception)
            {
                commSupport.PrintMessage("Exception when reading parameters. Run help command for information about usage", true);
            }


            protocol = string.IsNullOrEmpty(protocol) ? "http" : protocol;
            _qms     = new Uri(protocol + "://localhost:4799/QMS/Service");
            links    = new List <string>();
            ExportLinks();
        }
Beispiel #6
0
        private static void RunInLinkMode()
        {
            if (string.IsNullOrEmpty(qvsCluster) || string.IsNullOrEmpty(qvwsMachine) ||
                string.IsNullOrEmpty(csvFileName))
            {
                commSupport.PrintMessage("Please supply required parameters", true);
            }
            client = CreateQMSAPIClient(qms);
            QlikQvExport qvExportLinks = new QlikQvExport(commSupport, client);

            qvExportLinks.ExportLinks(space, protocol, qvsCluster, qvwsMachine, category, csvFileName);
        }
Beispiel #7
0
 private bool isPublisher(IQMS client)
 {
     try
     {
         License license = client.GetLicense(LicenseType.Publisher, Guid.Empty);
         return(license.LEFOk);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(false);
 }
Beispiel #8
0
        private static IQMS CreateQMSAPIClient(Uri uri)
        {
            QMSClient client = null;

            try
            {
                client = new QMSClient("BasicHttpBinding_IQMS", uri.AbsoluteUri);
                ServiceKeyEndpointBehavior serviceKeyEndpointBehavior = new ServiceKeyEndpointBehavior();
                client.Endpoint.Behaviors.Add(serviceKeyEndpointBehavior);
                ServiceKeyClientMessageInspector.ServiceKey = client.GetTimeLimitedServiceKey();
            }
            catch (Exception e)
            {
                commSupport.PrintMessage("Exception when creating QMs client, run help command for information about usage. Exeception: " + e.Message, true);
            }
            return(client);
        }
Beispiel #9
0
        private static void RunInDocMode()
        {
            if (string.IsNullOrEmpty(cloudDeploymentUrl) || string.IsNullOrEmpty(qvsCluster) || string.IsNullOrEmpty(jwtToken))
            {
                commSupport.PrintMessage("Please supply required parameters", true);
            }

            client = CreateQMSAPIClient(qms);

            try
            {
                SetUpStartValues();
                DistributeDocumentsOrFiles(commSupport, proxyname, proxyport);
            }
            catch (Exception e)
            {
                commSupport.PrintMessage("Exception: " + e.Message, true);
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            commSupport = new CommunicationSupport();
            client      = CreateQMSAPIClient(qms);
            if (args.Length == 1 && args[0].Equals("-help"))
            {
                DisplayDocUploaderHelp();
            }


            if (args.Contains("-mode=link"))
            {
                RunInLinkMode(args);
            }
            else if (args.Contains("-mode=doc"))
            {
                RunInDocMode(args);
            }
            else
            {
                commSupport.PrintMessage("'mode' parameter missing or faulty", true);
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            if (args.Length == 0 || args[0] == "-h")
            {
                PrintUsage();
                return;
            }

            //try
            //{
                // create a QMS API client
                apiClient = new QMSClient();

                //If you want to connect to a server different from the one used when creating the service reference,
                //do as follows:                                
                // 
                //NTLM only (default installation)
                //IQMS apiClient = new QMSClient("BasicHttpBinding_IQMS", "http://*****:*****@"\\unc\some", Name = "MyMount" });
                //    // save settings
                //    apiClient.SaveQVSSettings(qvsSettings);
                //    Console.WriteLine("Settings saved. New mount added.");
                //}
            //}
            //catch (System.Exception ex)
            //{
            //    Console.WriteLine("An exception occurred: " + ex.Message);
            //}
            // wait for user to press any key
            //Console.ReadLine();
        }
Beispiel #12
0
 public QlikQvExport(CommunicationSupport commSup, IQMS qmsClient)
 {
     client      = qmsClient;
     commSupport = commSup;
 }
Beispiel #13
0
        static int TriggerTask(EDXTask t)
        {
            /*
             * Completed   0   The task has completed successfully. (same as 6)
             * Waiting     1   The task is waiting to be executed.
             * Running     2   The task is running
             * Aborting    3   The task is aborting the execution.
             * Failed      4   The task failed.
             * Warning     5   The task completed with a warning.
             * Completed   6   The task has completed successfully.
             * Error       9   An unknown error occured
             * Exception   10  Catch exception error
             */

            var exitCode = 0;

            LogProperties logProperties = new LogProperties {
                TaskNameOrId = t.TaskNameOrId, ExecId = "-1"
            };

            try
            {
                // Create a QMS API client
                IQMS apiClient = String.IsNullOrEmpty(t.ServiceAddress) ? new QMSClient() : new QMSClient("BasicHttpBinding_IQMS", t.ServiceAddress);

                // Retrieve a time limited service key
                ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey();

                TaskInfo taskInfo = new TaskInfo();

                if (!IsGuid(t.TaskNameOrId))
                {
                    List <TaskInfo> taskList = apiClient.FindEDX(t.TaskNameOrId);

                    // Find correct task with support for multiple qds
                    if (taskList.Count > 0)
                    {
                        int i = 0;

                        for (i = 0; i < taskList.Count; i++)
                        {
                            if (taskList[i].Name == t.TaskNameOrId)
                            {
                                break;
                            }
                        }

                        taskInfo = new TaskInfo
                        {
                            Name    = taskList[i].Name,
                            ID      = taskList[i].ID,
                            QDSID   = taskList[i].QDSID,
                            Enabled = taskList[i].Enabled
                        };
                    }
                }
                else
                {
                    taskInfo = apiClient.GetTask(Guid.Parse(t.TaskNameOrId));
                }

                if (taskInfo.Name != null)
                {
                    // Trigger the task
                    TriggerEDXTaskResult result = apiClient.TriggerEDXTask(Guid.Empty, taskInfo.Name, t.Password, t.VariableName, t.VariableValues);

                    if (result.EDXTaskStartResult == EDXTaskStartResult.Success)
                    {
                        logProperties.ExecId = result.ExecId.ToString();

                        if (t.Verbosity > 0)
                        {
                            LogHelper.Log(LogLevel.Info, String.Format("Name: {0}, ID: {1}, Enabled: {2}, Sleep: {3} seconds, Timeout: {4}", taskInfo.Name, taskInfo.ID, taskInfo.Enabled ? "Yes" : "No", t.Sleep / 1000, t.TimeOut == -1 ? "Indefinitely" : t.TimeOut / 60000 + " minutes"), logProperties);
                        }

                        LogHelper.Log(LogLevel.Info, "Started", logProperties);

                        EDXStatus executionStatus = null;

                        if (t.TimeOut != 0)
                        {
                            // Wait until the task is completed or TIMEOUT has passed.
                            SpinWait.SpinUntil(() =>
                            {
                                Thread.Sleep(t.Sleep);

                                // Retrieve a new service key if sleep time is above 18 minutes to be safe (timeout is 20 minutes in QV11)
                                if (t.Sleep > 18 * 60 * 1000)
                                {
                                    if (t.Verbosity > 1)
                                    {
                                        LogHelper.Log(LogLevel.Info, "GetTimeLimitedServiceKey()", logProperties);
                                    }

                                    ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey();
                                }

                                // Get the current state of the task.
                                try
                                {
                                    executionStatus = apiClient.GetEDXTaskStatus(Guid.Empty, result.ExecId);
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.Log(LogLevel.Warn, String.Format("{0}", ex.Message.Replace(Environment.NewLine, " ")), logProperties);
                                }

                                if (executionStatus != null && t.Verbosity > 1 && executionStatus.TaskStatus != TaskStatusValue.Running)
                                {
                                    LogHelper.Log(LogLevel.Info, executionStatus.TaskStatus.ToString(), logProperties);
                                }

                                // Return true if the task has completed.
                                return(executionStatus != null && (executionStatus.TaskStatus != TaskStatusValue.Running && executionStatus.TaskStatus != TaskStatusValue.Waiting));
                            }, t.TimeOut);

                            // Write the result
                            if (executionStatus != null)
                            {
                                if (executionStatus.TaskStatus == TaskStatusValue.Completed)
                                {
                                    // datetime parsing needs culture formatting, catch it for now and avoid...
                                    try
                                    {
                                        TimeSpan span = DateTime.Parse(executionStatus.FinishTime).Subtract(DateTime.Parse(executionStatus.StartTime));
                                        LogHelper.Log(LogLevel.Info, String.Format("{0} (Duration: {1})", executionStatus.TaskStatus, span), logProperties);
                                    }
                                    catch (Exception)
                                    {
                                        LogHelper.Log(LogLevel.Info, String.Format("{0}", executionStatus.TaskStatus), logProperties);
                                    }
                                }
                                else
                                {
                                    // If something went wrong, point to the logfile for the task execution
                                    exitCode = (Int32)executionStatus.TaskStatus;
                                    LogHelper.Log(LogLevel.Error, String.Format("{0} (Error code: {1})", executionStatus.TaskStatus, exitCode), logProperties);
                                    LogHelper.Log(LogLevel.Error, "Logfile: " + executionStatus.LogFileFullPath, logProperties);
                                }
                            }
                            else
                            {
                                exitCode = 9;
                                LogHelper.Log(LogLevel.Error, String.Format("Failed to get execution status (Error code: {0})", exitCode), logProperties);
                            }
                        }
                    }
                    else
                    {
                        exitCode = 9;
                        LogHelper.Log(LogLevel.Error, String.Format("{0} (Error code: {1})", result.EDXTaskStartResult, exitCode), logProperties);
                    }
                }
                else
                {
                    exitCode = 9;
                    LogHelper.Log(LogLevel.Error, "TaskNotFound (Error code: 9)", logProperties);
                }
            }
            catch (Exception ex)
            {
                exitCode = 10;
                LogHelper.Log(LogLevel.Error, String.Format("{0} (Error code: {1})", ex.Message.Replace(Environment.NewLine, " "), exitCode), logProperties);
            }

            return(exitCode);
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            if (args.Length == 0 || args[0] == "-h")
            {
                PrintUsage();
                return;
            }

            //try
            //{
            // create a QMS API client
            apiClient = new QMSClient();

            //If you want to connect to a server different from the one used when creating the service reference,
            //do as follows:
            //
            //NTLM only (default installation)
            //IQMS apiClient = new QMSClient("BasicHttpBinding_IQMS", "http://*****:*****@"\\unc\some", Name = "MyMount" });
            //    // save settings
            //    apiClient.SaveQVSSettings(qvsSettings);
            //    Console.WriteLine("Settings saved. New mount added.");
            //}
            //}
            //catch (System.Exception ex)
            //{
            //    Console.WriteLine("An exception occurred: " + ex.Message);
            //}
            // wait for user to press any key
            //Console.ReadLine();
        }