public T LoadConfiguration <T>(string configStoreInfor) where T : class { if (string.IsNullOrEmpty(configStoreInfor)) { return(null); } string storeFileName = GetCacheInfor(configStoreInfor); if (!File.Exists(storeFileName)) { return(null); } try { T resultLoad = ObjectXmlSerializer.LoadFromXml <T>(storeFileName); return(resultLoad); } catch { return(null); } }
public ActionResult LostCoffee(CoffeeInit req) { var clientInfo = this.TempData["ClientInfo"] as ClientInfo; string EtmID = clientInfo.EtmCode; //string EtmID = "ETM0027"; var list = ObjectXmlSerializer.LoadFromXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml")); if (list.Find(o => o.EtmID == EtmID).CupNumber < req.CupNumber) { return(this.Json(new { retCode = 1, Message = "提交失败,饮品剩余数量不足!" })); } list.Find(o => o.EtmID == EtmID).CupNumber -= req.CupNumber; //检测剩余杯数,发短信 try { if (list.Find(o => o.EtmID == EtmID).CupNumber <= int.Parse(ConfigurationManager.AppSettings["EnableSmsCupNumber"]) && list.Find(o => o.EtmID == EtmID).SendSMS == "0" && ConfigurationManager.AppSettings["EnableSms"] == "true") { list.Find(o => o.EtmID == EtmID).CupNumber = 1; const string takedateUrl = "api/Coffee/SendSms"; var fullPath = ETong.Coffee.Web.Models.Config.GetApiFullPath(takedateUrl); var client = new HttpClientUtility(new Uri(fullPath)); Logger.Write(Log.Log_Type.Info, string.Format("调用{0}", fullPath)); var resultT = SecurityHttpClient.Post <string, ResponseData <string> >(fullPath, EtmID); Logger.Write(Log.Log_Type.Info, string.Format("{0}结束,result={1}", fullPath, Json(resultT.dataMap))); } } catch (Exception ex) { Logger.Write(Log.Log_Type.Info, string.Format("短信发送失败etmid={0},err={1}", EtmID, ex.ToString())); } Logger.Write(Log.Log_Type.Info, string.Format("减库存etmid={0},CupNumber={1}", EtmID, req.CupNumber)); ObjectXmlSerializer.SaveToXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml"), list); return(this.Json(new { retCode = 0, Message = "成功" })); }
public ActionResult Rest() { var clientInfo = this.TempData["ClientInfo"] as ClientInfo; string EtmID = clientInfo.EtmCode; //string EtmID = "ETM0027"; var list = ObjectXmlSerializer.LoadFromXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml")); list.Find(o => o.EtmID == EtmID).SendSMS = "0"; list.Find(o => o.EtmID == EtmID).CupNumber = list.Find(o => o.EtmID == "ETMDefault").CupNumber; ObjectXmlSerializer.SaveToXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml"), list); return(this.Json(new { retCode = 0, Message = "" })); }
public void ReadSetting() { try { if (System.IO.File.Exists(this.SETTING_PATH)) { RegSetting._instance = ObjectXmlSerializer.LoadFromXml <RegSetting>(this.SETTING_PATH); } } catch (System.Exception err) { Log.WriteError("读取配置信息错误", err); } }
private T LoadConfiguration <T>(string cacheKey, string configFile, bool needLog) where T : class { var config = ObjectXmlSerializer.LoadFromXml <T>(configFile, needLog); if (config != null) { AddToCache(cacheKey, config, configFile, needLog); } else { throw new LoadFileException(typeof(T).Name, configFile); } return(config); }
public ActionResult Init() { var clientInfo = this.TempData["ClientInfo"] as ClientInfo; string EtmID = clientInfo.EtmCode; //string EtmID = "ETM0027"; var list = ObjectXmlSerializer.LoadFromXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml")); var result = list.Find(o => o.EtmID == EtmID); if (result == null) { var defaultResult = list.Find(o => o.EtmID == "ETMDefault"); result = (CoffeeInit)Copy(defaultResult); result.EtmID = EtmID; result.DrinkList = null; list.Add(result); ObjectXmlSerializer.SaveToXml <List <CoffeeInit> >(Server.MapPath("~/cache/Coffee.xml"), list); } result.DrinkList = list.Find(o => o.EtmID == "ETMDefault").DrinkList; return(this.Json(result)); }
private static Dictionary <string, DatabaseInstance> LoadDatabaseList() { string EncrytIV = "Weiche88"; DatabaseList list = ObjectXmlSerializer.LoadFromXml <DatabaseList>(DataAccessSetting.DatabaseConfigFile); if (list == null || list.DatabaseInstances == null || list.DatabaseInstances.Length == 0) { throw new DatabaseNotSpecifiedException(); } Dictionary <string, DatabaseInstance> hashtable = new Dictionary <string, DatabaseInstance>(list.DatabaseInstances.Length); foreach (DatabaseInstance instance in list.DatabaseInstances) { DatabaseInstance conn = null; if (ConfigurationHelper.IsNeedEncryt) { if (ConfigurationManager.AppSettings["EncryptKey"] == String.Empty) { throw new ConnStringEncrytSettingException(); } try { instance.ConnectionString = SecurityHelper.Dencrypt(instance.ConnectionString, ConfigurationManager.AppSettings["EncryptKey"], EncrytIV); conn = instance; } catch { throw new ConnStringDeEncrytException(instance.Name); } } else { conn = instance; } hashtable.Add(instance.Name.ToUpper(), conn); } return(hashtable); }
/// <summary> /// 创建订单 /// </summary> /// <param name="ord"></param> /// <returns></returns> public OrderGroupResult CreateOrder(CoffeeOrder ord) { if (ord == null) { throw new ArgumentNullException("order"); } var s = new OrderManager(); string orderDescribe = ""; //验证产品单价 var list = ObjectXmlSerializer.LoadFromXml <List <CoffeeInit> >(System.Web.HttpContext.Current.Server.MapPath("~/cache/Coffee.xml")); var ordDetails = ord.DrinkList.GroupBy(o => o.Value).Select(o => (new Drink() { Name = o.Min(item => item.Name), Value = o.Key, Number = o.Sum(item => item.Number), Price = o.Sum(item => item.Number * item.Price), Materials = null })); foreach (var item in ordDetails) { if (item.Price != list[0].DrinkList.Find(o => o.Value == item.Value).Price *item.Number) { throw new Exception("产品单价有误!"); } orderDescribe = orderDescribe == "" ? orderDescribe : orderDescribe + "@#"; orderDescribe += String.Format("名称:{0}@#金额:{1}元@#数量:{2}", item.Name, item.Price, item.Number); } //验证订单金额金额 if (ord.TotalAmount != ord.DrinkList.Sum(o => o.Price * o.Number) + ord.Fee) { throw new Exception("订单金额有误!"); } var orderinfo = new OrderInfo { memberId = ord.MemberId, message = "", orderAmount = ord.Amount.ToString(CultureInfo.InvariantCulture), orderDescribe = orderDescribe, orderFrom = ord.OrderFrom.ToString(), orderType = OrderType.ToString(), storeId = this.GetStoreInfo().StoreId, storeName = this.GetStoreInfo().StoreName, totalAmount = (ord.TotalAmount).ToString(CultureInfo.InvariantCulture), orderEtm = ord.OrderETMID, deleiveryFee = ord.Fee, memberName = ord.MemberName }; var mresult = s.CreateOrder(orderinfo); Logger.Write(Log.Log_Type.Info, string.Format("主订单创建成功,order={0}", JsonConvert.SerializeObject(mresult))); var context = new CoffeeOrderContext(); for (int i = 0; i < ord.DrinkList.Count; i++) { var item = ord.DrinkList[i]; var coffeeDetail = new BM_COFFEE_DETAIL() { ORDER_ID = mresult.dataMap.orderId, ID = mresult.dataMap.orderId + i.ToString(), ADD_FEE = 0, AMOUNT = item.Number * item.Price, CAPACITY = item.Capacity, COFFEE_TYPE = item.Value, COFFEE_TYPENAME = item.Name, CREATE_DATE = DateTime.Now, PRICE = item.Price, DESCRIPTION = "", QUANTITY = item.Number, TOTAL = item.Number * item.Price, MATERIALS = JsonConvert.SerializeObject(item.Materials), ISSUED = 0 }; Logger.Write(Log.Log_Type.Info, string.Format("订单详情,Detail={0}", JsonConvert.SerializeObject(coffeeDetail))); context.BM_COFFEE_DETAIL.Add(coffeeDetail); } context.SaveChanges(); OrderGroupResult result = new OrderGroupResult(); result.GroupId = mresult.dataMap.orderId; result.Items = new List <OrderItemResult>(); result.Items.Add(new OrderItemResult() { Amount = ord.TotalAmount, ItemName = orderinfo.orderDescribe, OrderId = mresult.dataMap.orderId, Qty = ord.Quantity, StoreId = orderinfo.storeId, StoreName = orderinfo.storeName }); result.TotalAmount = ord.TotalAmount; return(result); }