private void CheckForExistingSessionUser() { string userid = Data[0]; List <LockProcedure> instances = localSafe.Load(); LockProcedure found = null; foreach (LockProcedure lp in instances) { if (lp.UserID == userid) { found = lp; break; } } if (found != null) { string send = $"ACK_REQ_EXSISTING_SESSION_USER:{userid}/{found.StandID}/{found.DateTime.ToString("hh_mm_ss_dd_MM_yyyy")};"; SendMessageToSocket(send); } else { string send = $"NACK_REQ_EXISTING_SESSION_USER:{userid};"; SendMessageToSocket(send); } }
public bool LockBikeStand(LockProcedure lp) { MySqlCommand cmd = Connection.CreateCommand(); cmd.CommandText = "INSERT INTO `sessions`(`userid`, `stand_id`, `lock_moment`, `verification_key`) VALUES (@1, @2, @3, @4); UPDATE stands SET taken = true WHERE stand_id = @5;"; // cmd.Parameters.AddWithValue("@1", lp.UserID); cmd.Parameters.AddWithValue("@2", lp.StandID); cmd.Parameters.AddWithValue("@3", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); cmd.Parameters.AddWithValue("@4", lp.Key); cmd.Parameters.AddWithValue("@5", lp.StandID); Connection.Open(); int rowsAffected = cmd.ExecuteNonQuery(); Connection.Close(); if (rowsAffected > 0) { return(true); } return(false); }
private void ProcessLockProcedure() { string stand_id = Data[0]; List <LockProcedure> instances = localSafe.Load(); List <string> standIDsToSkip = new List <string>(); bool notFound = true; for (int i = instances.Count - 1; i >= 0; i--) { if (instances[i].StandID == stand_id && instances[i].IsLocked && !CheckIfStandAlreadyLocked(standIDsToSkip, instances[i].StandID)) { standIDsToSkip.Add(instances[i].StandID); notFound = false; string send = "lockBicycleStand"; SendMessageToSerialPort(send); } } if (notFound) { LockProcedure procedure = new LockProcedure(stand_id, LockProcedure.StartingWith.StandID); instances.Add(procedure); } localSafe.Save(instances); }