public Commodity(XmlNode xmlNode) : base(xmlNode) { XmlNodeList commodityBaseNodeList = xmlNode.SelectNodes("commodityBase"); if (commodityBaseNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in commodityBaseNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { commodityBaseIDRef = item.Attributes["id"].Name; CommodityBase ob = CommodityBase(); IDManager.SetID(commodityBaseIDRef, ob); } else if (item.Attributes.ToString() == "href") { commodityBaseIDRef = item.Attributes["href"].Name; } else { commodityBase = new CommodityBase(item); } } } XmlNodeList commodityDetailsNodeList = xmlNode.SelectNodes("commodityDetails"); if (commodityDetailsNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in commodityDetailsNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { commodityDetailsIDRef = item.Attributes["id"].Name; CommodityDetails ob = CommodityDetails(); IDManager.SetID(commodityDetailsIDRef, ob); } else if (item.Attributes.ToString() == "href") { commodityDetailsIDRef = item.Attributes["href"].Name; } else { commodityDetails = new CommodityDetails(item); } } } XmlNodeList unitNodeList = xmlNode.SelectNodes("unit"); if (unitNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in unitNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { unitIDRef = item.Attributes["id"].Name; QuantityUnit ob = QuantityUnit(); IDManager.SetID(unitIDRef, ob); } else if (item.Attributes.ToString() == "href") { unitIDRef = item.Attributes["href"].Name; } else { unit = new QuantityUnit(item); } } } XmlNodeList currencyNodeList = xmlNode.SelectNodes("currency"); if (currencyNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in currencyNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { currencyIDRef = item.Attributes["id"].Name; Currency ob = Currency(); IDManager.SetID(currencyIDRef, ob); } else if (item.Attributes.ToString() == "href") { currencyIDRef = item.Attributes["href"].Name; } else { currency = new Currency(item); } } } XmlNodeList exchangeIdNodeList = xmlNode.SelectNodes("exchangeId"); if (exchangeIdNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in exchangeIdNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { exchangeIdIDRef = item.Attributes["id"].Name; ExchangeId ob = ExchangeId(); IDManager.SetID(exchangeIdIDRef, ob); } else if (item.Attributes.ToString() == "href") { exchangeIdIDRef = item.Attributes["href"].Name; } else { exchangeId = new ExchangeId(item); } } } XmlNodeList publicationNodeList = xmlNode.SelectNodes("publication"); if (publicationNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in publicationNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { publicationIDRef = item.Attributes["id"].Name; CommodityInformationSource ob = CommodityInformationSource(); IDManager.SetID(publicationIDRef, ob); } else if (item.Attributes.ToString() == "href") { publicationIDRef = item.Attributes["href"].Name; } else { publication = new CommodityInformationSource(item); } } } XmlNodeList specifiedPriceNodeList = xmlNode.SelectNodes("specifiedPrice"); if (specifiedPriceNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in specifiedPriceNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { specifiedPriceIDRef = item.Attributes["id"].Name; SpecifiedPriceEnum ob = SpecifiedPriceEnum(); IDManager.SetID(specifiedPriceIDRef, ob); } else if (item.Attributes.ToString() == "href") { specifiedPriceIDRef = item.Attributes["href"].Name; } else { specifiedPrice = new SpecifiedPriceEnum(item); } } } XmlNodeList deliveryDatesNodeList = xmlNode.SelectNodes("deliveryDates"); if (deliveryDatesNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in deliveryDatesNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { deliveryDatesIDRef = item.Attributes["id"].Name; DeliveryDatesEnum ob = DeliveryDatesEnum(); IDManager.SetID(deliveryDatesIDRef, ob); } else if (item.Attributes.ToString() == "href") { deliveryDatesIDRef = item.Attributes["href"].Name; } else { deliveryDates = new DeliveryDatesEnum(item); } } } XmlNodeList deliveryDateNodeList = xmlNode.SelectNodes("deliveryDate"); if (deliveryDateNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in deliveryDateNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { deliveryDateIDRef = item.Attributes["id"].Name; AdjustableDate ob = AdjustableDate(); IDManager.SetID(deliveryDateIDRef, ob); } else if (item.Attributes.ToString() == "href") { deliveryDateIDRef = item.Attributes["href"].Name; } else { deliveryDate = new AdjustableDate(item); } } } XmlNodeList deliveryDateYearMonthNodeList = xmlNode.SelectNodes("deliveryDateYearMonth"); if (deliveryDateYearMonthNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in deliveryDateYearMonthNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { deliveryDateYearMonthIDRef = item.Attributes["id"].Name; XsdTypeGYearMonth ob = XsdTypeGYearMonth(); IDManager.SetID(deliveryDateYearMonthIDRef, ob); } else if (item.Attributes.ToString() == "href") { deliveryDateYearMonthIDRef = item.Attributes["href"].Name; } else { deliveryDateYearMonth = new XsdTypeGYearMonth(item); } } } XmlNodeList deliveryDateRollConventionNodeList = xmlNode.SelectNodes("deliveryDateRollConvention"); if (deliveryDateRollConventionNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in deliveryDateRollConventionNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { deliveryDateRollConventionIDRef = item.Attributes["id"].Name; Offset ob = Offset(); IDManager.SetID(deliveryDateRollConventionIDRef, ob); } else if (item.Attributes.ToString() == "href") { deliveryDateRollConventionIDRef = item.Attributes["href"].Name; } else { deliveryDateRollConvention = new Offset(item); } } } XmlNodeList multiplierNodeList = xmlNode.SelectNodes("multiplier"); if (multiplierNodeList.Count > 1 ) { throw new Exception(); } foreach (XmlNode item in multiplierNodeList) { if (item.Attributes["href"] != null || item.Attributes["id"] == null) { if (item.Attributes["id"] != null) { multiplierIDRef = item.Attributes["id"].Name; PositiveDecimal ob = PositiveDecimal(); IDManager.SetID(multiplierIDRef, ob); } else if (item.Attributes.ToString() == "href") { multiplierIDRef = item.Attributes["href"].Name; } else { multiplier = new PositiveDecimal(item); } } } }
/// <summary> /// /// </summary> /// <param name="commodityType"></param> /// <param name="commodityDetails"></param> /// <param name="currency"></param> /// <param name="multiplier"></param> /// <param name="specifiedPrice"></param> /// <param name="deliveryDateRollConvention"></param> /// <param name="priceQuoteUnits"></param> /// <param name="deliveryDates"></param> /// <param name="exchangeId"></param> /// <param name="informationSource"></param> /// <returns></returns> public static Commodity Create(string commodityType, string commodityDetails, string currency, int multiplier, SpecifiedPriceEnum specifiedPrice, Offset deliveryDateRollConvention, PriceQuoteUnitsEnum priceQuoteUnits, DeliveryDatesEnum deliveryDates, string exchangeId, string informationSource) { var commodity = new Commodity { currency = new Currency { Value = currency }, commodityBase = new CommodityBase { Value = commodityType }, commodityDetails = new CommodityDetails { Value = commodityDetails }, deliveryDateRollConvention = deliveryDateRollConvention, Item1 = deliveryDates, multiplier = multiplier, multiplierSpecified = true, specifiedPriceSpecified = true, unit = new QuantityUnit(), specifiedPrice = specifiedPrice }; commodity.unit.Value = priceQuoteUnits.ToString(); if (exchangeId != null) { commodity.Item = ExchangeIdHelper.Parse(exchangeId); } else { commodity.Item = InformationSourceHelper.Create(informationSource); } return(commodity); }