예제 #1
0
        int IsStop()
        {
            if (dgvTack.Rows.Count > 0)
            {
                foreach (var task in listTaskControl)
                {
                    SystemTask systemTask = task.SystemTask;

                    string strDown = GetDownString(GetUrl(string.Format("API/FxtTask.svc/TaskById/{0}", systemTask.Id)));

                    if (Utils.GetJObjectValue(strDown, "Type").Equals("1"))//是否存在该任务
                    {
                        SysTask sysTask = Utils.Deserialize <SysTask>(Utils.GetJObjectValue(strDown, "Data"));
                        if (sysTask.Status.Equals(2))//任务是否需要暂停
                        {
                            task.BackgroundWorker.Wait();
                            systemTask.RowObject.Cells["RunStatus"].Value = "暂停";
                        }
                        else if (sysTask.Status.Equals(0))//任务是否需要继续
                        {
                            task.BackgroundWorker.Resume();
                            systemTask.RowObject.Cells["RunStatus"].Value = "进行中";
                        }
                        else if (sysTask.Status.Equals(3))//任务是否需要停止
                        {
                            task.BackgroundWorker.Stop();
                            systemTask.RowObject.Cells["RunStatus"].Value = "撤销";
                        }
                    }
                    else if (Utils.GetJObjectValue(strDown, "Type").Equals("0"))//不存在该任务
                    {
                        if (systemTask.RowObject.Index != -1)
                        {
                            dgvTack.Rows.Remove(systemTask.RowObject);
                        }
                    }
                    current++;
                    Thread.Sleep(1000);
                }
            }
            return(current);
        }
예제 #2
0
        void StartRun(SystemTask systemTask)
        {
            bool isSuspend = false;

            if (systemTask.Status.Equals(2))
            {
                isSuspend = true;
            }
            BackgroundWorkerTimer bwTimer = new BackgroundWorkerTimer();

            #region BackgroundWorkerTimer 任务
            bwTimer.Runing += (s, e) =>
            {
                CustomEventArgs customEventArgs = ((CustomEventArgs)e);
                SystemTask      doSystemTask    = customEventArgs.Argument as SystemTask;
                int             index           = -1;
                index = doSystemTask.RowObject.Index;
                if (customEventArgs.RunComplete != null && customEventArgs.RunComplete.Cancelled)//取消
                {
                    //e.Cancel = true;
                    //break;
                }
                else if (customEventArgs.RunComplete != null && customEventArgs.RunComplete.Error != null)//错误
                {
                }
                else//成功或者继续执行
                {
                    string strGet = string.Empty;
                    if (doSystemTask.TaskType.Equals(1))
                    {
                        #region  估
                        List <DataCollateral> list = customEventArgs.ListObject as List <DataCollateral>;
                        strGet = GetDownString(doSystemTask.Url2.Replace("{id}", list[customEventArgs.Index].Id.ToString()));
                        if (!Utils.IsNullOrEmpty(strGet) && Utils.GetJObjectValue(strGet, "Type").Equals("1"))//成功
                        {
                            doSystemTask.SuccessCount = IntNull(doSystemTask.SuccessCount);
                        }
                        else//失败
                        {
                            doSystemTask.FailureCount = IntNull(doSystemTask.FailureCount);
                            SysTaskLog sysTaskLog = new SysTaskLog()
                            {
                                TaskId  = doSystemTask.Id,
                                Message = Utils.GetJObjectValue(strGet, "Message")
                            };
                            SendString(GetUrl("API/FxtTask.svc/TLC/"), new { data = Utils.Serialize(sysTaskLog) });
                        }
                        #endregion
                    }
                    else if (doSystemTask.TaskType.Equals(0))
                    {
                        #region 押品拆分
                        object[,] arrayItem = customEventArgs.ListObject as object[, ];
                        ExcelHelper excelHelper   = customEventArgs.ExcelHelper as ExcelHelper;
                        object      objCollateral = excelHelper.TaskExcelStandardization(arrayItem,
                                                                                         customEventArgs.StandardizationHeader, customEventArgs.Index);
                        DataCollateral model = objCollateral as DataCollateral;
                        if (model != null)
                        {
                            model.UploadFileId  = doSystemTask.UploadFileId;
                            model.BankId        = doSystemTask.BankId;
                            model.BankProjectId = doSystemTask.BankProjectId;
                            model.Status        = 0;//默认什么都没有

                            strGet = SendString(GetUrl("API/FxtTask.svc/CreateCollateral/"), new { data = Utils.Serialize(model) });
                        }
                        //!model.Id.Equals(0) 是否已存在拆分过的押品
                        if ((!Utils.IsNullOrEmpty(strGet) && Utils.GetJObjectValue(strGet, "Type").Equals("1")) ||
                            (model != null && !model.Id.Equals(0)))
                        {
                            doSystemTask.SuccessCount = IntNull(doSystemTask.SuccessCount);
                        }
                        else if ((!Utils.IsNullOrEmpty(strGet) && Utils.GetJObjectValue(strGet, "Type").Equals("0")) || model == null)
                        {
                            doSystemTask.FailureCount = IntNull(doSystemTask.FailureCount);
                            SysTaskLog sysTaskLog = new SysTaskLog()
                            {
                                TaskId  = doSystemTask.Id,
                                Message = objCollateral.ToString()
                            };
                            //失败了就记录日志
                            SendString(GetUrl("API/FxtTask.svc/TLC/"), new { data = Utils.Serialize(sysTaskLog) });
                        }
                        #endregion
                    }
                    //是否下标小于0
                    if (!index.Equals(-1))
                    {
                        dgvTack.Rows[index].Cells["SuccessCount"].Value = doSystemTask.SuccessCount;
                        dgvTack.Rows[index].Cells["FailureCount"].Value = doSystemTask.FailureCount;
                    }

                    SendString(GetUrl("API/FxtTask.svc/TUSF/"), new { data = Utils.Serialize(doSystemTask) });

                    if (customEventArgs.Index == doSystemTask.Count - 1 && doSystemTask != null)
                    {
                        string strSuccess = SendString(doSystemTask.Url3, new { data = Utils.Serialize(doSystemTask) });
                        if (Utils.GetJObjectValue(strSuccess, "Type").Equals("1"))
                        {
                            if (!doSystemTask.RowObject.Index.Equals(-1))
                            {
                                doSystemTask.RowObject.Cells["RunStatus"].Value = "成功";
                            }
                            Thread.Sleep(3000);
                            //因为线程,所以异步操作
                            this.Invoke(new EventHandler((object sender, EventArgs es) =>
                            {
                                if (!index.Equals(-1))
                                {
                                    dgvTack.Rows.Remove(dgvTack.Rows[index]);
                                }
                            }));

                            //if (listExists.Where(ie => ie.Equals(doSystemTask.Id)).Any())
                            //{
                            //    listExists.Remove(doSystemTask.Id);
                            //}

                            //var taskControl = listTaskControl.Where(item => item.SystemTask.Id.Equals(doSystemTask.Id));
                            //if (taskControl.Any())
                            //{
                            //    listTaskControl.Remove(taskControl.FirstOrDefault());
                            //}
                        }
                    }
                }
            };
            #endregion
            bool isAdd = false;
            if (systemTask.TaskType.Equals(0) && !Utils.IsNullOrEmpty(systemTask.FileUrl))//拆分
            {
                ExcelHelper excelHelper             = new ExcelHelper(GetUrl(systemTask.FileUrl, "excelParentUrl"));
                string      path                    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Homologous/ExcelToModel.xml");
                Dictionary <int, string> listHeader = excelHelper.TaskExcelColumns(path);
                //excelHelper.TaskExcelStandardization(excelHelper.TaskReadExcel(), listHeader);
                object[,] arrayItem = excelHelper.TaskReadExcel();
                bwTimer.count       = arrayItem.GetLength(0);
                systemTask.Count    = arrayItem.GetLength(0);
                bwTimer.Set(systemTask, arrayItem, listHeader, excelHelper);
                isAdd = true;
            }
            else if (systemTask.TaskType.Equals(1))//复估
            {
                string strDown = GetDownString(systemTask.Url1.Replace("{id}", systemTask.UploadFileId.ToString()));
                List <DataCollateral> listData = Utils.Deserialize <List <DataCollateral> >(Utils.GetJObjectValue(strDown, "Data"));
                if (listData != null)
                {
                    bwTimer.count    = listData.Count;
                    systemTask.Count = bwTimer.count;
                }
                bwTimer.Set(systemTask, listData);
                isAdd = true;
            }

            if (isAdd)
            {
                systemTask.RowObject.Cells["Count"].Value = systemTask.Count;
                bwTimer.Start(isSuspend);
                listTaskControl.Add(new TaskControl()
                {
                    SystemTask = systemTask, BackgroundWorker = bwTimer
                });
            }
        }