Exemplo n.º 1
0
        /// <summary>
        /// Create a new e-vehicle having the given identification.
        /// </summary>
        /// <param name="Id">The unique identification of the e-vehicle pool.</param>
        /// <param name="MaxAdminStatusListSize">The default size of the admin status list.</param>
        internal eVehicle(eVehicle_Id Id,
                          eMobilityStation Station,
                          Action <eVehicle> Configurator = null,
                          RemoteEVehicleCreatorDelegate RemoteEVehicleCreator = null,
                          eVehicleAdminStatusType AdminStatus = eVehicleAdminStatusType.Operational,
                          eVehicleStatusType Status           = eVehicleStatusType.Available,
                          UInt16 MaxAdminStatusListSize       = DefaultMaxAdminStatusListSize,
                          UInt16 MaxStatusListSize            = DefaultMaxStatusListSize)

            : this(Id,
                   Station.Provider,
                   Configurator,
                   RemoteEVehicleCreator,
                   AdminStatus,
                   Status,
                   MaxAdminStatusListSize,
                   MaxStatusListSize)

        {
            this.Station = Station;
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new e-vehicle having the given identification.
        /// </summary>
        /// <param name="Id">The unique identification of the e-vehicle pool.</param>
        /// <param name="MaxAdminStatusListSize">The default size of the admin status list.</param>
        internal eVehicle(eVehicle_Id Id,
                          eMobilityProvider Provider,
                          Action <eVehicle> Configurator = null,
                          RemoteEVehicleCreatorDelegate RemoteEVehicleCreator = null,
                          eVehicleAdminStatusType AdminStatus = eVehicleAdminStatusType.Operational,
                          eVehicleStatusType Status           = eVehicleStatusType.Available,
                          UInt16 MaxAdminStatusListSize       = DefaultMaxAdminStatusListSize,
                          UInt16 MaxStatusListSize            = DefaultMaxStatusListSize)

            : base(Id)

        {
            #region Initial checks

            if (Provider == null)
            {
                throw new ArgumentNullException(nameof(Provider), "The e-mobility provider must not be null!");
            }

            #endregion

            #region Init data and properties

            this.Provider = Provider;

            this.Description = new I18NString();

            this._UserComment            = new I18NString();
            this._ServiceProviderComment = new I18NString();
            this.GeoLocation             = null;

            this._PaymentOptions = new ReactiveSet <PaymentOptions>();

            this._AdminStatusSchedule = new StatusSchedule <eVehicleAdminStatusType>(MaxAdminStatusListSize);
            this._AdminStatusSchedule.Insert(AdminStatus);

            this._StatusSchedule = new StatusSchedule <eVehicleStatusType>(MaxStatusListSize);
            this._StatusSchedule.Insert(Status);

            #endregion

            #region Init events


            #endregion

            #region Link events

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

            this._StatusSchedule.OnStatusChanged += (Timestamp, EventTrackingId, StatusSchedule, OldStatus, NewStatus)
                                                    => UpdateStatus(Timestamp, EventTrackingId, OldStatus, NewStatus);

            #endregion

            this.OnPropertyChanged += UpdateData;

            Configurator?.Invoke(this);

            this.RemoteEVehicle = RemoteEVehicleCreator?.Invoke(this);
        }