/// <summary> /// Create a new EVSE identification /// based on the given charging station identification. /// </summary> /// <param name="ChargingStationId">A charging station identification.</param> /// <param name="AdditionalSuffix">An additional EVSE suffix.</param> public static EVSE_Id CreateEVSEId(this ChargingStation_Id ChargingStationId, String AdditionalSuffix) { var Suffix = ChargingStationId.Suffix; if (Suffix.StartsWith("TATION", StringComparison.Ordinal)) { Suffix = "VSE" + Suffix.Substring(6); } return(EVSE_Id.Parse(ChargingStationId.OperatorId, Suffix + AdditionalSuffix ?? "")); }
/// <summary> /// Create a ChargingStationId based on the given EVSEIds. /// </summary> /// <param name="EVSEIds">An enumeration of EVSEIds.</param> public static ChargingStation_Id?Create(IEnumerable <EVSE_Id> EVSEIds, String HelperId = "", Byte Length = 15, Func <String, String> Mapper = null) { #region Initial checks if (EVSEIds == null) { return(null); } var _EVSEIds = EVSEIds.ToArray(); if (_EVSEIds.Length == 0) { return(null); } #endregion #region A single EVSE Id... // It is just a single EVSE Id... if (_EVSEIds.Length == 1) { return(Create(_EVSEIds[0])); } #endregion // Multiple OperatorIds which do not match! if (_EVSEIds.Select(evse => evse.OperatorId.ToString()).Distinct().Count() > 1) { return(null); } #region EVSEIdSuffix contains '*'... if (_EVSEIds.Any(EVSEId => EVSEId.Suffix.Contains('*') || EVSEId.Suffix.Contains('-'))) { var EVSEIdPrefixStrings = _EVSEIds. Select(EVSEId => EVSEId.Suffix.Split(StarSplitter, StringSplitOptions.RemoveEmptyEntries)). Select(SuffixElements => SuffixElements.Take(SuffixElements.Length - 1).AggregateWith("*", "")). Where(NewSuffix => NewSuffix != ""). Distinct(). ToArray(); if (EVSEIdPrefixStrings.Length != 1) { return(null); } return(Parse(_EVSEIds[0].OperatorId, EVSEIdPrefixStrings[0])); } #endregion #region ...or use longest prefix... else { var _Array = _EVSEIds.Select(evse => evse.ToString()).ToArray(); var _MinLength = (Int32)_Array.Select(v => v.Length).Min(); var _Prefix = ""; for (var i = 0; i < _MinLength; i++) { if (_Array.All(v => v[i] == _Array[0][i])) { _Prefix += _Array[0][i]; } } if (((UInt64)_Prefix.Length) > _EVSEIds[0].OperatorId.Length + 1) { var TmpEVSEId = EVSE_Id.Parse(_Prefix); if (TmpEVSEId.Format == OperatorIdFormats.ISO) { if (((UInt64)_Prefix.Length) > _EVSEIds[0].OperatorId.Length + 2) { _Prefix = TmpEVSEId.Suffix; //TmpEVSEId.OperatorId + "*S" + TmpEVSEId.Suffix; } else { return(null); } } return(Parse(_EVSEIds[0].OperatorId, _Prefix)); } } #endregion #region ...or generate a hash of the EVSEIds! if (Length < 12) { Length = 12; } if (Length > 50) { Length = 50; } var Suffíx = new SHA1CryptoServiceProvider(). ComputeHash(Encoding.UTF8.GetBytes(EVSEIds.Select(evseid => evseid.ToString()). AggregateWith(HelperId ?? ","))). ToHexString(). SubstringMax(Length). ToUpper(); return(Parse(_EVSEIds[0].OperatorId, Mapper != null ? Mapper(Suffíx) : Suffíx)); #endregion }
/// <summary> /// Create a ChargingStationId based on the given EVSEIds. /// </summary> /// <param name="EVSEIds">An enumeration of EVSEIds.</param> public static ChargingStation_Id Create(IEnumerable <EVSE_Id> EVSEIds) { #region Initial checks if (EVSEIds == null) { return(null); } var _EVSEIds = EVSEIds.ToArray(); if (_EVSEIds.Length == 0) { return(null); } // It is just a single EVSE Id... if (_EVSEIds.Length == 1) { return(Create(_EVSEIds[0])); } #endregion #region Multiple EVSE Ids... String[] EVSEIdPrefixStrings = null; #region EVSEIdSuffix contains '*' or '-'... if (_EVSEIds.Any(EVSEId => EVSEId.Suffix.Contains('*') || EVSEId.Suffix.Contains('-'))) { EVSEIdPrefixStrings = _EVSEIds. Select(EVSEId => EVSEId.OriginId.Split('*', '-')). Select(EVSEIdElements => { if (EVSEIdElements.Length < 4) { return new String[] { "" } } ; if (_EVSEIds[0].Format == IdFormatType.NEW) { if (EVSEIdElements[2].StartsWith("E")) { EVSEIdElements[2] = "S" + EVSEIdElements[2].Substring(1); } } return(EVSEIdElements); }). Select(EVSEIdElements => EVSEIdElements. Take(EVSEIdElements.Length - 1). AggregateWith("*", "")). Where(v => v != ""). Distinct(). ToArray(); } #endregion #region ...or use longest prefix! else { var _Array = _EVSEIds.Select(EVSEId => EVSEId.OriginId).ToArray(); var _MinLength = _Array.Select(v => v.Length).Min(); var _Prefix = ""; for (var i = 0; i < _MinLength; i++) { if (_Array.All(v => v[i] == _Array[0][i])) { _Prefix += _Array[0][i]; } } if (_Prefix.Length > _EVSEIds[0].OperatorId.OriginId.Length + 1) { var TmpEVSEId = EVSE_Id.Parse(_Prefix); if (TmpEVSEId.Format == IdFormatType.NEW) { if (_Prefix.Length > _EVSEIds[0].OperatorId.OriginId.Length + 2) { _Prefix = TmpEVSEId.OperatorId.OriginId + "*S" + TmpEVSEId.Suffix; } else { return(null); } } EVSEIdPrefixStrings = new String[1] { _Prefix }; } else { return(null); } } #endregion if (EVSEIdPrefixStrings.Length == 1) { var Id = EVSEIdPrefixStrings.First(); if (Id.Contains('-')) { Id = Id.Replace("-", "*"); } var IdElements = Id.Split(new String[] { "*" }, StringSplitOptions.None); return(ChargingStation_Id.Parse(IdElements[0] + "*" + IdElements[1] + "*S" + IdElements.Skip(2).Aggregate("*"))); } #endregion return(null); }