Esempio n. 1
0
        public static void InitializeQuartz()
        {
            try
            {
                Task.Run(async() =>
                {
                    StdSchedulerFactory factory = new StdSchedulerFactory(LocalConfig());

                    // get a scheduler
                    IScheduler sched = await factory.GetScheduler();
                    // sched.ListenerManager.AddTriggerListener(new TriggerListener("TriggerListner"));
                    //ILogger Logger = new MemoryLogger(1000);
                    //sched.ListenerManager.AddJobListener(Logger);
                    //sched.ListenerManager.AddTriggerListener(Logger);
                    //sched.ListenerManager.AddSchedulerListener(Logger);

                    if (!sched.IsStarted)
                    {
                        await sched.Start();
                    }

                    //  Console.WriteLine("Local Server has been started..");

                    //while (true)
                    //{
                    //    Thread.Sleep(60 * 60000);
                    //}
                }).Wait();
            }
            catch (Exception e)
            {
                BOTService serviceMethod = new BOTService();
                serviceMethod.insertLog("Issue In Initializing Quartz", "Exception: " + e.Message, 0, 0); //No Tenant Id and GroupId at this Point so setting it to 0.
            }
        }
Esempio n. 2
0
        static void Main()
        {
            BOTService client = new BOTService();

            // Use the 'client' variable to call operations on the service.

            // Always close the client.
            QuartzHelper quartzHelper = new QuartzHelper();

            quartzHelper.CreateJob("A", "B", "C", "0 0/1 * 1/1 * ? *", 2, 1);
        }
Esempio n. 3
0
        public async void CreateJob(string serverName, string strQueueName, string strBotName, string strChronExp, int groupid, int tenantid)
        {
            string strTenantid = string.Empty;
            string strGroupid  = string.Empty;

            try
            {
                NameValueCollection configuration = LocalConfig();                          //Defining Local Configuation and mapping with DataBase
                StdSchedulerFactory factory       = new StdSchedulerFactory(configuration); // Creating Scheduler Factory Object.
                IScheduler          sched         = await factory.GetScheduler();           // Initializing Default Scheduler.

                strTenantid = Convert.ToString(tenantid);
                strGroupid  = Convert.ToString(groupid);

                // define the job and tie it to our HelloJob class
                IJobDetail job = JobBuilder.Create <HelloJob>()
                                 .WithIdentity(strBotName + strQueueName + strChronExp, strBotName)
                                 .UsingJobData("strChronExp", strChronExp)
                                 .UsingJobData("ServerName", serverName)
                                 .UsingJobData("DateTime", DateTime.Now.ToString())
                                 .UsingJobData("QueueName", strQueueName)
                                 .UsingJobData("BotName", strBotName)
                                 .UsingJobData("tenantid", strTenantid)
                                 .UsingJobData("strGroupid", strGroupid)
                                 .Build();

                // Trigger the job to run now, and then every 40 seconds
                ITrigger trigger = TriggerBuilder.Create()                                                        //Trigger the Job and Run.
                                   .WithIdentity(strBotName + strQueueName + strChronExp, strBotName)
                                   .ForJob(job.Key)                                                               // To identify job using Key
                                   .WithCronSchedule(strChronExp, cron => { cron.InTimeZone(TimeZoneInfo.Utc); }) //"0 0/1 * 1/1 * ? *"
                                   .StartNow()
                                   .Build();

                await sched.ScheduleJob(job, trigger);                                                 //Schedule the Job using Trigger

                //Quartz.JobKey jobKey = new JobKey(strBotName + strQueueName + strChronExp);
                //await sched.DeleteJob(jobKey);

                //BOTService botService = new BOTService();
            }
            catch (Exception e)
            {
                BOTService serviceMethod = new BOTService();
                serviceMethod.insertLog("CreateJob Exception", "Exception: " + e.Message, Convert.ToInt32(strGroupid), Convert.ToInt32(strTenantid));
            }
        }
Esempio n. 4
0
        public async void DeleteJob(string serverName, string strQueueName, string strBotName, string strChronExp, int tenantid)
        {
            try
            {
                NameValueCollection configuration = LocalConfig();
                StdSchedulerFactory factory       = new StdSchedulerFactory(configuration);
                IScheduler          sched         = await factory.GetScheduler();

                Quartz.JobKey jobKey = new JobKey(strBotName + strQueueName + strChronExp);
                await sched.DeleteJob(jobKey);
            }
            catch (Exception e)
            {
                BOTService serviceMethod = new BOTService();
                serviceMethod.insertLog("Delete Job Exception", "Exception: " + e.Message, tenantid, tenantid); //No Group Id Found at this point.
            }
        }
Esempio n. 5
0
        public bool AutomationRequest(RequestInput _requestInput)
        {
            //string strExchangeTopic = ConfigurationManager.AppSettings["ExchangeTopicName"];
            //string strRoutingLevel = ConfigurationManager.AppSettings["RoutingSupport"];

            string     strExchangeTopic = string.Empty;
            string     strRoutingLevel  = string.Empty;
            string     routingKey       = string.Empty;
            BOTService client           = new BOTService();

            strExchangeTopic = "robot.x.automation";
            strRoutingLevel  = "ProfileLevel";

            DataTable dt = client.GetRQDetailsByName(_requestInput.AutomationGroupName, _requestInput.TenantName);

            if (dt.Rows.Count > 0)
            {
                string servername = dt.Rows[0][0].ToString();

                var factory = new ConnectionFactory()
                {
                };
                factory.UserName = dt.Rows[0][2].ToString();
                factory.Password = dt.Rows[0][3].ToString();
                factory.HostName = dt.Rows[0][0].ToString();
                factory.Port     = (int)dt.Rows[0][1];

                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        _requestInput.UniqueRequestNumber = "MsgReqNo_" + DateTime.Now.Ticks.ToString();

                        if (strRoutingLevel == "ProfileLevel")
                        {
                            routingKey = _requestInput.TenantName + "." + _requestInput.AutomationGroupName;
                        }
                        else
                        {
                            routingKey = _requestInput.TenantName + "." + _requestInput.AutomationGroupName + "." + _requestInput.AutomationProcessName;
                        }

                        var props = channel.CreateBasicProperties();
                        props.DeliveryMode = 2; //persistent
                        props.Headers      = new Dictionary <string, object>();
                        props.Headers["source_message_id"] = "MsgReqNo_" + DateTime.Now.Ticks.ToString();

                        #region CalculateQueueDepth

                        #endregion CalculateQueueDepth

                        //var message = RobotLibrary.XMLHelper.Serialize(_requestInput);
                        var message = JsonConvert.SerializeObject(_requestInput);
                        var body    = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish(exchange: strExchangeTopic,
                                             routingKey: routingKey,
                                             basicProperties: props,
                                             body: body);
                    }
                return(true); //acknowledgement
            }
            return(false);
        }
Esempio n. 6
0
        public bool AutomationRequestForProcess(string action, string botname, string ProcessName, DataTable result, string chronExpression)
        {
            string UserId      = string.Empty;
            string BotId       = string.Empty;
            string Password    = string.Empty;
            string RobotPwd    = string.Empty;
            int    TenantId    = 0;
            int    GroupId     = 0;
            string ServerName  = string.Empty;
            string MachineName = string.Empty;
            int    PortNumber  = 0;

            BOTService botServiceClient = new BOTService();

            try
            {
                if ((result.Rows[0][1] != null) && (result.Rows[0][1] != System.DBNull.Value))
                {
                    UserId = (string)result.Rows[0][1];
                }
                if ((result.Rows[0][2] != null) && (result.Rows[0][2] != System.DBNull.Value))
                {
                    Password = (string)result.Rows[0][2];
                }
                if ((result.Rows[0][3] != null) && (result.Rows[0][3] != System.DBNull.Value))
                {
                    TenantId = (int)result.Rows[0][3];
                }
                if ((result.Rows[0][3] != null) && (result.Rows[0][3] != System.DBNull.Value))
                {
                    GroupId = (int)result.Rows[0][4];
                }
                if ((result.Rows[0][7] != null) && (result.Rows[0][7] != System.DBNull.Value))
                {
                    ServerName = (string)result.Rows[0][7];
                }
                if ((result.Rows[0][8] != null) && (result.Rows[0][8] != System.DBNull.Value))
                {
                    PortNumber = (int)result.Rows[0][8];
                }
                if ((result.Rows[0][10] != null) && (result.Rows[0][10] != System.DBNull.Value))
                {
                    MachineName = (string)result.Rows[0][10];
                }
                if ((result.Rows[0][11] != null) && (result.Rows[0][11] != System.DBNull.Value))
                {
                    BotId = (string)result.Rows[0][11];
                }
                if ((result.Rows[0][12] != null) && (result.Rows[0][12] != System.DBNull.Value))
                {
                    RobotPwd = (string)result.Rows[0][12];
                }
                string message = action + "!#~=~!#" + botname + "!#~=~!#" + BotId + "!#~=~!#" + RobotPwd + "!#~=~!#" + TenantId + "!#~=~!#" + GroupId + "!#~=~!#" + "robot.q.Process" + "!#~=~!#" + chronExpression;

                var factory = new ConnectionFactory()
                {
                    HostName = ServerName
                };
                factory.UserName = UserId;
                factory.Password = Password;
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        //var props = channel.CreateBasicProperties();
                        //props.DeliveryMode = 1; //non persistent
                        //props.Headers = new Dictionary<string, object>();

                        //Logger.Log.Logger.LogData("ScheduleAdded", Logger.LogLevel.Debug);

                        /*load Generator Code*/
                        if (action == "Start" || "schedule" == action)
                        {
                            try
                            {
                                ConnectionFactory factory1 = new ConnectionFactory();

                                factory1.HostName = "localhost";
                                factory1.UserName = "******";
                                factory1.Password = "******";

                                using (var connection1 = factory.CreateConnection())
                                {
                                    using (var channel1 = connection.CreateModel())
                                    {
                                        //channel1.QueuePurge("robot.q.automation");
                                    }
                                }
                                //BOTService AutomationRequest = new BOTService();

                                RequestInput _requestInput = new RequestInput();

                                _requestInput.TenantName            = "InnoWise";                   // need to remove Hardcoding.
                                _requestInput.AutomationGroupName   = "Default";
                                _requestInput.AutomationProcessName = ProcessName;
                                List <string> lstSearchParam = new List <string>();
                                lstSearchParam.Add("SearchField1");
                                lstSearchParam.Add("Infosys Ltd.");
                                _requestInput.InputSearchParameters      = lstSearchParam;
                                _requestInput.RequestNumber              = "100";
                                _requestInput.RequestTimeoutSLAInSeconds = 100000;
                                AutomationRequest(_requestInput);
                            }
                            catch (Exception e)
                            {
                            }
                        }


                        //BOTService botServiceClient = new BOTService();
                        int result1        = botServiceClient.PiyushLogs("Process Started By Piyush in Hello Job");
                        int ScheduleStatus = botServiceClient.CreateScheduleStatus("robot.q.Process", botname, chronExpression, "STARTED", GroupId, TenantId, DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"), "");

                        var props = channel.CreateBasicProperties();
                        props.DeliveryMode = 1; //non persistent
                        props.Headers      = new Dictionary <string, object>();

                        var body = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish(exchange: "",
                                             routingKey: MachineName,
                                             basicProperties: props,
                                             body: body);
                    }
                return(true); //acknowledgement
            }
            catch (Exception ex)
            {
                int ScheduleStatus = botServiceClient.CreateScheduleStatus("robot.q.Process", botname, chronExpression, "ERROR", GroupId, TenantId, DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToLocalTime().ToString());
                int ScheduleError  = botServiceClient.PiyushLogs("Error in HelloJob : " + ex.Message);
                return(false);
            }
        }
Esempio n. 7
0
        public bool AutomationRequest(string action, string botname, string QueueName, DataTable result, string chronExpression)
        {
            string UserId      = string.Empty;
            string BotId       = string.Empty;
            string Password    = string.Empty;
            string RobotPwd    = string.Empty;
            int    TenantId    = 0;
            int    GroupId     = 0;
            string ServerName  = string.Empty;
            string MachineName = string.Empty;
            int    PortNumber  = 0;

            BOTService botServiceClient = new BOTService();

            try
            {
                if ((result.Rows[0][1] != null) && (result.Rows[0][1] != System.DBNull.Value))
                {
                    UserId = (string)result.Rows[0][1];
                }
                if ((result.Rows[0][2] != null) && (result.Rows[0][2] != System.DBNull.Value))
                {
                    Password = (string)result.Rows[0][2];
                }
                if ((result.Rows[0][3] != null) && (result.Rows[0][3] != System.DBNull.Value))
                {
                    TenantId = (int)result.Rows[0][3];
                }
                if ((result.Rows[0][3] != null) && (result.Rows[0][3] != System.DBNull.Value))
                {
                    GroupId = (int)result.Rows[0][4];
                }
                if ((result.Rows[0][7] != null) && (result.Rows[0][7] != System.DBNull.Value))
                {
                    ServerName = (string)result.Rows[0][7];
                }
                if ((result.Rows[0][8] != null) && (result.Rows[0][8] != System.DBNull.Value))
                {
                    PortNumber = (int)result.Rows[0][8];
                }
                if ((result.Rows[0][10] != null) && (result.Rows[0][10] != System.DBNull.Value))
                {
                    MachineName = (string)result.Rows[0][10];
                }
                if ((result.Rows[0][11] != null) && (result.Rows[0][11] != System.DBNull.Value))
                {
                    BotId = (string)result.Rows[0][11];
                }
                if ((result.Rows[0][12] != null) && (result.Rows[0][12] != System.DBNull.Value))
                {
                    RobotPwd = (string)result.Rows[0][12];
                }
                string message = action + "!#~=~!#" + botname + "!#~=~!#" + BotId + "!#~=~!#" + RobotPwd + "!#~=~!#" + TenantId + "!#~=~!#" + GroupId + "!#~=~!#" + QueueName + "!#~=~!#" + chronExpression;

                var factory = new ConnectionFactory()
                {
                    HostName = ServerName
                };
                factory.UserName = UserId;
                factory.Password = Password;
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        //BOTService botServiceClient = new BOTService();
                        int result1        = botServiceClient.PiyushLogs("Process Started By Piyush in Hello Job");
                        int ScheduleStatus = botServiceClient.CreateScheduleStatus(QueueName, botname, chronExpression, "STARTED", GroupId, TenantId, DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"), "");

                        var props = channel.CreateBasicProperties();
                        props.DeliveryMode = 1; //non persistent
                        props.Headers      = new Dictionary <string, object>();

                        var body = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish(exchange: "",
                                             routingKey: MachineName,
                                             basicProperties: props,
                                             body: body);
                    }
                return(true); //acknowledgement
            }
            catch (Exception ex)
            {
                int ScheduleStatus = botServiceClient.CreateScheduleStatus(QueueName, botname, chronExpression, "ERROR", GroupId, TenantId, DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToLocalTime().ToString());
                int ScheduleError  = botServiceClient.PiyushLogs("Error in HelloJob : " + ex.Message);
                return(false);
            }
        }