コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }