/// <summary>
        /// Convert an eMIP EVSE identification into a WWCP EVSE identification.
        /// </summary>
        /// <param name="EVSEId">An eMIP EVSE identification.</param>
        public static WWCP.EVSE_Id?ToWWCP(this EVSE_Id EVSEId)
        {
            if (WWCP.EVSE_Id.TryParse(EVSEId.ToString(), out WWCP.EVSE_Id WWCPEVSEId))
            {
                return(WWCPEVSEId);
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Create a ChargingStationId based on the given EVSE identification.
        /// </summary>
        /// <param name="EVSEId">An EVSEId.</param>
        /// <param name="RemoveLastStar">Generate a charging station identification by removing the last star part.</param>
        public static ChargingStation_Id Create(EVSE_Id EVSEId,
                                                Boolean RemoveLastStar = true)
        {
            var _Suffix = EVSEId.Suffix;

            if (RemoveLastStar)
            {
                var _HasAStar = EVSEId.Suffix.LastIndexOf("*");

                if (_HasAStar > 0)
                {
                    _Suffix = _Suffix.Substring(0, _HasAStar);
                }
            }

            return(Parse(EVSEId.OperatorId, _Suffix.ToUpper()));

            //var _Array = new String[] {
            //                 EVSEId.OperatorId.CountryCode.Alpha2Code,
            //                 EVSEId.OperatorId.Suffix
            //             }.Concat(EVSEId.ToString().Substring(2 + EVSEId.OperatorId.Suffix.Length).ToUpper().Split('*', '-')).ToArray();

            //if (EVSEId.Format == OperatorIdFormats.eMI3 || EVSEId.Format == OperatorIdFormats.eMI3_STAR)
            //{
            //    if (_Array[2].StartsWith("E", StringComparison.Ordinal))
            //        _Array[2] = "S" + _Array[2].Substring(1);
            //}
            //else
            //{
            //    if (!_Array[2].StartsWith("S", StringComparison.Ordinal))
            //         _Array[2] = "S" + _Array[2];
            //}


            //// e.g. "DE*822*E123456"
            //if (_Array.Length == 3)
            //{

            //    if (EVSEId.ToString().Contains('-'))
            //        return Parse(_Array.AggregateWith("-"));

            //    return Parse(_Array.AggregateWith("*"));

            //}

            //// e.g. "DE*822*E123456*1" => "DE*822*S123456"
            //if (EVSEId.ToString().Contains('-'))
            //    return Parse(_Array.Take(_Array.Length - 1).AggregateWith("-"));

            //if (_Array[0].StartsWith("+"))
            //    return Parse(_Array.Take(1).Select(item => Country.ParseTelefonCode(item.Substring(1)).Alpha2Code).Concat(_Array.Skip(1).Take(_Array.Length - 1)).AggregateWith("*"));

            //else
            //    return Parse(_Array.Take(_Array.Length - 1).AggregateWith("*"));
        }
Beispiel #3
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 ?? ""));
        }
        /// <summary>
        /// Convert a WWCP EVSE identification into an eMIP EVSE identification.
        /// </summary>
        /// <param name="EVSEId">A WWCP EVSE identification.</param>
        /// <param name="CustomEVSEIdMapper">A delegate to customize the mapping of EVSE identifications.</param>
        public static EVSE_Id?ToEMIP(this WWCP.EVSE_Id EVSEId,
                                     CustomEVSEIdMapperDelegate CustomEVSEIdMapper = null)
        {
            if (EVSE_Id.TryParse(CustomEVSEIdMapper != null
                                     ? CustomEVSEIdMapper(EVSEId.ToString())
                                     : EVSEId.ToString(),
                                 out EVSE_Id eMIPEVSEId))
            {
                return(eMIPEVSEId);
            }

            return(null);
        }
        /// <summary>
        /// Create a new charge detail record.
        /// </summary>
        /// <param name="CDRNature">State of the charging session.</param>
        /// <param name="ServiceSessionId">GIREVE session id for this charging session.</param>
        /// <param name="RequestedServiceId">The unique identification of the requested service for this charging session.</param>
        /// <param name="EVSEId">The unique identification of the EVSE used for charging.</param>
        /// <param name="UserContractIdAlias">Alias of the contract id between the end-user and the eMSP. This alias may have been anonymised by the eMSP.</param>
        /// <param name="UserId">The unique identification of the user.</param>
        /// <param name="StartTime">Start time of the charging session.</param>
        /// <param name="EndTime">End time of the charging session, or the timestamp of the meter reading for intermediate charge detail records.</param>
        ///
        /// <param name="ExecPartnerSessionId">Charging session identification at the operator.</param>
        /// <param name="ExecPartnerOperatorId">The unique identification of the charging operator.</param>
        /// <param name="SalesPartnerSessionId">Charging session identification at the e-mobility provider.</param>
        /// <param name="SalesPartnerOperatorId">The unique identification of the e-mobility provider.</param>
        /// <param name="PartnerProductId">The unique identification of the charging product.</param>
        /// <param name="MeterReports">An optional enumeration of meter reports.</param>
        ///
        /// <param name="InternalData">An optional dictionary of customer-specific data.</param>
        public ChargeDetailRecord(CDRNatures CDRNature,
                                  ServiceSession_Id ServiceSessionId,
                                  Service_Id RequestedServiceId,
                                  EVSE_Id EVSEId,
                                  User_Id UserId,
                                  DateTime StartTime,
                                  DateTime EndTime,

                                  Contract_Id?UserContractIdAlias         = null,
                                  ServiceSession_Id?ExecPartnerSessionId  = null,
                                  Operator_Id?ExecPartnerOperatorId       = null,
                                  ServiceSession_Id?SalesPartnerSessionId = null,
                                  Provider_Id?SalesPartnerOperatorId      = null,
                                  PartnerProduct_Id?PartnerProductId      = null,
                                  IEnumerable <MeterReport> MeterReports  = null,

                                  IReadOnlyDictionary <String, Object> InternalData = null)

            : base(InternalData)

        {
            this.CDRNature           = CDRNature;
            this.ServiceSessionId    = ServiceSessionId;
            this.RequestedServiceId  = RequestedServiceId;
            this.EVSEId              = EVSEId;
            this.UserContractIdAlias = UserContractIdAlias;
            this.UserId              = UserId;
            this.StartTime           = StartTime;
            this.EndTime             = EndTime;

            this.ExecPartnerSessionId   = ExecPartnerSessionId;
            this.ExecPartnerOperatorId  = ExecPartnerOperatorId;
            this.SalesPartnerSessionId  = SalesPartnerSessionId;
            this.SalesPartnerOperatorId = SalesPartnerOperatorId;
            this.PartnerProductId       = PartnerProductId;
            this.MeterReports           = MeterReports ?? new MeterReport[0];
        }
Beispiel #6
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
        }