Эх сурвалжийг харах

2020/04/17 Jessica
Actions:
1. Transaction Id 產生方式改變 用Table autoincrement Id,因此調整相關邏輯
2. 紀錄遠端可下發命令電樁回覆參數
3.建立卡號判斷是否可充電的服務
4.Domain DLL 版號: 04817db

Jessica.Tseng 5 жил өмнө
parent
commit
c2f18e5b43

+ 26 - 0
EVCB_OCPP.WSServer/BusinessService/BusinessServiceFactory.cs

@@ -0,0 +1,26 @@
+using EVCB_OCPP.Packet.Messages.SubTypes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EVCB_OCPP.WSServer.BusinessService
+{
+
+    public interface IBusinessService
+    {
+        IdTagInfo Authorize(string idTag);
+    }
+
+    static public class BusinessServiceFactory
+    {
+
+        static public IBusinessService CreateBusinessService(string customerId, bool isLocalHandle)
+        {
+
+            return new FakeLocalBusinessService(customerId);
+        }
+
+    }
+}

+ 40 - 0
EVCB_OCPP.WSServer/BusinessService/FakeLocalBusinessService.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using EVCB_OCPP.Packet.Messages.SubTypes;
+
+namespace EVCB_OCPP.WSServer.BusinessService
+{
+    public class FakeLocalBusinessService : IBusinessService
+    {
+        Dictionary<string, IdTagInfo> localAuthDic = new Dictionary<string, IdTagInfo>()
+        {
+            { "AC5CDC3D", new IdTagInfo(){  status= AuthorizationStatus.Invalid} },
+            { "48C4CBD9257A", new IdTagInfo(){  status= AuthorizationStatus.Invalid} },
+            { "3DDC5CAC", new IdTagInfo(){  status= AuthorizationStatus.Invalid} },
+           { "3EFBDEAC", new IdTagInfo(){  status= AuthorizationStatus.Invalid} },
+
+        };
+
+        string customerId = string.Empty;
+
+        public FakeLocalBusinessService(string customerId)
+        {
+            this.customerId = customerId;
+        }
+
+        public IdTagInfo Authorize(string idTag)
+        {
+            IdTagInfo result = new IdTagInfo() { status = AuthorizationStatus.Accepted };
+
+            if (localAuthDic.ContainsKey(idTag))
+            {
+                result = localAuthDic[idTag];
+            }
+            return result;
+
+        }
+    }
+}

+ 29 - 0
EVCB_OCPP.WSServer/BusinessService/LocalBusinessService.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using EVCB_OCPP.Packet.Messages.SubTypes;
+
+namespace EVCB_OCPP.WSServer.BusinessService
+{
+    public class LocalBusinessService : IBusinessService
+    {
+
+       
+      
+        string customerId = string.Empty;
+
+        public LocalBusinessService(string customerId)
+        {
+            this.customerId = customerId;
+        }
+
+        public IdTagInfo Authorize(string idTag)
+        {
+
+            return new IdTagInfo() { status = AuthorizationStatus.Accepted };
+
+        }
+    }
+}

+ 22 - 0
EVCB_OCPP.WSServer/BusinessService/OuterBusinessService.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using EVCB_OCPP.Packet.Messages.SubTypes;
+
+namespace EVCB_OCPP.WSServer.BusinessService
+{
+    public class OuterBusinessService : IBusinessService
+    {
+        public OuterBusinessService(string customerId)
+        {
+
+        }
+
+        public IdTagInfo Authorize(string idTag)
+        {
+           return new IdTagInfo() { status = AuthorizationStatus.Accepted };
+        }
+    }
+}

BIN
EVCB_OCPP.WSServer/DLL/EVCB_OCPP.Domain.dll


+ 5 - 0
EVCB_OCPP.WSServer/EVCB_OCPP.WSServer.csproj

@@ -72,6 +72,10 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="BusinessService\BusinessServiceFactory.cs" />
+    <Compile Include="BusinessService\FakeLocalBusinessService.cs" />
+    <Compile Include="BusinessService\LocalBusinessService.cs" />
+    <Compile Include="BusinessService\OuterBusinessService.cs" />
     <Compile Include="Dto\ConnectorErrorStauts.cs" />
     <Compile Include="GlobalConfig.cs" />
     <Compile Include="Helper\Convertor.cs" />
@@ -136,6 +140,7 @@
       <Name>SuperWebSocket.NET45</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
     <PreBuildEvent>

+ 51 - 32
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -11,6 +11,7 @@ using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
 using EVCB_OCPP.Packet.Messages.Core;
 using EVCB_OCPP.Packet.Messages.SubTypes;
+using EVCB_OCPP.WSServer.BusinessService;
 using EVCB_OCPP.WSServer.Dto;
 using Newtonsoft.Json;
 using OCPPPackage.Profiles;
@@ -21,7 +22,7 @@ namespace EVCB_OCPP.WSServer.Message
 
     internal partial class ProfileHandler
     {
-        private List<string> idtag_RejecttionList = new List<string>() { "AC5CDC3D", "48C4CBD9257A","3DDC5CAC" };
+     
         int counnter = 0;
         internal MessageResult ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
         {
@@ -207,45 +208,67 @@ namespace EVCB_OCPP.WSServer.Message
                 case Actions.StartTransaction:
                     {
                         StartTransactionRequest _request = request as StartTransactionRequest;
-                        long _pastTime = DateTimeOffset.Now.AddYears(-20).ToUnixTimeSeconds();
-                        int _tranId = (int)(_pastTime % 100000000) * 10 + _request.connectorId;
+                        IdTagInfo _idTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };
 
+                        int _transactionId = -1;
+                        if (DateTime.Compare(DateTime.UtcNow.AddSeconds(-10), _request.timestamp.ToUniversalTime()) >= 0)
+                        {
+                            var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString(), true);
+                            _idTagInfo = businessService.Authorize(_request.idTag);
+
+                        }
 
-                        //需處理StopTransactionOnInvalidId 情境,時間若和當前時間差距10秒,發動Authorize詢問後在回覆
                         using (var db = new MainDBContext())
                         {
                             var _CustomerId = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).Include(x => x.Customer).
                                  Select(x => x.CustomerId).FirstOrDefault();
 
-                            db.TransactionRecord.Add(new TransactionRecord()
+                            var _existedTx = db.TransactionRecord.Where(x => x.CustomerId == _CustomerId && x.ChargeBoxId == session.ChargeBoxId
+                               && x.ConnectorId == _request.connectorId && x.StartTime == _request.timestamp).Select(C => new { C.Id }).AsNoTracking().FirstOrDefault();
+                            TransactionRecord _newTransaction = new TransactionRecord();
+
+
+                            if (_existedTx.Id >= 0)
                             {
-                                ChargeBoxId = session.ChargeBoxId,
-                                ConnectorId = (byte)_request.connectorId,
-                                CreatedOn = DateTime.Now,
-                                StartIdTag = _request.idTag,
-                                MeterStart = _request.meterStart,
-                                CustomerId = _CustomerId,
-                                StartTime = _request.timestamp,
-                                ReservationId = _request.reservationId.HasValue ? _request.reservationId.Value : 0,
-                                TransactionId = _tranId
-
-                            });
+                                _newTransaction = new TransactionRecord()
+                                {
+                                    ChargeBoxId = session.ChargeBoxId,
+                                    ConnectorId = (byte)_request.connectorId,
+                                    CreatedOn = DateTime.Now,
+                                    StartIdTag = _request.idTag,
+                                    MeterStart = _request.meterStart,
+                                    CustomerId = _CustomerId,
+                                    StartTime = _request.timestamp,
+                                    ReservationId = _request.reservationId.HasValue ? _request.reservationId.Value : 0,
 
-                            db.SaveChanges();
-                        }
 
+                                };
 
+                                db.TransactionRecord.Add(_newTransaction);
 
-                        var confirm = new StartTransactionConfirmation()
-                        {
-                            idTagInfo = new Packet.Messages.SubTypes.IdTagInfo()
+                                db.SaveChanges();
+
+                                _transactionId = _newTransaction.Id;
+                                Console.WriteLine("***************************************************** ");
+                                Console.WriteLine(string.Format("{0} :TransactionId {1} ", session.ChargeBoxId, _newTransaction.Id));
+                                Console.WriteLine("***************************************************** ");
+                            }
+                            else
                             {
-                                status = idtag_RejecttionList.Contains(_request.idTag) ? AuthorizationStatus.Invalid : AuthorizationStatus.Accepted
-                            },
-                            transactionId = _tranId
+                                _transactionId = _existedTx.Id;
+                                Console.WriteLine("Duplication ***************************************************** " + _existedTx.Id);
+                            }
+
+
+
 
+                        }
 
 
+                        var confirm = new StartTransactionConfirmation()
+                        {
+                            idTagInfo = _idTagInfo,
+                            transactionId = _transactionId
                         };
 
 
@@ -286,7 +309,7 @@ namespace EVCB_OCPP.WSServer.Message
 
                         using (var db = new MainDBContext())
                         {
-                            var transaction = db.TransactionRecord.Where(x => x.TransactionId == _request.transactionId
+                            var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
                              && x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
 
                             if (transaction != null)
@@ -325,14 +348,10 @@ namespace EVCB_OCPP.WSServer.Message
                 case Actions.Authorize:
                     {
                         AuthorizeRequest _request = request as AuthorizeRequest;
-
+                        var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString(), true);
                         var confirm = new AuthorizeConfirmation()
                         {
-
-                            idTagInfo = new Packet.Messages.SubTypes.IdTagInfo()
-                            {
-                                status = idtag_RejecttionList.Contains(_request.idTag) ? AuthorizationStatus.Invalid : AuthorizationStatus.Accepted
-                            }
+                            idTagInfo = businessService.Authorize(_request.idTag)
                         };
                         result.Message = confirm;
                         result.Success = true;
@@ -531,7 +550,7 @@ namespace EVCB_OCPP.WSServer.Message
                                             ConfigureName = item.key,
                                             ReadOnly = item.IsReadOnly,
                                             ConfigureSetting = item.value,
-                                            Exists=true
+                                            Exists = true
                                         });
                                     }
                                 }

+ 2 - 1
EVCB_OCPP.WSServer/Message/LocalAuthListManagementProfileHandler.cs

@@ -55,7 +55,8 @@ namespace EVCB_OCPP.WSServer.Message
                             {
                                 operation.FinishedOn = DateTime.Now;
                                 operation.Status = 1;//電樁有回覆
-                                operation.EVSE_Status = (int)_confirm.updateStatus;//OK                              
+                                operation.EVSE_Status = (int)_confirm.updateStatus;//OK     
+                                operation.EVSE_Value = _confirm.updateStatus.ToString();
                                 db.SaveChanges();
                             }
 

+ 1 - 0
EVCB_OCPP.WSServer/Message/RemoteTriggerHandler.cs

@@ -34,6 +34,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 operation.FinishedOn = DateTime.Now;
                                 operation.Status = 1;//電樁有回覆
                                 operation.EVSE_Status = (int)_confirm.status;//OK
+                                operation.EVSE_Value = _confirm.status.ToString();
                                 db.SaveChanges();
                             }
 

+ 2 - 0
EVCB_OCPP.WSServer/Message/ReservationProfileHandler.cs

@@ -34,6 +34,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 operation.FinishedOn = DateTime.Now;
                                 operation.Status = 1;//電樁有回覆
                                 operation.EVSE_Status = (int)_confirm.status;//OK
+                                operation.EVSE_Value = _confirm.status.ToString();
                                 db.SaveChanges();
                             }
 
@@ -53,6 +54,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 operation.FinishedOn = DateTime.Now;
                                 operation.Status = 1;//電樁有回覆
                                 operation.EVSE_Status = (int)_confirm.status;//OK
+                                operation.EVSE_Value = _confirm.status.ToString();
                                 db.SaveChanges();
                             }
 

+ 2 - 0
EVCB_OCPP.WSServer/Message/SmartChargingProfileHandler.cs

@@ -40,6 +40,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 operation.FinishedOn = DateTime.Now;
                                 operation.Status = 1;//電樁有回覆
                                 operation.EVSE_Status = (int)_confirm.status;//OK
+                                operation.EVSE_Value = _confirm.status.ToString();
                                 db.SaveChanges();
                             }
 
@@ -59,6 +60,7 @@ namespace EVCB_OCPP.WSServer.Message
                                 operation.FinishedOn = DateTime.Now;
                                 operation.Status = 1;//電樁有回覆
                                 operation.EVSE_Status = (int)_confirm.status;//OK
+                                operation.EVSE_Value = _confirm.status.ToString();
                                 db.SaveChanges();
                             }
 

+ 1 - 1
EVCB_OCPP.WSServer/NLog.config

@@ -43,6 +43,6 @@
     <logger name="*" minlevel="Debug" writeTo="f" />
     -->
     <logger name="*" minlevel="Debug" writeTo="f" />
-    <logger name="*" minlevel="Debug" writeTo="Console" />
+    <logger name="*" minlevel="Trace" writeTo="Console" />
   </rules>
 </nlog>

+ 8 - 1
TestTool.RemoteTriggerAPP/FTPClient.cs

@@ -51,8 +51,10 @@ namespace TestTool.RemoteTriggerAPP
     {
 
         public delegate void UploadDataCompletedEventHandler(FtpState state);
+        public delegate void UploadDataProgressEventHandler(double percent);
         public event UploadDataCompletedEventHandler OnUploadSuccessful;
         public event UploadDataCompletedEventHandler OnUploadFail;
+        public event UploadDataProgressEventHandler OnUploadProgress;
         private int uploadTimeOut = 5 * 1000 * 60;
 
         public string Host
@@ -127,7 +129,7 @@ namespace TestTool.RemoteTriggerAPP
             reqFTP.UseBinary = true;
             // 上传文件时通知服务器文件的大小 
             reqFTP.ContentLength = fileInf.Length;
-            int buffLength = 2048;// 缓冲大小设置为2kb 
+            int buffLength = 2048000;// 缓冲大小设置为200kb 
             byte[] buff = new byte[buffLength];
             // 打开一个文件流 (System.IO.FileStream) 去读上传的文件 
             using (FileStream fs = fileInf.OpenRead())
@@ -148,6 +150,11 @@ namespace TestTool.RemoteTriggerAPP
                         contentLen = fs.Read(buff, 0, buffLength);
                         startbye += contentLen;
 
+                      
+                        double percent = (double)((decimal)startbye / reqFTP.ContentLength) * 100;
+                        OnUploadProgress?.Invoke(percent);
+
+
                     }
                     // 关闭两个流 
                     strm.Close();

+ 35 - 31
TestTool.RemoteTriggerAPP/MainWindow.xaml

@@ -5,19 +5,24 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:TestTool.RemoteTriggerAPP"      
         mc:Ignorable="d"
-        Title="下發測試用工具(公司內網) V1.1.4(20200221)" Height="450" Width="670">
+        Title="下發測試用工具(公司內網) V1.1.8(20200303)" Height="450" Width="670">
     <Grid Margin="0,2,0,-2">
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="109*"/>
+            <ColumnDefinition Width="222*"/>
+        </Grid.ColumnDefinitions>
         <Label Content="Charge Box Id:" HorizontalAlignment="Left" Height="27" Margin="69,23,0,0" VerticalAlignment="Top" Width="91"/>
-        <Label Content="Connector Id:" HorizontalAlignment="Left" Height="27" Margin="336,23,0,0" VerticalAlignment="Top" Width="92"/>
-        <TextBox Name="uxChargeBoxIdTb" Text="OCTT_1" HorizontalAlignment="Left" Height="27" Margin="179,23,0,0" VerticalAlignment="Top" Width="148"/>
-        <TextBox Name="uxConnectorIdTb" Text="1" HorizontalAlignment="Left" Height="27" Margin="428,23,0,0" VerticalAlignment="Top" Width="35"/>
-        <ComboBox Name="uxCmdCb" HorizontalAlignment="Left" Margin="212,163,0,0" VerticalAlignment="Top" Width="253" Height="34" SelectionChanged="UxCmdCb_SelectionChanged">
+        <Label Content="Connector Id:" HorizontalAlignment="Left" Height="27" Margin="118,23,0,0" VerticalAlignment="Top" Width="92" Grid.Column="1"/>
+        <TextBox Name="uxChargeBoxIdTb" Text="OCTT_1" HorizontalAlignment="Left" Height="27" Margin="179,23,0,0" VerticalAlignment="Top" Width="148" Grid.ColumnSpan="2"/>
+        <TextBox Name="uxConnectorIdTb" Text="1" HorizontalAlignment="Left" Height="27" Margin="210,23,0,0" VerticalAlignment="Top" Width="35" Grid.Column="1"/>
+        <ComboBox Name="uxCmdCb" HorizontalAlignment="Left" Margin="212,163,0,0" VerticalAlignment="Top" Width="253" Height="34" SelectionChanged="UxCmdCb_SelectionChanged" Grid.ColumnSpan="2">
             <ComboBoxItem>ChangeAvailability_Inoperative</ComboBoxItem>
             <ComboBoxItem>ChangeAvailability_Operative</ComboBoxItem>
             <ComboBoxItem>ChangeConfiguration</ComboBoxItem>
             <ComboBoxItem>ClearCache</ComboBoxItem>
             <ComboBoxItem>GetConfiguration</ComboBoxItem>
             <ComboBoxItem>RemoteStartTransaction</ComboBoxItem>
+            <ComboBoxItem>RemoteStartTransaction_ChargingProfile</ComboBoxItem>
             <ComboBoxItem>RemoteStopTransaction</ComboBoxItem>
             <ComboBoxItem>SoftReset</ComboBoxItem>
             <ComboBoxItem>HardReset</ComboBoxItem>
@@ -25,12 +30,11 @@
             <ComboBoxItem>GetLocalListVersion</ComboBoxItem>
             <ComboBoxItem>SendLocalAuthorizationList_Full</ComboBoxItem>
             <ComboBoxItem>SendLocalAuthorizationList_Diff</ComboBoxItem>
-            <ComboBoxItem>GetDiagnostics</ComboBoxItem>
+            <ComboBoxItem>GetDiagnostics_FTP</ComboBoxItem>
+            <ComboBoxItem>GetDiagnostics_HTTP</ComboBoxItem>
             <ComboBoxItem>ReserveNow</ComboBoxItem>
             <ComboBoxItem>CancelReservation</ComboBoxItem>
-            <ComboBoxItem>SetChargingProfile_TxDefault</ComboBoxItem>
-            <ComboBoxItem>SetChargingProfile_Tx</ComboBoxItem>
-            <ComboBoxItem>RemoteStartTransaction_ChargingProfile</ComboBoxItem>
+            <ComboBoxItem>SetChargingProfile</ComboBoxItem>       
             <ComboBoxItem>ClearChargingProfile</ComboBoxItem>
             <ComboBoxItem>GetCompositeSchedule</ComboBoxItem>
             <ComboBoxItem>TriggerMessage_BootNotification</ComboBoxItem>
@@ -41,34 +45,34 @@
             <ComboBoxItem>TriggerMessage_StatusNotification</ComboBoxItem>
         </ComboBox>
         <Label  Content="Remote Trigger Cmd:" HorizontalAlignment="Left" Height="27" Margin="69,165,0,0" VerticalAlignment="Top" Width="137"/>
-        <Button Name="uxSubmitBtn" Content="Submit" HorizontalAlignment="Left" Margin="478,165,0,0" VerticalAlignment="Top" Width="51" Height="34" Click="UxSubmitBtn_Click"/>
-        <TextBox Name="uxMsgTb" HorizontalAlignment="Left" Height="80" Margin="58,329,0,0" VerticalAlignment="Top" Width="471"/>
+        <Button Name="uxSubmitBtn" Content="Submit" HorizontalAlignment="Left" Margin="260,165,0,0" VerticalAlignment="Top" Width="51" Height="34" Click="UxSubmitBtn_Click" Grid.Column="1"/>
+        <TextBox Name="uxMsgTb" HorizontalAlignment="Left" Height="80" Margin="58,329,0,0" VerticalAlignment="Top" Width="471" Grid.ColumnSpan="2"/>
         <Label Content="Msg:" HorizontalAlignment="Left" Height="27" Margin="58,298,0,0" VerticalAlignment="Top" Width="43" RenderTransformOrigin="0.744,3.407"/>
         <Label Content="Id Tag:" HorizontalAlignment="Left" Height="27" Margin="71,74,0,0" VerticalAlignment="Top" Width="47"/>
         <TextBox x:Name="uxIdTagTb" Text="TestTool" HorizontalAlignment="Left" Height="27" Margin="128,74,0,0" VerticalAlignment="Top" Width="63" RenderTransformOrigin="3.714,1"/>
-        <Label Content="TransactionId:" HorizontalAlignment="Left" Height="27" Margin="380,74,0,0" VerticalAlignment="Top" Width="100"/>
-        <TextBox x:Name="uxTransactionIdTb" Text="0" HorizontalAlignment="Left" Height="27" Margin="485,74,0,0" VerticalAlignment="Top" Width="44" RenderTransformOrigin="3.714,1"/>
-        <Label Content="ParentId Tag:" HorizontalAlignment="Left" Height="27" Margin="212,74,0,0" VerticalAlignment="Top" Width="87"/>
-        <TextBox x:Name="uxParentIdTagTb" Text="TestTool" HorizontalAlignment="Left" Height="27" Margin="299,74,0,0" VerticalAlignment="Top" Width="73" RenderTransformOrigin="3.714,1"/>
+        <Label Content="TransactionId:" HorizontalAlignment="Left" Height="27" Margin="162,74,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1"/>
+        <TextBox x:Name="uxTransactionIdTb" Text="0" HorizontalAlignment="Left" Height="27" Margin="267,74,0,0" VerticalAlignment="Top" Width="44" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
+        <Label Content="ParentId Tag:" HorizontalAlignment="Left" Height="27" Margin="212,74,0,0" VerticalAlignment="Top" Width="87" Grid.ColumnSpan="2"/>
+        <TextBox x:Name="uxParentIdTagTb" Text="TestTool" HorizontalAlignment="Left" Height="27" Margin="81,74,0,0" VerticalAlignment="Top" Width="73" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
         <Label Content="Configuration Key:" HorizontalAlignment="Left" Height="27" Margin="71,119,0,0" VerticalAlignment="Top" Width="120"/>
-        <TextBox x:Name="uxConfigKeyTb" Text="ConnectionTimeOut" HorizontalAlignment="Left" Height="27" Margin="196,119,0,0" VerticalAlignment="Top" Width="138" RenderTransformOrigin="3.714,1"/>
-        <Label Content=" Value:" HorizontalAlignment="Left" Height="27" Margin="339,119,0,0" VerticalAlignment="Top" Width="54"/>
-        <TextBox x:Name="uxConfigValueTb" Text="30" HorizontalAlignment="Left" Height="27" Margin="398,117,0,0" VerticalAlignment="Top" Width="52" RenderTransformOrigin="3.714,1"/>
+        <TextBox x:Name="uxConfigKeyTb" Text="ConnectionTimeOut" HorizontalAlignment="Left" Height="27" Margin="196,119,0,0" VerticalAlignment="Top" Width="138" RenderTransformOrigin="3.714,1" Grid.ColumnSpan="2"/>
+        <Label Content=" Value:" HorizontalAlignment="Left" Height="27" Margin="121,119,0,0" VerticalAlignment="Top" Width="54" Grid.Column="1"/>
+        <TextBox x:Name="uxConfigValueTb" Text="30" HorizontalAlignment="Left" Height="27" Margin="180,117,0,0" VerticalAlignment="Top" Width="52" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
         <Label  Content="Upload Firmware:" HorizontalAlignment="Left" Height="27" Margin="69,217,0,0" VerticalAlignment="Top" Width="113"/>
 
-        <TextBox x:Name="uxUploadFileTb" Text="" HorizontalAlignment="Left" Height="27" Margin="182,217,0,0" VerticalAlignment="Top" Width="210" RenderTransformOrigin="3.714,1"/>
-        <Button x:Name="uxFileSubmitBtn" Content="..." HorizontalAlignment="Left" Margin="405,215,0,0" VerticalAlignment="Top" Width="46" Height="29" Click="uxFileSubmitBtn_Click"/>
-        <Button x:Name="uxUploadBtn" Content="Upload" HorizontalAlignment="Left" Margin="477,212,0,0" VerticalAlignment="Top" Width="52" Height="34" Click="uxUploadBtn_Click"/>
+        <TextBox x:Name="uxUploadFileTb" Text="" HorizontalAlignment="Left" Height="27" Margin="182,217,0,0" VerticalAlignment="Top" Width="210" RenderTransformOrigin="3.714,1" Grid.ColumnSpan="2"/>
+        <Button x:Name="uxFileSubmitBtn" Content="..." HorizontalAlignment="Left" Margin="187,215,0,0" VerticalAlignment="Top" Width="46" Height="29" Click="uxFileSubmitBtn_Click" Grid.Column="1"/>
+        <Button x:Name="uxUploadBtn" Content="Upload" HorizontalAlignment="Left" Margin="259,212,0,0" VerticalAlignment="Top" Width="52" Height="34" Click="uxUploadBtn_Click" Grid.Column="1"/>
         <Label  Content="Publish Version:" HorizontalAlignment="Left" Height="27" Margin="69,266,0,0" VerticalAlignment="Top" Width="113"/>
-        <ComboBox x:Name="uxPublishCb" HorizontalAlignment="Left" Margin="179,266,0,0" VerticalAlignment="Top" Width="213" Height="34" SelectionChanged="uxPublishCb_SelectionChanged"/>
-        <Button x:Name="uxRefreshBtn" Content="Refresh" HorizontalAlignment="Left" Margin="410,266,0,0" VerticalAlignment="Top" Width="53" Height="34" Click="uxRefreshBtn_Click"/>
-        <Button x:Name="uxPublishBtn" Content="Publish" HorizontalAlignment="Left" Margin="476,266,0,0" VerticalAlignment="Top" Width="53" Height="34" Click="uxPublishBtn_Click"/>
-        <Label Content="ReservationId:" HorizontalAlignment="Left" Height="27" Margin="480,23,0,0" VerticalAlignment="Top" Width="100"/>
-        <TextBox x:Name="uxReservationTb" Text="0" HorizontalAlignment="Left" Height="27" Margin="585,23,0,0" VerticalAlignment="Top" Width="44" RenderTransformOrigin="3.714,1"/>
-        <Button x:Name="uxClearPublishBtn" Content="Clear Publish" HorizontalAlignment="Left" Margin="543,266,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="uxClearPublishBtn_Click"/>
-        <Button x:Name="uxFTPUploadBtn" Content="Upload(FTP)" HorizontalAlignment="Left" Margin="543,212,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="uxFTPUploadBtn_Click" RenderTransformOrigin="2.058,0.529"/>
-        <Label Content=" Expiry Time:" HorizontalAlignment="Left" Height="27" Margin="455,119,0,0" VerticalAlignment="Top" Width="80"/>
-        
-        <TextBox x:Name="uxExpiryTimeTb"  Margin="543,117,10,273" Text="2020/02/06 12:00"></TextBox>
+        <ComboBox x:Name="uxPublishCb" HorizontalAlignment="Left" Margin="179,266,0,0" VerticalAlignment="Top" Width="213" Height="34" SelectionChanged="uxPublishCb_SelectionChanged" Grid.ColumnSpan="2"/>
+        <Button x:Name="uxRefreshBtn" Content="Refresh" HorizontalAlignment="Left" Margin="192,266,0,0" VerticalAlignment="Top" Width="53" Height="34" Click="uxRefreshBtn_Click" Grid.Column="1"/>
+        <Button x:Name="uxPublishBtn" Content="Publish" HorizontalAlignment="Left" Margin="258,266,0,0" VerticalAlignment="Top" Width="53" Height="34" Click="uxPublishBtn_Click" Grid.Column="1"/>
+        <Label Content="ReservationId:" HorizontalAlignment="Left" Height="27" Margin="262,23,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1"/>
+        <TextBox x:Name="uxReservationTb" Text="0" HorizontalAlignment="Left" Height="27" Margin="367,23,0,0" VerticalAlignment="Top" Width="44" RenderTransformOrigin="3.714,1" Grid.Column="1"/>
+        <Button x:Name="uxClearPublishBtn" Content="Clear Publish" HorizontalAlignment="Left" Margin="325,266,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="uxClearPublishBtn_Click" Grid.Column="1"/>
+        <Button x:Name="uxFTPUploadBtn" Content="Upload(FTP)" HorizontalAlignment="Left" Margin="325,212,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="uxFTPUploadBtn_Click" RenderTransformOrigin="2.058,0.529" Grid.Column="1"/>
+        <Label Content=" Expiry Time:" HorizontalAlignment="Left" Height="27" Margin="237,119,0,0" VerticalAlignment="Top" Width="80" Grid.Column="1"/>
+
+        <TextBox x:Name="uxExpiryTimeTb"  Margin="325,117,10,273" Text="2020/02/06 12:00" Grid.Column="1"></TextBox>
     </Grid>
 </Window>

+ 165 - 87
TestTool.RemoteTriggerAPP/MainWindow.xaml.cs

@@ -31,6 +31,8 @@ using EVCB_OCPP.Packet.Messages.LocalAuthListManagement;
 using EVCB_OCPP.Packet.Messages.FirmwareManagement;
 using EVCB_OCPP.Packet.Messages.Reservation;
 using EVCB_OCPP.Packet.Messages.SmartCharging;
+using System.Threading;
+using System.Net.Http;
 
 namespace TestTool.RemoteTriggerAPP
 {
@@ -41,14 +43,18 @@ namespace TestTool.RemoteTriggerAPP
     {
         string action = "";
         List<PublishVersion> publishes = new List<PublishVersion>();
+        FTPClient UploadClient = new FTPClient(@"ftp://test.evsocket.phihong.com.cn", "testocpp", "testocpp");
+        string chargingProfilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "chargingProfile.json");
         int selectedPublish = -1;
         public MainWindow()
         {
 
             InitializeComponent();
+            UploadClient.OnUploadProgress += UploadClient_OnUploadProgress;
 
         }
 
+
         private void UxSubmitBtn_Click(object sender, RoutedEventArgs e)
         {
 
@@ -97,7 +103,16 @@ namespace TestTool.RemoteTriggerAPP
                     break;
                 case "RemoteStartTransaction_ChargingProfile":
                     {
-                        SetRemoteStartTransaction(true);
+                        var chargingProfile = VerifyChargingProfile(chargingProfilePath);
+                        if (chargingProfile != null)
+                        {
+                            SetRemoteStartTransaction(chargingProfile);
+                        }
+                        else
+                        {
+                            uxMsgTb.Text = "Please check chargingProfile.json exist in " + AppDomain.CurrentDomain.BaseDirectory;
+                        }
+
                     }
                     break;
                 case "RemoteStopTransaction":
@@ -139,9 +154,14 @@ namespace TestTool.RemoteTriggerAPP
                     }
                     break;
                 #endregion
-                case "GetDiagnostics":
+                case "GetDiagnostics_FTP":
+                    {
+                        GetDiagnostics(true);
+                    }
+                    break;
+                case "GetDiagnostics_HTTP":
                     {
-                        GetDiagnostics();
+                        GetDiagnostics(false);
                     }
                     break;
                 case "ReserveNow":
@@ -164,16 +184,21 @@ namespace TestTool.RemoteTriggerAPP
                         GetCompositeSchedule();
                     }
                     break;
-                case "SetChargingProfile_TxDefault":
-                    {
-                        SetChargingProfile(true);
-                    }
-                    break;
-                case "SetChargingProfile_Tx":
+                case "SetChargingProfile":
                     {
-                        SetChargingProfile(false);
+                        var chargingProfile = VerifyChargingProfile(chargingProfilePath);
+                        if (chargingProfile != null)
+                        {
+                            SetChargingProfile(chargingProfile);
+                        }
+                        else
+                        {
+                            uxMsgTb.Text = "Please check chargingProfile.json exist in " + AppDomain.CurrentDomain.BaseDirectory;
+                        }
+
                     }
                     break;
+
                 #region Trigger Profile
                 case "TriggerMessage_BootNotification":
                 case "TriggerMessage_DiagnosticsStatusNotification":
@@ -192,42 +217,32 @@ namespace TestTool.RemoteTriggerAPP
             }
         }
 
-        private void SetChargingProfile(bool isDefault)
+        private SetChargingProfileRequest VerifyChargingProfile(string path)
+        {
+            SetChargingProfileRequest request = null;
+
+            if (!File.Exists(path)) return request;
+
+            try
+            {
+                request = JsonConvert.DeserializeObject<SetChargingProfileRequest>(File.ReadAllText(path));
+            }
+            catch
+            {
+
+            }
+            return request;
+        }
+
+
+        private void SetChargingProfile(SetChargingProfileRequest csProfile)
         {
             try
             {
 
                 var uuid = Guid.NewGuid().ToString();
-                var request = new SetChargingProfileRequest()
-                {
-                    connectorId = Convert.ToInt32(uxConnectorIdTb.Text),
-                    csChargingProfiles = new csChargingProfiles()
-                    {
-                        chargingProfileId = Convert.ToInt32(DateTime.Now.ToUniversalTime().ToString("yyMMddHHmm")),
-                        chargingProfileKind = ChargingProfileKindType.Absolute,
-                        chargingProfilePurpose = isDefault ? ChargingProfilePurposeType.TxDefaultProfile : ChargingProfilePurposeType.TxProfile,
-                        recurrencyKind = RecurrencyKindType.Daily,
-                        stackLevel = 1,
-                        chargingSchedule = new ChargingSchedule()
-                        {
-                            chargingRateUnit = ChargingRateUnitType.A,
-                            duration = 300,
-                            minChargingRate = 0,
-                            startSchedule = DateTime.Now.ToUniversalTime().Date,
-                            chargingSchedulePeriod = new List<ChargingSchedulePeriod>()
-                                        {
-                                             new ChargingSchedulePeriod()
-                                             { limit=10, startPeriod=0, numberPhases=3 },
-                                              new ChargingSchedulePeriod()
-                                             { limit=2, startPeriod=60, numberPhases=3 },
-                                               new ChargingSchedulePeriod()
-                                             { limit=8, startPeriod=120, numberPhases=3 }
-                                        }
-                        }
-                    }
-                };
 
-                WritetoDB(uuid, request);
+                WritetoDB(uuid, csProfile);
                 uxMsgTb.Text = string.Format("UUID:{0}", uuid);
             }
             catch (Exception ex)
@@ -347,7 +362,7 @@ namespace TestTool.RemoteTriggerAPP
             }
         }
 
-        private void GetDiagnostics()
+        private void GetDiagnostics(bool ftp)
         {
             try
             {
@@ -356,7 +371,7 @@ namespace TestTool.RemoteTriggerAPP
                 var request = new GetDiagnosticsRequest()
                 {
 
-                    location = new Uri("ftp://phihong:y42j%2f4cj84@test.evsocket.phihong.com.cn/"),
+                    location = new Uri(ftp ? "ftp://evseocpp:evseocpp@test.evsocket.phihong.com.cn/" : "http://test.evsocket.phihong.com.cn:9003/api/file/"),
                     retries = 1,
                     retryInterval = 30,
                     startTime = DateTime.Now.AddHours(-1).ToUniversalTime(),
@@ -407,20 +422,60 @@ namespace TestTool.RemoteTriggerAPP
                     listVersion = Convert.ToInt32(DateTime.Now.ToUniversalTime().ToString("yyMMddHHmm")),
                     updateType = isFull ? UpdateType.Full : UpdateType.Differential,
                     localAuthorizationList = new List<AuthorizationData>()
+                    //localAuthorizationList = new List<AuthorizationData>()
+                    //{
+                    //     new AuthorizationData()
+                    //     {
+
+                    //          idTagInfo=new IdTagInfo(){  expiryDate=DateTime.Now.ToUniversalTime().AddDays(3), status=  AuthorizationStatus.Accepted},
+                    //           idTag="F5902677"
+                    //     }, new AuthorizationData()
+                    //     {
+                    //          idTagInfo=new IdTagInfo(){  expiryDate=DateTime.Now.ToUniversalTime().AddDays(3), status=  AuthorizationStatus.Expired},
+                    //           idTag="772690F5"
+                    //     }
+                    //}
+
+                };
+
+                request.localAuthorizationList.Add(new AuthorizationData()
+                {
+                    idTag="F5902677",
+                    idTagInfo = new IdTagInfo()
                     {
-                         new AuthorizationData()
-                         {
-
-                              idTagInfo=new IdTagInfo(){  expiryDate=DateTime.Now.ToUniversalTime().AddDays(3), status=  AuthorizationStatus.Accepted},
-                               idTag="123"
-                         }, new AuthorizationData()
-                         {
-                              idTagInfo=new IdTagInfo(){  expiryDate=DateTime.Now.ToUniversalTime().AddDays(3), status=  AuthorizationStatus.Expired},
-                               idTag="456"
-                         }
+                        parentIdTag = "0000000000000000001",
+                        expiryDate = DateTime.UtcNow.AddMonths(1),
+                        status = AuthorizationStatus.ConcurrentTx
                     }
+                });
+
+                request.localAuthorizationList.Add(new AuthorizationData()
+                {
+                    idTag = "772690F5",
+                    idTagInfo = new IdTagInfo()
+                    {
+                        parentIdTag = "0000000000000000001",
+                        expiryDate = DateTime.UtcNow.AddMonths(1),
+                        status = AuthorizationStatus.Accepted
+                    }
+                });
+
+                for (int i = 0; i < 23; i++)
+                {
+                    request.localAuthorizationList.Add(new AuthorizationData()
+                    {
+                        idTag = DateTime.Now.ToString("yyyyMMddHHmmss" + i.ToString("00000")),
+                        idTagInfo = new IdTagInfo()
+                        {
+                            parentIdTag = "0000000000000000001",
+                            expiryDate = DateTime.UtcNow.AddMonths(1),
+                            status = AuthorizationStatus.Accepted
+                        }
+
+                    });
+
+                }
 
-                };
 
                 WritetoDB(uuid, request);
                 uxMsgTb.Text = string.Format("UUID:{0}", uuid);
@@ -456,7 +511,7 @@ namespace TestTool.RemoteTriggerAPP
         private void SetGetConfiguration()
         {
             try
-            {           
+            {
                 string uuid = Guid.NewGuid().ToString();
                 var request = new GetConfigurationRequest()
                 {
@@ -481,7 +536,7 @@ namespace TestTool.RemoteTriggerAPP
         }
 
 
-        private void SetRemoteStartTransaction(bool hasProfile = false)
+        private void SetRemoteStartTransaction(SetChargingProfileRequest csProfile = null)
         {
             try
             {
@@ -492,32 +547,9 @@ namespace TestTool.RemoteTriggerAPP
                     idTag = uxIdTagTb.Text
 
                 };
-                if (hasProfile)
+                if (csProfile != null)
                 {
-                    request.chargingProfile = new csChargingProfiles()
-                    {
-                        chargingProfileId = Convert.ToInt32(DateTime.Now.ToUniversalTime().ToString("yyMMddHHmm")),
-                        chargingProfileKind = ChargingProfileKindType.Absolute,
-                        chargingProfilePurpose = ChargingProfilePurposeType.TxProfile,
-                        recurrencyKind = RecurrencyKindType.Daily,
-                        stackLevel = 1,
-                        chargingSchedule = new ChargingSchedule()
-                        {
-                            chargingRateUnit = ChargingRateUnitType.A,
-                            duration = 300,
-                            minChargingRate = 0,
-                            startSchedule = DateTime.Now.ToUniversalTime().Date,
-                            chargingSchedulePeriod = new List<ChargingSchedulePeriod>()
-                                        {
-                                             new ChargingSchedulePeriod()
-                                             { limit=10, startPeriod=0, numberPhases=3 },
-                                              new ChargingSchedulePeriod()
-                                             { limit=2, startPeriod=60, numberPhases=3 },
-                                               new ChargingSchedulePeriod()
-                                             { limit=8, startPeriod=120, numberPhases=3 }
-                                        }
-                        }
-                    };
+                    request.chargingProfile = csProfile.csChargingProfiles;
                 }
 
                 WritetoDB(uuid, request);
@@ -759,6 +791,8 @@ namespace TestTool.RemoteTriggerAPP
             }
         }
 
+
+
         private void uxUploadBtn_Click(object sender, RoutedEventArgs e)
         {
             if (string.IsNullOrEmpty(uxUploadFileTb.Text))
@@ -798,7 +832,6 @@ namespace TestTool.RemoteTriggerAPP
             ufObj.FileUrl = new Uri(Properties.Settings.Default.FilePreUrl + ufObj.FilePath.Replace("~/", "")).ToString();
             ufObj.IsOnline = true;
 
-
             using (var db = new MainDBContext())
             {
                 db.UploadFile.Add(ufObj);
@@ -814,15 +847,55 @@ namespace TestTool.RemoteTriggerAPP
                 db.SaveChanges();
             }
 
-            FTPClient UploadClient = new FTPClient(@"ftp://test.evsocket.phihong.com.cn", "testocpp", "testocpp");
-            bool uploadResult = UploadClient.FtpUploadBroken(uxUploadFileTb.Text, @"ftp://test.evsocket.phihong.com.cn/" + ufObj.FileName);
+            string filePath = uxUploadFileTb.Text;
+            uxMsgTb.Text = "Uploading........";
+
+            Task.Run(async () =>
+            {
+                await UploadTask(filePath, ufObj.FileName);
+            });
+
+
+
+
+
+
+
+
+
+
+        }
+
+        private async Task UploadTask(string filePath, string fileName)
+        {
+
+            bool uploadResult = UploadClient.FtpUploadBroken(filePath, @"ftp://test.evsocket.phihong.com.cn/" + fileName);
+
+            await Dispatcher.BeginInvoke(new Action(() =>
+            {
+                if (uploadResult)
+                {
+                    uxMsgTb.Text = "Current Progress :100 %";
+                    Thread.CurrentThread.Join(100);
+                }
+                uxMsgTb.Text = "Upload File Result :" + (uploadResult ? "Success" : "Fail");
+
+
+            }));
 
 
 
-            uxMsgTb.Text = "Upload File Result :" + (uploadResult ? "Success" : "Fail");
 
         }
 
+        private void UploadClient_OnUploadProgress(double percent)
+        {
+            Dispatcher.BeginInvoke(new Action(() =>
+            {
+                uxMsgTb.Text = "Current Progress :" + (int)percent + " %";
+
+            }));
+        }
 
         private void uxFTPUploadBtn_Click(object sender, RoutedEventArgs e)
         {
@@ -879,12 +952,17 @@ namespace TestTool.RemoteTriggerAPP
                 db.SaveChanges();
             }
 
-            FTPClient UploadClient = new FTPClient(@"ftp://test.evsocket.phihong.com.cn", "testocpp", "testocpp");
-            bool uploadResult = UploadClient.FtpUploadBroken(uxUploadFileTb.Text, @"ftp://test.evsocket.phihong.com.cn/" + ufObj.FileName);
 
 
+            string filePath = uxUploadFileTb.Text;
+            uxMsgTb.Text = "Uploading........";
+
+            Task.Run(async () =>
+            {
+                await UploadTask(filePath, ufObj.FileName);
+            });
+
 
-            uxMsgTb.Text = "Upload File Result :" + (uploadResult ? "Success" : "Fail");
         }
 
 

+ 36 - 0
TestTool.RemoteTriggerAPP/chargingProfile.json

@@ -0,0 +1,36 @@
+{
+  "connectorId": 1,
+  "csChargingProfiles": {
+    "chargingProfileId": 2003030239,
+    "transactionId": null,
+    "stackLevel": 1,
+    "chargingProfilePurpose": "TxDefaultProfile",
+    "chargingProfileKind": "Absolute",
+    "recurrencyKind": "Daily",
+    "validFrom": null,
+    "validTo": null,
+    "chargingSchedule": {
+      "duration": 300,
+      "startSchedule": "2020-03-03T00:00:00.000Z",
+      "chargingRateUnit": "A",
+      "chargingSchedulePeriod": [
+        {
+          "startPeriod": 0,
+          "limit": 10.0,
+          "numberPhases": 3
+        },
+        {
+          "startPeriod": 60,
+          "limit": 2.0,
+          "numberPhases": 3
+        },
+        {
+          "startPeriod": 120,
+          "limit": 8.0,
+          "numberPhases": 3
+        }
+      ],
+      "minChargingRate": 0.0
+    }
+  }
+}