/// <summary> /// 更新商家编码,返回失败的商品,同时置成功商品的IsUpdate为TRUE,标识已同步到淘宝 /// </summary> /// <param name="nick"></param> /// <param name="itemdic"></param> /// <returns></returns> private Dictionary <string, string> UpdateOuterId(string nick, Dictionary <string, string> itemdic, DoWorkEventArgs e) { Dictionary <string, string> failedItemsDic = new Dictionary <string, string>(); List <string> iidlist = itemdic.Keys.ToList(); ItemReq req = new ItemReq(); ItemRsp response = new ItemRsp(); string session = SystemHelper.GetSessionKey(nick); float n = iidlist.Count; int temp = 0;//作用是避免进度值propgress没有改变时得重复报告 for (int i = 0; i < n; i++) { if (workerUpdate.CancellationPending) { e.Cancel = true; break; } if (workerUpdate.CancellationPending) { e.Cancel = true; break; } string iid = iidlist[i]; req.Iid = iid; req.OuterId = itemdic.SingleOrDefault(it => it.Key == iid).Value; try { response = TopService.ItemUpdate(session, req); if (response.Item == null) { failedItemsDic.Add(req.Iid, req.OuterId); } else { ItemService.UpdateItemIsUpdate(iid, true); } } catch (System.Exception ex) { failedItemsDic.Add(req.Iid, req.OuterId); continue; } //进度报告 int propgress = (int)((float)(i + 1) / n * 100); if (propgress > temp) { workerUpdate.ReportProgress(propgress, null); } temp = propgress; } return(failedItemsDic); }
/// <summary> /// 将上架计划列表中的宝贝更新到淘宝,返回成功宝贝的iid /// </summary> /// <param name="itemdic"></param> /// <returns></returns> private Dictionary <string, string> UpdateListPlan(string nick, Dictionary <string, string> itemdic, BackgroundWorker backWorker, DoWorkEventArgs e) { Dictionary <string, string> successitems = new Dictionary <string, string>(); List <string> iidlist = itemdic.Keys.ToList(); ItemReq req = new ItemReq(); ItemRsp response = new ItemRsp(); string session = SystemHelper.GetSessionKey(nick); float n = iidlist.Count; int temp = 0;//作用是避免进度值propgress没有改变时得重复报告 for (int i = 0; i < n; i++) { if (backWorker.CancellationPending) { e.Cancel = true; break; } string iid = iidlist[i]; req.Iid = iid; req.ApproveStatus = "onsale"; req.ListTime = itemdic.SingleOrDefault(it => it.Key == iid).Value; try { response = TopService.ItemUpdate(session, req); if (response.Item != null) { successitems.Add(req.Iid, req.ListTime); } } catch (Exception) { continue; } //进度报告 int propgress = (int)((float)(i + 1) / n * 100); if (propgress > temp) { backWorker.ReportProgress(propgress, null); } temp = propgress; } return(successitems); }