Пример #1
0
        /// <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 ?? ""));
        }
Пример #2
0
        /// <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().Skip(1).Any())
            {
                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.eMI3)
                    {
                        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
        }