static void Timer_Elapsed(object sender, ElapsedEventArgs e) { timer.Enabled = false; WriteDBMessage row = null; int rowsAdded = 0; uint number = 0; try { while ((row = ReadWriteFifo(Mode.READ, null)) != null) { switch (row.message) { case DATABASE_MESSAGE_TYPE.LOGIN: cmdLogin.Parameters["@Date"].Value = ((WriteDBMessageLogin)row).date; rowsAdded = cmdLogin.ExecuteNonQuery(); break; } } } catch (Exception ex) { //Console.WriteLine("Error : '{0}'", ex.Message); } timer.Enabled = true; }
static void Timer_Elapsed(object sender, ElapsedEventArgs e) { timer.Enabled = false; WriteDBMessage row = null; int rowsAdded = 0; uint number = 0; double lat = 0; string latStr = ""; double lon = 0; string longStr = ""; int degrees = 0; double minutes = 0; try { while ((row = ReadWriteFifo(Mode.READ, null)) != null) { switch (row.message) { case DATABASE_MESSAGE_TYPE.LOGIN: cmdLogin.Parameters["@TerminalID"].Value = ((WriteDBMessageLogin)row).IMEI; cmdLogin.Parameters["@Date"].Value = ((WriteDBMessageLogin)row).date; rowsAdded = cmdLogin.ExecuteNonQuery(); break; case DATABASE_MESSAGE_TYPE.LOCATION: cmdLocation.Parameters["@IMEI"].Value = ((WriteDBMessageLocation)row).IMEI; cmdLocation.Parameters["@TrackTime"].Value = ((WriteDBMessageLocation)row).trackTime; cmdLocation.Parameters["@currTime"].Value = ((WriteDBMessageLocation)row).currTime; number = BitConverter.ToUInt32(((WriteDBMessageLocation)row).longitude.Reverse().ToArray(), 0); lon = (180 * number) / 324000000.0; degrees = (int)lon; minutes = 60 * (lon - degrees); longStr = string.Format("{0}º{1}{2}", degrees, minutes, (((WriteDBMessageLocation)row).courseStatus[0] & 0x08) == 0 ? "E" : "W"); cmdLocation.Parameters["@Longitude"].Value = longStr; number = BitConverter.ToUInt32(((WriteDBMessageLocation)row).lattitude.Reverse().ToArray(), 0); lat = (90 * number) / 162000000.0; degrees = (int)lat; minutes = 60 * (lat - degrees); latStr = string.Format("{0}º{1}{2}", degrees, minutes, (((WriteDBMessageLocation)row).courseStatus[0] & 0x04) == 0 ? "S" : "N"); cmdLocation.Parameters["@Lattitude"].Value = latStr; cmdLocation.Parameters["@speed"].Value = ((WriteDBMessageLocation)row).speed; locationMessage.IMEI = byteState.Value.IMEI; rowsAdded = cmdLocation.ExecuteNonQuery(); break; } } } catch (Exception ex) { //Console.WriteLine("Error : '{0}'", ex.Message); } timer.Enabled = true; }
public static WriteDBMessage ReadWriteFifo(Mode mode, WriteDBMessage message) { Object thisLock2 = new Object(); lock (thisLock2) { switch (mode) { case Mode.READ: if (fifo.Count > 0) { message = fifo[0]; fifo.RemoveAt(0); } break; case Mode.WRITE: fifo.Add(message); break; } } return message; }