예제 #1
0
        /// <summary>
        /// Create a new charging tariff having the given identification.
        /// </summary>
        /// <param name="Id">The unique identification of the charing tariff.</param>
        /// <param name="TariffGroup">The charging tariff group of this charging tariff.</param>
        /// <param name="Name">The offical (multi-language) name of this charging tariff.</param>
        /// <param name="Description">An optional (multi-language) description of this charging tariff.</param>
        public ChargingTariff(ChargingTariff_Id Id,
                              ChargingTariffGroup TariffGroup,
                              I18NString Name,
                              I18NString Description,
                              Brand Brand,

                              Uri TariffUrl,
                              Currency Currency,
                              EnergyMix EnergyMix,
                              IEnumerable <ChargingTariffElement> TariffElements)

            : this(Id,
                   TariffGroup.Operator,
                   Name,
                   Description,
                   Brand,

                   TariffUrl,
                   Currency,
                   EnergyMix,
                   TariffElements)

        {
            this.TariffGroup = TariffGroup;
        }
예제 #2
0
        /// <summary>
        /// Create a new charging tariff having the given identification.
        /// </summary>
        /// <param name="Id">The unique identification of the charing tariff.</param>
        /// <param name="Operator">The charging station operator of this charging tariff.</param>
        /// <param name="Name">The offical (multi-language) name of this charging tariff.</param>
        /// <param name="Description">An optional (multi-language) description of this charging tariff.</param>
        public ChargingTariff(ChargingTariff_Id Id,
                              ChargingStationOperator Operator,
                              I18NString Name,
                              I18NString Description,
                              Brand Brand,

                              Uri TariffUrl,
                              Currency Currency,
                              EnergyMix EnergyMix,
                              IEnumerable <ChargingTariffElement> TariffElements)

            : base(Id)

        {
            #region Initial checks

            if (Operator == null)
            {
                throw new ArgumentNullException(nameof(Operator), "The given charging station operator must not be null!");
            }

            if (TariffElements == null || !TariffElements.Any())
            {
                throw new ArgumentNullException(nameof(TariffElements), "The given enumeration of tariff elements must not be null or empty!");
            }

            #endregion

            #region Init data and properties

            this.Operator    = Operator;
            this.Name        = Name;
            this.Description = Description ?? new I18NString();
            this.Brand       = Brand;

            this.TariffURI      = TariffUrl;
            this.Currency       = Currency;
            this.EnergyMix      = EnergyMix;
            this.TariffElements = TariffElements;

            #endregion
        }
예제 #3
0
        /// <summary>
        /// Create and register a new charging tariff having the given
        /// unique charging tariff identification.
        /// </summary>
        /// <param name="Id">The unique identification of the charing tariff.</param>
        /// <param name="Name">The offical (multi-language) name of this charging tariff.</param>
        /// <param name="Description">An optional (multi-language) description of this charging tariff.</param>
        /// <param name="OnSuccess">An optional delegate to configure the new charging tariff after its successful creation.</param>
        /// <param name="OnError">An optional delegate to be called whenever the creation of the charging tariff failed.</param>
        public ChargingTariff CreateChargingTariff(ChargingTariff_Id Id,
                                                   I18NString Name,
                                                   I18NString Description,
                                                   Brand Brand,
                                                   Uri TariffUrl,
                                                   Currency Currency,
                                                   EnergyMix EnergyMix,
                                                   IEnumerable <ChargingTariffElement> TariffElements,

                                                   Action <ChargingTariff> OnSuccess = null,
                                                   Action <ChargingStationOperator, ChargingTariff_Id> OnError = null)

        {
            lock (_ChargingTariffs)
            {
                #region Initial checks

                if (_ChargingTariffs.ContainsKey(Id))
                {
                    //if (OnError != null)
                    //    OnError?.Invoke(this, Id);

                    throw new ArgumentException("Invalid tariff!");
                }

                #endregion

                var _ChargingTariff = new ChargingTariff(Id,
                                                         this,
                                                         Name,
                                                         Description,
                                                         Brand,
                                                         TariffUrl,
                                                         Currency,
                                                         EnergyMix,
                                                         TariffElements);


                if (ChargingTariffAddition.SendVoting(DateTime.UtcNow, this, _ChargingTariff))
                {
                    _ChargingTariffs.Add(_ChargingTariff.Id, _ChargingTariff);

                    //_ChargingTariff.OnEVSEDataChanged                             += UpdateEVSEData;
                    //_ChargingTariff.OnEVSEStatusChanged                           += UpdateEVSEStatus;
                    //_ChargingTariff.OnEVSEAdminStatusChanged                      += UpdateEVSEAdminStatus;

                    //_ChargingTariff.OnChargingStationDataChanged                  += UpdateChargingStationData;
                    //_ChargingTariff.OnChargingStationStatusChanged                += UpdateChargingStationStatus;
                    //_ChargingTariff.OnChargingStationAdminStatusChanged           += UpdateChargingStationAdminStatus;

                    ////_ChargingTariff.OnDataChanged                                 += UpdateChargingTariffData;
                    ////_ChargingTariff.OnAdminStatusChanged                          += UpdateChargingTariffAdminStatus;

                    OnSuccess?.Invoke(_ChargingTariff);

                    ChargingTariffAddition.SendNotification(DateTime.UtcNow,
                                                            this,
                                                            _ChargingTariff);

                    return(_ChargingTariff);
                }

                return(null);
            }
        }
예제 #4
0
        /// <summary>
        /// Return a JSON representation of the given charging tariff.
        /// </summary>
        /// <param name="Embedded">Whether this data is embedded into another data structure, e.g. into a charging station operator.</param>
        public JObject ToJSON(Boolean Embedded = false,
                              InfoStatus ExpandRoamingNetworkId          = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandChargingStationOperatorId = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandChargingPoolId            = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandEVSEIds      = InfoStatus.Expand,
                              InfoStatus ExpandBrandIds     = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandDataLicenses = InfoStatus.ShowIdOnly)


        => JSONObject.Create(

            Id.ToJSON("@id"),

            Embedded
                             ? null
                             : new JProperty("@context", "https://open.charging.cloud/contexts/wwcp+json/ChargingTariff"),

            Name.IsNeitherNullNorEmpty()
                             ? Name.ToJSON("name")
                             : null,

            Description.IsNeitherNullNorEmpty()
                             ? Description.ToJSON("description")
                             : null,

            Brand != null
                             ? ExpandBrandIds.Switch(
                () => new JProperty("brandId", Brand.Id.ToString()),
                () => new JProperty("brand", Brand.ToJSON()))
                             : null,

            (!Embedded || DataSource != Operator.DataSource)
                             ? DataSource.ToJSON("dataSource")
                             : null,

            //(!Embedded || DataLicenses != Operator.DataLicenses)
            //    ? ExpandDataLicenses.Switch(
            //        () => new JProperty("dataLicenseIds",  new JArray(DataLicenses.SafeSelect(license => license.Id.ToString()))),
            //        () => new JProperty("dataLicenses",    DataLicenses.ToJSON()))
            //    : null,


            new JProperty("currency", Currency.ISOCode),

            TariffURI != null
                             ? new JProperty("URI", TariffURI.ToString())
                             : null,

            TariffElements.Any()
                             ? new JProperty("elements", new JArray(TariffElements.Select(TariffElement => TariffElement.ToJSON())))
                             : null,

            EnergyMix != null
                             ? new JProperty("energy_mix", EnergyMix.ToJSON())
                             : null,



            Operator.ChargingStationGroups.Any(group => group.Tariff == this)
                             ? new JProperty("chargingStations", new JArray(Operator.ChargingStationGroups.
                                                                            Where(group => group.Tariff == this).
                                                                            Select(group => group.AllowedMemberIds.
                                                                                   Select(id => id.ToString()))))
                             : null,

            Operator.EVSEGroups.Any(group => group.Tariff == this)
                             ? new JProperty("EVSEs", new JArray(Operator.EVSEGroups.
                                                                 Where(group => group.Tariff == this).
                                                                 Select(group => group.AllowedMemberIds.
                                                                        Select(id => id.ToString()))))
                             : null



            //                 #region Embedded means it is served as a substructure of e.g. a charging station operator

            //                 Embedded
            //                     ? null
            //                     : ExpandRoamingNetworkId.Switch(
            //                           () => new JProperty("roamingNetworkId",           RoamingNetwork.Id. ToString()),
            //                           () => new JProperty("roamingNetwork",             RoamingNetwork.    ToJSON(Embedded:                          true,
            //                                                                                                                            ExpandChargingStationOperatorIds:  InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingPoolIds:             InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingStationIds:          InfoStatus.Hidden,
            //                                                                                                                            ExpandEVSEIds:                     InfoStatus.Hidden,
            //                                                                                                                            ExpandBrandIds:                    InfoStatus.Hidden,
            //                                                                                                                            ExpandDataLicenses:                InfoStatus.Hidden))),

            //                 Embedded
            //                     ? null
            //                     : ExpandChargingStationOperatorId.Switch(
            //                           () => new JProperty("chargingStationOperatorId",  Operator.Id.       ToString()),
            //                           () => new JProperty("chargingStationOperator",    Operator.          ToJSON(Embedded:                          true,
            //                                                                                                                            ExpandRoamingNetworkId:            InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingPoolIds:             InfoStatus.Hidden,
            //                                                                                                                            ExpandChargingStationIds:          InfoStatus.Hidden,
            //                                                                                                                            ExpandEVSEIds:                     InfoStatus.Hidden,
            //                                                                                                                            ExpandBrandIds:                    InfoStatus.Hidden,
            //                                                                                                                            ExpandDataLicenses:                InfoStatus.Hidden))),

            //                 #endregion

            //                 ExpandEVSEIds.Switch(
            //                     () => new JProperty("EVSEIds",
            //                                         EVSEIds.SafeAny()
            //                                             ? new JArray(EVSEIds.
            //                                                                               OrderBy(evseid => evseid).
            //                                                                               Select (evseid => evseid.ToString()))
            //                                             : null),

            //                     () => new JProperty("EVSEs",
            //                                         EVSEs.SafeAny()
            //                                             ? new JArray(EVSEs.
            //                                                                               OrderBy(evse   => evse.Id).
            //                                                                               Select (evse   => evse.  ToJSON(Embedded: true)))
            //                                             : null))

            );