public static bool AddVersion(tb_version_model model)
        {
            tb_version_dal dal = new tb_version_dal();

            using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
            {
                PubConn.Open();
                return(dal.Add(PubConn, model));
            }
        }
        public JsonResult Copy(int id)
        {
            tb_task_model     model         = new tb_task_model();
            tb_version_model  vermodel      = new tb_version_model();
            tb_tempdata_model tempdatamodel = new tb_tempdata_model();

            return(this.Visit(Core.EnumUserRole.Admin, () =>
            {
                try
                {
                    tb_task_dal dal = new tb_task_dal();
                    tb_version_dal dalversion = new tb_version_dal();
                    tb_tempdata_dal tempdatadal = new tb_tempdata_dal();

                    using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
                    {
                        PubConn.Open();

                        //取出需要复制的数据
                        model = dal.GetOneTask(PubConn, id);
                        tempdatamodel = tempdatadal.GetByTaskID(PubConn, id);
                        vermodel = dalversion.GetCurrentVersion(PubConn, id, model.taskversion);

                        //分别插入
                        model.taskstate = 0;
                        model.taskcreatetime = DateTime.Now;
                        model.taskversion = 1;
                        int taskid = dal.AddTask(PubConn, model);

                        vermodel.taskid = taskid;
                        vermodel.version = 1;
                        vermodel.versioncreatetime = DateTime.Now;
                        vermodel.commit_id = string.Empty;
                        dalversion.Add(PubConn, vermodel);

                        tempdatamodel.taskid = taskid;
                        tempdatamodel.tempdatalastupdatetime = DateTime.Now;
                        tempdatadal.Add(PubConn, tempdatamodel);
                    }
                    return Json(new { code = 1, state = "复制成功" });
                }
                catch (Exception ex)
                {
                    return Json(new { code = -1, msg = ex.Message });
                }
            }));
        }
Exemple #3
0
        public ActionResult Add(IFormFile TaskDll, tb_task_model model, string tempdatajson)
        {
            return(this.Visit(EnumUserRole.Admin, () =>
            {
                string filename = TaskDll.FileName;
                byte[] dllbyte;
                using (var dll = TaskDll.OpenReadStream())
                {
                    dllbyte = new byte[dll.Length];
                    dll.Read(dllbyte, 0, Convert.ToInt32(dll.Length));
                }

                tb_task_dal dal = new tb_task_dal();
                tb_version_dal dalversion = new tb_version_dal();
                tb_tempdata_dal tempdatadal = new tb_tempdata_dal();
                //model.taskcreateuserid = Common.GetUserId(this);
                using (DbConn PubConn = DbConn.CreateConn(Config.TaskConnectString))
                {
                    PubConn.Open();
                    model.taskcreatetime = DateTime.Now;
                    model.taskversion = 1;
                    int taskid = dal.AddTask(PubConn, model);
                    dalversion.Add(PubConn, new tb_version_model()
                    {
                        taskid = taskid,
                        version = 1,
                        versioncreatetime = DateTime.Now,
                        zipfile = dllbyte,
                        zipfilename = System.IO.Path.GetFileName(filename)
                    });
                    tempdatadal.Add(PubConn, new tb_tempdata_model()
                    {
                        taskid = taskid,
                        tempdatajson = tempdatajson,
                        tempdatalastupdatetime = DateTime.Now
                    });
                }
                return RedirectToAction("index");
            }));
        }
 public ActionResult Add(HttpPostedFileBase TaskDll, tb_task_model model, string tempdatajson)
 {
     return(this.Visit(Core.EnumUserRole.Admin, () =>
     {
         string filename = TaskDll.FileName;
         Stream dll = TaskDll.InputStream;
         byte[] dllbyte = new byte[dll.Length];
         dll.Read(dllbyte, 0, Convert.ToInt32(dll.Length));
         tb_task_dal dal = new tb_task_dal();
         tb_version_dal dalversion = new tb_version_dal();
         tb_tempdata_dal tempdatadal = new tb_tempdata_dal();
         //model.taskcreateuserid = Common.GetUserId(this);
         using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
         {
             PubConn.Open();
             model.taskcreatetime = DateTime.Now;
             model.taskversion = 1;
             ConvertServiceTypeToFlag(model);
             int taskid = dal.AddTask(PubConn, model);
             dalversion.Add(PubConn, new tb_version_model()
             {
                 taskid = taskid,
                 version = 1,
                 versioncreatetime = DateTime.Now,
                 zipfile = dllbyte,
                 zipfilename = System.IO.Path.GetFileName(filename),
                 commit_id = string.Empty
             });
             tempdatadal.Add(PubConn, new tb_tempdata_model()
             {
                 taskid = taskid,
                 tempdatajson = tempdatajson,
                 tempdatalastupdatetime = DateTime.Now
             });
         }
         return RedirectToAction("index");
     }));
 }
 public ActionResult Update(HttpPostedFileBase TaskDll, tb_task_model model, string tempdatajson)
 {
     return(this.Visit(Core.EnumUserRole.Admin, () =>
     {
         try
         {
             tb_task_dal dal = new tb_task_dal();
             tb_version_dal dalversion = new tb_version_dal();
             tb_tempdata_dal tempdatadal = new tb_tempdata_dal();
             byte[] dllbyte = null;
             string filename = "";
             int change = model.taskversion;
             if (change == -1)
             {
                 if (TaskDll == null)
                 {
                     throw new Exception("没有文件!");
                 }
                 filename = TaskDll.FileName;
                 Stream dll = TaskDll.InputStream;
                 dllbyte = new byte[dll.Length];
                 dll.Read(dllbyte, 0, Convert.ToInt32(dll.Length));
                 //model.taskcreateuserid = Common.GetUserId(this);
             }
             using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
             {
                 PubConn.Open();
                 var task = dal.GetOneTask(PubConn, model.id);
                 if (task.taskstate == (int)Dyd.BaseService.TaskManager.Core.EnumTaskState.Running)
                 {
                     throw new Exception("当前任务在运行中,请停止后提交");
                 }
                 if (change == -1)
                 {
                     model.taskversion = dalversion.GetVersion(PubConn, model.id) + 1;
                 }
                 model.taskupdatetime = DateTime.Now;
                 ConvertServiceTypeToFlag(model);
                 dal.UpdateTask(PubConn, model);
                 if (change == -1)
                 {
                     dalversion.Add(PubConn, new tb_version_model()
                     {
                         taskid = model.id,
                         version = model.taskversion,
                         versioncreatetime = DateTime.Now,
                         zipfile = dllbyte,
                         zipfilename = System.IO.Path.GetFileName(filename),
                         commit_id = string.Empty
                     });
                 }
                 tempdatadal.UpdateByTaskID(PubConn, new tb_tempdata_model()
                 {
                     taskid = model.id,
                     tempdatajson = tempdatajson,
                     tempdatalastupdatetime = DateTime.Now
                 });
                 return RedirectToAction("index");
             }
         }
         catch (Exception exp)
         {
             ModelState.AddModelError("", exp.Message);
             return View();
         }
     }));
 }
        public JsonResult Update(HttpPostedFileBase TaskDll, tb_task_model model, string tempdatajson)
        {
            HttpPostedFileBase file = Request.Files[0];

            return(this.Visit(Core.EnumUserRole.Admin, () =>
            {
                try
                {
                    tb_task_dal dal = new tb_task_dal();
                    tb_version_dal dalversion = new tb_version_dal();
                    tb_tempdata_dal tempdatadal = new tb_tempdata_dal();
                    byte[] dllbyte = null;
                    string filename = "";
                    int change = model.taskversion;
                    if (change == -1)
                    {
                        if (TaskDll == null)
                        {
                            return Json(new { code = -1, message = "没有文件" });
                        }
                        filename = TaskDll.FileName;
                        Stream dll = TaskDll.InputStream;
                        dllbyte = new byte[dll.Length];
                        dll.Read(dllbyte, 0, Convert.ToInt32(dll.Length));
                        //model.taskcreateuserid = Common.GetUserId(this);
                    }
                    using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
                    {
                        PubConn.Open();
                        var task = dal.GetOneTask(PubConn, model.id);
                        if (task.taskstate == (int)Dyd.BaseService.TaskManager.Core.EnumTaskState.Running)
                        {
                            return Json(new { code = -1, message = "当前任务在运行中,请停止后提交" });
                        }
                        if (change == -1)
                        {
                            model.taskversion = dalversion.GetVersion(PubConn, model.id) + 1;
                        }
                        model.taskupdatetime = DateTime.Now;
                        dal.UpdateTask(PubConn, model);
                        if (change == -1)
                        {
                            dalversion.Add(PubConn, new tb_version_model()
                            {
                                taskid = model.id,
                                version = model.taskversion,
                                versioncreatetime = DateTime.Now,
                                zipfile = dllbyte,
                                zipfilename = System.IO.Path.GetFileName(filename)
                            });
                        }
                        tempdatadal.UpdateByTaskID(PubConn, new tb_tempdata_model()
                        {
                            taskid = model.id,
                            tempdatajson = tempdatajson,
                            tempdatalastupdatetime = DateTime.Now
                        });
                        return Json(new { code = 0, message = "上传成功" });
                    }
                }
                catch (Exception exp)
                {
                    return Json(new { code = -1, message = exp.Message });
                }
            }));
        }