Beispiel #1
0
        public void RedAsync()
        {
            string color   = ValidatorEnv.IsExit() ? ExitLightRed : EntryLightRed;
            int    timeout = _timeoutSec;
            string cmd     = "<commands>" +
                             "<command>" +
                             "<name>SetLED</name>" +
                             "<params>" +
                             "<param><key>" + color + "</key><value>on</value></param>" +
                             "<param><key>timeout</key><value>" + timeout * 1000 + "</value></param>" +
                             "</params>" +
                             "</command>" +
                             "</commands>";

            Net45Task.Run(() =>
            {
                HttpSync(cmd, gateUrl);
            });

            PlayErrorSongAsync();


            // TODO no need it for now
            //whenever a 'normal' command executed ,reset the 'long open/close' command
            //_toggleOpenCloseCommand.Reset();
            // TODO no need it for now
        }
Beispiel #2
0
        public void ListenNonBlockIO()
        {
            Net45Task.Run(() =>
            {
                if (!HttpListener.IsSupported)
                {
                    _log.Info("OS not support HTTP Listener");
                    return;
                }

                currentListener.Start();
                _log.Info("HTTP Listener started..");

                while (true)
                {
                    try
                    {
                        Listen();
                        Thread.Sleep(5000);
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex);
                    }
                }
            });
        }
        public void ListenNonBlock(int port)
        {
            Net45Task.Run(() =>
            {
                var done     = false;
                var listener = new UdpClient(port);
                var groupEP  = new IPEndPoint(IPAddress.Any, port);
                string received_data;
                byte[] receive_byte_array;

                _log.Error("############Service started###########");
                while (true)
                {
                    try
                    {
                        receive_byte_array = listener.Receive(ref groupEP);

                        received_data = Encoding.UTF8.GetString(receive_byte_array, 0, receive_byte_array.Length);

                        ParseJSONCommand(received_data);
                    }
                    catch (Exception e)
                    {
                        _log.Error(e);
                        Console.WriteLine(e.ToString());
                    }
                }
            });
        }
Beispiel #4
0
        public void ListenAsync()
        {
            Net45Task.Run(() =>
            {
                var done     = false;
                var listener = new UdpClient(ListeningPort);
                var groupEP  = new IPEndPoint(IPAddress.Any, ListeningPort);
                string received_data;
                byte[] receive_byte_array;

                _log.Error("############Service started###########");
                while (true)
                {
                    try
                    {
                        receive_byte_array = listener.Receive(ref groupEP);
                        received_data      = Encoding.UTF8.GetString(receive_byte_array, 0, receive_byte_array.Length);
                        //_log.Debug("############## CARD COMMAND  ####################");
                        //_log.Debug(received_data);
                        //_log.Debug("################ CARD COMMAND  ####################");

                        ParseCommand(received_data);
                    }
                    catch (Exception e)
                    {
                        _log.Error(e);
                    }
                }
            });
        }
Beispiel #5
0
 private void PlayErrorSongAsync()
 {
     Net45Task.Run(() =>
     {
         var simpleSound = new SoundPlayer(Properties.Resources.wrong1);
         simpleSound.Play();
     });
 }
Beispiel #6
0
 public void PlayOkSongAsync()
 {
     Net45Task.Run(() =>
     {
         SoundPlayer simpleSound = new SoundPlayer(Properties.Resources.correct1);
         simpleSound.Play();
     });
 }
Beispiel #7
0
        public void HeartbeatServiceNonBlockIO()
        {
            var baseUrl_wirecard = ValidatorEnv.DeviceControllerHeartbeatUrl;
            var interval         = ValidatorEnv.DeviceControllerHeartbeatIntervalSec;
            var baseUrl_pico     = ValidatorEnv.DeviceControllerPincodeHeartbeatUrl;

            Net45Task.Run(() =>
            {
                while (true)
                {
                    if (ValidatorEnv.IsExit())
                    {
                        try
                        {
                            var url = baseUrl_wirecard + "?status=" + ExitReader_Status.ToString().ToLowerInvariant()
                                      + "&type=A";
                            //_log.Debug("[Heartbeat Exit Reader] : " + url);
                            HttpSync("", url, "POST", false);
                        }
                        catch (Exception ex)
                        {
                            //_log.Error(ex);
                        }
                    }
                    else
                    {
                        try
                        {
                            var url = baseUrl_wirecard + "?status=" + EntryReader_Status.ToString().ToLowerInvariant()
                                      + "&type=B";
                            //_log.Debug("[Heartbeat Entry Reader] : " + url);
                            HttpSync("", url, "POST", false);
                        }
                        catch (Exception ex)
                        {
                            //_log.Error(ex);
                        }
                        try
                        {
                            var url = baseUrl_pico + "?status=" + PicoReader_Status.ToString().ToLowerInvariant();
                            //_log.Debug("[Heartbeat Pico Reader] : " + url);
                            HttpSync("", url, "POST", false);
                        }
                        catch (Exception ex)
                        {
                            //_log.Error(ex);
                        }
                    }

                    Thread.Sleep(1000 * interval);
                }
            });
        }
Beispiel #8
0
 public Task RunInTransactionAsync(Action <SQLiteAsyncConnection> action)
 {
     return(Net45Task.Run(() => {
         var conn = this.GetConnection();
         using (conn.Lock()) {
             conn.BeginTransaction();
             try {
                 action(this);
                 conn.Commit();
             }
             catch (Exception) {
                 conn.Rollback();
                 throw;
             }
         }
     }));
 }
 public void SendCommandAsync(string commandText, int sendingPort)
 {
     Net45Task.Run(() =>
     {
         try
         {
             var sending_socket    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             var sending_end_point = new IPEndPoint(IPAddress.Parse(LocalIP), sendingPort);
             var send_buffer       = Encoding.UTF8.GetBytes(commandText);
             sending_socket.SendTo(send_buffer, sending_end_point);
             // _log.Info("[Validator COMMAND Sender] : " + commandText);
         }
         catch (Exception ex)
         {
             _log.Error(ex);
         }
     });
 }
Beispiel #10
0
 public void SendCommandAsync(string xmlCmd)
 {
     Net45Task.Run(() =>
     {
         try
         {
             var sending_socket    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             var sending_end_point = new IPEndPoint(IPAddress.Parse(SendingIp), SendingPort);
             var send_buffer       = Encoding.UTF8.GetBytes(xmlCmd);
             sending_socket.SendTo(send_buffer, sending_end_point);
             _log.Info("[COMMAND SENT] : " + xmlCmd);
         }
         catch (Exception ex)
         {
             _log.Error(ex);
         }
     });
 }
Beispiel #11
0
        public void OffAllLights()
        {
            string cmd = "<commands>" +
                         "<command>" +
                         "<name>SetLED</name>" +
                         "<params>" +
                         "<param><key>" + ExitLightRed + "</key><value>off</value></param>" +
                         "<param><key>timeout</key><value>" + 1 * 1000 + "</value></param>" +
                         "</params>" +
                         "</command>" +
                         "<command>" +
                         "<name>SetLED</name>" +
                         "<params>" +
                         "<param><key>" + EntryLightRed + "</key><value>off</value></param>" +
                         "<param><key>timeout</key><value>" + 1 * 1000 + "</value></param>" +
                         "</params>" +
                         "</command>" +
                         "<command>" +
                         "<name>SetLED</name>" +
                         "<params>" +
                         "<param><key>" + ExitLightBlue + "</key><value>off</value></param>" +
                         "<param><key>timeout</key><value>" + 1 * 1000 + "</value></param>" +
                         "</params>" +
                         "</command>" +
                         "<command>" +
                         "<name>SetLED</name>" +
                         "<params>" +
                         "<param><key>" + EntryLightBlue + "</key><value>off</value></param>" +
                         "<param><key>timeout</key><value>" + 1 * 1000 + "</value></param>" +
                         "</params>" +
                         "</command>" +
                         "</commands>";

            Net45Task.Run(() =>
            {
                HttpSync(cmd, gateUrl);
            });
        }
Beispiel #12
0
        public void OpenAndGreenAsync()
        {
            if (ValidatorEnv.IsExit())
            {
                Net45Task.Run(() =>
                {
                    ExitAndGreenSync();
                    PlayOkSongAsync();
                });
                return;
            }

            int    timeout = _timeoutSec;
            string cmd     = "<commands>" +
                             "<command>" +
                             "<name>SetLED</name>" +
                             "<params>" +
                             "<param><key>" + Entry + "</key><value>on</value></param>" +
                             "<param><key>timeout</key><value>" + timeout * 1000 + "</value></param>" +
                             "</params>" +
                             "</command>" +
                             "<command>" +
                             "<name>SetLED</name>" +
                             "<params>" +
                             "<param><key>" + EntryLightBlue + "</key><value>on</value></param>" +
                             "<param><key>timeout</key><value>" + timeout * 1000 + "</value></param>" +
                             "</params>" +
                             "</command>" +
                             "</commands>";

            Net45Task.Run(() =>
            {
                HttpSync(cmd, gateUrl);
            });

            PlayOkSongAsync();
        }
Beispiel #13
0
        public void SerialPortListenAsync()
        {
            if (OnDataReceived == null)
            {
                throw new InvalidOperationException("must set callback [OnDataReceived] first.");
            }

            Net45Task.Run(() =>
            {
                logger.Info("Starting Open Virtual COM");

                var mySerialPort = new SerialPort(ValidatorEnv.COM_PORT);

                mySerialPort.BaudRate  = 115200;
                mySerialPort.Parity    = Parity.None;
                mySerialPort.StopBits  = StopBits.One;
                mySerialPort.DataBits  = 8;
                mySerialPort.Handshake = Handshake.None;
                mySerialPort.RtsEnable = true;
                mySerialPort.DtrEnable = true;

                mySerialPort.ReadTimeout = 500;

                mySerialPort.ErrorReceived += (sender, args) =>
                {
                    logger.Error("######error");
                    logger.Error(args.EventType);
                };

                // keep trying until open the com
                var failOpen = true;
                while (failOpen)
                {
                    try
                    {
                        mySerialPort.Open();
                        Thread.Sleep(1000);
                        failOpen = false;
                    }
                    catch
                    {
                        logger.Error("### COM OPEN FAILED ###  - TRYING AGAIN .");
                    }
                }

                logger.Info("####COM PORT opened...");
                while (true)
                {
                    try
                    {
                        string message = mySerialPort.ReadLine();

                        logger.Debug("################  COM LISTENER START  #############");
                        logger.Debug(message);
                        logger.Debug("################  COM LISTENER END  #############");

                        LastScanned = message;

                        ProgramIdleChecker.StubActivity();
                        if (!FrmScanning.SingleInstance.UpdateMsgWorker.Busy())
                        {
                            FrmScanning.SingleInstance.UpdateMsgWorker.RunAsync();
                        }
                        OnDataReceived(message);


                        Thread.Sleep(500);
                    }
                    catch (TimeoutException ex)
                    {
                        //COM is idle
                    }
                }
            });
        }