private void FingerprintClient_OnTouch(FingerPrintClient client, iClockEventArg evt)
 {
     try {
         using (var context = new WorkflowContext()) {
             var entity = new Domain.Entities.Queue.FingerPrint();
             entity.AttState     = evt.AttState;
             entity.EnrolmentNo  = evt.EnrollNumber;
             entity.IP           = evt.IP;
             entity.MachineNo    = evt.MachineNo;
             entity.IsInvalid    = evt.IsInValid;
             entity.MachineDate  = evt.CreatedDate;
             entity.Port         = evt.Port;
             entity.Status       = "NOT_QUEUE";
             entity.VerifyMethod = evt.VerifyMethod;
             entity.WorkCode     = evt.WorkCode;
             context.FingerPrints.Add(entity);
             if (context.ChangeTracker.HasChanges())
             {
                 context.SaveChanges();
             }
             SendToRabbitMQ(MessageCommandEnum.PUSH, entity.Id.ToString());
         }
     } catch (Exception ex) {
         logger.Error(ex.Message, ex);
     }
 }
 private void SendError(FingerPrintClient client)
 {
     try {
         string        email      = ConfigurationManager.AppSettings["Email"] != null ? ConfigurationManager.AppSettings["Email"] : "*****@*****.**";
         string        password   = ConfigurationManager.AppSettings["Password"] != null ? ConfigurationManager.AppSettings["Password"] : "******";
         string        reciepent  = ConfigurationManager.AppSettings["Reciepent"] != null ? ConfigurationManager.AppSettings["Reciepent"] : "*****@*****.**";
         List <string> reciepents = new List <string>();
         if (reciepent.Split(',').Count() > 1)
         {
             var emails = reciepent.Split(',');
             foreach (string item in emails)
             {
                 reciepents.Add(item);
             }
         }
         else
         {
             reciepents.Add(reciepent);
         }
         var    userInfo     = UserInfo.CreateUserData(email, password, ExchangeVersion.Exchange2013);
         var    emailService = new EmailService(userInfo);
         string message      = string.Format("{0} network connection was losted please try to ping the Fingerprint IP: {1} if it is still problem, please contact to Programming Teams. <br/><br/>Note: Fingerprint is going to reconnect if network connection work properly.", client, client.IP);
         emailService.SendEmail("iClock Queue Service Alert", GetEmailContent(message), reciepents);
     } catch (Exception e) {
         logger.Error(e.Message, e);
     }
 }
 public void Startup()
 {
     using (var dbContext = new WorkflowContext()) {
         try {
             var fingerPrintMachines = dbContext.FingerPrintMachines.Where(p => p.Active).ToList();
             if (fingerPrintMachines.Count > 0)
             {
                 fingerPrintMachines.ForEach(entity => {
                     ConnectionConfig config = new ConnectionConfig()
                     {
                         IP            = entity.IP,
                         Port          = entity.Port,
                         MachineNumber = entity.MachineNo,
                         Status        = entity.Status
                     };
                     IFingerPrintClient client = new FingerPrintClient(config);
                     client.OnTouch           += FingerprintClient_OnTouch;
                     fingerPrintClients.Add(client);
                 });
             }
         } catch (Exception ex) {
             logger.Error(ex.Message, ex);
         }
     }
 }
 public void Start()
 {
     fingerPrintClients.ForEach(c => {
         try {
             c.Connect(true, (iclock, connected) => {
                 if (connected)
                 {
                     FingerPrintClient client = c as FingerPrintClient;
                     logger.InfoFormat("{0} connected", c.ToString());
                     SendToRabbitMQ(MessageCommandEnum.CONNECT, client.IP);
                 }
                 return(true);
             });
         } catch (Exception ex) {
             logger.Error(ex.Message, ex);
         }
     });
 }
 public void PingFingerPrintConnection()
 {
     try {
         if (fingerPrintClients != null && fingerPrintClients.Count > 0)
         {
             fingerPrintClients.ForEach(c => {
                 FingerPrintClient client = c as FingerPrintClient;
                 bool isConnected         = client.IsNetConnected();
                 if (!isConnected && client.IsConnected == true)
                 {
                     logger.ErrorFormat("{0} not reply", client.ToString());
                     client.RetryConnect();
                     SendToRabbitMQ(MessageCommandEnum.CONNECTION_ERROR, client.IP);
                     SendError(client);
                 }
             });
         }
     } catch (Exception ex) {
         logger.Error(ex.Message, ex);
     }
 }