public ShipmentEx GetRates(Address originAddress, Address destinationAddress, List <Package> packages) { var shipment = new ShipmentEx(originAddress, destinationAddress, packages) { RateAdjusters = _adjusters }; return(getRates(ref shipment)); }
/// <summary> /// 获得费率 /// </summary> /// <param name="shipment"></param> /// <returns></returns> private ShipmentEx getRates(ref ShipmentEx shipment) { //AbstractShippingProvider provider = _provider as AbstractShippingProvider; //provider.Shipment = shipment; //provider.GetRates(); //return shipment; var threads = new ArrayList(_providers.Count); foreach (AbstractShippingProvider provider in _providers) { provider.Shipment = shipment; var thread = new Thread(provider.GetRates); thread.Name = provider.Name; thread.Start(); threads.Add(thread); } while (threads.Count > 0) { for (var x = (threads.Count - 1); x > -1; x--) { if (((Thread)threads[x]).ThreadState == ThreadState.Stopped) { ((Thread)threads[x]).Abort(); threads.RemoveAt(x); } } Thread.Sleep(1); } return(shipment); }
/// <summary> /// 创建在线运单 /// </summary> /// <param name="shipEx"></param> /// <returns></returns> public CreateShipRep CreateShip(ShipmentEx shipEx) { CreateShipRep rep = new CreateShipRep(); List <ShipReply> result = new List <ShipReply>(); ShipReply reply = null; FedExShipProvider ship = new FedExShipProvider(_key, _password, _accountNumber, _meterNumber); ship.Shipment = shipEx; ship.Url = _url; //生成主单 ship.CreateShipment(); if (ship.ShipReplyEx != null) { ship.ShipReplyEx.Master = true; result.Add(ship.ShipReplyEx); ShipManager shipManage = new ShipManager(); List <Package> pkgList = new List <Package>(); foreach (Package item in shipEx.Packages) { pkgList.Add(item); } pkgList.RemoveAt(0); //生成副单 int i = 0; foreach (Package item in pkgList) { FedExShipSubProvider shipSub = new FedExShipSubProvider(_key, _password, _accountNumber, _meterNumber, ship.ShipReplyEx.TrackFormId, ship.ShipReplyEx.TrackNumber); shipSub.Shipment = shipEx; shipSub.SequenceNumber = i + 2; shipSub.CurPackage = item; i++; shipSub.Url = _url; shipManage.AddProvider(shipSub); } List <ShipReply> tmpList = shipManage.CreateShips(); foreach (ShipReply item in tmpList) { item.MasterTrackFormId = ship.ShipReplyEx.TrackFormId; item.MasterTrackNumber = ship.ShipReplyEx.MasterTrackNumber; } result.AddRange(tmpList); } // shipManage. // reply=ship.CreateShipment(_url); rep.ReplyList = result; if (result == null) { rep.Message = "邮编地址与地区不匹配,生成运单失败!"; } //rep.Message = ship.ErrorMessage;//英文错误提示,翻译成中文 return(rep); }