|
@@ -22,112 +22,122 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
try
|
|
|
{
|
|
|
switch (action)
|
|
|
- {
|
|
|
+ {
|
|
|
|
|
|
- case Actions.FirmwareStatusNotification:
|
|
|
- {
|
|
|
- FirmwareStatusNotificationRequest _request = request as FirmwareStatusNotificationRequest;
|
|
|
-
|
|
|
- if (_request.status == Packet.Messages.SubTypes.FirmwareStatus.Idle)
|
|
|
+ case Actions.FirmwareStatusNotification:
|
|
|
{
|
|
|
- string requestId = Guid.NewGuid().ToString();
|
|
|
- using (var db = new MainDBContext())
|
|
|
- {
|
|
|
- var machine = db.Machine.Where(x => x.FW_AssignedVersion.HasValue == true &&
|
|
|
- x.FW_AssignedVersion != x.FW_VersionReport && x.ChargeBoxId == session.ChargeBoxId)
|
|
|
- .Select(x => new { x.Id, x.FW_AssignedVersion }).AsNoTracking().FirstOrDefault();
|
|
|
+ FirmwareStatusNotificationRequest _request = request as FirmwareStatusNotificationRequest;
|
|
|
|
|
|
- if (machine != null)
|
|
|
+ if (_request.status == Packet.Messages.SubTypes.FirmwareStatus.Idle)
|
|
|
+ {
|
|
|
+ string requestId = Guid.NewGuid().ToString();
|
|
|
+ using (var db = new MainDBContext())
|
|
|
{
|
|
|
- var mv = db.MachineVersionFile.Include(c => c.UploadFile)
|
|
|
- .Where(c => c.Id == machine.FW_AssignedVersion.Value).First();
|
|
|
-
|
|
|
- string downloadUrl = mv.UploadFile.FileUrl;
|
|
|
+ var machine = db.Machine.Where(x => x.FW_AssignedVersion.HasValue == true && x.FW_AssignedVersion.HasValue
|
|
|
+ && x.FW_AssignedVersion != x.FW_VersionReport && x.ChargeBoxId == session.ChargeBoxId)
|
|
|
+ .Select(x => new { x.Id, x.FW_AssignedVersion }).AsNoTracking().FirstOrDefault();
|
|
|
|
|
|
- var _updateFWrequest = new UpdateFirmwareRequest()
|
|
|
- {
|
|
|
- location = new Uri(downloadUrl),
|
|
|
- retries = 3,
|
|
|
- retrieveDate = DateTime.Now,
|
|
|
- retryInterval = 10
|
|
|
- };
|
|
|
- db.MachineOperateRecord.Add(new MachineOperateRecord()
|
|
|
+ if (machine != null)
|
|
|
{
|
|
|
- CreatedOn = DateTime.Now,
|
|
|
- ChargeBoxId = session.ChargeBoxId,
|
|
|
- SerialNo = requestId,
|
|
|
- RequestContent = JsonConvert.SerializeObject(_updateFWrequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
- EVSE_Status = 0,
|
|
|
- EVSE_Value = "Fw Version:" + machine.FW_AssignedVersion,
|
|
|
- Status = 0,
|
|
|
- RequestType = 0,
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
- db.ServerMessage.Add(new ServerMessage()
|
|
|
- {
|
|
|
- ChargeBoxId = session.ChargeBoxId,
|
|
|
- CreatedBy = "Server",
|
|
|
- CreatedOn = DateTime.Now,
|
|
|
- OutAction = _updateFWrequest.Action.ToString(),
|
|
|
- OutRequest = JsonConvert.SerializeObject(_updateFWrequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
- SerialNo = requestId,
|
|
|
- InMessage = string.Empty
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
- db.SaveChanges();
|
|
|
+ var mv = db.MachineVersionFile.Include(c => c.UploadFile)
|
|
|
+ .Where(c => c.Id == machine.FW_AssignedVersion.Value).First();
|
|
|
+
|
|
|
+ string downloadUrl = mv.UploadFile.FileUrl;
|
|
|
+
|
|
|
+ var _updateFWrequest = new UpdateFirmwareRequest()
|
|
|
+ {
|
|
|
+ location = new Uri(downloadUrl),
|
|
|
+ retries = 3,
|
|
|
+ retrieveDate = DateTime.Now,
|
|
|
+ retryInterval = 10
|
|
|
+ };
|
|
|
+
|
|
|
+ db.MachineOperateRecord.Add(new MachineOperateRecord()
|
|
|
+ {
|
|
|
+ CreatedOn = DateTime.Now,
|
|
|
+ ChargeBoxId = session.ChargeBoxId,
|
|
|
+ SerialNo = requestId,
|
|
|
+ RequestContent = JsonConvert.SerializeObject(_updateFWrequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ EVSE_Status = 0,
|
|
|
+ EVSE_Value = "Fw Version:" + machine.FW_AssignedVersion,
|
|
|
+ Status = 0,
|
|
|
+ RequestType = 0,
|
|
|
+ Action = _updateFWrequest.Action.ToString()
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ db.ServerMessage.Add(new ServerMessage()
|
|
|
+ {
|
|
|
+ ChargeBoxId = session.ChargeBoxId,
|
|
|
+ CreatedBy = "Server",
|
|
|
+ CreatedOn = DateTime.Now,
|
|
|
+ OutAction = _updateFWrequest.Action.ToString(),
|
|
|
+ OutRequest = JsonConvert.SerializeObject(_updateFWrequest, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ SerialNo = requestId,
|
|
|
+ InMessage = string.Empty
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ db.SaveChanges();
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- using (var db = new MainDBContext())
|
|
|
+ else
|
|
|
{
|
|
|
- var item = db.MachineOperateRecord.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.RequestType == 0)
|
|
|
- .OrderByDescending(x => x.CreatedOn).FirstOrDefault();
|
|
|
+ using (var db = new MainDBContext())
|
|
|
+ {
|
|
|
+ var item = db.MachineOperateRecord.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.RequestType == 0)
|
|
|
+ .OrderByDescending(x => x.CreatedOn).FirstOrDefault();
|
|
|
+ if (item != null)
|
|
|
+ {
|
|
|
+ item.EVSE_Status = (int)_request.status;
|
|
|
+ item.FinishedOn = DateTime.Now;
|
|
|
+ if(string.IsNullOrEmpty(item.EVSE_Value))
|
|
|
+ {
|
|
|
+ Console.WriteLine("怎麼悾悾的");
|
|
|
+ }
|
|
|
|
|
|
- item.EVSE_Status = (int)_request.status;
|
|
|
- item.FinishedOn = DateTime.Now;
|
|
|
+ if (!string.IsNullOrEmpty(item.EVSE_Value) && _request.status == Packet.Messages.SubTypes.FirmwareStatus.Installed)
|
|
|
+ {
|
|
|
+ int version = 0;
|
|
|
+ int.TryParse(item.EVSE_Value.Split(':').Last(), out version);
|
|
|
+ var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
+ machine.FW_VersionReport = version;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(item.EVSE_Value) && _request.status == Packet.Messages.SubTypes.FirmwareStatus.Installed)
|
|
|
- {
|
|
|
- int version = 0;
|
|
|
- int.TryParse(item.EVSE_Value.Split(':').Last(), out version);
|
|
|
- var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
- machine.FW_VersionReport = version;
|
|
|
- }
|
|
|
|
|
|
- db.SaveChanges();
|
|
|
+
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- var confirm = new FirmwareStatusNotificationConfirmation() { };
|
|
|
+ var confirm = new FirmwareStatusNotificationConfirmation() { };
|
|
|
|
|
|
- result.Message = confirm;
|
|
|
- result.Success = true;
|
|
|
- }
|
|
|
- break;
|
|
|
- case Actions.DiagnosticsStatusNotification:
|
|
|
- {
|
|
|
- DiagnosticsStatusNotificationRequest _request = request as DiagnosticsStatusNotificationRequest;
|
|
|
+ result.Message = confirm;
|
|
|
+ result.Success = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Actions.DiagnosticsStatusNotification:
|
|
|
+ {
|
|
|
+ DiagnosticsStatusNotificationRequest _request = request as DiagnosticsStatusNotificationRequest;
|
|
|
|
|
|
- var confirm = new DiagnosticsStatusNotificationConfirmation() { };
|
|
|
+ var confirm = new DiagnosticsStatusNotificationConfirmation() { };
|
|
|
|
|
|
- result.Message = confirm;
|
|
|
- result.Success = true;
|
|
|
+ result.Message = confirm;
|
|
|
+ result.Success = true;
|
|
|
|
|
|
- }
|
|
|
- break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- {
|
|
|
- Console.WriteLine(string.Format("Not Implement {0} Logic", request.GetType().ToString().Replace("OCPPPackage.Messages.FirmwareManagement.", "")));
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ Console.WriteLine(string.Format("Not Implement {0} Logic", request.GetType().ToString().Replace("OCPPPackage.Messages.FirmwareManagement.", "")));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -149,7 +159,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
case Actions.GetDiagnostics:
|
|
|
{
|
|
|
string evse_rep = string.Empty;
|
|
|
- if(confirm is GetDiagnosticsConfirmation)
|
|
|
+ if (confirm is GetDiagnosticsConfirmation)
|
|
|
{
|
|
|
var confirmation = confirm as GetDiagnosticsConfirmation;
|
|
|
evse_rep = confirmation.fileName;
|
|
@@ -163,7 +173,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
operation.FinishedOn = DateTime.Now;
|
|
|
operation.Status = 1;//電樁有回覆
|
|
|
operation.EVSE_Status = (int)1;//OK
|
|
|
- operation.EVSE_Value = evse_rep;
|
|
|
+ operation.EVSE_Value = string.IsNullOrEmpty(evse_rep)?operation.EVSE_Value: evse_rep;
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
|