public Main() { InitializeComponent(); // Check if another instance of ALK is running if (CommonUtil.CheckIfAnotherInstanceIsRunning("ALK")) { MessageBox.Show("An instance of ALK is already running.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } APIUtils.Start(); //Notification Trinity.SignalR.Client signalrClient = Trinity.SignalR.Client.Instance; // setup variables _smartCardFailed = 0; _fingerprintFailed = 0; _displayLoginButtonStatus = false; _popupModel = new Trinity.BE.PopupModel(); #region Initialize and register events double _sessionTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["session_timeout"]); if (_sessionTimeout > 0) { this._timerCheckLogout = new System.Timers.Timer(); this._timerCheckLogout.AutoReset = true; this._timerCheckLogout.Interval = _sessionTimeout * 1000; this._timerCheckLogout.Elapsed += TimeCheckLogout_EventHandler; } // _jsCallCS _jsCallCS = new JSCallCS(this.LayerWeb, this); _jsCallCS.OnNRICFailed += JSCallCS_OnNRICFailed; _jsCallCS.OnShowMessage += JSCallCS_ShowMessage; _jsCallCS.OnLogOutCompleted += JSCallCS_OnLogOutCompleted; // SmartCard SmartCard.Instance.GetCardInfoSucceeded += GetCardInfoSucceeded; // Fingerprint Fingerprint.Instance.OnIdentificationCompleted += Fingerprint_OnIdentificationCompleted; Fingerprint.Instance.OnDeviceDisconnected += Fingerprint_OnDeviceDisconnected; // NRIC _nric = CodeBehind.Authentication.NRIC.GetInstance(LayerWeb); _nric.OnNRICSucceeded += NRIC_OnNRICSucceeded; _nric.OnShowMessage += OnShowMessage; // Supervisee _superviseeParticulars = new CodeBehind.SuperviseeParticulars(LayerWeb, _jsCallCS, this); _eventCenter = EventCenter.Default; _eventCenter.OnNewEvent += EventCenter_OnNewEvent; #endregion Lib.LayerWeb = LayerWeb; LayerWeb.Url = new Uri(String.Format("file:///{0}/View/html/Layout.html", CSCallJS.curDir)); LayerWeb.ObjectForScripting = _jsCallCS; }
public JSCallCS(WebBrowser web) { this._web = web; _thisType = this.GetType(); _printMUBAndTTLabel = new CodeBehind.PrintMUBAndTTLabels(this); _printMUBAndTTLabel.OnPrintMUBLabelsSucceeded += PrintMUBLabels_OnPrintMUBLabelSucceeded; _printMUBAndTTLabel.OnPrintMUBLabelsFailed += PrintMUBLabels_OnPrintMUBLabelFailed; _printMUBAndTTLabel.OnPrintTTLabelsSucceeded += PrintTTLabels_OnPrintTTLabelSucceeded; _printMUBAndTTLabel.OnPrintTTLabelsFailed += PrintTTLabels_OnPrintTTLabelFailed; _printMUBAndTTLabel.OnPrintMUBAndTTLabelsException += PrintMUBAndTTLabels_OnPrintTTLabelException; _popupModel = new Trinity.BE.PopupModel(); }
private void Main_OnFacialRecognitionFailed() { Session session = Session.Instance; if (!session.IsFacialAuthenticated) { FacialRecognition.Instance.OnFacialRecognitionFailed -= Main_OnFacialRecognitionFailed; FacialRecognition.Instance.OnFacialRecognitionSucceeded -= Main_OnFacialRecognitionSucceeded; FacialRecognition.Instance.OnFacialRecognitionProcessing -= Main_OnFacialRecognitionProcessing; FacialRecognition.Instance.OnCameraInitialized -= Main_OnCameraInitialized; this.Invoke((MethodInvoker)(() => { FacialRecognition.Instance.Dispose(); })); Trinity.BE.User user = (Trinity.BE.User)session[CommonConstants.USER_LOGIN]; string errorMessage = "User '" + user.Name + "' cannot complete facial authentication"; Trinity.SignalR.Client.Instance.SendToAppDutyOfficers(user.UserId, "Facial authentication failed", errorMessage, EnumNotificationTypes.Error); // show message box to user //MessageBox.Show("Facial authentication failed", "Facial Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error); Trinity.BE.PopupModel popupModel = new Trinity.BE.PopupModel(); popupModel.Title = "Authorization Failed"; popupModel.Message = "Facial Recognition failed.\nPlease report to the Duty Officer"; popupModel.IsShowLoading = false; popupModel.IsShowOK = true; LayerWeb.InvokeScript("showPopupModal", JsonConvert.SerializeObject(popupModel)); // navigate to smartcard login page NavigateTo(NavigatorEnums.Authentication_SmartCard); // reset counter _fingerprintFailed = 0; } try { StackTrace trace = new StackTrace(); int caller = 1; StackFrame frame = trace.GetFrame(caller); string callerName = frame.GetMethod().Name; LogManager.Debug("Main_OnFacialRecognitionFailed: " + callerName); } catch (Exception) { } }
private void _NavigateToFormThread(object pram) { NavigatorEnums navigatorEnum = (NavigatorEnums)pram; // navigate if (navigatorEnum == NavigatorEnums.Authentication_SmartCard) { LayerWeb.LoadPageHtml("Authentication/SmartCard.html"); LayerWeb.RunScript("$('.status-text').css('color','#000').text('Please place your smart card on the reader.');"); SmartCard.Instance.Start(); } else if (navigatorEnum == NavigatorEnums.Authentication_Fingerprint) { Session session = Session.Instance; Trinity.BE.User user = (Trinity.BE.User)session[CommonConstants.USER_LOGIN]; LayerWeb.LoadPageHtml("Authentication/FingerPrint.html"); LayerWeb.RunScript("$('.status-text').css('color','#000').text('Please place your thumb print on the reader.');"); //if (user.LeftThumbFingerprint == null && user.RightThumbFingerprint == null) //{ // LayerWeb.RunScript("$('.status-text').css('color','#000').text('Please place your thumb print on the reader.');"); //} //else //{ // string errMsg = user.Name + "'s Fingerprint could not be found."; // LayerWeb.RunScript("$('.status-text').css('color','#000').text('" + errMsg + "');"); //} try { Fingerprint.Instance.Start(new System.Collections.Generic.List <byte[]>() { user.LeftThumbFingerprint, user.RightThumbFingerprint }); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (navigatorEnum == NavigatorEnums.Authentication_Facial) { Session session = Session.Instance; Trinity.BE.User user = (Trinity.BE.User)session[CommonConstants.USER_LOGIN]; if ((user.User_Photo1 == null || user.User_Photo1.Length == 0) && (user.User_Photo2 == null || user.User_Photo2.Length == 0)) { Trinity.BE.PopupModel popupModel = new Trinity.BE.PopupModel(); popupModel.Title = "Authorization Failed"; popupModel.Message = "User '" + user.Name + "' doesn't have any photos"; popupModel.IsShowLoading = false; popupModel.IsShowOK = true; LayerWeb.InvokeScript("showPopupModal", JsonConvert.SerializeObject(popupModel)); // navigate to smartcard login page NavigateTo(NavigatorEnums.Authentication_SmartCard); return; } LayerWeb.LoadPageHtml("Authentication/FacialRecognition.html"); LayerWeb.RunScript("$('.status-text').css('color','#000').text('Please remain still as Facial Recognition Check takes place.');"); FacialRecognition.Instance.OnFacialRecognitionFailed += Main_OnFacialRecognitionFailed; FacialRecognition.Instance.OnFacialRecognitionSucceeded += Main_OnFacialRecognitionSucceeded; FacialRecognition.Instance.OnFacialRecognitionProcessing += Main_OnFacialRecognitionProcessing; FacialRecognition.Instance.OnCameraInitialized += Main_OnCameraInitialized; this.Invoke((MethodInvoker)(() => { Point startLocation = new Point((Screen.PrimaryScreen.Bounds.Size.Width / 2) - 800 / 2, (Screen.PrimaryScreen.Bounds.Size.Height / 2) - 450 / 2); //Point startLocation = new Point((Screen.PrimaryScreen.Bounds.Size.Width / 2) - 400 / 2, (Screen.PrimaryScreen.Bounds.Size.Height / 2) - 400 / 2); try { FacialRecognition.Instance.StartFacialRecognition(startLocation, new System.Collections.Generic.List <byte[]>() { user.User_Photo1, user.User_Photo2 }); } catch (Exception ex) { MessageBox.Show(ex.Message); } })); } else if (navigatorEnum == NavigatorEnums.Authentication_NRIC) { _nric.Start(); } else if (navigatorEnum == NavigatorEnums.Supervisee_Particulars) { _superviseeParticulars.Start(); //btnConfirm.Enabled = true; } else if (navigatorEnum == NavigatorEnums.Supervisee_NRIC) { _superviseeParticulars.Start(); CSCallJS.DisplayNRICLogin(LayerWeb); } // set current page _currentPage = navigatorEnum; // display options in Authentication_SmartCard page if (_displayLoginButtonStatus && _currentPage == NavigatorEnums.Authentication_SmartCard) { _displayLoginButtonStatus = false; CSCallJS.DisplayLogoutButton(this.LayerWeb, _displayLoginButtonStatus); } // display options in the rest if (!_displayLoginButtonStatus && _currentPage != NavigatorEnums.Authentication_SmartCard) { _displayLoginButtonStatus = true; CSCallJS.DisplayLogoutButton(this.LayerWeb, _displayLoginButtonStatus); } }