protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //{"ext":"\"11\"","msg":"","result":"Exec successful,0/1 is error!ReplicateCount is1"}


                SortedDictionary <string, string> pams = GetRequestPost(Request.RequestContext.HttpContext.Request);
                // CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + System.Guid.NewGuid() + ".txt", JsonConvert.SerializeObject(pams));//创建文件   JsonConvert.SerializeObject(pams);
                string        result       = pams["result"] == null ? "" : pams["result"].ToString();
                SuccessStatus notifyResult = SuccessStatus.Other;
                bool          isSucess     = true;
                if (result.IndexOf("successful") > -1)
                {
                    isSucess     = true;
                    notifyResult = SuccessStatus.Success;
                }
                else
                {
                    isSucess     = false;
                    notifyResult = SuccessStatus.Failed;
                    CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", JsonConvert.SerializeObject(pams));//创建文件
                }

                UpdateNotifyRequest request = new UpdateNotifyRequest()
                {
                    UpdateStatusId = pams["ext"] == null || string.IsNullOrEmpty(pams["ext"])? "0" : pams["ext"].ToString().Replace("\\", ""),
                    ResponseParams = JsonConvert.SerializeObject(pams),
                    NotifyResult   = notifyResult,
                    IsSucess       = isSucess
                };

                IPolicyNotify notify = new DefaultPolicyNotify();
                EmptyResponse res    = notify.UpdateNotify(request);
                if (res.ErrCode == PolicyService.Enums.ResultType.Failed)
                {
                    string log = DateTime.Now + ":回调内容:" + JsonConvert.SerializeObject(pams) + ",更新回调结果:" + JsonConvert.SerializeObject(res);
                    CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", log);//创建文件
                    Response.Write("F");
                    //Response.End();
                }
                else
                {
                    Response.Write("S");
                }
                //Response.End();
            }
            catch (Exception ex)
            {
                CoreHelper.CreateFile(System.Configuration.ConfigurationManager.AppSettings["NotifyErrLogPath"] + "\\Qunar\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", JsonConvert.SerializeObject(ex));//创建文件
            }
        }
        public override void Invoke(IHandlerContext context)
        {
            try
            {
                QunarUploadPolicyRequest qunarRequest = CoreHelper.ChangeToChild <UpLoadPolicyRequest, QunarUploadPolicyRequest>(context.Request);

                Dictionary <UploadTypeDetail, PolicyRecord> dicRec = new Dictionary <UploadTypeDetail, PolicyRecord>();

                List <SeatDiscountDto> seatDiscountList = new List <SeatDiscountDto>();
                if (qunarRequest.PolicyType != QunarPolicyType.COMMON)
                {
                    SeatDiscountListResponse seatRep = JsonConvert.DeserializeObject <SeatDiscountListResponse>(CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SeatDiscountListUrl"], ""));//获取舱位折扣列表
                    seatDiscountList = seatRep.SeatDiscountList;
                }
                Dictionary <string, string> lstUploadedId = new Dictionary <string, string>();
                #region  择要封装哪个节点
                foreach (KeyValuePair <UploadTypeDetail, List <Policies> > item in qunarRequest.PolicyData)
                {
                    if (item.Value.Count > 0)
                    {
                        Policies ps = item.Value.LastOrDefault();
                        //if (item.Key != UploadTypeDetail.IncrementalDelete)
                        //{

                        item.Value.ForEach(x =>
                        {
                            if (!lstUploadedId.ContainsKey(x.Id.ToString()))
                            {
                                lstUploadedId.Add(x.Id.ToString(), x.PartnerPolicyId);
                            }
                        });
                        // }
                        dicRec.Add(item.Key, new PolicyRecord {
                            LastPolicyId = ps.Id, LastUpdateTime = ps.UpdateTime
                        });
                        DivideTask(item.Key, item.Value, qunarRequest, seatDiscountList, ChangeToQunarAddPolicy, ChangeToQunarDelPolicy);//开始多任务处理
                    }
                }
                #endregion
                string logPath = qunarRequest.FormatFilePath + "\\" + DateTime.Now.Year + "\\" + DateTime.Now.Month + "\\" + DateTime.Now.Day + "\\" + DateTime.Now.Hour + "\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xml";
                string zipPath = qunarRequest.FormatZipFilePath + "\\" + DateTime.Now.Year + "\\" + DateTime.Now.Month + "\\" + DateTime.Now.Day + "\\" + DateTime.Now.Hour + "\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".zip";

                if (qunarAddPolicy.ToList().Count <= 0 && qunarDelPolicy.ToList().Count <= 0)
                {
                    OnMiddlewareWorking(new EventMsg {
                        Status = RunStatus.Normal, Msg = "经过去哪儿格式化组件筛选完后没有要上传的政策"
                    });
                    return;
                }

                #region 保存上传记录
                PolicyNotifyRequest notifyRequest = new PolicyNotifyRequest();
                SaveNotifyResponse  notifyRes     = new SaveNotifyResponse();

                notifyRequest = new PolicyNotifyRequest()
                {
                    // DicRec = dicRec,
                    UploadType      = qunarRequest.UploadType,
                    PolicyRec       = context.UploadResponse.PolicyRec[qunarRequest.UploadType],//最后一条政策记录
                    Purchaser       = PurchaserType.Qunar,
                    NotifyResult    = 0,
                    FileNamePath    = zipPath,
                    ResponseParams  = "",
                    RequestParams   = qunarRequest.SqlWhere,
                    Remark          = IPAddressHelper.GetInternalIP(),
                    OperName        = qunarRequest.OperName,
                    UploadCount     = qunarRequest.UploadCount,
                    BeforePolicyRec = context.UploadResponse.BeforePolicyRecord == null ? new PolicyRecord() : context.UploadResponse.BeforePolicyRecord,
                    CommisionMoney  = qunarRequest.CommisionMoney,
                    CommisionPoint  = qunarRequest.CommsionPoint,
                    UploadPolicyIds = lstUploadedId,
                    PolicyType      = (PoliciesType)Enum.Parse(typeof(PoliciesType), qunarRequest.PolicyType.ToString())
                };
                string notifyContent = CoreHelper.DoPost(System.Configuration.ConfigurationManager.AppSettings["SavePolicyNotifyUrl"].ToString(), notifyRequest);
                notifyRes = JsonConvert.DeserializeObject <SaveNotifyResponse>(notifyContent);//先查询一遍,获取要上传的政策
                if (notifyRes.ErrCode == ResultType.Failed)
                {
                    context.UploadResponse = new UploadPolicyResponse {
                        ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "保存上传记录失败"
                    };
                    return;
                }
                #endregion

                #region 封装去哪儿政策类
                QunarPolicy policyBase = new QunarPolicy()
                {
                    username     = ConfigurationManager.AppSettings["QunarUsername"].ToString(),
                    password     = ConfigurationManager.AppSettings["QunarPassword"].ToString(),
                    type         = qunarRequest.PolicyType,
                    execType     = qunarRequest.UploadType == UploadType.FullUpload ? ExecType.FULL : ExecType.ADD,
                    addPolicy    = qunarAddPolicy.ToList(),                              //添加政策节点
                    deletePolicy = qunarDelPolicy.ToList(),                              //删除政策节点
                    ext          = JsonConvert.SerializeObject(notifyRes.UploadStatusId) //保存xml文件路径
                };
                #endregion

                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "封装去哪儿政策类成功,扩展信息:" + JsonConvert.SerializeObject(notifyRes.UploadStatusId) + ",开始序列化成功xml..."
                });
                string xmlContent = XmlHelper.Serializer(typeof(QunarPolicy), policyBase); //序列化成xml
                CoreHelper.CreateFile(logPath, xmlContent);                                //创建文件
                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Normal, Msg = "序列化xml并创建文件成功,生成的xml文件路径:" + logPath + ",开始压缩并上传..."
                });
                context.UploadResponse.FormatPolicyFilePath    = logPath;//保存xml文件路径
                context.UploadResponse.FormatPolicyZipFilePath = zipPath;
                context.UploadResponse.UploadStatusId          = notifyRes.UploadStatusId;
                Next.Invoke(context);
            }catch (Exception ex)
            {
                OnMiddlewareWorking(new EventMsg {
                    Status = RunStatus.Exception, Msg = "格式化去哪儿数据失败!" + JsonConvert.SerializeObject(ex)
                });
                context.UploadResponse = new UploadPolicyResponse {
                    ErrCode = PolicyService.Enums.ResultType.Failed, ErrMsg = "格式化去哪儿数据失败!", Excption = ex
                };
                return;
            }
        }