Exemple #1
0
        public ActionResult DeleteTask(int taskid)
        {
            //TODO: Check lại
            TaskProcess task = taskService.findTask(taskid);

            if (task == null)
            {
                return(HttpNotFound());
            }
            Step step = stepService.findStep(task.Step.Id);
            //lấy group thuộc process
            int    idGroup = task.Step.Process.Group.Id;
            string idUser  = User.Identity.GetUserId();
            Group  group   = groupService.findGroup(idGroup);

            //check xem có thuộc process trong group
            Participate user = participateService.findMemberInGroup(idUser, idGroup);

            if (user == null)
            {
                return(HttpNotFound());
            }

            string taskPath = string.Format("Upload/{0}/{1}/{2}/{3}", task.Step.Process.Group.Id, task.Step.Process.Id, task.Step.Id, task.Id);

            fileService.removeDirectory(taskPath);

            taskService.deletetask(task);

            SetFlash(FlashType.success, "Delete Successfully");
            return(RedirectToRoute("GroupControlLocalizedDefault", new { controller = "process", action = "show", groupslug = group.groupSlug, groupid = group.Id, processid = step.IdProcess }));
        }
Exemple #2
0
        public ActionResult ShowFormTask(int taskid)
        {
            string      idUser = User.Identity.GetUserId();
            TaskProcess task   = taskService.findTask(taskid);

            if (task == null)
            {
                return(HttpNotFound());
            }
            Step        step  = stepService.findStep(task.IdStep);
            Group       group = groupService.findGroup(step.Process.Group.Id);
            List <Role> role  = db.Roles.Where(x => x.IdProcess == task.Step.Process.Id).ToList();

            //file
            string             taskPath = string.Format("Upload/{0}/{1}/{2}/{3}", group.Id, task.Step.Process.Id, task.Step.Id, task.Id);
            List <FileManager> files    = fileService.findFiles(group.Id, taskPath);

            ViewData["Step"]        = step;
            ViewData["ListRole"]    = role;
            ViewData["Group"]       = group;
            Session["idTask"]       = task.Id;
            ViewData["UserRoles"]   = participateService.getRoleOfMember(idUser, group.Id);
            ViewData["Files"]       = files;
            ViewData["FileMaxSize"] = db.ConfigRules.Find("filesize");
            if (task.ValueFormJson == null)
            {
                return(RedirectToRoute("GroupControlLocalizedDefault", new { controller = "process", action = "ShowTask", taskid = taskid }));
            }
            return(View(task));
        }
Exemple #3
0
        protected Task(string name, TaskProcess process, int initalDelay, int repetitionDelay)
        {
            TaskProcess = process;
            Name = name;

            InitialDelay = initalDelay;
            RepetitionDelay = repetitionDelay;
            LastExecution = Timer.GetTime();
            NextExecution = LastExecution + initalDelay;
        }
        public void editFromTask(int idTask, string name, int?role, string description, string formBuilder)
        {
            TaskProcess task = findTask(idTask);

            task.Name          = name;
            task.Description   = description;
            task.ValueFormJson = formBuilder;
            task.IdRole        = role;
            task.Updated_At    = DateTime.Now;
            db.SaveChanges();
        }
        public void addListTaskRun(List <TaskProcess> listtask, List <Role> rolerun, List <Step> liststep)
        {
            if (listtask != null)
            {
                TaskProcess taskrun = new TaskProcess();
                foreach (TaskProcess task in listtask)
                {
                    if (task.IdRole != null)
                    {
                        foreach (Role role in rolerun)
                        {
                            if (task.Role.Name == role.Name)
                            {
                                taskrun.IdRole = role.Id;
                                break;
                            }
                        }
                    }
                    else
                    {
                        taskrun.IdRole = null;
                    }
                    Process processrun = new Process();
                    foreach (Step step in liststep)
                    {
                        if (task.Step.Key == step.Key)
                        {
                            taskrun.IdStep = step.Id;
                            processrun     = step.Process;
                            break;
                        }
                    }
                    taskrun.Name           = task.Name;
                    taskrun.Description    = task.Description;
                    taskrun.ValueInputText = task.ValueInputText;
                    taskrun.ValueInputFile = task.ValueInputFile;
                    taskrun.ValueFormJson  = task.ValueFormJson;
                    taskrun.Color          = task.Color;
                    taskrun.Position       = task.Position;
                    taskrun.IsRun          = true;
                    taskrun.Created_At     = DateTime.Now;
                    taskrun.Updated_At     = DateTime.Now;
                    db.TaskProcesses.Add(taskrun);
                    db.SaveChanges();


                    //copy folder task
                    string taskPath    = string.Format("Upload/{0}/{1}/{2}/{3}", task.Step.Process.IdGroup, task.Step.IdProcess, task.IdStep, task.Id);
                    string taskRunPath = string.Format("Upload/{0}/{1}/{2}/{3}", processrun.IdGroup, processrun.Id, taskrun.IdStep, taskrun.Id);
                    fileService.copyDirectory(taskPath, taskRunPath);
                }
            }
        }
        public void editTask(int idTask, string name, int?role, string description, string inputConfig, string fileConfig)
        {
            TaskProcess task = findTask(idTask);

            task.Name           = name;
            task.Description    = description;
            task.IdRole         = role;
            task.ValueInputText = inputConfig;
            task.ValueInputFile = fileConfig;
            task.Updated_At     = DateTime.Now;
            db.SaveChanges();
        }
        public int getLastPosition(int idStep)
        {
            TaskProcess task = db.TaskProcesses.Where(x => x.IdStep == idStep).OrderByDescending(x => x.Position).FirstOrDefault();

            if (task == null)
            {
                return(0);
            }
            else
            {
                return(task.Position);
            }
        }
        public void changePosition(string position)
        {
            JArray jPos = JArray.Parse(position);

            foreach (JObject taskPos in jPos)
            {
                int         tId  = taskPos["idTask"].ToObject <int>();
                int         tPos = taskPos["position"].ToObject <int>();
                TaskProcess task = db.TaskProcesses.Find(tId);
                task.Position   = tPos;
                task.Updated_At = DateTime.Now;
            }
            db.SaveChanges();
        }
Exemple #9
0
    private void SetBottomBtnLable(QuestTraceInfo taskInfo)
    {
        TaskProcess process = taskInfo.GetTaskProcess();

        if (process == TaskProcess.TaskProcess_None)
        {
            m_label_btn_bottom_Label.text = "接取";
        }
        else if (process == TaskProcess.TaskProcess_Doing)
        {
            m_label_btn_bottom_Label.text = "放弃";
        }
        else if (process == TaskProcess.TaskProcess_CanDone)
        {
            //开启自动完成
            if (taskInfo.QuestTable.dwAutoCanDone)
            {
                TimerAxis.Instance().KillTimer(MISSIONCANDONE_TIMER, this);
                TimerAxis.Instance().SetTimer(MISSIONCANDONE_TIMER, 1000, this);

                missionCanDoneBtnCd = CONST_MissionCanDoneBtnCd;
                string btnDes = string.Format("完成({0})", missionCanDoneBtnCd);
                m_label_btn_bottom_Label.text = btnDes;
            }
            else
            {
                if (TimerAxis.Instance().IsExist(MISSIONCANDONE_TIMER, this))
                {
                    TimerAxis.Instance().KillTimer(MISSIONCANDONE_TIMER, this);
                }
                m_label_btn_bottom_Label.text = "完成";
            }
            UIParticleWidget p = m_btn_btn_bottom.GetComponent <UIParticleWidget>();
            if (p == null)
            {
                p       = m_btn_btn_bottom.gameObject.AddComponent <UIParticleWidget>();
                p.depth = 20;
            }
            if (p != null)
            {
                p.SetDimensions(260, 54);
                p.ReleaseParticle();
                p.AddRoundParticle();
            }
        }
    }
Exemple #10
0
 void Process(TaskProcess tp)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(obj =>
     {
         if (tp.processTime > DateTime.Now)
         {
             var ts = tp.processTime - DateTime.Now;
             Thread.Sleep(ts);
         }
         var task = tp.task;
         task.Process();
         if (task.Status == TaskStatus.Waitting && task.NextProcessTime.HasValue)
         {
             AddProcessQueue(task, task.NextProcessTime.Value);
         }
     }));
 }
        private Task CreateTask(RECommand command, int parentId, TaskProcess processCallback, TaskComplete completeCallback)
        {
            var taskId = string.Format("{0}_{1}", parentId, command);
            var task   = new Task(command, parentId, taskId);

            if (_tasksDictionary.ContainsKey(taskId))
            {
                _tasksDictionary.Remove(taskId);
            }

            _tasksDictionary.Add(taskId, task);

            task.ProcessCallback  = processCallback;
            task.CompleteCallback = completeCallback;

            return(task);
        }
Exemple #12
0
    void CanDoneBtn()
    {
        QuestTraceInfo taskInfo = QuestTranceManager.GetInstance().GetQuestTraceInfo(m_nTaskid);

        if (taskInfo == null)
        {
            Engine.Utility.Log.Error(" No Found taskindo id {0}", m_nTaskid);
            return;
        }

        TaskProcess process = taskInfo.GetTaskProcess();

        if (process == TaskProcess.TaskProcess_CanDone)
        {
            onClick_Btn_bottom_Btn(null);
        }
    }
Exemple #13
0
        public JsonResult AddFormTask(string name, int?idRole, string description, string formBuilder, HttpPostedFileBase fileupload)
        {
            HttpStatusCode status = HttpStatusCode.OK;
            string         message;
            object         response;
            int            idstep = (int)Session["idStep"];
            Step           step   = stepService.findStep(idstep);


            if (name == "")
            {
                status   = HttpStatusCode.InternalServerError;
                message  = "Created Task Successfully";
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            if (idRole != null)
            {
                int  idR  = idRole.GetValueOrDefault();
                Role role = roleService.findRoleOfProcess(idR, step.Process.Id);
                if (role == null)
                {
                    //role not exist
                    status   = HttpStatusCode.InternalServerError;
                    message  = "Role not exist";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
            }

            TaskProcess task = taskService.AddFormTask(step.Id, name, idRole, description, formBuilder);
            //create directory
            Group  group         = groupService.findGroup(step.Process.Group.Id);
            string directoryPath = String.Format("Upload/{0}/{1}/{2}/{3}", group.Id, step.Process.Id, step.Id, task.Id);

            fileService.createDirectory(directoryPath);

            fileService.saveFile(group.Id, fileupload, directoryPath, Direction.Task);

            SetFlash(FlashType.success, "Created Task Successfully");
            message  = "Created Task Successfully";
            response = new { message = message, status = status };
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public TaskProcess AddFormTask(int idStep, string name, int?role, string description, string formBuilder)
        {
            TaskProcess task = new TaskProcess();

            task.IdStep        = idStep;
            task.Name          = name;
            task.IdRole        = role;
            task.Description   = description;
            task.ValueFormJson = formBuilder;
            task.IsRun         = false;
            task.Color         = commonService.getRandomColor();
            task.Position      = getLastPosition(idStep) + 1;
            task.Created_At    = DateTime.Now;
            task.Updated_At    = DateTime.Now;
            db.TaskProcesses.Add(task);
            db.SaveChanges();
            return(task);
        }
Exemple #15
0
    void onClick_Btn_bottom_Btn(GameObject caster)
    {
        this.HideSelf();
        QuestTraceInfo taskInfo = QuestTranceManager.GetInstance().GetQuestTraceInfo(m_nTaskid);

        if (taskInfo == null)
        {
            Engine.Utility.Log.Error(" No Found taskindo id {0}", m_nTaskid);
            return;
        }

        if (taskInfo.Received)
        {
            TaskProcess process = taskInfo.GetTaskProcess();
            if (taskInfo.taskSubType == TaskSubType.Guild)
            {
                if (process == TaskProcess.TaskProcess_CanDone)
                {
                    if (CanPutInKanpsack())
                    {
                        Protocol.Instance.RequestFinishTask(m_nTaskid);
                    }
                }
            }
            else
            {
                if (process == TaskProcess.TaskProcess_Doing)
                {
                    Protocol.Instance.RequestDelTask(m_nTaskid);
                }
                else if (process == TaskProcess.TaskProcess_CanDone)
                {
                    if (CanPutInKanpsack())
                    {
                        Protocol.Instance.RequestDialogSelect(1, m_strStep);
                    }
                }
            }
        }
        else
        {
            Protocol.Instance.RequestDialogSelect(1, m_strStep);
        }
    }
Exemple #16
0
 internal void AddProcessQueue(TaskAgent task, DateTime processTime)
 {
     if (task.Status != TaskStatus.Waitting)
     {
         return;
     }
     lock (lockObject)
     {
         if (queue.ContainsKey(task.Id))
         {
             queue.Remove(task.Id);
         }
         var process = new TaskProcess()
         {
             task = task, processTime = processTime
         };
         queue.Add(process.Id, process);
     }
 }
        public TaskProcess addtask(int idStep, string name, int?role, string description, string inputConfig, string fileConfig)
        {
            TaskProcess task = new TaskProcess();

            task.IdStep         = idStep;
            task.Name           = name;
            task.IdRole         = role;
            task.Description    = description;
            task.IsRun          = false;
            task.ValueInputText = inputConfig;
            task.ValueInputFile = fileConfig;
            task.Color          = commonService.getRandomColor();
            task.Position       = getLastPosition(idStep) + 1;
            task.Created_At     = DateTime.Now;
            task.Updated_At     = DateTime.Now;
            db.TaskProcesses.Add(task);
            db.SaveChanges();
            return(task);
        }
Exemple #18
0
        public ActionResult AddFormTask(int stepid)
        {
            string idUser = User.Identity.GetUserId();
            Step   step   = stepService.findStep(stepid);

            if (step == null)
            {
                return(HttpNotFound());
            }
            Process     ps    = processService.findProcess(step.IdProcess);
            Group       group = groupService.findGroup(ps.IdGroup);
            TaskProcess pr    = new TaskProcess();
            List <Role> role  = db.Roles.Where(x => x.IdProcess == step.IdProcess).ToList();

            ViewData["Step"]        = step;
            ViewData["ListRole"]    = role;
            ViewData["Group"]       = group;
            Session["idStep"]       = step.Id;
            ViewData["UserRoles"]   = participateService.getRoleOfMember(idUser, group.Id);
            ViewData["FileMaxSize"] = db.ConfigRules.Find("filesize");
            return(View(pr));
        }
Exemple #19
0
        public JsonResult uploadFile(int groupid, int?processid, int?stepid, int?taskid, HttpPostedFileBase FileUpload, Direction direction)
        {
            HttpStatusCode status = HttpStatusCode.OK;
            string         message;
            object         response;

            if (FileUpload.ContentLength == 0)
            {
                status   = HttpStatusCode.NoContent;
                message  = "Your File is empty";
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            ConfigRule fileSizeRule   = db.ConfigRules.Find("filesize");
            bool       isFileOverSize = fileService.checkFileOverSize(FileUpload);

            if (isFileOverSize)
            {
                status   = HttpStatusCode.InternalServerError;
                message  = string.Format("This file is too big ({0} {1} maximum)", fileSizeRule.Value, fileSizeRule.Unit);
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            string filePath;

            if (direction == Direction.Process)
            {
                Process pr = processService.findProcess(processid.GetValueOrDefault());
                if (pr == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Process not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}/{1}", pr.IdGroup, pr.Id);
            }
            else if (direction == Direction.Step)
            {
                Step st = stepService.findStep(stepid.GetValueOrDefault());
                if (st == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Step not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}/{1}/{2}", st.Process.Group.Id, st.Process.Id, st.Id);
            }
            else if (direction == Direction.Task)
            {
                TaskProcess tp = taskService.findTask(taskid.GetValueOrDefault());
                if (tp == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Task not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}/{1}/{2}/{3}", tp.Step.Process.Group.Id, tp.Step.Process.Id, tp.Step.Id, tp.Id);
            }
            else
            {
                Group gr = groupService.findGroup(groupid);
                if (gr == null)
                {
                    status   = HttpStatusCode.NotFound;
                    message  = "Group not found";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                filePath = String.Format("Upload/{0}", gr.Id);
            }
            FileManager f    = fileService.saveFile(groupid, FileUpload, filePath, direction);
            object      data = new
            {
                id   = f.Id,
                name = f.Name
            };

            message  = "Save File Sucessfull";
            response = new { message = message, data = data, status = status };
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
 internal RepeatingTaskWithInitialDelay(string name, TaskProcess process, int initialDelay, int repetitionDelay)
     : base(name, process, initialDelay, repetitionDelay)
 {
     TaskStatus = TaskStatus.DelayedWait;
 }
Exemple #21
0
        public JsonResult Import(int groupid, HttpPostedFileBase fileupload)
        {
            string         IdUser  = User.Identity.GetUserId();
            string         AppPath = AppDomain.CurrentDomain.BaseDirectory;
            HttpStatusCode status  = HttpStatusCode.OK;
            string         message;
            object         response;
            Group          group;
            Process        pr;

            try
            {
                using (var scope = new TransactionScope())
                {
                    ZipFile  zip      = ZipFile.Read(fileupload.InputStream);
                    ZipEntry jsonFile = zip.FirstOrDefault(x => x.FileName == "data.json");
                    if (jsonFile == null)
                    {
                        throw new ServerSideException("File is damaged, please try other file");
                    }
                    //jsonFile.Password = "******";
                    var     passsword = "clockworks-pms";
                    JObject data;
                    using (StreamReader sr = new StreamReader(jsonFile.OpenReader(passsword), Encoding.UTF8))
                    {
                        data = JsonConvert.DeserializeObject <JObject>(sr.ReadToEnd());
                    }
                    //xử lý data
                    group = groupService.findGroup(groupid);
                    //process
                    pr             = new Process();
                    pr.Name        = (string)data["processname"];
                    pr.Description = (string)data["description"];
                    pr.IdOwner     = IdUser;
                    pr.IdGroup     = groupid;
                    pr.DataJson    = data["draw"].ToString();
                    pr.Avatar      = (string)data["avatar"];
                    pr.IsRun       = false;
                    pr.Created_At  = DateTime.Now;
                    pr.Updated_At  = DateTime.Now;
                    db.Processes.Add(pr);
                    db.SaveChanges();

                    //file process
                    JArray processFile = (JArray)data["files"];
                    if (processFile.Any())
                    {
                        foreach (JToken file in processFile)
                        {
                            ZipEntry f = zip.FirstOrDefault(x => x.FileName == string.Format("Upload/{0}/{1}", (string)data["processid"], file.ToString()));
                            if (f != null)
                            {
                                Stream         st          = f.OpenReader();
                                ZipInputStream zp          = new ZipInputStream(st);
                                string         processPath = string.Format("Upload/{0}/{1}", groupid.ToString(), pr.Id.ToString());
                                fileService.createDirectory(processPath);
                                //System.IO.File.SetAttributes(Path.Combine(AppPath, processPath), FileAttributes.Temporary);
                                using (FileStream fileStream = System.IO.File.Create(string.Format("{0}/{1}/{2}", AppPath, processPath, file.ToString())))
                                {
                                    string fileId;
                                    do
                                    {
                                        fileId = commonService.getRandomString(50);
                                    } while (fileService.findFile(fileId) != null);
                                    FileManager fm = new FileManager();
                                    fm.Id        = fileId;
                                    fm.IdGroup   = groupid;
                                    fm.Name      = Path.GetFileName(fileStream.Name);
                                    fm.Type      = Path.GetExtension(fileStream.Name);
                                    fm.Path      = processPath;
                                    fm.Direction = Direction.Process.ToString();
                                    fm.Create_At = DateTime.Now;
                                    fm.Update_At = DateTime.Now;
                                    db.FileManagers.Add(fm);
                                    //zp.Seek(0, SeekOrigin.Begin);
                                    zp.CopyTo(fileStream);
                                }
                            }
                        }
                    }
                    //role
                    JArray      roles    = (JArray)data["roles"];
                    List <Role> roleList = new List <Role>();
                    foreach (var role in roles)
                    {
                        Role rl = new Role {
                            Process = pr
                        };
                        rl.IdProcess   = pr.Id;
                        rl.Name        = (string)role["rolename"];
                        rl.Description = (string)role["description"];
                        rl.IsRun       = false;
                        rl.Create_At   = DateTime.Now;
                        rl.Update_At   = DateTime.Now;
                        roleList.Add(rl);
                    }
                    db.Roles.AddRange(roleList);
                    db.SaveChanges();

                    JArray steps = (JArray)data["steps"];
                    foreach (JToken step in steps)
                    {
                        Step st = new Step {
                            Process = pr
                        };
                        st.IdProcess   = pr.Id;
                        st.Name        = (string)step["stepname"];
                        st.Description = (string)step["description"];
                        st.StartStep   = (bool)step["draw"]["isStartStep"];
                        st.Key         = (int)step["draw"]["key"];
                        st.Figure      = (string)step["draw"]["figure"];
                        st.NextStep1   = (int)step["draw"]["nextstep1"];
                        st.NextStep2   = (int)step["draw"]["nextstep2"];
                        st.Color       = commonService.getRandomColor();
                        st.IsRun       = false;
                        st.Created_At  = DateTime.Now;
                        st.Updated_At  = DateTime.Now;
                        db.Steps.Add(st);
                        db.SaveChanges();

                        //File Step
                        JArray stepFile = (JArray)step["files"];
                        if (stepFile.Any())
                        {
                            foreach (JToken file in stepFile)
                            {
                                ZipEntry f = zip.FirstOrDefault(x => x.FileName == string.Format("Upload/{0}/{1}/{2}", (string)data["processid"], (string)step["stepid"], file.ToString()));
                                if (f != null)
                                {
                                    Stream         stm      = f.OpenReader();
                                    ZipInputStream zp       = new ZipInputStream(stm);
                                    string         stepPath = string.Format("Upload/{0}/{1}/{2}", groupid.ToString(), pr.Id.ToString(), st.Id.ToString());
                                    fileService.createDirectory(stepPath);
                                    //System.IO.File.SetAttributes(Path.Combine(AppPath, processPath), FileAttributes.Temporary);
                                    using (FileStream fileStream = System.IO.File.Create(string.Format("{0}/{1}/{2}", AppPath, stepPath, file.ToString())))
                                    {
                                        string fileId;
                                        do
                                        {
                                            fileId = commonService.getRandomString(50);
                                        } while (fileService.findFile(fileId) != null);
                                        FileManager fm = new FileManager();
                                        fm.Id        = fileId;
                                        fm.IdGroup   = groupid;
                                        fm.Name      = Path.GetFileName(fileStream.Name);
                                        fm.Type      = Path.GetExtension(fileStream.Name);
                                        fm.Path      = stepPath;
                                        fm.Direction = Direction.Step.ToString();
                                        fm.Create_At = DateTime.Now;
                                        fm.Update_At = DateTime.Now;
                                        db.FileManagers.Add(fm);

                                        //zp.Seek(0, SeekOrigin.Begin);
                                        zp.CopyTo(fileStream);
                                    }
                                }
                            }
                        }

                        //Task
                        JArray tasks = (JArray)step["tasks"];
                        foreach (JToken task in tasks)
                        {
                            int?rid;
                            if ((string)task["role"] == "")
                            {
                                rid = null;
                            }
                            else
                            {
                                rid = roleList.First(x => x.Name == (string)task["role"]).Id;
                            }
                            string      jText = task["config"]["input"].ToString();
                            string      jFile = task["config"]["file"].ToString();
                            string      jForm = task["config"]["form"].ToString();
                            TaskProcess tk    = new TaskProcess {
                                Step = st
                            };
                            tk.IdStep      = st.Id;
                            tk.IdRole      = rid;
                            tk.Name        = (string)task["taskname"];
                            tk.Description = (string)task["description"];
                            if (jText != "")
                            {
                                tk.ValueInputText = jText;
                            }
                            if (jFile != "")
                            {
                                tk.ValueInputFile = jFile;
                            }
                            if (jForm != "")
                            {
                                tk.ValueFormJson = jForm;
                            }
                            tk.Color      = commonService.getRandomColor();
                            tk.Position   = (int)task["position"];
                            tk.IsRun      = false;
                            tk.Created_At = DateTime.Now;
                            tk.Updated_At = DateTime.Now;
                            db.TaskProcesses.Add(tk);
                            db.SaveChanges();
                            //file task
                            //File Step
                            JArray taskFile = (JArray)task["files"];
                            if (taskFile.Any())
                            {
                                foreach (JToken file in taskFile)
                                {
                                    ZipEntry f = zip.FirstOrDefault(x => x.FileName == string.Format("Upload/{0}/{1}/{2}/{3}", (string)data["processid"], (string)step["stepid"], (string)step["taskid"], file.ToString()));
                                    if (f != null)
                                    {
                                        Stream         stm      = f.OpenReader();
                                        ZipInputStream zp       = new ZipInputStream(stm);
                                        string         taskPath = string.Format("Upload/{0}/{1}/{2}/{3}", groupid.ToString(), pr.Id.ToString(), st.Id.ToString(), tk.Id.ToString());
                                        fileService.createDirectory(taskPath);
                                        //System.IO.File.SetAttributes(Path.Combine(AppPath, processPath), FileAttributes.Temporary);
                                        using (FileStream fileStream = System.IO.File.Create(string.Format("{0}/{1}/{2}", AppPath, taskPath, file.ToString())))
                                        {
                                            string fileId;
                                            do
                                            {
                                                fileId = commonService.getRandomString(50);
                                            } while (fileService.findFile(fileId) != null);
                                            FileManager fm = new FileManager();
                                            fm.Id        = fileId;
                                            fm.IdGroup   = groupid;
                                            fm.Name      = Path.GetFileName(fileStream.Name);
                                            fm.Type      = Path.GetExtension(fileStream.Name);
                                            fm.Path      = taskPath;
                                            fm.Direction = Direction.Task.ToString();
                                            fm.Create_At = DateTime.Now;
                                            fm.Update_At = DateTime.Now;
                                            db.FileManagers.Add(fm);

                                            //zp.Seek(0, SeekOrigin.Begin);
                                            zp.CopyTo(fileStream);
                                        }
                                    }
                                }
                            }
                        }
                        db.SaveChanges();
                    }

                    //process
                    scope.Complete();
                }
                message = "Import Sucess";
                object d = new
                {
                    groupid   = group.Id,
                    groupslug = group.groupSlug,
                    processid = pr.Id,
                };

                response = new { message = message, data = d, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                status   = HttpStatusCode.InternalServerError;
                message  = e.GetType().Name == "ServerSideException" ? e.Message : "Something not right";
                response = new { message = message, detail = e.Message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #22
0
        public JsonResult EditFormTask(string name, int?idRole, string description, string formBuilder)
        {
            ///////////////////////////
            /// chỉ được edit task thuộc process mà mình quản lý
            ///////////////////////////
            HttpStatusCode status = HttpStatusCode.OK;
            string         message;
            object         response;
            int            idTask = int.Parse(Session["idTask"].ToString());
            TaskProcess    task   = taskService.findTask(idTask);


            if (task == null)
            {
                message  = "Task not exit";
                status   = HttpStatusCode.InternalServerError;
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            Step step = stepService.findStep(task.Step.Id);
            //lấy group thuộc process
            int    idGroup = task.Step.Process.Group.Id;
            string idUser  = User.Identity.GetUserId();

            //check xem có thuộc process trong group
            Participate user = participateService.findMemberInGroup(idUser, idGroup);

            if (user == null)
            {
                message  = "Task not found";
                status   = HttpStatusCode.Forbidden;
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            if (name == "")
            {
                status   = HttpStatusCode.InternalServerError;
                message  = "Created Task Successfully";
                response = new { message = message, status = status };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            if (idRole != null)
            {
                int  idR  = idRole.GetValueOrDefault();
                Role role = roleService.findRoleOfProcess(idR, step.Process.Id);
                if (role == null)
                {
                    //role not exist
                    status   = HttpStatusCode.InternalServerError;
                    message  = "Role not exist";
                    response = new { message = message, status = status };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
            }

            taskService.editFromTask(task.Id, name, idRole, description, formBuilder);
            SetFlash(FlashType.success, "Created Task Successfully");
            message  = "Created Task Successfully";
            response = new { message = message, status = status };
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public TaskProcess findTask(int idTask)
        {
            TaskProcess task = db.TaskProcesses.Find(idTask);

            return(task);
        }
Exemple #24
0
 internal ImmediateRunOnceTask(string name, TaskProcess process)
     : base(name, process, 0, 0)
 {
     TaskStatus = TaskStatus.Running;
 }
Exemple #25
0
 internal DelayedTask(string name, TaskProcess process, int initialDelay)
     : base(name, process, initialDelay, 0)
 {
     TaskStatus = TaskStatus.DelayedWait;
 }
 public void deletetask(TaskProcess task)
 {
     db.TaskProcesses.Remove(task);
     db.SaveChanges();
 }
Exemple #27
0
 public ITask CreateRepeatingTaskWithDelay(string name, TaskProcess process, int initalDelay, int repetitionDelay)
 {
     var newTask = new TaskTypes.RepeatingTaskWithInitialDelay(name, process, initalDelay, repetitionDelay);
     _taskList.Add(newTask);
     return newTask;
 }
Exemple #28
0
 public ITask CreateOneOffTask(string name, TaskProcess process)
 {
     var newTask = new TaskTypes.ImmediateRunOnceTask(name, process);
     _taskList.Add(newTask);
     return newTask;
 }
Exemple #29
0
        public int Process(BackgroundWorker bw, FormValOption formValOption, TaskProcess taskProcess)
        {
            string outputDirectory = formValOption.OutPutFolder;

            if (string.IsNullOrWhiteSpace(outputDirectory))
            {
                MessageBox.Show("请选择输出目录", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(ConstData.STOP_PROCESS);
            }
            DialogResult dialogResult = MessageBox.Show("开始处理前将关闭所有word文件", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (dialogResult == DialogResult.Yes)
            {
                foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
                {
                    p.Kill();
                }
            }
            else
            {
                return(ConstData.STOP_PROCESS);
            }
            Dictionary <string, string> rows = formValOption.FileGrid;
            int count = rows.Count;
            int i     = 0;

            foreach (KeyValuePair <string, string> kv in rows)
            {
                if (!bw.CancellationPending)
                {
                    i++;
                    string filename = kv.Key;
                    string filepath = kv.Value;
                    string result   = "";
                    try
                    {
                        if (!String.IsNullOrWhiteSpace(filepath) && File.Exists(filepath))
                        {
                            string targetFile = outputDirectory + @"\" + filename;
                            taskProcess(formValOption, filepath, targetFile, ref result);
                            result = ConstData.SUCCESS;
                        }
                        else
                        {
                            result = ConstData.WITHOUT_FILE;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("***" + filename + ":  " + ex.Message);
                        result = ConstData.FAIL;
                    }
                    finally
                    {
                        string data = (i - 1) + "," + result;
                        bw.ReportProgress(i * 100 / count, data);
                        Thread.Sleep(1000);
                    }
                }
            }
            return(ConstData.FINISH_PROCESS);
        }
 public AddEditProcessWindow(TaskProcess taskProcess, List <Department> DeptCollection, List <Employee> EmpCollection, List <DocumentState> StateCollection)
 {
     InitializeComponent();
     DataContext = new AddEditProcessViewModel(taskProcess, DeptCollection, EmpCollection, StateCollection);
 }
Exemple #31
0
 public ITask CreateOneOffTaskWithDelay(string name, TaskProcess process, int initialDelay)
 {
     var newTask = new TaskTypes.DelayedTask(name, process, initialDelay);
     _taskList.Add(newTask);
     return newTask;
 }
        public void GetValue(int parentId, int fieldIndex, TaskProcess completeCallback)
        {
            var task = CreateTask(RECommand.GetValue, parentId, completeCallback, null);

            Send(Address, task, OSCValue.Int(fieldIndex));
        }
Exemple #33
0
 internal RepeatingTask(string name, TaskProcess process, int repetitionDelay)
     : base(name, process, 0, repetitionDelay)
 {
     TaskStatus = TaskStatus.Running;
 }
        public void RefreshObjects(int parentId, TaskProcess processCallback, TaskComplete completeCallback)
        {
            var task = CreateTask(RECommand.GetObjects, parentId, processCallback, completeCallback);

            Send(Address, task, OSCValue.Int(0));
        }
        public void AjaxAuthorize(ActionExecutingContext filterContext, Participate user)
        {
            string idUser = HttpContext.Current.User.Identity.GetUserId();
            int    groupid;

            if (filterContext.Controller.ValueProvider.GetValue("groupid") != null)
            {
                groupid = int.Parse(filterContext.Controller.ValueProvider.GetValue("groupid").AttemptedValue);
            }
            //else if (HttpContext.Current.Session["groupid"] != null)
            //    groupid = (int)HttpContext.Current.Session["groupid"];
            else if (filterContext.Controller.ValueProvider.GetValue("processid") != null)
            {
                int     processId = int.Parse(filterContext.Controller.ValueProvider.GetValue("processid").AttemptedValue);
                Process process   = db.Processes.Find(processId);
                if (process == null)
                {
                    filterContext.Result = new JsonResult
                    {
                        Data = new { message = "Process Not Found", status = HttpStatusCode.NotFound },
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                    return;
                }
                groupid = process.IdGroup;
            }
            else if (filterContext.Controller.ValueProvider.GetValue("stepid") != null)
            {
                int  stepId = int.Parse(filterContext.Controller.ValueProvider.GetValue("stepid").AttemptedValue);
                Step step   = db.Steps.Find(stepId);
                if (step == null)
                {
                    filterContext.Result = new JsonResult
                    {
                        Data = new { message = "Step Not Found", status = HttpStatusCode.NotFound },
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                    return;
                }
                groupid = step.Process.IdGroup;
            }
            else if (filterContext.Controller.ValueProvider.GetValue("taskid") != null)
            {
                int         taskId = int.Parse(filterContext.Controller.ValueProvider.GetValue("taskid").AttemptedValue);
                TaskProcess task   = db.TaskProcesses.Find(taskId);
                if (task == null)
                {
                    filterContext.Result = new JsonResult
                    {
                        Data = new { message = "Task Not Found", status = HttpStatusCode.NotFound },
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                    return;
                }
                groupid = task.Step.Process.IdGroup;
            }
            else
            {
                filterContext.Result = new JsonResult
                {
                    Data = new { message = "Group Not Found", status = HttpStatusCode.NotFound },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                return;
            }


            Group group = groupService.findGroup(groupid);

            if (group == null)
            {
                filterContext.Result = new JsonResult
                {
                    Data = new { message = "Group Not Found", status = HttpStatusCode.NotFound },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                return;
            }
            user = participateService.findMemberInGroup(idUser, groupid);
            if (user == null)
            {
                filterContext.Result = new JsonResult
                {
                    Data = new { message = "You not belong to this group", status = HttpStatusCode.NotFound },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                return;
            }
            if (Role != null)
            {
                bool       isOwner   = group.IdOwner == idUser ? true : false;
                UserRole[] userRoles = new UserRole[3];
                if (isOwner)
                {
                    userRoles[0] = UserRole.Owner;
                }
                if (user.IsAdmin)
                {
                    userRoles[1] = UserRole.Admin;
                }
                if (user.IsManager)
                {
                    userRoles[2] = UserRole.Manager;
                }
                bool checkrole = userRoles.Intersect(this.Role).Any();
                if (!checkrole)
                {
                    filterContext.Result = new JsonResult
                    {
                        Data = new { message = "You dont have permission", status = HttpStatusCode.Forbidden },
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                    return;
                }
            }
            HttpContext.Current.Session["idgroup"] = groupid;
        }