public OCPIResponse(OCPIRequest Request, Int32 StatusCode, String StatusMessage, String AdditionalInformation = null, DateTime?Timestamp = null, HTTPResponse HTTPResponse = null, Request_Id?RequestId = null, Correlation_Id?CorrelationId = null, Party_Id?FromPartyId = null, CountryCode?FromCountryCode = null, Party_Id?ToPartyId = null, CountryCode?ToCountryCode = null) { this.Request = Request; this.StatusCode = StatusCode; this.StatusMessage = StatusMessage; this.AdditionalInformation = AdditionalInformation; this.Timestamp = Timestamp ?? DateTime.UtcNow; this.HTTPResponse = HTTPResponse; this.RequestId = RequestId; this.CorrelationId = CorrelationId; this.FromPartyId = FromPartyId; this.FromCountryCode = FromCountryCode; this.ToPartyId = ToPartyId; this.ToCountryCode = ToCountryCode; }
/// <summary> /// Try to parse the given text representation of a token. /// </summary> /// <param name="Text">The text to parse.</param> /// <param name="Token">The parsed token.</param> /// <param name="ErrorResponse">An optional error response.</param> /// <param name="TokenIdURL">An optional token identification, e.g. from the HTTP URL.</param> /// <param name="CustomTokenParser">A delegate to parse custom token JSON objects.</param> public static Boolean TryParse(String Text, out Token Token, out String ErrorResponse, CountryCode?CountryCodeURL = null, Party_Id?PartyIdURL = null, Token_Id?TokenIdURL = null, CustomJObjectParserDelegate <Token> CustomTokenParser = null) { try { return(TryParse(JObject.Parse(Text), out Token, out ErrorResponse, CountryCodeURL, PartyIdURL, TokenIdURL, CustomTokenParser)); } catch (Exception e) { Token = null; ErrorResponse = "The given text representation of a token is invalid: " + e.Message; return(false); } }
/// <summary> /// Parse the given text representation of a token. /// </summary> /// <param name="Text">The text to parse.</param> /// <param name="TokenIdURL">An optional token identification, e.g. from the HTTP URL.</param> /// <param name="CustomTokenParser">A delegate to parse custom token JSON objects.</param> public static Token Parse(String Text, CountryCode?CountryCodeURL = null, Party_Id?PartyIdURL = null, Token_Id?TokenIdURL = null, CustomJObjectParserDelegate <Token> CustomTokenParser = null) { if (TryParse(Text, out Token token, out String ErrorResponse, CountryCodeURL, PartyIdURL, TokenIdURL, CustomTokenParser)) { return(token); } throw new ArgumentException("The given text representation of a token is invalid: " + ErrorResponse, nameof(Text)); }
/// <summary> /// Parse the given text representation of a session. /// </summary> /// <param name="Text">The text to parse.</param> /// <param name="SessionIdURL">An optional session identification, e.g. from the HTTP URL.</param> /// <param name="CustomSessionParser">A delegate to parse custom session JSON objects.</param> public static Session Parse(String Text, CountryCode?CountryCodeURL = null, Party_Id?PartyIdURL = null, Session_Id?SessionIdURL = null, CustomJObjectParserDelegate <Session> CustomSessionParser = null) { if (TryParse(Text, out Session session, out String ErrorResponse, CountryCodeURL, PartyIdURL, SessionIdURL, CustomSessionParser)) { return(session); } throw new ArgumentException("The given text representation of a session is invalid: " + ErrorResponse, nameof(Text)); }
/// <summary> /// Parse the given text representation of a tariff. /// </summary> /// <param name="Text">The text to parse.</param> /// <param name="TariffIdURL">An optional tariff identification, e.g. from the HTTP URL.</param> /// <param name="CustomTariffParser">A delegate to parse custom tariff JSON objects.</param> public static Tariff Parse(String Text, CountryCode?CountryCodeURL = null, Party_Id?PartyIdURL = null, Tariff_Id?TariffIdURL = null, CustomJObjectParserDelegate <Tariff> CustomTariffParser = null) { if (TryParse(Text, out Tariff tariff, out String ErrorResponse, CountryCodeURL, PartyIdURL, TariffIdURL, CustomTariffParser)) { return(tariff); } throw new ArgumentException("The given text representation of a tariff is invalid: " + ErrorResponse, nameof(Text)); }
/// <summary> /// Try to parse the given JSON representation of a token. /// </summary> /// <param name="JSON">The JSON to parse.</param> /// <param name="Token">The parsed token.</param> /// <param name="ErrorResponse">An optional error response.</param> /// <param name="CountryCodeURL">An optional country code, e.g. from the HTTP URL.</param> /// <param name="PartyIdURL">An optional party identification, e.g. from the HTTP URL.</param> /// <param name="TokenIdURL">An optional token identification, e.g. from the HTTP URL.</param> /// <param name="CustomTokenParser">A delegate to parse custom token JSON objects.</param> public static Boolean TryParse(JObject JSON, out Token Token, out String ErrorResponse, CountryCode?CountryCodeURL = null, Party_Id?PartyIdURL = null, Token_Id?TokenIdURL = null, CustomJObjectParserDelegate <Token> CustomTokenParser = null) { try { Token = default; if (JSON?.HasValues != true) { ErrorResponse = "The given JSON object must not be null or empty!"; return(false); } #region Parse CountryCode [optional] if (JSON.ParseOptionalStruct("country_code", "country code", CountryCode.TryParse, out CountryCode? CountryCodeBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!CountryCodeURL.HasValue && !CountryCodeBody.HasValue) { ErrorResponse = "The country code is missing!"; return(false); } if (CountryCodeURL.HasValue && CountryCodeBody.HasValue && CountryCodeURL.Value != CountryCodeBody.Value) { ErrorResponse = "The optional country code given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse PartyIdURL [optional] if (JSON.ParseOptionalStruct("party_id", "party identification", Party_Id.TryParse, out Party_Id? PartyIdBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!PartyIdURL.HasValue && !PartyIdBody.HasValue) { ErrorResponse = "The party identification is missing!"; return(false); } if (PartyIdURL.HasValue && PartyIdBody.HasValue && PartyIdURL.Value != PartyIdBody.Value) { ErrorResponse = "The optional party identification given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse Id [optional] if (JSON.ParseOptionalStruct("uid", "token identification", Token_Id.TryParse, out Token_Id? TokenIdBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!TokenIdURL.HasValue && !TokenIdBody.HasValue) { ErrorResponse = "The token identification is missing!"; return(false); } if (TokenIdURL.HasValue && TokenIdBody.HasValue && TokenIdURL.Value != TokenIdBody.Value) { ErrorResponse = "The optional token identification given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse Type [mandatory] if (!JSON.ParseMandatoryEnum("type", "token type", out TokenTypes Type, out ErrorResponse)) { return(false); } #endregion #region Parse ContractId [mandatory] if (!JSON.ParseMandatory("contract_id", "contract identification", Contract_Id.TryParse, out Contract_Id ContractId, out ErrorResponse)) { return(false); } #endregion #region Parse VisualNumber [optional] var VisualNumber = JSON.GetString("visual_number"); #endregion #region Parse Issuer [mandatory] if (!JSON.ParseMandatoryText("issuer", "issuer", out String Issuer, out ErrorResponse)) { return(false); } #endregion #region Parse GroupId [optional] if (JSON.ParseOptional("group_id", "group identification", Group_Id.TryParse, out Group_Id? GroupId, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse IsValid [mandatory] if (!JSON.ParseMandatory("valid", "token is valid", out Boolean IsValid, out ErrorResponse)) { return(false); } #endregion #region Parse WhitelistType [mandatory] if (!JSON.ParseMandatoryEnum("whitelist", "whitelist type", out WhitelistTypes WhitelistType, out ErrorResponse)) { return(false); } #endregion #region Parse UILanguage [optional] if (JSON.ParseOptionalEnum("language", "user-interface language", out Languages? UILanguage, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse DefaultProfile [optional] if (JSON.ParseOptionalEnum("default_profile_type", "user-interface language", out ProfileTypes? DefaultProfile, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse EnergyContract [optional] if (JSON.ParseOptionalJSON("energy_contract", "energy contract", OCPIv2_2.EnergyContract.TryParse, out EnergyContract EnergyContract, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse LastUpdated [mandatory] if (!JSON.ParseMandatory("last_updated", "last updated", out DateTime LastUpdated, out ErrorResponse)) { return(false); } #endregion Token = new Token(CountryCodeBody ?? CountryCodeURL.Value, PartyIdBody ?? PartyIdURL.Value, TokenIdBody ?? TokenIdURL.Value, Type, ContractId, Issuer, IsValid, WhitelistType, VisualNumber, GroupId, UILanguage, DefaultProfile, EnergyContract, LastUpdated); if (CustomTokenParser != null) { Token = CustomTokenParser(JSON, Token); } return(true); } catch (Exception e) { Token = default; ErrorResponse = "The given JSON representation of a token is invalid: " + e.Message; return(false); } }
/// <summary> /// Try to parse the given JSON representation of a session. /// </summary> /// <param name="JSON">The JSON to parse.</param> /// <param name="Session">The parsed session.</param> /// <param name="ErrorResponse">An optional error response.</param> /// <param name="CountryCodeURL">An optional country code, e.g. from the HTTP URL.</param> /// <param name="PartyIdURL">An optional party identification, e.g. from the HTTP URL.</param> /// <param name="SessionIdURL">An optional session identification, e.g. from the HTTP URL.</param> /// <param name="CustomSessionParser">A delegate to parse custom session JSON objects.</param> public static Boolean TryParse(JObject JSON, out Session Session, out String ErrorResponse, CountryCode?CountryCodeURL = null, Party_Id?PartyIdURL = null, Session_Id?SessionIdURL = null, CustomJObjectParserDelegate <Session> CustomSessionParser = null) { try { Session = default; if (JSON?.HasValues != true) { ErrorResponse = "The given JSON object must not be null or empty!"; return(false); } #region Parse CountryCode [optional] if (JSON.ParseOptionalStruct("country_code", "country code", CountryCode.TryParse, out CountryCode? CountryCodeBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!CountryCodeURL.HasValue && !CountryCodeBody.HasValue) { ErrorResponse = "The country code is missing!"; return(false); } if (CountryCodeURL.HasValue && CountryCodeBody.HasValue && CountryCodeURL.Value != CountryCodeBody.Value) { ErrorResponse = "The optional country code given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse PartyIdURL [optional] if (JSON.ParseOptionalStruct("party_id", "party identification", Party_Id.TryParse, out Party_Id? PartyIdBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!PartyIdURL.HasValue && !PartyIdBody.HasValue) { ErrorResponse = "The party identification is missing!"; return(false); } if (PartyIdURL.HasValue && PartyIdBody.HasValue && PartyIdURL.Value != PartyIdBody.Value) { ErrorResponse = "The optional party identification given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse Id [optional] if (JSON.ParseOptionalStruct("id", "session identification", Session_Id.TryParse, out Session_Id? SessionIdBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!SessionIdURL.HasValue && !SessionIdBody.HasValue) { ErrorResponse = "The session identification is missing!"; return(false); } if (SessionIdURL.HasValue && SessionIdBody.HasValue && SessionIdURL.Value != SessionIdBody.Value) { ErrorResponse = "The optional session identification given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse Start [mandatory] if (!JSON.ParseMandatory("start_date_time", "start timestamp", out DateTime Start, out ErrorResponse)) { return(false); } #endregion #region Parse End [optional] if (JSON.ParseOptional("end_date_time", "end timestamp", out DateTime? End, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse KWh [mandatory] if (!JSON.ParseMandatory("kwh", "charged kWh", out Decimal KWh, out ErrorResponse)) { return(false); } #endregion #region Parse CDRToken [mandatory] if (!JSON.ParseMandatoryJSON("cdr_token", "charge detail record token", OCPIv2_1_1.CDRToken.TryParse, out CDRToken CDRToken, out ErrorResponse)) { return(false); } #endregion #region Parse AuthMethod [mandatory] if (!JSON.ParseMandatoryEnum("auth_method", "authentication method", out AuthMethods AuthMethod, out ErrorResponse)) { return(false); } #endregion #region Parse AuthorizationReference [optional] if (JSON.ParseOptionalStruct("authorization_reference", "authorization reference", OCPIv2_1_1.AuthorizationReference.TryParse, out AuthorizationReference? AuthorizationReference, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse LocationId [mandatory] if (!JSON.ParseMandatory("location_id", "location identification", Location_Id.TryParse, out Location_Id LocationId, out ErrorResponse)) { return(false); } #endregion #region Parse EVSEUId [mandatory] if (!JSON.ParseMandatory("evse_uid", "EVSE identification", EVSE_UId.TryParse, out EVSE_UId EVSEUId, out ErrorResponse)) { return(false); } #endregion #region Parse ConnectorId [mandatory] if (!JSON.ParseMandatory("connector_id", "connector identification", Connector_Id.TryParse, out Connector_Id ConnectorId, out ErrorResponse)) { return(false); } #endregion #region Parse MeterId [optional] if (JSON.ParseOptional("meter_id", "meter identification", Meter_Id.TryParse, out Meter_Id? MeterId, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse EnergyMeter [optional] if (JSON.ParseOptionalJSON("energy_meter", "energy meter", OCPIv2_1_1.EnergyMeter.TryParse, out EnergyMeter EnergyMeter, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse TransparencySoftwares [optional] if (JSON.ParseOptionalJSON("transparency_softwares", "transparency softwares", TransparencySoftware.TryParse, out IEnumerable <TransparencySoftware> TransparencySoftwares, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse Currency [mandatory] if (!JSON.ParseMandatory("currency", "currency", OCPIv2_1_1.Currency.TryParse, out Currency Currency, out ErrorResponse)) { return(false); } #endregion #region Parse ChargingPeriods [optional] if (JSON.ParseOptionalJSON("charging_periods", "charging periods", ChargingPeriod.TryParse, out IEnumerable <ChargingPeriod> ChargingPeriods, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse TotalCosts [optional] if (JSON.ParseOptionalJSON("total_cost", "total costs", Price.TryParse, out Price? TotalCosts, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse Status [mandatory] if (!JSON.ParseMandatoryEnum("status", "session status", out SessionStatusTypes Status, out ErrorResponse)) { return(false); } #endregion #region Parse LastUpdated [mandatory] if (!JSON.ParseMandatory("last_updated", "last updated", out DateTime LastUpdated, out ErrorResponse)) { return(false); } #endregion Session = new Session(CountryCodeBody ?? CountryCodeURL.Value, PartyIdBody ?? PartyIdURL.Value, SessionIdBody ?? SessionIdURL.Value, Start, KWh, CDRToken, AuthMethod, LocationId, EVSEUId, ConnectorId, Currency, Status, End, AuthorizationReference, MeterId, EnergyMeter, TransparencySoftwares, ChargingPeriods, TotalCosts, LastUpdated); if (CustomSessionParser != null) { Session = CustomSessionParser(JSON, Session); } return(true); } catch (Exception e) { Session = default; ErrorResponse = "The given JSON representation of a session is invalid: " + e.Message; return(false); } }
/// <summary> /// Try to parse the given JSON representation of a tariff. /// </summary> /// <param name="JSON">The JSON to parse.</param> /// <param name="Tariff">The parsed tariff.</param> /// <param name="ErrorResponse">An optional error response.</param> /// <param name="CountryCodeURL">An optional country code, e.g. from the HTTP URL.</param> /// <param name="PartyIdURL">An optional party identification, e.g. from the HTTP URL.</param> /// <param name="TariffIdURL">An optional tariff identification, e.g. from the HTTP URL.</param> /// <param name="CustomTariffParser">A delegate to parse custom tariff JSON objects.</param> public static Boolean TryParse(JObject JSON, out Tariff Tariff, out String ErrorResponse, CountryCode?CountryCodeURL = null, Party_Id?PartyIdURL = null, Tariff_Id?TariffIdURL = null, CustomJObjectParserDelegate <Tariff> CustomTariffParser = null) { try { Tariff = default; if (JSON?.HasValues != true) { ErrorResponse = "The given JSON object must not be null or empty!"; return(false); } #region Parse CountryCode [optional] if (JSON.ParseOptionalStruct("country_code", "country code", CountryCode.TryParse, out CountryCode? CountryCodeBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!CountryCodeURL.HasValue && !CountryCodeBody.HasValue) { ErrorResponse = "The country code is missing!"; return(false); } if (CountryCodeURL.HasValue && CountryCodeBody.HasValue && CountryCodeURL.Value != CountryCodeBody.Value) { ErrorResponse = "The optional country code given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse PartyIdURL [optional] if (JSON.ParseOptionalStruct("party_id", "party identification", Party_Id.TryParse, out Party_Id? PartyIdBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!PartyIdURL.HasValue && !PartyIdBody.HasValue) { ErrorResponse = "The party identification is missing!"; return(false); } if (PartyIdURL.HasValue && PartyIdBody.HasValue && PartyIdURL.Value != PartyIdBody.Value) { ErrorResponse = "The optional party identification given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse Id [optional] if (JSON.ParseOptionalStruct("id", "tariff identification", Tariff_Id.TryParse, out Tariff_Id? TariffIdBody, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } if (!TariffIdURL.HasValue && !TariffIdBody.HasValue) { ErrorResponse = "The tariff identification is missing!"; return(false); } if (TariffIdURL.HasValue && TariffIdBody.HasValue && TariffIdURL.Value != TariffIdBody.Value) { ErrorResponse = "The optional tariff identification given within the JSON body does not match the one given in the URL!"; return(false); } #endregion #region Parse Currency [mandatory] if (!JSON.ParseMandatory("currency", "currency", OCPIv2_1_1.Currency.TryParse, out Currency Currency, out ErrorResponse)) { return(false); } #endregion #region Parse TariffType [optional] if (JSON.ParseOptionalEnum("type", "tariff type", out TariffTypes? TariffType, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse TariffAltText [optional] if (JSON.ParseOptionalJSON("tariff_alt_text", "tariff alternative text", DisplayText.TryParse, out IEnumerable <DisplayText> TariffAltText, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse TariffAltURL [optional] if (JSON.ParseOptional("tariff_alt_url", "tariff alternative URL", URL.TryParse, out URL? TariffAltURL, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse MinPrice [optional] if (JSON.ParseOptionalJSON("min_price", "minimum price", Price.TryParse, out Price? MinPrice, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse MaxPrice [optional] if (JSON.ParseOptionalJSON("max_price", "maximum price", Price.TryParse, out Price? MaxPrice, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse TariffElements [mandatory] if (JSON.ParseMandatoryJSON("elements", "tariff elements", TariffElement.TryParse, out IEnumerable <TariffElement> TariffElements, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse Start [optional] if (JSON.ParseOptional("start_date_time", "start timestamp", out DateTime? Start, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse End [optional] if (JSON.ParseOptional("end_date_time", "end timestamp", out DateTime? End, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse EnergyMix [optional] if (JSON.ParseOptionalJSON("energy_mix", "energy mix", OCPIv2_1_1.EnergyMix.TryParse, out EnergyMix EnergyMix, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse LastUpdated [mandatory] if (!JSON.ParseMandatory("last_updated", "last updated", out DateTime LastUpdated, out ErrorResponse)) { return(false); } #endregion Tariff = new Tariff(CountryCodeBody ?? CountryCodeURL.Value, PartyIdBody ?? PartyIdURL.Value, TariffIdBody ?? TariffIdURL.Value, Currency, TariffElements, TariffType, TariffAltText, TariffAltURL, MinPrice, MaxPrice, Start, End, EnergyMix, LastUpdated); if (CustomTariffParser != null) { Tariff = CustomTariffParser(JSON, Tariff); } return(true); } catch (Exception e) { Tariff = default; ErrorResponse = "The given JSON representation of a tariff is invalid: " + e.Message; return(false); } }