示例#1
0
        public ChargingTariffGroup Add(ChargingTariff Tariff)
        {
            lock (_ChargingTariffs)
            {
                _ChargingTariffs.Add(Tariff.Id, Tariff);
            }

            return(this);
        }
示例#2
0
        /// <summary>
        /// Compares two charging tariffs for equality.
        /// </summary>
        /// <param name="ChargingTariff">A charging tariff to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(ChargingTariff ChargingTariff)
        {
            if ((Object)ChargingTariff == null)
            {
                return(false);
            }

            return(Id.Equals(ChargingTariff.Id));
        }
示例#3
0
        /// <summary>
        /// Compares two instances of this object.
        /// </summary>
        /// <param name="ChargingTariff">A charging tariff object to compare with.</param>
        public Int32 CompareTo(ChargingTariff ChargingTariff)
        {
            if ((Object)ChargingTariff == null)
            {
                throw new ArgumentNullException(nameof(ChargingTariff), "The given charging tariff must not be null!");
            }

            return(Id.CompareTo(ChargingTariff.Id));
        }
示例#4
0
        /// <summary>
        /// Create a new charging station group.
        /// </summary>
        /// <param name="Id">The unique identification of the charing station group.</param>
        /// <param name="Operator">The charging station operator of this charging station group.</param>
        /// <param name="Name">The offical (multi-language) name of this charging station group.</param>
        /// <param name="Description">An optional (multi-language) description of this charging station group.</param>
        ///
        /// <param name="Members">An enumeration of charging stations member building this charging station group.</param>
        /// <param name="MemberIds">An enumeration of charging station identifications which are building this charging station group.</param>
        /// <param name="AutoIncludeStations">A delegate deciding whether to include new charging stations automatically into this group.</param>
        ///
        /// <param name="StatusAggregationDelegate">A delegate called to aggregate the dynamic status of all subordinated charging stations.</param>
        /// <param name="MaxGroupStatusListSize">The default size of the charging station group status list.</param>
        /// <param name="MaxGroupAdminStatusListSize">The default size of the charging station group admin status list.</param>
        internal ChargingStationGroup(ChargingStationGroup_Id Id,
                                      ChargingStationOperator Operator,
                                      I18NString Name,
                                      I18NString Description = null,

                                      Brand Brand           = null,
                                      Priority?Priority     = null,
                                      ChargingTariff Tariff = null,
                                      IEnumerable <DataLicense> DataLicenses = null,

                                      IEnumerable <ChargingStation> Members               = null,
                                      IEnumerable <ChargingStation_Id> MemberIds          = null,
                                      Func <ChargingStation, Boolean> AutoIncludeStations = null,

                                      Func <ChargingStationStatusReport, ChargingStationGroupStatusTypes> StatusAggregationDelegate = null,
                                      UInt16 MaxGroupStatusListSize      = DefaultMaxGroupStatusListSize,
                                      UInt16 MaxGroupAdminStatusListSize = DefaultMaxGroupAdminStatusListSize)

            : base(Id)

        {
            #region Initial checks

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

            if (IEnumerableExtensions.IsNullOrEmpty(Name))
            {
                throw new ArgumentNullException(nameof(Name), "The name of the charging station group 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.Priority     = Priority;
            this.Tariff       = Tariff;
            this.DataLicenses = DataLicenses?.Any() == true ? new ReactiveSet <DataLicense>(DataLicenses) : new ReactiveSet <DataLicense>();

            this._AllowedMemberIds   = MemberIds != null ? new HashSet <ChargingStation_Id>(MemberIds) : new HashSet <ChargingStation_Id>();
            this.AutoIncludeStations = AutoIncludeStations ?? (MemberIds == null ? (Func <ChargingStation, Boolean>)(station => true) : station => false);
            this._ChargingStations   = new ConcurrentDictionary <ChargingStation_Id, ChargingStation>();

            this.StatusAggregationDelegate = StatusAggregationDelegate;

            this._AdminStatusSchedule = new StatusSchedule <ChargingStationGroupAdminStatusTypes>(MaxGroupAdminStatusListSize);
            this._AdminStatusSchedule.Insert(ChargingStationGroupAdminStatusTypes.Unknown);

            this._StatusSchedule = new StatusSchedule <ChargingStationGroupStatusTypes>     (MaxGroupStatusListSize);
            this._StatusSchedule.Insert(ChargingStationGroupStatusTypes.Unknown);

            #endregion

            #region Init events

            // ChargingStationGroup events
            this.ChargingStationAddition = new VotingNotificator <DateTime, ChargingStationGroup, ChargingStation, Boolean>(() => new VetoVote(), true);
            this.ChargingStationRemoval  = new VotingNotificator <DateTime, ChargingStationGroup, ChargingStation, Boolean>(() => new VetoVote(), true);

            // ChargingStation events
            this.EVSEAddition = new VotingNotificator <DateTime, ChargingStation, EVSE, Boolean>(() => new VetoVote(), true);
            this.EVSERemoval  = new VotingNotificator <DateTime, ChargingStation, EVSE, Boolean>(() => new VetoVote(), true);

            // EVSE events

            #endregion

            #region Link events

            this._AdminStatusSchedule.OnStatusChanged += (Timestamp, EventTrackingId, StatusSchedule, OldStatus, NewStatus)
                                                         => UpdateAdminStatus(Timestamp, EventTrackingId, OldStatus, NewStatus);

            // ChargingStationGroup events
            //this.OnChargingStationAddition.OnVoting       += (timestamp, evseoperator, pool, vote) => EVSEOperator.ChargingStationAddition.SendVoting      (timestamp, evseoperator, pool, vote);
            //this.OnChargingStationAddition.OnNotification += (timestamp, evseoperator, pool)       => EVSEOperator.ChargingStationAddition.SendNotification(timestamp, evseoperator, pool);
            //
            //this.OnChargingStationRemoval. OnVoting       += (timestamp, evseoperator, pool, vote) => EVSEOperator.ChargingStationRemoval. SendVoting      (timestamp, evseoperator, pool, vote);
            //this.OnChargingStationRemoval. OnNotification += (timestamp, evseoperator, pool)       => EVSEOperator.ChargingStationRemoval. SendNotification(timestamp, evseoperator, pool);

            // ChargingStation events
            this.OnEVSEAddition.OnVoting       += (timestamp, station, evse, vote) => Operator.EVSEAddition.SendVoting(timestamp, station, evse, vote);
            this.OnEVSEAddition.OnNotification += (timestamp, station, evse) => Operator.EVSEAddition.SendNotification(timestamp, station, evse);

            this.OnEVSERemoval.OnVoting       += (timestamp, station, evse, vote) => Operator.EVSERemoval.SendVoting(timestamp, station, evse, vote);
            this.OnEVSERemoval.OnNotification += (timestamp, station, evse) => Operator.EVSERemoval.SendNotification(timestamp, station, evse);

            #endregion


            if (Members?.Any() == true)
            {
                Members.ForEach(station => Add(station));
            }
        }
示例#5
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);
            }
        }