internal Card(int cardNo, string punchesstr, int readId, int id, List <int> _postes) { _cardNo = cardNo; _punches = new Punches(punchesstr, _postes); _readId = readId; _id = id; }
internal bool sendCard(int cardNumber, Punches punches, int zeroTime) { var ms = new MemoryStream(); var bw = new BinaryWriter(ms); bw.Write((byte)64); // type 0=> cardnumber bw.Write((short)punches.PunchesInfo.Count); // la taille bw.Write((int)cardNumber); bw.Write((int)0); //codeday obsolete bw.Write((int)0); foreach (int[] p in punches.PunchesInfo) { int codeNumber = (int)p[0]; int codeTime = (int)(p[1] + zeroTime) * 10; bw.Write((int)codeNumber); bw.Write((int)codeTime); } byte[] barray = ms.ToArray(); bool b = tempSocket.Connected; if (b) { tempSocket.Send(barray, barray.Length, 0); } return(b); }
private void senderBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { while (!senderBackgroundWorker.CancellationPending) { object[] oo; if (_actionToDo.TryDequeue(out oo)) { try { // just do it actionType _action = (actionType)oo[0]; switch (_action) { case actionType.eCard: { // récupération des paramètres int cardno = (int)oo[1]; Punches p = oo[2] as Punches; int zt = (int)oo[3]; string info = oo[4] as string; // petite attente Thread.Sleep(1000 * finishToReadOut_base + _rand.Next(1000 * finishToReadOut_random)); // et envoi des données if (_sender != null) { _sender.sendCard(cardno, p, zt); } // notification qu'il y a eu une action senderBackgroundWorker.ReportProgress(0, info); } break; case actionType.ePunch: { // récupération des paramètres int poste = (int)oo[1]; int cardno = (int)oo[2]; int timeCode = (int)oo[3]; string info = oo[4] as string; // petite attente Thread.Sleep(1000 * radioTransmitTime_base + _rand.Next(1000 * radioTransmitTime_random)); // et envoi des données if (_sender != null) { _sender.sendPunch(poste, cardno, timeCode); } // notification qu'il y a eu une action senderBackgroundWorker.ReportProgress(0, info); } break; } } catch (Exception ex) { senderBackgroundWorker.ReportProgress(0, ex.Message); } } else { Thread.Sleep(500); } } }