/// <summary> /// Parse the given string as an e-mobility provider identification. /// </summary> /// <param name="CountryCode">A country code.</param> /// <param name="Suffix">The suffix of an e-mobility provider identification.</param> /// <param name="IdFormat">The optional format of the e-mobility provider identification.</param> public static NavigationProvider_Id Parse(Country CountryCode, String Suffix, ProviderIdFormats IdFormat = ProviderIdFormats.ISO_HYPHEN) { #region Initial checks if (CountryCode == null) { throw new ArgumentNullException(nameof(CountryCode), "The given country must not be null!"); } if (Suffix.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Suffix), "The given e-mobility provider identification suffix must not be null or empty!"); } #endregion switch (IdFormat) { case ProviderIdFormats.DIN_STAR: return(Parse(CountryCode.Alpha2Code + "*" + Suffix)); case ProviderIdFormats.ISO: return(Parse(CountryCode.Alpha2Code + Suffix)); default: // ISO_HYPHEN: return(Parse(CountryCode.Alpha2Code + "-" + Suffix)); } }
/// <summary> /// Try to parse the given text representation of an e-mobility provider identification. /// </summary> /// <param name="CountryCode">A country code.</param> /// <param name="Suffix">The suffix of an e-mobility provider identification.</param> /// <param name="ProviderId">The parsed e-mobility provider identification.</param> /// <param name="IdFormat">The optional format of the e-mobility provider identification.</param> public static Boolean TryParse(Country CountryCode, String Suffix, out NavigationProvider_Id ProviderId, ProviderIdFormats IdFormat = ProviderIdFormats.ISO_HYPHEN) { #region Initial checks if (CountryCode == null || Suffix.IsNullOrEmpty()) { ProviderId = default(NavigationProvider_Id); return(false); } #endregion switch (IdFormat) { case ProviderIdFormats.DIN_STAR: return(TryParse(CountryCode.Alpha2Code + "*" + Suffix, out ProviderId)); case ProviderIdFormats.ISO: return(TryParse(CountryCode.Alpha2Code + Suffix, out ProviderId)); default: // ISO_HYPHEN: return(TryParse(CountryCode.Alpha2Code + "-" + Suffix, out ProviderId)); } }
/// <summary> /// Try to parse the given text representation of an e-mobility e-mobility provider identification. /// </summary> /// <param name="CountryCode">A country code.</param> /// <param name="Suffix">The suffix of an e-mobility e-mobility provider identification.</param> /// <param name="ProviderId">The parsed e-mobility e-mobility provider identification.</param> /// <param name="IdFormat">The optional format of the e-mobility e-mobility provider identification.</param> public static Boolean TryParse(Country CountryCode, String Suffix, out Provider_Id ProviderId, ProviderIdFormats IdFormat = ProviderIdFormats.eMI3_HYPHEN) { #region Initial checks if (CountryCode == null || Suffix.IsNullOrEmpty() || Suffix.Trim().IsNullOrEmpty()) { ProviderId = default(Provider_Id); return(false); } #endregion switch (IdFormat) { case ProviderIdFormats.eMI3: return(TryParse(CountryCode.Alpha2Code + Suffix, out ProviderId)); default: return(TryParse(CountryCode.Alpha2Code + "-" + Suffix, out ProviderId)); } }
/// <summary> /// Return the identification in the given format. /// </summary> /// <param name="Format">The format of the identification.</param> public String ToString(ProviderIdFormats Format) { switch (Format) { case ProviderIdFormats.DIN: return(String.Concat(CountryCode.Alpha2Code, Suffix)); case ProviderIdFormats.DIN_STAR: return(String.Concat(CountryCode.Alpha2Code, "*", Suffix)); case ProviderIdFormats.DIN_HYPHEN: return(String.Concat(CountryCode.Alpha2Code, "-", Suffix)); case ProviderIdFormats.ISO: return(String.Concat(CountryCode.Alpha2Code, Suffix)); default: // ISO_HYPHEN return(String.Concat(CountryCode.Alpha2Code, "-", Suffix)); } }
/// <summary> /// Parse the given string as an e-mobility provider identification. /// </summary> /// <param name="CountryCode">A country code.</param> /// <param name="Suffix">The suffix of an e-mobility provider identification.</param> /// <param name="IdFormat">The optional format of the e-mobility provider identification.</param> public static Provider_Id Parse(Country CountryCode, String Suffix, ProviderIdFormats IdFormat = ProviderIdFormats.ISO_HYPHEN) { #region Initial checks if (CountryCode == null) { throw new ArgumentNullException(nameof(CountryCode), "The given country must not be null!"); } Suffix = Suffix?.Trim(); if (Suffix.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Suffix), "The given e-mobility provider identification suffix must not be null or empty!"); } #endregion return(IdFormat switch { ProviderIdFormats.DIN => Parse(CountryCode.Alpha2Code + Suffix), ProviderIdFormats.DIN_STAR => Parse(CountryCode.Alpha2Code + "*" + Suffix), ProviderIdFormats.DIN_HYPHEN => Parse(CountryCode.Alpha2Code + "-" + Suffix), ProviderIdFormats.ISO => Parse(CountryCode.Alpha2Code + Suffix), _ => Parse(CountryCode.Alpha2Code + "-" + Suffix) });
/// <summary> /// Generate a new Electric Vehicle Service Provider (EVSP Id) /// based on the given string. /// </summary> /// <param name="CountryCode">The Alpha-2-CountryCode.</param> /// <param name="Separator">The separator '-' (ISO) or '*|-' DIN to use.</param> /// <param name="ProviderId">The EV Service Provider identification.</param> private EVSP_Id(Country CountryCode, ProviderIdFormats Separator, String ProviderId) { this._CountryCode = CountryCode; this._IdFormat = Separator; this._ProviderId = ProviderId; }
/// <summary> /// Create a new charging e-mobility provider identification. /// </summary> /// <param name="CountryCode">The country code.</param> /// <param name="Suffix">The suffix of the charging e-mobility provider identification.</param> /// <param name="Format">The format of the charging e-mobility provider identification.</param> private Provider_Id(Country CountryCode, String Suffix, ProviderIdFormats Format = ProviderIdFormats.eMI3_HYPHEN) { this.CountryCode = CountryCode; this.Suffix = Suffix; this.Format = Format; }
/// <summary> /// Parse the given string as an EV Service Provider identification. /// </summary> /// <param name="CountryAndProviderId">The country code and EV Service Provider identification as a string.</param> /// <param name="EVSEProviderId">The parsed EV Service Provider identification.</param> public static Boolean TryParse(String CountryAndProviderId, out EVSP_Id EVSEProviderId) { #region Initial checks if (CountryAndProviderId.IsNullOrEmpty()) { EVSEProviderId = null; return(false); } #endregion try { var _MatchCollection = Regex.Matches(CountryAndProviderId.Trim().ToUpper(), CountryAndProviderId_RegEx, RegexOptions.IgnorePatternWhitespace); if (_MatchCollection.Count != 1) { EVSEProviderId = null; return(false); } Country __CountryCode; if (Country.TryParseAlpha2Code(_MatchCollection[0].Groups[1].Value, out __CountryCode)) { ProviderIdFormats Separator = ProviderIdFormats.ISO_HYPHEN; switch (_MatchCollection[0].Groups[2].Value) { case "": Separator = ProviderIdFormats.DIN | ProviderIdFormats.ISO; break; case "-": Separator = ProviderIdFormats.DIN_HYPHEN | ProviderIdFormats.ISO_HYPHEN; break; case "*": Separator = ProviderIdFormats.DIN_STAR; break; default: throw new ArgumentException("Illegal EV Service Provider identification!", "CountryAndProviderId"); } EVSEProviderId = new EVSP_Id(__CountryCode, Separator, _MatchCollection[0].Groups[3].Value); return(true); } } catch (Exception e) { } EVSEProviderId = null; return(false); }
/// <summary> /// Try to parse the given text representation of an e-mobility e-mobility provider identification. /// </summary> /// <param name="CountryCode">A country code.</param> /// <param name="Suffix">The suffix of an e-mobility e-mobility provider identification.</param> /// <param name="IdFormat">The optional format of the e-mobility e-mobility provider identification.</param> public static Provider_Id?TryParse(Country CountryCode, String Suffix, ProviderIdFormats IdFormat = ProviderIdFormats.eMI3_HYPHEN) { if (TryParse(CountryCode, Suffix, out Provider_Id _ProviderId, IdFormat)) { return(_ProviderId); } return(new Provider_Id?()); }
/// <summary> /// Return a string representation of this object /// in the given Id format. /// </summary> public String ToString(ProviderIdFormats IdFormat) { switch (IdFormat) { case ProviderIdFormats.DIN_HYPHEN | ProviderIdFormats.ISO_HYPHEN: return(String.Concat(CountryCode.Alpha2Code.ToUpper(), "-", _ProviderId.ToString())); case ProviderIdFormats.DIN_STAR: return(String.Concat(CountryCode.Alpha2Code.ToUpper(), "*", _ProviderId.ToString())); default: return(String.Concat(CountryCode.Alpha2Code.ToUpper(), _ProviderId.ToString())); } }
/// <summary> /// Return a text representation of the given provider identification format. /// </summary> /// <param name="ProviderIdFormat">A provider identification format.</param> public static String AsText(this ProviderIdFormats ProviderIdFormat) { switch (ProviderIdFormat) { case ProviderIdFormats.eMI3: return("eMI3"); case ProviderIdFormats.eMI3_HYPHEN: return("eMI3"); default: return("Gireve"); } }
/// <summary> /// Generate a new e-mobility provider identification. /// </summary> /// <param name="CountryCode">The country code.</param> /// <param name="Suffix">The suffix of the e-mobility provider identification.</param> /// <param name="Format">The format of the e-mobility provider identification.</param> private NavigationProvider_Id(Country CountryCode, String Suffix, ProviderIdFormats Format = ProviderIdFormats.ISO_HYPHEN) { #region Initial checks if (Suffix.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Suffix), "The e-mobility provider identification suffix must not be null or empty!"); } #endregion this.CountryCode = CountryCode; this.Suffix = Suffix; this.Format = Format; }
/// <summary> /// Change the EVSP Id format. /// </summary> /// <param name="NewIdFormat">The new EVSP Id format.</param> /// <returns>A new EVSPId object.</returns> public EVSP_Id ChangeIdFormat(ProviderIdFormats NewIdFormat) { return(new EVSP_Id(this._CountryCode, NewIdFormat, this.ProviderId)); }
/// <summary> /// Return a new e-mobility provider identification in the given format. /// </summary> /// <param name="NewFormat">The new e-mobility provider identification format.</param> public NavigationProvider_Id ChangeFormat(ProviderIdFormats NewFormat) => new NavigationProvider_Id(CountryCode, Suffix, NewFormat);
/// <summary> /// Return a new charging e-mobility provider identification in the given format. /// </summary> /// <param name="NewFormat">The new charging e-mobility provider identification format.</param> public Provider_Id ChangeFormat(ProviderIdFormats NewFormat) => new Provider_Id(CountryCode, Suffix, NewFormat);
/// <summary> /// Return a new e-mobility provider identification in the given format. /// </summary> /// <param name="NewFormat">The new e-mobility provider identification format.</param> public eMobilityProvider_Id ChangeFormat(ProviderIdFormats NewFormat) => new eMobilityProvider_Id(CountryCode, Suffix, NewFormat);