public void SynInvnetoryQty() { if (!IsActive) { throw new Exception("当前线程已终止,请调用Start()重新启动。"); } ThirdPartInventoryArgs args = new ThirdPartInventoryArgs(); //CommonConst commonConst = new CommonConst(); int batchNumber = Common.BatchNumber; int batch = (batchNumber > ThirdPartInventory.Count) ? 1 : (ThirdPartInventory.Count % batchNumber == 0 ? ThirdPartInventory.Count / batchNumber : (ThirdPartInventory.Count / batchNumber + 1)); List <ThirdPartInventoryEntity> qtylist; for (int i = 0; i < batch; i++) { qtylist = ThirdPartInventory.Skip(i * batchNumber).Take(batchNumber).ToList(); args.ThirdPartInventoryList = qtylist; try { OnRunningBefor(this, args); if (!IsActive) { break; } On_Running(this, args); if (!IsActive) { break; } OnRunningAfter(this, args); if (!IsActive) { break; } } catch (Exception ex) { ThirdPartInventoryErrorArgs errorArgs = new ThirdPartInventoryErrorArgs(); errorArgs.Exception = ex; errorArgs.ThirdPartInventoryList = qtylist; OnError(this, errorArgs); if (!IsActive) { break; } } } }
private void WriteErrorLog(object sender, ThirdPartInventoryErrorArgs args) { ExceptionHelper.HandleException(args.Exception); string error = string.Format("{0} \r\n {1}", args.Exception.Message, args.Exception.StackTrace); List <ThirdPartInventoryEntity> list = args.ThirdPartInventoryList; XmlSerializer ser = new XmlSerializer(typeof(List <ThirdPartInventoryEntity>)); MemoryStream stream = new MemoryStream(); ser.Serialize(stream, list); string xmlString = Encoding.UTF8.GetString(stream.GetBuffer()); stream.Dispose(); WriteLog(string.Format("出错数据:\r\n{0}", xmlString)); WriteLog(string.Format("{0}\r\n", error), true); if (Common.ThirdPartSynType == SynType.Queue) { ThirdPartInventoryBPBase bp = sender as ThirdPartInventoryBPBase; if (bp != null) { bp.Abort(); } } }
protected virtual void On_Error(object sender, ThirdPartInventoryErrorArgs args) { }