Esempio n. 1
0
        private void Upload()
        {
            //网站名称获取ID
            int webId = WebsiteManager.GetWebIdByWebName(this.网站名称);

            if (webId == 0)
            {
                log.Debug(string.Format("传入网站名称错误:(城市名称:所有,网站名称:{0})", this.网站名称 == null ? "null" : this.网站名称));
                return;
            }
            //开始数据上传
            while (true)
            {
                System.Threading.Thread.Sleep(this.频率);
                //查询需要整理的案例
                log.Debug(string.Format("查询需要整理的案例数据:(城市名称:所有,网站名称:{0})",
                                        (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString()));
                List <VIEW_案例信息_城市表_网站表> list = CaseLogManager.获取当前要整理入库的案例(this.网站名称, this.一次上传个数);
                if (list == null || list.Count < 1)
                {
                    log.Debug(string.Format("案例数据已整理发布完成:(城市名称:所有,网站名称:{0})",
                                            (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString()));
                    continue;
                }
                //数据上传
                log.Debug(string.Format("已查询到需要整理的案例数据{0}个,发布数据中:(城市名称:所有,网站名称:{1})", list.Count, this.网站名称 == null ? "null" : this.网站名称));
                list.ForEach(delegate(VIEW_案例信息_城市表_网站表 _obj)
                {
                    log.Debug(string.Format("发布数据中:(ID:{0},城市名称:{1},网站名称:{2})", _obj.ID, _obj.城市, _obj.网站));
                });
                #region 多个上传
                List <案例库上传信息过滤表>      过滤案例List = null;
                Dictionary <long, int> dic      = new Dictionary <long, int>();
                if (!CaseApi.发布需要整理的数据到服务器(list, out 过滤案例List, out dic))
                {
                    log.Debug(string.Format("发布需要整理的数据到服务器_异常:(城市名称:所有,网站名称:{0},案例ID个数:{1})",
                                            (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                            list.Count));
                    break;
                }
                //记录过滤掉的案例ID
                log.Debug(string.Format("获取到要过滤的案例ID:(城市名称:所有,网站名称:{0},案例ID个数:{1},过滤ID数组个数:{2})",
                                        (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                        list.Count, 过滤案例List == null ? 0 : 过滤案例List.Count));
                if (过滤案例List != null && 过滤案例List.Count > 0)
                {
                    过滤案例List.ForEach(delegate(案例库上传信息过滤表 _obj)
                    {
                        log.Debug(string.Format("过滤掉的案例:(ID:{0},城市ID:{1},网站ID:{2})", _obj.案例ID, _obj.城市ID, _obj.网站ID.ToString2()));
                    });
                    log.Debug(string.Format("将上传时被过滤的信息记录到表中:(城市名称:所有,网站名称:{0},案例ID个数:{1},过滤ID数组个数:{2})",
                                            (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                            list.Count, 过滤案例List.Count));
                    if (!CaseFilterLogManager.将上传时被过滤的信息记录到表中(webId, 过滤案例List))
                    {
                        log.Debug(string.Format("将上传时被过滤的信息记录到表中_异常:(城市名称:所有,网站名称{0},案例ID个数{1},过滤ID数组个数:{2})",
                                                (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                                list.Count, 过滤案例List.Count));
                        break;
                    }
                }

                //统计入库失败的案例个数
                log.Debug(string.Format("统计入库失败的案例个数:(城市名称:所有,网站名称:{0},案例ID:{1},案例ID个数:{2})",
                                        (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                        Convert.ToInt64(list[list.Count - 1].ID), list.Count));
                string message = "";
                if (!ProjectCaseCountManager.UpdateNotImportCaseCount(list, 过滤案例List, out message))
                {
                    log.Debug(string.Format("统计入库失败的案例个数_系统异常:(案例ID个数{0})", list.Count));
                    break;
                }
                //记录上传成功的案例ID
                log.Debug(string.Format("将当前已经整理入库的案例记录表中:(城市名称:所有,网站名称:{0},案例ID:{1},案例ID个数:{2})",
                                        (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                        Convert.ToInt64(list[list.Count - 1].ID), list.Count));
                if (!CaseLogManager.将当前已经整理入库的案例记录表中(list, dic))
                {
                    log.Debug(string.Format("将当前已经整理入库的案例记录表中_系统异常:(城市名称:所有,网站名称:{0},案例ID:{1},案例ID个数:{2})",
                                            (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                            Convert.ToInt64(list[list.Count - 1].ID), list.Count));
                    break;
                }
                log.Debug(string.Format("当前案例ID数据记录完成:(城市名称:所有,网站名称:{0},案例ID:{1},案例ID个数:{2})",
                                        (this.网站名称 == null ? "null" : this.网站名称) + "$" + webId.ToString(),
                                        Convert.ToInt64(list[list.Count - 1].ID), list.Count));
                #endregion
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="list"></param>
        /// <param name="failList">返回失败的案例</param>
        /// <returns></returns>
        public static bool ImportCase(List <VIEW_案例信息_城市表_网站表> list, out List <VIEW_案例信息_城市表_网站表> failList, out string message)
        {
            message  = "";
            failList = new List <VIEW_案例信息_城市表_网站表>();
            List <案例库上传信息过滤表>      过滤案例List = null;
            Dictionary <long, int> dic      = new Dictionary <long, int>();

            if (!CaseApi.发布需要整理的数据到服务器(list, out 过滤案例List, out dic))
            {
                message = "fxt服务异常";
                log.Debug(string.Format("发布需要整理的数据到服务器_异常:(案例ID个数:{0})", list.Count));
                return(false);
            }
            using (DataClassesDataContext db = new DataClassesDataContext())
            {
                db.Connection.Open();
                //开始事务
                var tran = db.Connection.BeginTransaction();
                try
                {
                    db.Transaction = tran;

                    //删除此次案例的滤记录
                    List <long> caseIdList = new List <long>();
                    if (list != null)
                    {
                        foreach (VIEW_案例信息_城市表_网站表 caseView in list)
                        {
                            caseIdList.Add(caseView.ID);
                        }
                        if (!CaseFilterLogManager.DeleteCaseFilterByCaseIds(caseIdList.ToArray(), db: db))
                        {
                            message = "系统异常";
                            log.Debug(string.Format("删除此次案例的滤记录_异常:(案例ID个数:{0},过滤ID数组个数:{1})",
                                                    list.Count, 过滤案例List.Count));
                            tran.Rollback();
                            return(false);
                        }
                    }

                    //记录过滤掉的案例ID
                    if (过滤案例List != null && 过滤案例List.Count > 0)
                    {
                        foreach (案例库上传信息过滤表 obj in 过滤案例List)
                        {
                            VIEW_案例信息_城市表_网站表 obj2 = list.Find(delegate(VIEW_案例信息_城市表_网站表 obj3) { return(obj3.ID == obj.案例ID); });
                            if (obj2 != null)
                            {
                                failList.Add(obj2);
                            }
                        }
                        if (!CaseFilterLogManager.将上传时被过滤的信息记录到表中(过滤案例List, db))
                        {
                            message = "将上传时被过滤的信息记录到表中_系统异常";
                            log.Debug(string.Format("将上传时被过滤的信息记录到表中_异常:(案例ID个数:{0},过滤ID数组个数:{1})",
                                                    list.Count, 过滤案例List.Count));
                            tran.Rollback();
                            return(false);
                        }
                    }
                    //统计入库失败的案例个数
                    if (!ProjectCaseCountManager.UpdateNotImportCaseCount(list, 过滤案例List, out message, new DAL.DB.DataClass(db)))
                    {
                        log.Debug(string.Format("统计入库失败的案例个数_系统异常:(案例ID个数{0})", list.Count));
                        tran.Rollback();
                        return(false);
                    }
                    //记录上传成功的案例ID
                    if (!CaseLogManager.将当前已经整理入库的案例记录表中(list, dic, db))
                    {
                        message = "将当前已经整理入库的案例记录表中_系统异常";
                        log.Debug(string.Format("将当前已经整理入库的案例记录表中_系统异常:(案例ID个数{0})", list.Count));
                        tran.Rollback();
                        return(false);
                    }

                    db.Transaction.Commit();
                }
                catch (Exception ex)
                {
                    message = "系统异常";
                    log.Error(string.Format("系统异常ImportCase(List<VIEW_案例信息_城市表_网站表> list, out List<VIEW_案例信息_城市表_网站表> failList)", list.Count), ex);
                    tran.Rollback();
                    return(false);
                }
            }

            return(true);
        }