public override void Load() { Assembly cAssembly = Assembly.GetExecutingAssembly(); __cRuleItems = RulePropertyAttribute.GetRules(cAssembly); string sLocation = cAssembly.Location; string sPath = Path.GetDirectoryName(sLocation); string sTargetName = Path.GetFileNameWithoutExtension(sLocation) + ".set"; string sFileName = Path.Combine(sPath, sTargetName); string[] sDatas = File.ReadAllLines(sFileName, Encoding.UTF8); JObject cExchange = JsonConvert.DeserializeObject <JObject>(sDatas[0]); this.FullName = cExchange["FullName"].Value <string>(); this.ShortName = cExchange["ShortName"].Value <string>(); this.UpdateTime = cExchange["UpdateTime"].Value <DateTime>(); this.Products = JsonConvert.DeserializeObject <Dictionary <string, Product> >(sDatas[1]); //讀取基礎商品屬性表 this.BasePropertys = CreateProductPropertyList(sDatas[2]); //讀取使用者自訂商品屬性表 this.CustomPropertys = new Dictionary <string, ProductPropertyList>(16); Dictionary <string, JToken> sCustoms = JsonConvert.DeserializeObject <Dictionary <string, JToken> >(sDatas[3]); foreach (string sDataSource in sCustoms.Keys) { JToken cToken = sCustoms[sDataSource]; ProductPropertyList cPropertyList = CreateProductPropertyList(cToken.ToString(Formatting.None)); this.CustomPropertys.Add(sDataSource, cPropertyList); } }
private static ProductPropertyList CreateProductPropertyList(string jsonText) { ProductPropertyList cBasePropertyList = new ProductPropertyList(); Dictionary <string, TaiwanProductProperty> cPropertys = JsonConvert.DeserializeObject <Dictionary <string, TaiwanProductProperty> >(jsonText); foreach (TaiwanProductProperty cProperty in cPropertys.Values) { //設定交易時間列表給規則使用 RuleBase cProductRule = cProperty.ContractRule; if (cProductRule is IContractParameters) { IContractParameters cRule = cProductRule as IContractParameters; cRule.SetParameters(cProperty.Sessions); } cBasePropertyList.AddProperty(cProperty); } return(cBasePropertyList); }
public override void Save() { string sLocation = Assembly.GetExecutingAssembly().Location; string sPath = Path.GetDirectoryName(sLocation); string sTargetName = Path.GetFileNameWithoutExtension(sLocation) + ".set"; string sFileName = Path.Combine(sPath, sTargetName); this.UpdateTime = DateTime.Now; //更新寫入時間 string sCustomPropertys = "{}"; string sExchange = JsonConvert.SerializeObject(this); string sProducts = JsonConvert.SerializeObject(this.Products); string sBasePropertys = JsonConvert.SerializeObject(this.BasePropertys.Propertys); int iStringCount = sExchange.Length + sProducts.Length + sBasePropertys.Length; int iCustomCount = this.CustomPropertys.Count; if (iCustomCount > 0) { Dictionary <string, Dictionary <string, AbstractProductProperty> > cCustoms = new Dictionary <string, Dictionary <string, AbstractProductProperty> >(this.CustomPropertys.Count); foreach (string sKey in this.CustomPropertys.Keys) { ProductPropertyList cPropertyList = this.CustomPropertys[sKey]; cCustoms.Add(sKey, cPropertyList.Propertys); } sCustomPropertys = JsonConvert.SerializeObject(cCustoms); iStringCount += sCustomPropertys.Length; } StringBuilder cBuilder = new StringBuilder(iStringCount + 128); cBuilder.AppendLine(sExchange); //交易所資訊 cBuilder.AppendLine(sProducts); //產品資訊 cBuilder.AppendLine(sBasePropertys); //基礎商品屬性資訊 cBuilder.AppendLine(sCustomPropertys); //自訂商品屬性資訊 File.WriteAllText(sFileName, cBuilder.ToString(), Encoding.UTF8); }