public static void ServiceRunning()
 {
     RedisHelper.RedisListner((channel, msg) =>
     {
         try
         {
             //msg = "{'CommondType':2,'nodeid':1}";
             RedisCommondInfo redisCommondInfo = null;
             redisCommondInfo = new BSF.Serialization.JsonProvider().Deserialize <RedisCommondInfo>(msg);
             if (redisCommondInfo != null)
             {
                 if (redisCommondInfo.CommondType == EnumCommondType.TaskCommand && redisCommondInfo.NodeId == GlobalConfig.NodeID)
                 {
                     RunCommond();
                 }
                 else if (redisCommondInfo.CommondType == EnumCommondType.ConfigUpdate)
                 {
                     RedisHelper.RefreashRedisServerIP();
                 }
             }
         }
         catch (Exception ex)
         {
             LogHelper.AddNodeError($"Redis获取订阅消息出错,{ex.Message}", ex);
         }
     }, (info) =>
     {
         if (info != null)
         {
             LogHelper.AddNodeError("Redis订阅出错," + info.Message.NullToEmpty(), info.Exception);
         }
     });
 }
        public override void TestRun()
        {
            this.AppConfig = new BSF.BaseService.TaskManager.SystemRuntime.TaskAppConfigInfo();
            this.AppConfig.Add("sendmailhost", "smtp.163.com");
            this.AppConfig.Add("sendmailname", "*****@*****.**");
            this.AppConfig.Add("password", "472790378@");
            string json = new BSF.Serialization.JsonProvider().Serializer(this.AppConfig);

            base.TestRun();
        }
Esempio n. 3
0
        /// <summary>
        /// 开发人员自测运行入口
        /// 需要将项目配置为->控制台应用程序,写好Program类和Main入口函数
        /// </summary>
        public override void TestRun()
        {
            /*测试环境下任务的配置信息需要手工填写,正式环境下需要配置在任务配置中心里面*/
            this.AppConfig = new BSF.BaseService.TaskManager.SystemRuntime.TaskAppConfigInfo();
            this.AppConfig.Add("sendmailhost", "smtp.163.com");
            this.AppConfig.Add("sendmailname", "*****@*****.**");
            this.AppConfig.Add("password", "123@");
            string json = new BSF.Serialization.JsonProvider().Serializer(this.AppConfig); //可以拷贝配置到任务调度中

            base.TestRun();
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            //var o =  new CryptoHelper().Encrypt("cofnig");
            //var m = new CryptoHelper().Decrypt(o);
            //var a = 1;
            //CompressHelper.UnCompress(@"E:\111.zip",@"E:\111");


            //SqlHelper.ExcuteSql("server=192.168.17.201;Initial Catalog=dyd_bs_task;User ID=sa;Password=Xx~!@#;", (c) =>
            //{
            //    Domain.Dal.tb_version_dal versiondal = new Domain.Dal.tb_version_dal();
            //    versiondal.Edit(c, new tb_version_model()
            //    {
            //        id = 6,
            //        taskid = 8,
            //        version = 1,
            //        versioncreatetime = DateTime.Now,
            //        zipfile = System.IO.File.ReadAllBytes(@"E:\8.rar"),
            //        zipfilename = "8.rar"
            //    });
            //});

            BSF.BaseService.TaskManager.SystemRuntime.TaskAppConfigInfo tai = new BSF.BaseService.TaskManager.SystemRuntime.TaskAppConfigInfo();
            tai.Add("ConfigConnectString", @"server=192.168.17.205;Initial Catalog=dyd_new_config;User ID=sa;Password=Xx~!@#; ");
            string o = new BSF.Serialization.JsonProvider().Serializer(tai);
            int    a = 1;

            //EmailHelper email = new EmailHelper();
            //email.mailFrom = "*****@*****.**";
            //email.mailPwd = "472790378@";
            //email.mailSubject = "11";
            //email.mailBody = "111";
            //email.isbodyHtml = true;    //是否是HTML
            //email.host = "smtp.163.com";//如果是QQ邮箱则:smtp:qq.com,依次类推
            //email.mailToArray = new string[] { "*****@*****.**" };//接收者邮件集合
            //email.mailCcArray = new string[] { };//抄送者邮件集合
            //if (email.Send())
            //{


            //}
            //else
            //{

            //}
        }
Esempio n. 5
0
        static void Running()
        {
            //lastMaxID = 0;//仅测试
            RecoveryStartTasks();

            RedisHelper.RedisListner((channel, msg) =>
            {
                try
                {
                    RedisCommondInfo redisCommondInfo = null;
                    try { redisCommondInfo = new BSF.Serialization.JsonProvider().Deserialize <RedisCommondInfo>(msg); } catch { }
                    if (redisCommondInfo != null)
                    {
                        if (redisCommondInfo.CommondType == EnumCommondType.TaskCommand && redisCommondInfo.NodeId == GlobalConfig.NodeID)
                        {
                            RunCommond();
                        }
                        if (redisCommondInfo.CommondType == EnumCommondType.ConfigUpdate)
                        {
                            RedisHelper.RefreashRedisServerIP();
                        }
                    }
                    else
                    {
                        throw new Exception("redis命令无法识别");
                    }
                }
                catch (Exception exp)
                {
                    LogHelper.AddNodeError("Redis命令处理出错,msg:" + msg.NullToEmpty(), exp);
                }
            }, (info) =>
            {
                if (info != null)
                {
                    LogHelper.AddNodeError("Redis订阅出错," + info.Message.NullToEmpty(), info.Exception);
                }
            });

            RuningCommandLoop();
        }
Esempio n. 6
0
        /// <summary>
        /// 任务的开启
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        public bool Start(int taskid)
        {
            var taskruntimeinfo = TaskPoolManager.CreateInstance().Get(taskid.ToString());

            if (taskruntimeinfo != null)
            {
                throw new Exception("任务已在运行中");
            }

            taskruntimeinfo          = new NodeTaskRuntimeInfo();
            taskruntimeinfo.TaskLock = new TaskLock();
            SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
            {
                tb_task_dal taskdal              = new tb_task_dal();
                taskruntimeinfo.TaskModel        = taskdal.Get(c, taskid);
                tb_version_dal versiondal        = new tb_version_dal();
                taskruntimeinfo.TaskVersionModel = versiondal.GetCurrentVersion(c, taskid, taskruntimeinfo.TaskModel.taskversion);
            });
            string filelocalcachepath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalConfig.TaskDllCompressFileCacheDir + @"\" + taskruntimeinfo.TaskModel.id + @"\" + taskruntimeinfo.TaskModel.taskversion + @"\" +
                                        taskruntimeinfo.TaskVersionModel.zipfilename;
            string fileinstallpath             = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalConfig.TaskDllDir + @"\" + taskruntimeinfo.TaskModel.id;
            string fileinstallmainclassdllpath = fileinstallpath + @"\" + taskruntimeinfo.TaskModel.taskmainclassdllfilename;
            string taskshareddlldir            = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalConfig.TaskSharedDllsDir;

            BSF.Tool.IOHelper.CreateDirectory(filelocalcachepath);
            BSF.Tool.IOHelper.CreateDirectory(fileinstallpath);
            System.IO.File.WriteAllBytes(filelocalcachepath, taskruntimeinfo.TaskVersionModel.zipfile);

            CompressHelper.UnCompress(filelocalcachepath, fileinstallpath);
            //拷贝共享程序集
            BSF.Tool.IOHelper.CopyDirectory(taskshareddlldir, fileinstallpath);
            try
            {
                new TaskAssemblyRedirect().TryRebulidDll(fileinstallmainclassdllpath, taskruntimeinfo.TaskModel.taskmainclassnamespace);
                var dlltask      = new AppDomainLoader <BaseDllTask>().Load(fileinstallmainclassdllpath, taskruntimeinfo.TaskModel.taskmainclassnamespace, out taskruntimeinfo.Domain);
                var sdktaskmodel = new BSF.BaseService.TaskManager.Model.tb_task_model();
                PropertyHelper.Copy(taskruntimeinfo.TaskModel, sdktaskmodel);
                dlltask.SystemRuntimeInfo = new TaskSystemRuntimeInfo()
                {
                    TaskConnectString = GlobalConfig.TaskDataBaseConnectString,
                    TaskModel         = sdktaskmodel
                };
                //加载AppConfig配置
                var appconfig = new TaskAppConfigInfo();
                if (!string.IsNullOrEmpty(taskruntimeinfo.TaskModel.taskappconfigjson))
                {
                    appconfig = new BSF.Serialization.JsonProvider().Deserialize <TaskAppConfigInfo>(taskruntimeinfo.TaskModel.taskappconfigjson);
                }
                SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
                {
                    tb_config_dal configdal = new tb_config_dal();
                    var cs = configdal.GetList(c);
                    foreach (var o in cs)
                    {
                        if (!appconfig.ContainsKey(o.configkey))
                        {
                            appconfig.Add(o.configkey, o.configvalue);
                        }
                    }
                });

                dlltask.AppConfig       = appconfig;
                taskruntimeinfo.DllTask = dlltask;
                bool r = TaskPoolManager.CreateInstance().Add(taskid.ToString(), taskruntimeinfo);
                SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
                {
                    tb_task_dal taskdal = new tb_task_dal();
                    taskdal.UpdateTaskState(c, taskid, (int)EnumTaskState.Running);
                });
                LogHelper.AddTaskLog("节点开启任务成功", taskid);
                return(r);
            }
            catch (Exception exp)
            {
                DisposeTask(taskid, taskruntimeinfo, true);
                throw exp;
            }
        }
Esempio n. 7
0
        //
        // GET: /Task/

        public ActionResult Index(string taskid, string keyword, string CStime, string CEtime, int categoryid = -1, int nodeid = -1, int userid = -1, int state = -999, int pagesize = 10, int pageindex = 1)
        {
            return(this.Visit(EnumUserRole.None, () =>
            {
                #region 保存查询信息,优化操作体验
                var ps = Request.RequestParams();
                ps.Remove("userid");
                var sessionkey = "/task/index/";
                if (ps.Count == 0)
                {
                    if (HttpContext.Session.GetString(sessionkey) != null)
                    {
                        var ks = new BSF.Serialization.JsonProvider(BSF.Serialization.JsonAdapter.EnumJsonMode.Newtonsoft).Deserialize <List <KeyValuePair <string, object> > >(HttpContext.Session.GetString(sessionkey));
                        foreach (var k in ks)
                        {
                            if (!ViewData.ContainsKey(k.Key))
                            {
                                ViewData.Add(k);
                            }
                        }
                        taskid = (string)ViewBag.taskid;
                        keyword = (string)ViewBag.keyword;
                        CStime = (string)ViewBag.CStime;
                        CEtime = (string)ViewBag.CEtime;
                        categoryid = (int)ViewBag.categoryid;
                        nodeid = (int)ViewBag.nodeid;
                        userid = (int)ViewBag.userid;
                        state = (int)ViewBag.state;
                        pagesize = (int)ViewBag.pagesize;
                        pageindex = (int)ViewBag.pageindex;
                    }
                }
                ViewBag.taskid = taskid;
                ViewBag.keyword = keyword;
                ViewBag.CStime = CStime;
                ViewBag.CEtime = CEtime;
                ViewBag.categoryid = categoryid;
                ViewBag.nodeid = nodeid;
                ViewBag.userid = userid;
                ViewBag.state = state;
                ViewBag.pagesize = pagesize;
                ViewBag.pageindex = pageindex;

                HttpContext.Session.SetString(sessionkey, new BSF.Serialization.JsonProvider().Serializer(ViewData));
                #endregion

                tb_task_dal dal = new tb_task_dal();
                PagedList <tb_tasklist_model> pageList = null;
                int count = 0;
                using (DbConn PubConn = DbConn.CreateConn(Config.TaskConnectString))
                {
                    PubConn.Open();
                    List <tb_tasklist_model> List = dal.GetList(PubConn, taskid, keyword, CStime, CEtime, categoryid, nodeid, userid, state, pagesize, pageindex, out count);
                    pageList = new PagedList <tb_tasklist_model>(List, pageindex, pagesize, count);
                    List <tb_node_model> Node = new tb_node_dal().GetListAll(PubConn);
                    List <tb_category_model> Category = new tb_category_dal().GetList(PubConn, "");
                    List <tb_user_model> User = new tb_user_dal().GetAllUsers(PubConn);
                    ViewBag.Node = Node;
                    ViewBag.Category = Category;
                    ViewBag.User = User;
                }
                return View(pageList);
            }));
        }