/// <summary> /// Create and register a new roaming network having the given /// unique roaming network identification. /// </summary> /// <param name="RoamingNetworkId">The unique identification of the new roaming network.</param> /// <param name="Name">The multi-language name of the roaming network.</param> /// <param name="Description">A multilanguage description of the roaming networks object.</param> /// <param name="Configurator">An optional delegate to configure the new roaming network after its creation.</param> /// <param name="AdminStatus">The initial admin status of the roaming network.</param> /// <param name="Status">The initial status of the roaming network.</param> /// <param name="MaxAdminStatusListSize">The maximum number of entries in the admin status history.</param> /// <param name="MaxStatusListSize">The maximum number of entries in the status history.</param> /// <param name="ChargingStationSignatureGenerator">A delegate to sign a charging station.</param> /// <param name="ChargingPoolSignatureGenerator">A delegate to sign a charging pool.</param> /// <param name="ChargingStationOperatorSignatureGenerator">A delegate to sign a charging station operator.</param> public RoamingNetwork CreateNewRoamingNetwork(RoamingNetwork_Id RoamingNetworkId, I18NString Name, I18NString Description = null, Action <RoamingNetwork> Configurator = null, RoamingNetworkAdminStatusTypes AdminStatus = RoamingNetworkAdminStatusTypes.Operational, RoamingNetworkStatusTypes Status = RoamingNetworkStatusTypes.Available, UInt16 MaxAdminStatusListSize = RoamingNetwork.DefaultMaxAdminStatusListSize, UInt16 MaxStatusListSize = RoamingNetwork.DefaultMaxStatusListSize, ChargingStationSignatureDelegate ChargingStationSignatureGenerator = null, ChargingPoolSignatureDelegate ChargingPoolSignatureGenerator = null, ChargingStationOperatorSignatureDelegate ChargingStationOperatorSignatureGenerator = null, Func <RoamingNetwork_Id, String> ReservationLogFileNameCreator = null, Func <RoamingNetwork_Id, String> SessionLogFileNameCreator = null, Func <RoamingNetwork_Id, String> ChargeDetailRecordLogFileNameCreator = null) { #region Initial checks if (RoamingNetworkId == null) { throw new ArgumentNullException(nameof(RoamingNetworkId), "The given roaming network identification must not be null!"); } if (_RoamingNetworks.ContainsKey(RoamingNetworkId)) { throw new RoamingNetworkAlreadyExists(RoamingNetworkId); } #endregion var _RoamingNetwork = new RoamingNetwork(RoamingNetworkId, Name, Description, AdminStatus, Status, MaxAdminStatusListSize, MaxStatusListSize, ChargingStationSignatureGenerator, ChargingPoolSignatureGenerator, ChargingStationOperatorSignatureGenerator, SessionLogFileNameCreator, ChargeDetailRecordLogFileNameCreator); Configurator?.Invoke(_RoamingNetwork); if (RoamingNetworkAddition.SendVoting(this, _RoamingNetwork) && _RoamingNetworks.TryAdd(RoamingNetworkId, _RoamingNetwork)) { RoamingNetworkAddition.SendNotification(this, _RoamingNetwork); return(_RoamingNetwork); } throw new Exception(); }
public eVehicle RemoveEVehicle(eVehicle_Id eVehicleId) { eVehicle _eVehicle = null; if (TryGetEVehicleById(eVehicleId, out _eVehicle)) { if (eVehicleRemoval.SendVoting(DateTime.UtcNow, this, _eVehicle)) { if (_eVehicles.TryRemove(eVehicleId, out _eVehicle)) { eVehicleRemoval.SendNotification(DateTime.UtcNow, this, _eVehicle); return(_eVehicle); } } } return(null); }
public Boolean TryAdd(T Entity) { lock (Lock) { if (_Addition.SendVoting(DateTime.UtcNow, _Host, Entity)) { _Lookup.Add(Entity.Id, Entity); _Addition.SendNotification(DateTime.UtcNow, _Host, Entity); return(true); } return(false); } }
public Boolean TryAdd(T Entity) { lock (Lock) { if (_Addition.SendVoting(DateTime.UtcNow, _Host, Entity)) { _Lookup.Add(Entity.Id, Entity); foreach (var Id in Entity.Ids) { _MultiIdLookup.Add(Id, Entity); } _Addition.SendNotification(DateTime.UtcNow, _Host, Entity); return(true); } return(false); } }
/// <summary> /// Create and register a new roaming network having the given /// unique roaming network identification. /// </summary> /// <param name="RoamingNetworkId">The unique identification of the new roaming network.</param> /// <param name="AuthorizatorId">The unique identification for the Auth service.</param> /// <param name="Description">A multilanguage description of the roaming network.</param> /// <param name="Action">An optional delegate to configure the new EVSE operator after its creation.</param> public RoamingNetwork CreateNewRoamingNetwork(RoamingNetwork_Id RoamingNetworkId, Authorizator_Id AuthorizatorId = null, I18NString Description = null, Action <RoamingNetwork> Action = null) { #region Initial checks if (RoamingNetworkId == null) { throw new ArgumentNullException("RoamingNetworkId", "The given roaming network identification must not be null!"); } if (_RoamingNetworks.ContainsKey(RoamingNetworkId)) { throw new RoamingNetworkAlreadyExists(RoamingNetworkId); } #endregion var _RoamingNetwork = new RoamingNetwork(RoamingNetworkId, AuthorizatorId) { Description = Description }; Action.FailSafeInvoke(_RoamingNetwork); if (RoamingNetworkAddition.SendVoting(this, _RoamingNetwork)) { if (_RoamingNetworks.TryAdd(RoamingNetworkId, _RoamingNetwork)) { RoamingNetworkAddition.SendNotification(this, _RoamingNetwork); return(_RoamingNetwork); } } throw new Exception(); }
/// <summary> /// Create and register a new eVehicle having the given /// unique eVehicle identification. /// </summary> /// <param name="eVehicleId">The unique identification of the new eVehicle.</param> /// <param name="Configurator">An optional delegate to configure the new eVehicle before its successful creation.</param> /// <param name="OnSuccess">An optional delegate to configure the new eVehicle after its successful creation.</param> /// <param name="OnError">An optional delegate to be called whenever the creation of the eVehicle failed.</param> public eVehicle CreateNewEVehicle(eVehicle_Id eVehicleId = null, Action <eVehicle> Configurator = null, RemoteEVehicleCreatorDelegate RemoteeVehicleCreator = null, eVehicleAdminStatusType AdminStatus = eVehicleAdminStatusType.Operational, eVehicleStatusType Status = eVehicleStatusType.Available, Action <eVehicle> OnSuccess = null, Action <eMobilityStation, eVehicle_Id> OnError = null) { #region Initial checks if (eVehicleId == null) { eVehicleId = eVehicle_Id.Random(Provider.Id); } // Do not throw an exception when an OnError delegate was given! if (_eVehicles.Any(pool => pool.Id == eVehicleId)) { if (OnError == null) { throw new eVehicleAlreadyExistsInStation(this, eVehicleId); } else { OnError?.Invoke(this, eVehicleId); } } #endregion var _eVehicle = new eVehicle(eVehicleId, Provider, Configurator, RemoteeVehicleCreator, AdminStatus, Status); if (eVehicleAddition.SendVoting(DateTime.UtcNow, this, _eVehicle)) { if (_eVehicles.TryAdd(_eVehicle)) { _eVehicle.OnDataChanged += UpdateEVehicleData; _eVehicle.OnStatusChanged += UpdateEVehicleStatus; _eVehicle.OnAdminStatusChanged += UpdateEVehicleAdminStatus; //_eVehicle.OnNewReservation += SendNewReservation; //_eVehicle.OnCancelReservationResponse += SendOnCancelReservationResponse; //_eVehicle.OnNewChargingSession += SendNewChargingSession; //_eVehicle.OnNewChargeDetailRecord += SendNewChargeDetailRecord; OnSuccess?.Invoke(_eVehicle); eVehicleAddition.SendNotification(DateTime.UtcNow, this, _eVehicle); return(_eVehicle); } } return(null); }
/// <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); } }