コード例 #1
0
        /// <summary>
        /// Là bản tin Front End gửi khi muốn thực hiện trừ tiền luôn tài khoản xe qua trạm
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public Task <ChargeResponseBody> ChargeAsync(ChargeRequestBody body)
        {
            var req = new Base <ChargeRequestBody>
            {
                Length  = 48,
                Command = Command.ChargeRequest,
                Body    = body
            };

            return(SendAsync <ChargeResponseBody>(req));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: toanpv12345/working_ext
        public async Task RunAsync()
        {
            try
            {
                //anh de interval =3 :)
                //client port 25
                string encriptKey = "FC9DC415668CF44B";
                string serverIP   = "192.168.70.56";
                string account    = "vetc";
                string pwd        = "vetc@123";
                int    station    = 460;
                int    serverPort = 2699;

                var p  = new APIClient("10.6.4.22", 25, 30, encriptKey, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
                var re = await p.ConnectAsync(serverIP, serverPort, new ConnectRequestBody(account, pwd, station));

                Console.WriteLine(re?.Status);

                var charge = new ChargeRequestBody("AF001", station, 1);
                var re3    = await p.CheckinAsync(charge);

                Console.WriteLine(re3?.Status);

                var transaction = new TransactionRequestBody("AF001", 1, 2, re3.TicketId, PlateStatus.Match, re3.Plate, 1);
                var re4         = await p.CommitAsync(transaction);

                Console.WriteLine(re4?.Status);

                //var re2 = await p.ChargeAsync(charge);
                //Console.WriteLine(re2.Status);
                //var re5 = await p.RollbackAsync(transaction);
                //var re6 = await p.TerminateAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine($"{e.Message}\n{e.StackTrace}");
            }
            Console.Write("done");
            Console.ReadLine();
        }
コード例 #3
0
        // Main work of thread
        public async void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            try
            {
                // Create new connection
                byte[] byIVArray = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                var p = new APIClient(IPAdd, Port, Timeout, EncryptAES, byIVArray);

                // Loop for repeat
                for (round = 0; round < Loop; round++)
                {
                    // Loop for all step
                    for (int i = 0; i < listScenario.Count; i++)
                    {
                        switch (listScenario[i])
                        {
                            case "CONNECT":
                                // Get command parameter
                                int stationID = ComFunc.StringToInt32(objSettingConfig.allItems["CONNECTStation"]);
                                string serverIP = objSettingConfig.allItems["SocketServerIP"];
                                int serverPort = ComFunc.StringToInt32(objSettingConfig.allItems["SocketServerPort"]);
                                // Create command
                                ReportProgress("CONNECT to server ...");
                                var connectReq = new ConnectRequestBody(User, Pass, stationID);
                                // Send and Wait response
                                var re = await p.ConnectAsync(serverIP, serverPort, connectReq);
                                // Report status
                                ReportProgress("CONNECT result: " + re?.Status.ToString());
                                break;
                            case "SHAKE":
                                // Get command parameter
                                // Send command to server and wait response
                                ReportProgress("Send SHAKE to server ...");
                                var re2 = await p.ShakeAsync();
                                // Report status
                                ReportProgress("SHAKE result: " + re2?.Status.ToString());
                                break;
                            case "TERMINATE":
                                // Get command parameter
                                // Send command to server and Wait response
                                ReportProgress("Send TERMINATE to server ...");
                                var re3 = await p.TerminateAsync();
                                // Report status
                                ReportProgress("TERMINATE result: " + re3?.Status.ToString());
                                break;
                            case "CHECKIN":
                                // Get command parameter
                                string eTagCHECKIN = objSettingConfig.allItems["CHECKINEtag"];
                                int stationCHECKIN = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINStation"]);
                                int laneCHECKIN = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINLane"]);
                                // Send command to server and Wait response
                                ReportProgress("Send CHECKIN to server ...");
                                var checkin = new ChargeRequestBody(eTagCHECKIN, stationCHECKIN, laneCHECKIN);
                                var re4 = await p.CheckinAsync(checkin);
                                // Report status
                                ReportProgress("CHECKIN result: " + re4?.Status.ToString());
                                PlateRes = re4.Plate;
                                TicketRes = re4.TicketId;
                                break;
                            case "COMMIT":
                                // Get command parameter
                                string eTagCOMMIT = objSettingConfig.allItems["COMMITEtag"];
                                int stationCOMMIT = ComFunc.StringToInt32(objSettingConfig.allItems["COMMITStation"]);
                                int laneCOMMIT = ComFunc.StringToInt32(objSettingConfig.allItems["COMMITLane"]);
                                int imageCOMMIT = ComFunc.StringToInt32(objSettingConfig.allItems["COMMITImageCount"]);
                                // Send command to serve rand wait response
                                ReportProgress("Send COMMIT to server ...");
                                var transaction = new TransactionRequestBody(eTagCOMMIT, stationCOMMIT, laneCOMMIT, TicketRes, PlateStatus.Match, PlateRes, imageCOMMIT);
                                var re5 = await p.CommitAsync(transaction);
                                // Report status
                                ReportProgress("COMMIT result: " + re5?.Status.ToString());
                                break;
                            case "ROLLBACK":
                                // Get command parameter
                                string eTagROLLBACK = objSettingConfig.allItems["ROLLBACKEtag"];
                                int stationROLLBACK = ComFunc.StringToInt32(objSettingConfig.allItems["ROLLBACKStation"]);
                                int laneROLLBACK = ComFunc.StringToInt32(objSettingConfig.allItems["ROLLBACKLane"]);
                                int imageROLLBACK = ComFunc.StringToInt32(objSettingConfig.allItems["ROLLBACKImageCount"]);
                                // Send command to serve rand wait response
                                ReportProgress("Send ROLLBACK to server ...");
                                var rollback = new TransactionRequestBody(eTagROLLBACK, stationROLLBACK, laneROLLBACK, TicketRes, PlateStatus.Match, PlateRes, imageROLLBACK);
                                var re6 = await p.RollbackAsync(rollback);
                                // Report status
                                ReportProgress("ROLLBACK result: " + re6?.Status.ToString());
                                break;
                            case "CHARGE":
                                // Get command parameter
                                string eTagCHARGE = objSettingConfig.allItems["CHARGEEtag"];
                                int stationCHARGE = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINStation"]);
                                int laneCHARGE = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINLane"]);
                                // Send command to server and Wait response
                                ReportProgress("Send CHARGE to server ...");
                                var charge_req = new ChargeRequestBody(eTagCHARGE, stationCHARGE, laneCHARGE);
                                var re7 = await p.ChargeAsync(charge_req);
                                // Report status
                                break;
                            default:
                                ReportProgress("Error = Wrong Command");
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Report Error
                ReportProgress("Error = " + ex.Message);
            }

            // Report progress: complete
            ReportProgress("COMPLETED !");
        }
コード例 #4
0
        // Main work of thread
        public async void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            try
            {
                // Create new connection
                byte[] byIVArray = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                var    p         = new APIClient(IPAdd, Port, Timeout, EncryptAES, byIVArray);

                // Loop for repeat
                for (round = 0; round < Loop; round++)
                {
                    // Loop for all step
                    for (int i = 0; i < listScenario.Count; i++)
                    {
                        switch (listScenario[i])
                        {
                        case "CONNECT":
                            // Get command parameter
                            int    stationID  = ComFunc.StringToInt32(objSettingConfig.allItems["CONNECTStation"]);
                            string serverIP   = objSettingConfig.allItems["SocketServerIP"];
                            int    serverPort = ComFunc.StringToInt32(objSettingConfig.allItems["SocketServerPort"]);
                            // Create command
                            ReportProgress("CONNECT to server ...");
                            var connectReq = new ConnectRequestBody(User, Pass, stationID);
                            // Send and Wait response
                            var re = await p.ConnectAsync(serverIP, serverPort, connectReq);

                            // Report status
                            ReportProgress("CONNECT result: " + re?.Status.ToString());
                            break;

                        case "SHAKE":
                            // Get command parameter
                            // Send command to server and wait response
                            ReportProgress("Send SHAKE to server ...");
                            var re2 = await p.ShakeAsync();

                            // Report status
                            ReportProgress("SHAKE result: " + re2?.Status.ToString());
                            break;

                        case "TERMINATE":
                            // Get command parameter
                            // Send command to server and Wait response
                            ReportProgress("Send TERMINATE to server ...");
                            var re3 = await p.TerminateAsync();

                            // Report status
                            ReportProgress("TERMINATE result: " + re3?.Status.ToString());
                            break;

                        case "CHECKIN":
                            // Get command parameter
                            string eTagCHECKIN    = objSettingConfig.allItems["CHECKINEtag"];
                            int    stationCHECKIN = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINStation"]);
                            int    laneCHECKIN    = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINLane"]);
                            // Send command to server and Wait response
                            ReportProgress("Send CHECKIN to server ...");
                            var checkin = new ChargeRequestBody(eTagCHECKIN, stationCHECKIN, laneCHECKIN);
                            var re4     = await p.CheckinAsync(checkin);

                            // Report status
                            ReportProgress("CHECKIN result: " + re4?.Status.ToString());
                            PlateRes  = re4.Plate;
                            TicketRes = re4.TicketId;
                            break;

                        case "COMMIT":
                            // Get command parameter
                            string eTagCOMMIT    = objSettingConfig.allItems["COMMITEtag"];
                            int    stationCOMMIT = ComFunc.StringToInt32(objSettingConfig.allItems["COMMITStation"]);
                            int    laneCOMMIT    = ComFunc.StringToInt32(objSettingConfig.allItems["COMMITLane"]);
                            int    imageCOMMIT   = ComFunc.StringToInt32(objSettingConfig.allItems["COMMITImageCount"]);
                            // Send command to serve rand wait response
                            ReportProgress("Send COMMIT to server ...");
                            var transaction = new TransactionRequestBody(eTagCOMMIT, stationCOMMIT, laneCOMMIT, TicketRes, PlateStatus.Match, PlateRes, imageCOMMIT);
                            var re5         = await p.CommitAsync(transaction);

                            // Report status
                            ReportProgress("COMMIT result: " + re5?.Status.ToString());
                            break;

                        case "ROLLBACK":
                            // Get command parameter
                            string eTagROLLBACK    = objSettingConfig.allItems["ROLLBACKEtag"];
                            int    stationROLLBACK = ComFunc.StringToInt32(objSettingConfig.allItems["ROLLBACKStation"]);
                            int    laneROLLBACK    = ComFunc.StringToInt32(objSettingConfig.allItems["ROLLBACKLane"]);
                            int    imageROLLBACK   = ComFunc.StringToInt32(objSettingConfig.allItems["ROLLBACKImageCount"]);
                            // Send command to serve rand wait response
                            ReportProgress("Send ROLLBACK to server ...");
                            var rollback = new TransactionRequestBody(eTagROLLBACK, stationROLLBACK, laneROLLBACK, TicketRes, PlateStatus.Match, PlateRes, imageROLLBACK);
                            var re6      = await p.RollbackAsync(rollback);

                            // Report status
                            ReportProgress("ROLLBACK result: " + re6?.Status.ToString());
                            break;

                        case "CHARGE":
                            // Get command parameter
                            string eTagCHARGE    = objSettingConfig.allItems["CHARGEEtag"];
                            int    stationCHARGE = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINStation"]);
                            int    laneCHARGE    = ComFunc.StringToInt32(objSettingConfig.allItems["CHECKINLane"]);
                            // Send command to server and Wait response
                            ReportProgress("Send CHARGE to server ...");
                            var charge_req = new ChargeRequestBody(eTagCHARGE, stationCHARGE, laneCHARGE);
                            var re7        = await p.ChargeAsync(charge_req);

                            // Report status
                            break;

                        default:
                            ReportProgress("Error = Wrong Command");
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Report Error
                ReportProgress("Error = " + ex.Message);
            }

            // Report progress: complete
            ReportProgress("COMPLETED !");
        }