Procházet zdrojové kódy

clean partial code

Robert před 1 rokem
rodič
revize
5cf3601b95

+ 1 - 1
EVCB_OCPP.WSServer/Jobs/DenyModelCheckJob.cs

@@ -1,5 +1,6 @@
 using Dapper;
 using DnsClient.Internal;
+using Microsoft.Data.SqlClient;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
 using OCPPServer.Protocol;
@@ -7,7 +8,6 @@ using Quartz;
 using System;
 using System.Collections.Generic;
 using System.Configuration;
-using System.Data.SqlClient;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

+ 2 - 2
EVCB_OCPP.WSServer/Jobs/ServerMessageJob.cs

@@ -58,7 +58,7 @@ public class ServerMessageJob : IJob
             DateTime startDt = dateTimeNoew.AddSeconds(-30);
             DateTime dt = new DateTime(1991, 1, 1);
             DateTime currentTime = dateTimeNoew;
-            var commandList = db.ServerMessage.Where(c => c.ReceivedOn == dt && c.UpdatedOn == dt && c.CreatedOn >= startDt && c.CreatedOn <= currentTime).AsNoTracking().ToList();
+            var commandList = await db.ServerMessage.Where(c => c.ReceivedOn == dt && c.UpdatedOn == dt && c.CreatedOn >= startDt && c.CreatedOn <= currentTime).AsNoTracking().ToListAsync();
             var clientDic = protalServer.ClientDic;
 
             //處理主機傳送的有指令
@@ -158,7 +158,7 @@ public class ServerMessageJob : IJob
                             _UpdatedItem.UpdatedOn = dateTimeNoew;
                             db.Entry(_UpdatedItem).Property(x => x.UpdatedOn).IsModified = true;// 可以直接使用這方式強制某欄位要更新,只是查詢集合耗效能而己
 
-                            db.SaveChanges();
+                            await db.SaveChangesAsync();
 
                             #endregion
 

+ 27 - 15
EVCB_OCPP.WSServer/Jobs/ServerSetFeeJob.cs

@@ -5,6 +5,7 @@ using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages.Core;
 using EVCB_OCPP.WSServer.Dto;
 using EVCB_OCPP.WSServer.Message;
+using Microsoft.Data.SqlClient;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
@@ -13,11 +14,8 @@ using OCPPServer.Protocol;
 using Quartz;
 using System;
 using System.Collections.Generic;
-using System.Configuration;
 using System.Data;
-using System.Data.SqlClient;
 using System.Linq;
-using System.Text;
 using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Jobs;
@@ -152,21 +150,35 @@ public class ServerSetFeeJob : IJob
 
             if (client.IsAC)
             {
-                displayPricestrSql = "   SELECT  [AC_BillingMethod] as BillingMethod,[AC_FeeName] as FeeName,[AC_Fee] as ChargingFeebyHour" +
-            "  ,[AC_ParkingFee] as ParkingFee, [Currency]  FROM[StationMachine]  left join[dbo].[Station]" +
-            "  on[StationMachine].StationId = Station.[Id]  where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
-
-                strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee]  FROM[StationMachine]  left join [dbo].[StationFee]" +
-               " on[StationMachine].StationId = StationFee.StationId  where StationMachine.MachineId =@MachineId and StationFee.IsAC=1; ";
+                displayPricestrSql = """
+                    SELECT [AC_BillingMethod] as BillingMethod,[AC_FeeName] as FeeName,[AC_Fee] as ChargingFeebyHour ,[AC_ParkingFee] as ParkingFee, [Currency] 
+                    FROM[StationMachine] left join[dbo].[Station]
+                    on[StationMachine].StationId = Station.[Id] 
+                    where StationMachine.MachineId=@MachineId and Station.IsBilling=1;
+                    """;
+
+                strSql = """
+                    SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee] 
+                    FROM[StationMachine] left join [dbo].[StationFee]
+                    on[StationMachine].StationId = StationFee.StationId  
+                    where StationMachine.MachineId =@MachineId and StationFee.IsAC=1; 
+                    """;
             }
             else
             {
-                displayPricestrSql = "   SELECT  [DC_BillingMethod] as BillingMethod,[DC_FeeName] as FeeName,[DC_Fee] as ChargingFeebyHour" +
-           "  ,[DC_ParkingFee] as ParkingFee, [Currency]  FROM[StationMachine]  left join[dbo].[Station]" +
-           "  on[StationMachine].StationId = Station.[Id]  where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
-
-                strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee]  FROM[StationMachine]  left join [dbo].[StationFee]" +
-               " on[StationMachine].StationId = StationFee.StationId  where StationMachine.MachineId =@MachineId and StationFee.IsAC=0; ";
+                displayPricestrSql = """
+                    SELECT [DC_BillingMethod] as BillingMethod,[DC_FeeName] as FeeName,[DC_Fee] as ChargingFeebyHour ,[DC_ParkingFee] as ParkingFee, [Currency] 
+                    FROM[StationMachine] left join[dbo].[Station] 
+                    on[StationMachine].StationId = Station.[Id]
+                    where StationMachine.MachineId=@MachineId and Station.IsBilling=1; 
+                    """;
+
+                strSql = """
+                    SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee]
+                    FROM[StationMachine] left join [dbo].[StationFee]
+                    on[StationMachine].StationId = StationFee.StationId
+                    where StationMachine.MachineId =@MachineId and StationFee.IsAC=0;
+                    """;
 
             }
             var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1146 - 1201
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs


+ 1 - 1
EVCB_OCPP.WSServer/Message/FirmwareManagementProfileHandler.cs

@@ -212,7 +212,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 operation.Status = 1;//電樁有回覆
                                 operation.EVSE_Status = (int)255;//錯誤
                                 operation.EVSE_Value = errorMsg;
-                                db.SaveChanges();
+                                await db.SaveChangesAsync();
                             }
 
                         }

+ 1 - 1
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -572,7 +572,7 @@ namespace EVCB_OCPP.WSServer
                     if (machine != null)
                     {
                         machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
-                        db.SaveChanges();
+                        await db.SaveChangesAsync();
                     }
 
                 }

+ 8 - 5
EVCB_OCPP.WSServer/Service/LoadingBalanceService.cs

@@ -1,11 +1,10 @@
 using Dapper;
+using Microsoft.Data.SqlClient;
 using Microsoft.Extensions.Configuration;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
-using System.Configuration;
 using System.Data;
-using System.Data.SqlClient;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
@@ -284,7 +283,9 @@ namespace EVCB_OCPP.WSServer.Service
                 foreach (var chargeboxid in chargeboxids)
                 {
                     string txSql = "SELECT TOP(1) [Id] from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and StopTime = '1991-01-01 00:00:00.000'; ";
-                    var txId = await conn.ExecuteScalarAsync<Int64>(txSql, new { ChargeBoxId = chargeboxid });
+                    var param = new DynamicParameters();
+                    param.Add("ChargeBoxId", chargeboxid, DbType.String, ParameterDirection.Input, 50);
+                    var txId = await conn.ExecuteScalarAsync<Int64>(txSql, param);
                     if (txId > 0)
                     {
                         results.Add(chargeboxid);
@@ -314,11 +315,13 @@ namespace EVCB_OCPP.WSServer.Service
                 foreach (var charger in result)
                 {
                     string txSql = "SELECT TOP(1) [Id] from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and StopTime = '1991-01-01 00:00:00.000'; ";
-                    var txId = await conn.ExecuteScalarAsync<Int64>(txSql, new { ChargeBoxId = charger });
+                    var param = new DynamicParameters();
+                    param.Add("ChargeBoxId", charger, DbType.String, ParameterDirection.Input, 50);
+                    var txId = await conn.ExecuteScalarAsync<Int64>(txSql, param);
                     if (txId > 0)
                     {
                         string ratedPowerSql = "Select Sum(RatedPower) from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and [Online]=0; ";
-                        ratedPowers += await conn.ExecuteScalarAsync<int>(ratedPowerSql, new { ChargeBoxId = charger });
+                        ratedPowers += await conn.ExecuteScalarAsync<int>(ratedPowerSql, param);
                     }
                 }
             }

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů