public static PushEVSEStatusResult Flatten(IId AuthId, ISendStatus ISendStatus, IEnumerable <PushEVSEStatusResult> PushEVSEStatusResults, TimeSpan Runtime) { #region Initial checks if (PushEVSEStatusResults == null || !PushEVSEStatusResults.Any()) { return(new PushEVSEStatusResult(AuthId, ISendStatus, PushEVSEStatusResultTypes.Error, "!", new EVSEStatusUpdate[0], new Warning[0], Runtime)); } #endregion var All = PushEVSEStatusResults.ToArray(); var ResultOverview = All.GroupBy(_ => _.Result). ToDictionary(_ => _.Key, _ => new List <PushEVSEStatusResult>(_)); var Descriptions = All.Where(_ => _ != null). SafeSelect(_ => _.Description). AggregateWith(Environment.NewLine); var RejectedEVSEStatusUpdates = All.Where(_ => _ != null). SelectMany(_ => _.RejectedEVSEStatusUpdates); var Warnings = All.Where(_ => _ != null). SelectMany(_ => _.Warnings); foreach (var result in ResultOverview) { if (ResultOverview[result.Key].Count == All.Length) { return(new PushEVSEStatusResult(All[0].AuthId, ISendStatus, result.Key, Descriptions, RejectedEVSEStatusUpdates, Warnings, Runtime)); } } return(new PushEVSEStatusResult(All[0].AuthId, ISendStatus, PushEVSEStatusResultTypes.Partial, Descriptions, RejectedEVSEStatusUpdates, Warnings, Runtime)); }
public static PushEVSEStatusResult LockTimeout(IId AuthId, ISendStatus ISendStatus, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushEVSEStatusResult(AuthId, ISendStatus, PushEVSEStatusResultTypes.LockTimeout, Description, new EVSEStatusUpdate[0], Warnings, Runtime);
NoOperation(IId AuthId, ISendStatus ISendStatus, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushChargingPoolStatusResult(AuthId, ISendStatus, PushChargingPoolStatusResultTypes.NoOperation, Description, new ChargingPoolStatusUpdate[0], Warnings, Runtime);
Enqueued(IId AuthId, ISendStatus ISendStatus, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushEVSEStatusResult(AuthId, ISendStatus, PushEVSEStatusResultTypes.Enqueued, Description, new EVSEStatusUpdate[0], Warnings, Runtime);
Success(IId AuthId, ISendStatus ISendStatus, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushRoamingNetworkStatusResult(AuthId, ISendStatus, PushRoamingNetworkStatusResultTypes.Success, Description, new RoamingNetworkStatusUpdate[0], Warnings, Runtime);
Error(IId AuthId, ISendStatus ISendStatus, IEnumerable <EVSEStatusUpdate> RejectedEVSEs = null, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushEVSEStatusResult(AuthId, ISendStatus, PushEVSEStatusResultTypes.Error, Description, RejectedEVSEs, Warnings, Runtime);
AdminDown(IId AuthId, ISendStatus ISendStatus, IEnumerable <ChargingPoolStatusUpdate> RejectedEVSEStatusUpdates, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushEVSEStatusResult(AuthId, ISendStatus, PushEVSEStatusResultTypes.AdminDown, Description, new EVSEStatusUpdate[0], Warnings, Runtime);
OutOfService(IId AuthId, ISendStatus ISendStatus, IEnumerable <ChargingStationStatusUpdate> RejectedChargingPoolStatusUpdates, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushChargingPoolStatusResult(AuthId, ISendStatus, PushChargingPoolStatusResultTypes.OutOfService, Description, new ChargingPoolStatusUpdate[0], Warnings, Runtime);
Error(IId AuthId, ISendStatus ISendStatus, IEnumerable <ChargingStationOperatorStatusUpdate> RejectedChargingStationOperators = null, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushChargingStationOperatorStatusResult(AuthId, ISendStatus, PushChargingStationOperatorStatusResultTypes.Error, Description, RejectedChargingStationOperators, Warnings, Runtime);
AdminDown(IId AuthId, ISendStatus ISendStatus, IEnumerable <RoamingNetworkStatusUpdate> RejectedRoamingNetworkStatusUpdates, String Description = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) => new PushRoamingNetworkStatusResult(AuthId, ISendStatus, PushRoamingNetworkStatusResultTypes.AdminDown, Description, RejectedRoamingNetworkStatusUpdates, Warnings, Runtime);
/// <summary> /// Create a new PushEVSEStatus result. /// </summary> /// <param name="AuthId">The unqiue identification of the authenticator.</param> /// <param name="ISendStatus">An object implementing ISendStatus.</param> /// <param name="Result">The result of the operation.</param> /// <param name="Description">An optional description of the result code.</param> /// <param name="RejectedEVSEStatusUpdates">An enumeration of rejected EVSE status updates.</param> /// <param name="Warnings">Warnings or additional information.</param> /// <param name="Runtime">The runtime of the request.</param> internal PushEVSEStatusResult(IId AuthId, ISendStatus ISendStatus, PushEVSEStatusResultTypes Result, String Description = null, IEnumerable <EVSEStatusUpdate> RejectedEVSEStatusUpdates = null, IEnumerable <Warning> Warnings = null, TimeSpan?Runtime = null) : this(AuthId, Result, Description, RejectedEVSEStatusUpdates, Warnings, Runtime) { this.ISendStatus = ISendStatus; }
UpdateStatus(ISendStatus Sender, IEnumerable <EVSEStatusUpdate> StatusUpdates, DateTime?Timestamp, CancellationToken?CancellationToken, EventTracking_Id EventTrackingId, TimeSpan?RequestTimeout) { #region Initial checks if (StatusUpdates == null || !StatusUpdates.Any()) { return(PushEVSEStatusResult.NoOperation(Id, Sender)); } if (DisablePushStatus) { return(PushEVSEStatusResult.AdminDown(Id, Sender, StatusUpdates)); } #endregion #region Send OnEnqueueSendCDRRequest event //try //{ // OnEnqueueSendCDRRequest?.Invoke(StartTime, // Timestamp.Value, // this, // EventTrackingId, // RoamingNetwork.Id, // ChargeDetailRecord, // RequestTimeout); //} //catch (Exception e) //{ // e.Log(nameof(WWCPCPOAdapter) + "." + nameof(OnSendCDRRequest)); //} #endregion await DataAndStatusLock.WaitAsync().ConfigureAwait(false); try { var FilteredUpdates = StatusUpdates.Where(statusupdate => _IncludeEVSEs(statusupdate.EVSE) && _IncludeEVSEIds(statusupdate.EVSE.Id)). ToArray(); if (FilteredUpdates.Length > 0) { foreach (var Update in FilteredUpdates) { // Delay the status update until the EVSE data had been uploaded! if (!DisablePushData && EVSEsToAddQueue.Any(evse => evse == Update.EVSE)) { EVSEStatusChangesDelayedQueue.Add(Update); } else { EVSEStatusChangesFastQueue.Add(Update); } } FlushEVSEFastStatusTimer.Change(FlushEVSEFastStatusEvery, TimeSpan.FromMilliseconds(-1)); return(PushEVSEStatusResult.Enqueued(Id, Sender)); } return(PushEVSEStatusResult.NoOperation(Id, Sender)); } finally { DataAndStatusLock.Release(); } }
/// <summary> /// Create a new WWCP wrapper for the OICP roaming client for Charging Station Operators/CPOs. /// </summary> /// <param name="Id">The unique identification of the roaming provider.</param> /// <param name="Name">The offical (multi-language) name of the roaming provider.</param> /// <param name="Description">An optional (multi-language) description of the charging station operator roaming provider.</param> /// <param name="RoamingNetwork">A WWCP roaming network.</param> /// /// <param name="IncludeEVSEIds">Only include the EVSE matching the given delegate.</param> /// <param name="IncludeEVSEs">Only include the EVSEs matching the given delegate.</param> /// /// <param name="FlushEVSEDataAndStatusEvery">The service check intervall.</param> /// <param name="FlushEVSEFastStatusEvery">The status check intervall.</param> /// <param name="FlushChargeDetailRecordsEvery">The charge detail record intervall.</param> /// /// <param name="DisablePushData">This service can be disabled, e.g. for debugging reasons.</param> /// <param name="DisablePushStatus">This service can be disabled, e.g. for debugging reasons.</param> /// <param name="DisableAuthentication">This service can be disabled, e.g. for debugging reasons.</param> /// <param name="DisableSendChargeDetailRecords">This service can be disabled, e.g. for debugging reasons.</param> /// /// <param name="DNSClient">The attached DNS service.</param> protected AWWCPCSOAdapter(CSORoamingProvider_Id Id, I18NString Name, I18NString Description, RoamingNetwork RoamingNetwork, IncludeEVSEIdDelegate IncludeEVSEIds = null, IncludeEVSEDelegate IncludeEVSEs = null, TimeSpan?FlushEVSEDataAndStatusEvery = null, TimeSpan?FlushEVSEFastStatusEvery = null, TimeSpan?FlushChargeDetailRecordsEvery = null, Boolean DisablePushData = false, Boolean DisablePushStatus = false, Boolean DisableAuthentication = false, Boolean DisableSendChargeDetailRecords = false, String EllipticCurve = "P-256", ECPrivateKeyParameters PrivateKey = null, PublicKeyCertificates PublicKeyCertificates = null, DNSClient DNSClient = null) : base(Id, RoamingNetwork, EllipticCurve, PrivateKey, PublicKeyCertificates) { this.Name = Name; this.Description = Description; this._ISendData = this as ISendData; this._ISendStatus = this as ISendStatus; this._IncludeEVSEIds = IncludeEVSEIds ?? (evseid => true); this._IncludeEVSEs = IncludeEVSEs ?? (evse => true); this.DisablePushData = DisablePushData; this.DisablePushStatus = DisablePushStatus; this.DisableAuthentication = DisableAuthentication; this.DisableSendChargeDetailRecords = DisableSendChargeDetailRecords; this.FlushEVSEDataAndStatusEvery = FlushEVSEDataAndStatusEvery ?? DefaultFlushEVSEDataAndStatusEvery; this.FlushEVSEFastStatusEvery = FlushEVSEFastStatusEvery ?? DefaultFlushEVSEFastStatusEvery; this.FlushChargeDetailRecordsEvery = FlushChargeDetailRecordsEvery ?? DefaultFlushChargeDetailRecordsEvery; this.FlushEVSEDataAndStatusTimer = new Timer(FlushEVSEDataAndStatus); this.FlushEVSEFastStatusTimer = new Timer(FlushEVSEFastStatus); this.FlushChargeDetailRecordsTimer = new Timer(FlushChargeDetailRecords); this.EVSEsUpdateLog = new Dictionary <EVSE, List <PropertyUpdateInfos> >(); this.ChargingStationsUpdateLog = new Dictionary <ChargingStation, List <PropertyUpdateInfos> >(); this.ChargingPoolsUpdateLog = new Dictionary <ChargingPool, List <PropertyUpdateInfos> >(); this.DNSClient = DNSClient; this.EVSEsToAddQueue = new HashSet <EVSE>(); this.EVSEsToUpdateQueue = new HashSet <EVSE>(); this.EVSEsToRemoveQueue = new HashSet <EVSE>(); this.EVSEAdminStatusChangesFastQueue = new List <EVSEAdminStatusUpdate>(); this.EVSEAdminStatusChangesDelayedQueue = new List <EVSEAdminStatusUpdate>(); this.EVSEStatusChangesFastQueue = new List <EVSEStatusUpdate>(); this.EVSEStatusChangesDelayedQueue = new List <EVSEStatusUpdate>(); }