/// <summary> /// 取得商品屬性 /// </summary> /// <param name="symbol">商品來源代號或商品代號</param> /// <param name="dataSource">資料來源名稱</param> public AbstractProductProperty GetProperty(string symbol, string dataSource = null) { AbstractProductProperty cProperty = null; Product cProduct = GetProduct(symbol); if (dataSource != null) { ProductPropertyList cPropertyList = null; if (CustomPropertys.TryGetValue(dataSource, out cPropertyList)) { if (cProduct == null) { cProperty = cPropertyList.GetProperty(symbol); } else { cProperty = cPropertyList.GetProperty(cProduct); } } } if (cProperty == null) { if (cProduct == null) { cProperty = this.BasePropertys.GetProperty(symbol); } else { cProperty = this.BasePropertys.GetProperty(cProduct); } } return(cProperty); }
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; }
/// <summary> /// 新增商品屬性(如果商品已經存在會覆寫之前屬性設定) /// </summary> /// <param name="property">商品屬性類別</param> /// <param name="dataSource">資料來源名稱</param> public void AddProperty(AbstractProductProperty property, string dataSource = null) { if (dataSource == null) { BasePropertys.AddProperty(property); } else { ProductPropertyList cPropertyList = null; if (!CustomPropertys.TryGetValue(dataSource, out cPropertyList)) { cPropertyList = new ProductPropertyList(); CustomPropertys.Add(dataSource, cPropertyList); } cPropertyList.AddProperty(property); } }
/// <summary> /// 移除商品屬性 /// </summary> /// <param name="symbolId">商品代號</param> /// <param name="dataSource">資料來源名稱</param> public void RemoveProperty(string symbolId, string dataSource = null) { Product cProduct = GetProduct(symbolId); if (dataSource == null) { BasePropertys.RemoveProperty(cProduct); } else { ProductPropertyList cPropertyList = null; if (CustomPropertys.TryGetValue(dataSource, out cPropertyList)) { cPropertyList.RemoveProperty(cProduct); if (cPropertyList.Count == 0) { CustomPropertys.Remove(dataSource); } } } }