示例#1
0
        public bool TryGet(T sample, out T it)
        {
            rwLock.AcquireReaderLock(Timeout.Infinite);
            string path = null;

            it = default(T);
            try
            {
                path = GenPath(sample, false);
                //Console.WriteLine("TryGet******{0} {1}", path, idx);
                if (!File.Exists(path))
                {
                    return(false);
                }
                BaseTransfer transfer = GetTransfer();
                it = (IsSaveAsZip)?transfer.LoadZip <T>(path):transfer.Load <T>(path);
                return(true);
            }
            catch
            {
                if (path != null) //&& (e is SerializationException||e is FileLoadException) )
                {
                    File.Delete(path);
                }
                return(false);
            }
            finally
            {
                rwLock.ReleaseReaderLock();
            }
        }
 protected VirtualCollection(FileStream tempStream, BaseTransfer transfer)
 {
     Transfer                  = transfer;
     this.StoreStream          = tempStream;
     this.StoreStream.Position = this.StoreStream.Length;
     KeySelector               = it => it.GetHashCode();
     Init();
 }
        static private string BuildObjectString(object source, bool withBinaryFormatter)
        {
#if !SILVERLIGHT
            BaseTransfer transfer = withBinaryFormatter ? new BinaryTransfer() : (BaseTransfer) new XmlTransfer();
            return(Encoding.UTF8.GetString(transfer.ToBytes(source)));
#else
            BaseTransfer transfer = new JsonTransfer();
            var          chars    = transfer.ToBytes(source);
            return(Encoding.UTF8.GetString(chars, 0, chars.Length));
#endif
        }
示例#4
0
        public ApiParameter Exec2ApiParameter <TResult>(string cmd, BaseTransfer transfer)
        {
            TResult rlt     = Exec <TResult>(cmd);
            string  rltStr  = null;
            string  rltType = typeof(TResult).FullName;

            if (rlt != null)
            {
                rltType = rlt.GetType().FullName;
                rltStr  = transfer.ToText(rlt);
            }
            return(new ApiParameter()
            {
                TypeName = rltType, Serializer = transfer.GetType().FullName, Value = rltStr
            });
        }
示例#5
0
 //int idx = 0;
 public void Save(T it)
 {
     rwLock.AcquireWriterLock(Timeout.Infinite);
     try
     {
         string path = GenPath(it, true);
         //Console.WriteLine("Save******{0} {1}",path, idx);
         BaseTransfer transfer = GetTransfer();
         if (IsSaveAsZip)
         {
             transfer.SaveZip(it, path);
         }
         else
         {
             transfer.Save(it, path);
         }
     }finally
     {
         rwLock.ReleaseWriterLock();
     }
 }
 public PersistenList(FileStream tempStream, BaseTransfer transfer)
     : base(tempStream, transfer)
 {
 }
 public PersistenList(string tempFile, BaseTransfer transfer)
     : base(tempFile, transfer, FileMode.OpenOrCreate)
 {
 }
示例#8
0
        public string Exec2String <TResult>(string cmd, BaseTransfer transfer)
        {
            TResult rlt = Exec <TResult>(cmd);

            return(transfer.ToText(rlt));
        }
 protected VirtualCollection(string tempFile, BaseTransfer transfer, FileMode fileMode)
     : this(new FileStream(tempFile, fileMode), transfer)
 {
 }
示例#10
0
        private string Custom_TianJin(Order order, UserInfo userinfo)
        {
            string        reStr       = "";
            ENT311Message message_311 = new ENT311Message();



            Order_311        order_311     = new Order_311();
            OrderHead        orderhead_311 = new OrderHead();
            List <OrderList> orderlist_311 = new List <OrderList>();


            #region ///311报关头部
            orderhead_311.guid      = order.OrderGuid.ToString();
            orderhead_311.appType   = "1";
            orderhead_311.appTime   = DateTime.Now.ToString("yyyyMMddHHmmss");
            orderhead_311.appStatus = "2";
            orderhead_311.orderType = "I";

            orderhead_311.orderNo = order.OrderNo;
            //orderhead_311.goodsValue = order?.OrderTotal.ToString("f2");
            //orderhead_311.freight = "0";
            //orderhead_311.discount = "0";
            //orderhead_311.taxTotal = order?.OrderTotal.ToString("f2");
            //orderhead_311.acturalPaid = order?.OrderTotal.ToString("f2");


            decimal goodsValue  = 0; //商品实际成交价格
            decimal freight     = 0; //运杂费
            decimal discount    = 0; //抵扣金额
            decimal taxTotal    = 0; //税款
            decimal acturalPaid = 0; //实际支付



            orderhead_311.currency = "142";

            orderhead_311.buyerRegNo     = order.BuyerRegNo;
            orderhead_311.buyerName      = order.BuyerName;
            orderhead_311.buyerTelephone = order.BuyerTelephone;
            orderhead_311.buyerIdType    = order.BuyerIdType;
            orderhead_311.buyerIdNumber  = order.BuyerIdNumber;

            orderhead_311.payCode          = order.PayCode;
            orderhead_311.payName          = order.PayName;
            orderhead_311.payTransactionId = order.PayTransactionId;
            orderhead_311.batchNumbers     = userinfo.cebCode;
            orderhead_311.consignee        = order.Consignee;

            //orderhead_311.consigneeTelephone = order.ConsigneeTelephone;
            //orderhead_311.consignorAddress = order.ConsigneeAddress;
            //orderhead_311.consigneeDitrict = order.ConsigneeDitrict;


            orderhead_311.consigneeTelephone = order.ConsigneeTelephone;
            orderhead_311.consigneeAddress   = order.ConsigneeAddress;
            orderhead_311.consigneeDitrict   = order.ConsigneeDitrict;

            orderhead_311.note      = " ";
            orderhead_311.agentCode = userinfo.cebCode;

            orderhead_311.consigneeCountryCode = order.EtradeCountryCode;

            orderhead_311.consignorCname       = "智信通";
            orderhead_311.consignorAddress     = "智信通";
            orderhead_311.consignorTel         = "110";
            orderhead_311.consignorCountryCode = "156";

            orderhead_311.idCard            = order.IdCard;
            orderhead_311.idType            = order.IdType;
            orderhead_311.etradeCountryCode = order.EtradeCountryCode;
            orderhead_311.orderSerialNo     = userinfo.ecpCode + order.SubOrderNo;


            orderhead_311.ebcCode = userinfo.ebcCode;
            orderhead_311.ebcName = userinfo.ebcName;
            orderhead_311.ebpCode = userinfo.ebpCode;
            orderhead_311.ebpName = userinfo.ebpName;
            orderhead_311.ecpCode = userinfo.ecpCode;

            orderhead_311.cbeCode = userinfo.cebCode;

            BaseTransfer basetransfer = new BaseTransfer();
            basetransfer.copCode = userinfo.copCode;
            basetransfer.copName = userinfo.copName;
            basetransfer.dxpMode = "DXP";
            basetransfer.dxpId   = userinfo.dxpId;
            basetransfer.note    = " ";
            #endregion

            int count = 0;
            for (int i = 0; i < order.OrderItems.Count; i++)
            {
                OrderItem item = order.OrderItems[i];
                orderhead_311.ciqcurrency = item.CiqCurrency;
                orderhead_311.bizType     = item.OrderItemDetails == null?item.TradeType.ToString() : item.OrderItemDetails[0].TradeType.ToString();

                orderhead_311.intype = item.OrderItemDetails == null?item.TradeType.ToString() : item.OrderItemDetails[0].TradeType.ToString();

                if (item.OrderItemDetails == null)
                {
                    count++;
                    OrderList orderlist = new OrderList();

                    orderlist.gnum         = count.ToString();
                    orderlist.itemNo       = item.ProductSku?.Split('|')[0];
                    orderlist.itemName     = item.ItemName;
                    orderlist.gmodel       = item.ItemDescribe ?? " ";
                    orderlist.itemDescribe = item.ItemDescribe ?? " ";

                    orderlist.barCode = item.BarCode == "none" ? "0" : item.BarCode;
                    orderlist.unit    = item.Unit;
                    orderlist.qty     = item.Quantity.ToString();
                    orderlist.price   = item.PriceInclTax.ToString();


                    goodsValue += item.Quantity * item.PriceInclTax;//
                    discount   += item.Quantity * item.OrderDiscount;
                    taxTotal   += item.Quantity * item.OrderTax;

                    orderlist.totalPrice = item?.TotalPrice.ToString("f2");

                    orderlist.currency    = "142";
                    orderlist.ciqcountry  = item.CiqCountry;
                    orderlist.country     = item.Country;
                    orderlist.ciqcurrency = item.CiqCurrency;
                    orderlist.note        = " ";

                    orderlist.shelfGoodsName = item.ShelfGoodsName;
                    orderlist.wraptypeCode   = item.WrapTypeCode;
                    orderlist.purposeCode    = item.PurposeCode;
                    orderlist.goodsModel     = " ";
                    orderlist.goodsRegNo     = " ";
                    orderlist_311.Add(orderlist);
                }
                else
                {
                    for (int j = 0; j < item.OrderItemDetails.Count; j++)
                    {
                        count++;
                        OrderList orderlist = new OrderList();

                        orderlist.gnum         = count.ToString();
                        orderlist.itemNo       = item.OrderItemDetails[j].AttributeSku?.Split('|')[0];
                        orderlist.itemName     = item.ItemName;
                        orderlist.gmodel       = item.ItemDescribe ?? " ";
                        orderlist.itemDescribe = item.ItemDescribe ?? " ";

                        orderlist.barCode    = item.BarCode == "none" ? "0" : item.BarCode;
                        orderlist.unit       = item?.Unit;
                        orderlist.qty        = item?.OrderItemDetails?[j].Quantity.ToString("f2");
                        orderlist.price      = item?.OrderItemDetails[j].Price.ToString("f2");
                        orderlist.totalPrice = (item.OrderItemDetails[j].Quantity * item.OrderItemDetails[j].Price).ToString("f2"); // item?.OrderItemDetails==null item?.TotalPrice.ToString("f2"):item?.OrderItemDetails[j]..ToString("f2");

                        goodsValue += (item?.OrderItemDetails?[j].Quantity ?? 0) * (item?.OrderItemDetails[j].Price ?? 0);          //
                        discount   += (item?.OrderItemDetails?[j].Quantity ?? 0) * (item.OrderItemDetails?[j].OrderDiscount ?? 0);
                        taxTotal   += (item?.OrderItemDetails?[j].Quantity ?? 0) * (item.OrderItemDetails?[j].OrderTax ?? 0);



                        orderlist.currency    = "142";
                        orderlist.ciqcountry  = item.CiqCountry;
                        orderlist.country     = item.Country;
                        orderlist.ciqcurrency = item.CiqCurrency;
                        orderlist.note        = " ";

                        orderlist.shelfGoodsName = item.ShelfGoodsName;
                        orderlist.wraptypeCode   = item.WrapTypeCode;
                        orderlist.purposeCode    = item.PurposeCode;
                        orderlist.goodsModel     = " ";
                        orderlist.goodsRegNo     = " ";
                        orderlist_311.Add(orderlist);
                    }
                }
            }
            orderhead_311.goodsValue  = goodsValue.ToString("f2");
            orderhead_311.freight     = freight.ToString("f2");
            orderhead_311.discount    = discount.ToString("f2");
            orderhead_311.taxTotal    = taxTotal.ToString("f2");
            orderhead_311.acturalPaid = orderhead_311.acturalPaid = (goodsValue + freight + taxTotal - discount).ToString("f2");


            order_311.OrderHead = orderhead_311;
            order_311.OrderList = orderlist_311;

            message_311.Order        = order_311;
            message_311.BaseTransfer = basetransfer;
            message_311.guid         = "FBF24A92-B66D-4EE3-8A5B-1007C2A39777";
            message_311.version      = "v1.0";
            message_311.sendCode     = userinfo.cebCode;// "Q120600201905000322";
            message_311.reciptCode   = "121500";

            XmlSerializer xsOrder = new XmlSerializer(typeof(ENT311Message));
            using (var stream = new MemoryStream())
            {
                try
                {
                    XmlWriterSettings setting = new XmlWriterSettings();
                    setting.Encoding = Encoding.GetEncoding("UTF-8");

                    setting.Indent             = true;
                    setting.IndentChars        = "    ";
                    setting.NewLineChars       = "\r\n";
                    setting.OmitXmlDeclaration = false;

                    XmlWriter wrint = XmlWriter.Create(stream, setting);
                    var       n     = new XmlSerializerNamespaces();
                    n.Add("", "http://www.chinaport.gov.cn/ENT");


                    //n.Add("ceb", "http://www.chinaport.gov.cn/ceb");
                    //n.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                    xsOrder.Serialize(wrint, message_311, n);
                    wrint.Close();
                }
                catch (Exception ex)
                {
                }
                stream.Position = 0;
                StreamReader sr = new StreamReader(stream);
                reStr = sr.ReadToEnd();
                sr.Dispose();
                stream.Dispose();
                _IRabbitMQHelper.Publish <custom311Controller>(reStr);
            }
            return(reStr);
        }