/// <summary> /// validates currency type units. assumes three valid signals: price and priceRelative with units of curencyType, and /// priceMultiplier with no units /// </summary> /// <param name="signalType"></param> /// <param name="units"></param> /// <param name="currencyDescriptonType"></param> public static void validateUnits(SignalTypeEnumeratedType signalType, ItemBaseType units, currencyItemDescriptionType currencyDescriptonType) { if (signalType == SignalTypeEnumeratedType.price || signalType == SignalTypeEnumeratedType.priceRelative) { // the class could be currencyType, or a sub class currencyPerKWh, currencyPerKW type if (units.GetType().BaseType != typeof(currencyType) && units.GetType() != typeof(currencyType)) { throw new ExceptionInvalidSignal(ExceptionInvalidSignal.INVALID_UNITS); } currencyType c = (currencyType)units; if (c.itemDescription != currencyDescriptonType) { throw new ExceptionInvalidSignal(ExceptionInvalidSignal.INVALID_UNITS); } return; } if (signalType == SignalTypeEnumeratedType.priceMultiplier) { if (units != null) { throw new ExceptionInvalidSignal(ExceptionInvalidSignal.INVALID_UNITS); } return; } throw new ExceptionInvalidSignal(ExceptionInvalidSignal.INVALID_TYPE); }
//returns a formatted currency based on a speific culture public string GetCurrencyByType(currencyType ctype) { switch (ctype) { case currencyType.Swedish: { //formats currency to 2 decimal places return(sum.ToString("C2", System.Globalization.CultureInfo.CreateSpecificCulture("sv-SE"))); } case currencyType.Japanese: { //formats currency to no decimal place return(sum.ToString("C0", System.Globalization.CultureInfo.CreateSpecificCulture("ja-JP"))); } case currencyType.USD: { //formats currency to 2 decimal places return(sum.ToString("C2", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))); } case currencyType.Thai: { //formats currency to 2 decimal places return(sum.ToString("C2", System.Globalization.CultureInfo.CreateSpecificCulture("th-TH"))); } default: return(""); //added as reduncy because will not reach this section } }
/******************************************************************************/ private currencyType generateCurrency(currencyItemDescriptionType description) { currencyType currency = new currencyType(); currency.itemDescription = description; currency.itemUnits = ISO3AlphaCurrencyCodeContentType.USD; currency.siScaleCode = SiScaleCodeType.none; return(currency); }
public void currency() { currencyType c = new currencyType(); c.itemDescription = currencyItemDescriptionType.currency; c.itemUnits = ISO3AlphaCurrencyCodeContentType.USD; c.siScaleCode = SiScaleCodeType.none; testItemBase(c); }
/**********************************************************/ public override void validateUnits(SignalTypeEnumeratedType signalType, ItemBaseType units) { if (signalType == SignalTypeEnumeratedType.price) { if (units.GetType() != typeof(currencyType)) { throw new ExceptionInvalidSignal(ExceptionInvalidSignal.INVALID_UNITS); } currencyType c = (currencyType)units; if (c.itemDescription != currencyItemDescriptionType.currency) { throw new ExceptionInvalidSignal(ExceptionInvalidSignal.INVALID_UNITS); } return; } throw new ExceptionInvalidSignal(ExceptionInvalidSignal.INVALID_TYPE); }
public void generateOadrDistributeEvent() { oadrPayload payload = new oadrPayload(); payload.oadrSignedObject = new oadrSignedObject(); oadrDistributeEventType distributeEvent = new oadrDistributeEventType(); distributeEvent.schemaVersion = "2.0b"; distributeEvent.eiResponse = new EiResponseType(); distributeEvent.eiResponse.requestID = ""; distributeEvent.eiResponse.responseCode = "200"; distributeEvent.eiResponse.responseDescription = "OK"; distributeEvent.requestID = "OadrDisReq050214_092500_050"; distributeEvent.vtnID = "TH_VTN"; payload.oadrSignedObject.Item = distributeEvent; distributeEvent.oadrEvent = new oadrDistributeEventTypeOadrEvent[1]; oadrDistributeEventTypeOadrEvent oadrEvent = new oadrDistributeEventTypeOadrEvent(); distributeEvent.oadrEvent[0] = oadrEvent; eiEventType eiEvent = new eiEventType(); oadrEvent.eiEvent = eiEvent; eiEvent.eventDescriptor = new eventDescriptorType(); eiEvent.eventDescriptor.eventID = "Event050214_092500_550_0"; eiEvent.eventDescriptor.modificationNumber = 0; eiEvent.eventDescriptor.modificationDateTime = DateTime.ParseExact("2014-02-05T17:25:00Z", "yyyy-MM-ddTHH:mm:00Z", CultureInfo.InvariantCulture); eiEvent.eventDescriptor.modificationReason = "Update"; eiEvent.eventDescriptor.priority = 1; eiEvent.eventDescriptor.eiMarketContext = new eventDescriptorTypeEiMarketContext(); eiEvent.eventDescriptor.eiMarketContext.marketContext = "http://MarketContext1"; eiEvent.eventDescriptor.createdDateTime = DateTime.ParseExact("2014-02-05T17:25:00Z", "yyyy-MM-ddTHH:mm:00Z", CultureInfo.InvariantCulture); eiEvent.eventDescriptor.eventStatus = EventStatusEnumeratedType.completed; eiEvent.eventDescriptor.testEvent = "false"; eiEvent.eventDescriptor.vtnComment = "Sample Payload"; eiEvent.eventDescriptor.vtnComment = "comment"; // active period eiEvent.eiActivePeriod = new eiActivePeriodType(); eiEvent.eiActivePeriod.properties = new properties(); eiEvent.eiActivePeriod.properties.dtstart = new dtstart(); eiEvent.eiActivePeriod.properties.dtstart.datetime = DateTime.ParseExact("2014-02-05T17:35:00Z", "yyyy-MM-ddTHH:mm:00Z", CultureInfo.InvariantCulture); eiEvent.eiActivePeriod.properties.duration = new DurationPropType(); eiEvent.eiActivePeriod.properties.duration.duration = "PT5M"; eiEvent.eiActivePeriod.properties.xeiNotification = new DurationPropType(); eiEvent.eiActivePeriod.properties.xeiNotification.duration = "PT1M"; // signals eiEvent.eiEventSignals = new eiEventSignalsType(); eiEvent.eiEventSignals.eiEventSignal = new eiEventSignalType[1]; eiEventSignalType signal = new eiEventSignalType(); signal.intervals = new IntervalType[1]; signal.intervals[0] = new IntervalType(); signal.intervals[0].duration = new DurationPropType(); signal.intervals[0].duration.duration = "PT5M"; IntervalTypeUidUid uid = new IntervalTypeUidUid(); uid.text = "0"; signal.intervals[0].Item = uid; // signal payload signal.intervals[0].streamPayloadBase = new StreamPayloadBaseType[1]; signalPayloadType val = new signalPayloadType(); PayloadFloatType pft = new PayloadFloatType(); pft.value = (float)3.14; val.Item = pft; signal.intervals[0].streamPayloadBase[0] = val; eiEvent.eiEventSignals.eiEventSignal[0] = signal; // signal type signal.signalName = SignalNameEnumeratedType.ELECTRICITY_PRICE.ToString(); signal.signalType = SignalTypeEnumeratedType.price; signal.signalID = "SIG_02"; currencyType currency = new currencyType(); currency.itemDescription = currencyItemDescriptionType.currencyPerKWh; currency.itemUnits = ISO3AlphaCurrencyCodeContentType.USD; currency.siScaleCode = SiScaleCodeType.none; signal.itemBase = currency; signal.currentValue = new currentValueType(); PayloadFloatType pft2 = new PayloadFloatType(); pft2.value = (float)0.0; signal.currentValue.Item = pft2; signal.eiTarget = new EiTargetType(); signal.eiTarget.resourceID = new string[2]; signal.eiTarget.resourceID[0] = "resource1"; signal.eiTarget.resourceID[1] = "resource2"; oadrEvent.oadrResponseRequired = ResponseRequiredType.always; string xml = SerializeOadrObject.serializeOjbect(payload, payload.GetType()); Console.Out.WriteLine(xml); /*serializer = new XmlSerializer(typeof(eiEventSignalType)); * * MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)); * * signal = (eiEventSignalType)serializer.Deserialize(ms); * * Assert.IsNotNull(signal); * * ms.Close();*/ }
public GiftCardRewardBuilder WithCurrency(currencyType value) { this.currency = value; return(this); }