|
@@ -6,6 +6,7 @@ using EVCB_OCPP.Packet.Messages;
|
|
|
using EVCB_OCPP.Packet.Messages.Core;
|
|
|
using EVCB_OCPP.Packet.Messages.SubTypes;
|
|
|
using EVCB_OCPP.WSServer.Dto;
|
|
|
+using EVCB_OCPP.WSServer.Helper;
|
|
|
using EVCB_OCPP.WSServer.Service;
|
|
|
using Microsoft.Data.SqlClient;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
@@ -289,7 +290,8 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
VendorErrorCode = string.IsNullOrEmpty(_request.vendorErrorCode) ? string.Empty : _request.vendorErrorCode,
|
|
|
Id = Guid.NewGuid().ToString()
|
|
|
};
|
|
|
- await db.ConnectorStatus.AddAsync(_currentStatus);
|
|
|
+ db.ConnectorStatus.Add(_currentStatus);
|
|
|
+ await db.SaveChangesAsync();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -297,7 +299,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
- await db.MachineError.AddAsync(new MachineError()
|
|
|
+ db.MachineError.Add(new MachineError()
|
|
|
{
|
|
|
ConnectorId = (byte)_request.connectorId,
|
|
|
CreatedOn = _request.timestamp.HasValue ? _request.timestamp.Value : DateTime.UtcNow,
|
|
@@ -393,20 +395,19 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
"@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
|
|
|
- List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
- {
|
|
|
- new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
- new SqlParameter("ConnectorId", (byte)_request.connectorId),
|
|
|
- new SqlParameter("Value",value),
|
|
|
- new SqlParameter("CreatedOn",item.timestamp),
|
|
|
- new SqlParameter("ContextId",sampleVaule.context.HasValue ? (int)sampleVaule.context : 0),
|
|
|
- new SqlParameter("FormatId",sampleVaule.format.HasValue ? (int)sampleVaule.format : 0),
|
|
|
- new SqlParameter("MeasurandId",sampleVaule.measurand.HasValue ? (int)sampleVaule.measurand : 0),
|
|
|
- new SqlParameter("PhaseId",sampleVaule.phase.HasValue ? (int)sampleVaule.phase : 0),
|
|
|
- new SqlParameter("LocationId",sampleVaule.location.HasValue ? (int)sampleVaule.location : 0),
|
|
|
- new SqlParameter("UnitId",sampleVaule.unit.HasValue ? (int)sampleVaule.unit : 0),
|
|
|
- new SqlParameter("TransactionId",_request.transactionId.HasValue?_request.transactionId:-1),
|
|
|
- };
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>();
|
|
|
+ parameter.AddInsertMeterValueRecordSqlParameters(
|
|
|
+ chargeBoxId: session.ChargeBoxId
|
|
|
+ ,connectorId: (byte)_request.connectorId
|
|
|
+ ,value: value
|
|
|
+ ,createdOn: item.timestamp
|
|
|
+ ,contextId: sampleVaule.context.HasValue ? (int)sampleVaule.context : 0
|
|
|
+ ,formatId: sampleVaule.format.HasValue ? (int)sampleVaule.format : 0
|
|
|
+ ,measurandId: sampleVaule.measurand.HasValue ? (int)sampleVaule.measurand : 0
|
|
|
+ ,phaseId: sampleVaule.phase.HasValue ? (int)sampleVaule.phase : 0
|
|
|
+ ,locationId: sampleVaule.location.HasValue ? (int)sampleVaule.location : 0
|
|
|
+ ,unitId: sampleVaule.unit.HasValue ? (int)sampleVaule.unit : 0
|
|
|
+ ,transactionId: _request.transactionId.HasValue ? _request.transactionId.Value : -1);
|
|
|
|
|
|
db.Database.ExecuteSqlRaw(sp, parameter.ToArray());
|
|
|
}
|
|
@@ -706,45 +707,41 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
#region Save MeterValue
|
|
|
|
|
|
- if (_request.transactionData != null)
|
|
|
+ if (_request.transactionData != null &&
|
|
|
+ _request.transactionData.Count > 0)
|
|
|
{
|
|
|
- if (_request.transactionData.Count > 0)
|
|
|
+ using (var _meterDb = await metervaluedbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
- using (var _meterDb = await metervaluedbContextFactory.CreateDbContextAsync())
|
|
|
+ foreach (var item in _request.transactionData)
|
|
|
+ foreach (var sampleVaule in item.sampledValue)
|
|
|
{
|
|
|
- foreach (var item in _request.transactionData)
|
|
|
- {
|
|
|
- foreach (var sampleVaule in item.sampledValue)
|
|
|
- {
|
|
|
- decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
-
|
|
|
+ decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
|
|
|
- string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
- "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
|
|
|
- List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
- {
|
|
|
- new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
- new SqlParameter("ConnectorId", (byte)_ConnectorId),
|
|
|
- new SqlParameter("Value",value),
|
|
|
- new SqlParameter("CreatedOn",item.timestamp),
|
|
|
- new SqlParameter("ContextId",sampleVaule.context.HasValue ? (int)sampleVaule.context : 0),
|
|
|
- new SqlParameter("FormatId",sampleVaule.format.HasValue ? (int)sampleVaule.format : 0),
|
|
|
- new SqlParameter("MeasurandId",sampleVaule.measurand.HasValue ? (int)sampleVaule.measurand : 0),
|
|
|
- new SqlParameter("PhaseId",sampleVaule.phase.HasValue ? (int)sampleVaule.phase : 0),
|
|
|
- new SqlParameter("LocationId",sampleVaule.location.HasValue ? (int)sampleVaule.location : 0),
|
|
|
- new SqlParameter("UnitId",sampleVaule.unit.HasValue ? (int)sampleVaule.unit : 0),
|
|
|
- new SqlParameter("TransactionId",_request.transactionId),
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- _meterDb.Database.ExecuteSqlRaw(sp, parameter.ToArray());
|
|
|
- }
|
|
|
- }
|
|
|
+ string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
+ "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
+
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>();
|
|
|
+ parameter.AddInsertMeterValueRecordSqlParameters(
|
|
|
+ chargeBoxId: session.ChargeBoxId
|
|
|
+ ,connectorId: (byte)_ConnectorId
|
|
|
+ ,value: value
|
|
|
+ ,createdOn: item.timestamp
|
|
|
+ ,contextId: sampleVaule.context.HasValue ? (int)sampleVaule.context : 0
|
|
|
+ ,formatId: sampleVaule.format.HasValue ? (int)sampleVaule.format : 0
|
|
|
+ ,measurandId: sampleVaule.measurand.HasValue ? (int)sampleVaule.measurand : 0
|
|
|
+ ,phaseId: sampleVaule.phase.HasValue ? (int)sampleVaule.phase : 0
|
|
|
+ ,locationId: sampleVaule.location.HasValue ? (int)sampleVaule.location : 0
|
|
|
+ ,unitId: sampleVaule.unit.HasValue ? (int)sampleVaule.unit : 0
|
|
|
+ ,transactionId: _request.transactionId
|
|
|
+ );
|
|
|
+
|
|
|
+ _meterDb.Database.ExecuteSqlRaw(sp, parameter.ToArray());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -1158,21 +1155,20 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
"@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
|
|
|
- List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
- {
|
|
|
- new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
- new SqlParameter("ConnectorId", (byte)feedto.ConnectorId),
|
|
|
- new SqlParameter("Value",chargingCost),
|
|
|
- new SqlParameter("CreatedOn",DateTime.UtcNow),
|
|
|
- new SqlParameter("ContextId",(int)ReadingContext.Sample_Periodic),
|
|
|
- new SqlParameter("FormatId",(int)ValueFormat.Raw),
|
|
|
- new SqlParameter("MeasurandId",(int)Measurand.TotalCost),
|
|
|
- new SqlParameter("PhaseId", -1),
|
|
|
- new SqlParameter("LocationId", -1),
|
|
|
- new SqlParameter("UnitId", -1),
|
|
|
- new SqlParameter("TransactionId",feedto.Id),
|
|
|
- };
|
|
|
-
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>();
|
|
|
+ parameter.AddInsertMeterValueRecordSqlParameters(
|
|
|
+ chargeBoxId: session.ChargeBoxId,
|
|
|
+ connectorId: feedto.ConnectorId,
|
|
|
+ value: chargingCost,
|
|
|
+ createdOn: DateTime.UtcNow,
|
|
|
+ contextId: (int)ReadingContext.Sample_Periodic,
|
|
|
+ formatId: (int)ValueFormat.Raw,
|
|
|
+ measurandId: (int)Measurand.TotalCost,
|
|
|
+ phaseId: -1,
|
|
|
+ locationId: -1,
|
|
|
+ unitId: -1,
|
|
|
+ transactionId: feedto.Id
|
|
|
+ );
|
|
|
|
|
|
meterdb.Database.ExecuteSqlRaw(sp, parameter.ToArray());
|
|
|
}
|
|
@@ -1244,21 +1240,20 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
"@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
|
|
|
- List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
- {
|
|
|
- new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
- new SqlParameter("ConnectorId", (byte)feedto.ConnectorId),
|
|
|
- new SqlParameter("Value",chargingCost),
|
|
|
- new SqlParameter("CreatedOn",DateTime.UtcNow),
|
|
|
- new SqlParameter("ContextId",(int)ReadingContext.Sample_Periodic),
|
|
|
- new SqlParameter("FormatId",(int)ValueFormat.Raw),
|
|
|
- new SqlParameter("MeasurandId",(int)Measurand.ChargingCost),
|
|
|
- new SqlParameter("PhaseId", -1),
|
|
|
- new SqlParameter("LocationId", -1),
|
|
|
- new SqlParameter("UnitId", -1),
|
|
|
- new SqlParameter("TransactionId",feedto.Id),
|
|
|
- };
|
|
|
-
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>();
|
|
|
+ parameter.AddInsertMeterValueRecordSqlParameters(
|
|
|
+ chargeBoxId: session.ChargeBoxId,
|
|
|
+ connectorId: (byte)feedto.ConnectorId,
|
|
|
+ value: chargingCost,
|
|
|
+ createdOn: DateTime.UtcNow,
|
|
|
+ contextId: (int)ReadingContext.Sample_Periodic,
|
|
|
+ formatId: (int)ValueFormat.Raw,
|
|
|
+ measurandId: (int)Measurand.ChargingCost,
|
|
|
+ phaseId: -1,
|
|
|
+ locationId: -1,
|
|
|
+ unitId: -1,
|
|
|
+ transactionId: feedto.Id
|
|
|
+ );
|
|
|
|
|
|
meterdb.Database.ExecuteSqlRaw(sp, parameter.ToArray());
|
|
|
}
|