void Klient_ConnectionStatusNdyshoi(TCPKlient sender, TCPKlient.ConnectionStatus status) { //Check if this event was fired on a different thread, if it is then we must invoke it on the UI thread if (InvokeRequired) { Invoke(new TCPKlient.delConnectionStatusChanged(Klient_ConnectionStatusNdyshoi), sender, status); return; } lbRTLog.Items.Add(DateTime.Now + ": " + "Statusi TCP: " + status.ToString() + Environment.NewLine); }
void Klient_DataReceived(TCPKlient sender, object data) { //Kontrollo nese ka nevoje te invoked ne interface if (InvokeRequired) { try { Invoke(new TCPKlient.delDataReceived(Klient_DataReceived), sender, data); } catch { } return; } //Interpreto received data nga nodejs Server -> object as a string string strData = data as string; string strKliente = "Kliente"; string strKomanda = "komanda"; bool permbanKliente = strData.Contains(strKliente); bool permbanKomande = strData.Contains(strKomanda); if (permbanKliente) { //Degjo per Kliente Online klienteOnline.Text = ""; klienteOnline.Text += strData + Environment.NewLine; } else if (permbanKomande) { //Degjo per Komanda KomandaJSONInterface jsonNode = JsonConvert.DeserializeObject <KomandaJSONInterface>(strData); string komanda = jsonNode.komanda; string userId = jsonNode.attId; string emerIplote = jsonNode.emerIplote; string gishtId = jsonNode.gishtId; string privilegji = jsonNode.privilegji; string password = jsonNode.password; //lbRTLog.Items.Add(DateTime.Now + ": " + "Komandë nga WEB: " + jsonNode.komanda); if (komanda == "Hap_Skan_Finger") { skdHelper.sta_OnlineEnroll(lbRTLog, userId, gishtId, "1"); } if (komanda == "Reg_Perd") { skdHelper.sta_SetUserInfo(lbRTLog, userId, emerIplote, privilegji, password); } } //Shkruaj log dhe trego ne interface lbRTLog.Items.Add(DateTime.Now + ": " + strData + Environment.NewLine); }
private void BtnLidhuTCP_Click(object sender, EventArgs e) { string host = tbHost.Text.Trim(); string port = tbTCPPort.Text; string cfkHost = "Host:"; string cfgPort = "port:"; string[] cfgApiKeys = { cfkHost, cfgPort }; string[] cfgApiValues = { host, port.ToString() }; chkCfg.ShkruajTCPConfig(cfgApiKeys, cfgApiValues); //client.Connect(host, port); tcpKlient = new TCPKlient(IPAddress.Parse(host), int.Parse(port)); tcpKlient.Connect(); tcpKlient.DataReceived += new TCPKlient.delDataReceived(Klient_DataReceived); tcpKlient.ConnectionStatusChanged += new TCPKlient.delConnectionStatusChanged(Klient_ConnectionStatusNdyshoi); btnLidhuTCP.Enabled = false; tbHost.Enabled = false; tbTCPPort.Enabled = false; }
public TimeATT() { InitializeComponent(); #region Main_Load Cursor = Cursors.WaitCursor; skdHelper.sta_SetRTLogListBox(RealTimeEventListBox); Cursor = Cursors.Default; skdHelper.PergjigjePajisja += OnPergjigjePajisja; #endregion #region lidhu NET if (!chkCfg.GjejNetConfigFile()) { btnLidhu.Text = "Krijo Profil"; logHandler.PMLog(lbPMLog, "Per tu lidhur me pajisjen plotesoni NET"); } else { string[] vlerat = chkCfg.LexoNetCfg(); tbIp.Text = vlerat[0]; tbPort.Text = vlerat[1]; tbCommKey.Text = vlerat[2]; if (!chkCfg.VleresoIPv4(vlerat[0])) { logHandler.PMLog(lbPMLog, "Error *Kontrollo IP."); } else if (vlerat[1] == "" || Convert.ToInt32(vlerat[1]) <= 0 || Convert.ToInt32(vlerat[1]) > 65535) { logHandler.PMLog(lbPMLog, "Error *Porta e parregullt!"); } else if (vlerat[2] == "" || Convert.ToInt32(vlerat[2]) < 0 || Convert.ToInt32(vlerat[2]) > 999999) { logHandler.PMLog(lbPMLog, "Error *CommKey i parregullt!"); } else { int ret = skdHelper.sta_ConnectTCP(lbPMLog, tbIp.Text.Trim(), tbPort.Text.Trim(), tbCommKey.Text.Trim()); if (skdHelper.GetConnectState()) { skdHelper.sta_getBiometricType(); } if (ret == 1) { this.tbIp.ReadOnly = true; this.tbPort.ReadOnly = true; this.tbCommKey.ReadOnly = true; GetCapacityInfo(); GetDeviceInfo(); btnLidhu.Text = "Shkëput lidhjen"; btnLidhu.Refresh(); } else if (ret == -2) { btnLidhu.Text = "Lidhu"; btnLidhu.Refresh(); this.tbIp.ReadOnly = false; this.tbPort.ReadOnly = false; this.tbCommKey.ReadOnly = false; } } Cursor = Cursors.Default; } #endregion #region lidhu TCP if (chkCfg.GjejTCPConfigFile()) { string[] vlerat = chkCfg.LexoTCPCfg(); tbHost.Text = vlerat[0]; tbTCPPort.Text = vlerat[1]; tbHost.Enabled = false; tbTCPPort.Enabled = false; btnLidhuTCP.Enabled = false; tcpKlient = new TCPKlient(IPAddress.Parse(vlerat[0]), int.Parse(vlerat[1])); tcpKlient.Connect(); tcpKlient.DataReceived += new TCPKlient.delDataReceived(Klient_DataReceived); tcpKlient.ConnectionStatusChanged += new TCPKlient.delConnectionStatusChanged(Klient_ConnectionStatusNdyshoi); } //Initialize the events #endregion }