public bool ChangeDetails(User loggedInUser, List <string> columns, List <string> values) { string command = $"DB_UPDATE_DETAILS:{loggedInUser.UserId}/"; for (int i = 0; i < columns.Count; i++) { if (i + 1 == columns.Count) { command += columns[i] + "/"; } else { command += columns[i] + "%"; } } for (int i = 0; i < values.Count; i++) { if (i + 1 == values.Count) { command += values[i] + ";"; } else { command += values[i] + "%"; } } SendMessage(command); if (ReceivedString.StartsWith("ACK")) { return(true); } return(false); }
public string Req_VerificationKey(User loggedInUser) { SendMessage($"DB_REQ_VERIFICATIONKEY:{loggedInUser.UserId};"); if (ReceivedString.StartsWith("ACK")) { return(ReceivedData[0]); } return(null); }
public bool LockBike(string standId, User loggedInUser) { SendMessage($"DB_LOCK_BIKE:{standId}/{loggedInUser.UserId};"); if (ReceivedString.StartsWith("ACK")) { return(true); } return(false); }
private bool CheckDataError() { if (!string.IsNullOrEmpty(Protocol.ErrorString) && ReceivedString.IndexOf(Protocol.ErrorString) >= 0) { return(true); } return(false); }
public string Req_Check_Exsisting_session(User loggedInUser) { SendMessage($"DB_REQ_EXISTING_SESSION_USER:{loggedInUser.UserId};"); if (ReceivedString.StartsWith("ACK")) { DateTime dateTime = ParseLockMoment(ReceivedData[2]); return(dateTime.ToString("hh:mm:ss dd-MM-yyyy")); } return(null); }
public string[] Req_AllStandId() { SendMessage("DB_REQ_ALLSTANDID;"); if (ReceivedString.StartsWith("ACK")) { string[] allStands = ValuesStringTrimmer(ReceivedData[0]); return(allStands); } return(null); }
public void ChangeBalance(User loggedinUser, decimal value) { SendMessage($"DB_CHANGE_BALANCE:{loggedinUser.UserId}/{value};"); if (ReceivedString.StartsWith("ACK")) { decimal newbalance; if (decimal.TryParse(ReceivedData[1], out newbalance)) { loggedinUser.RaiseBalance(newbalance); } } }
private bool CheckDataExist(string data) { if (string.IsNullOrEmpty(data)) { return(true); } if (ReceivedString.Contains(data)) { return(true); } return(false); }
public decimal Req_Price(User loggedInUser) { SendMessage($"DB_REQ_PRICE:{loggedInUser.UserId};"); if (ReceivedString.StartsWith("ACK")) { decimal price; if (decimal.TryParse(ReceivedData[1], out price)) { return(price); } } return(0); }
public bool ReqLogin(string email_address, string password) { SendMessage($"DB_REQ_LOGIN:{email_address};"); string rPassword = ReceivedData[2]; if (ReceivedString.StartsWith("ACK")) { if (rPassword == password) { return(true); } } return(false); }
public User ReqUser(string userId) { SendMessage($"DB_REQ_USER:{userId};"); if (ReceivedString.StartsWith("ACK")) { string first_name = ReceivedData[1]; string last_name = ReceivedData[2]; DateTime date_of_birth = ParseBirthDate(ReceivedData[3]); string email_address = ReceivedData[4]; string password = ReceivedData[5]; Address address = ParseAddress(ReceivedData[6]); decimal balance = Convert.ToDecimal(ReceivedData[7]); return(new User(userId, first_name, last_name, date_of_birth, email_address, password, address, balance)); } return(null); }
public bool Registrate(string first_name, string last_name, DateTime date_of_birth, string email, string password, Address address) { if (first_name != null && last_name != null && date_of_birth != null && password != null && address != null) { if (CheckConnection()) { SendMessage($"DB_INSERT_REGISTRATE:{first_name}/{last_name}/{date_of_birth.Day}_{date_of_birth.Month}_{date_of_birth.Year}/{email}/{password}/{address};"); if (ReceivedString.StartsWith("ACK")) { return(true); } else { return(false); } } } return(false); }
public void SendMessage(string message) { clientSock = new TcpClient(); clientSock.Connect(Settings.IPAddress, Port); NetworkStream stream = clientSock.GetStream(); byte[] data = Encoding.ASCII.GetBytes(message); stream.Write(data, 0, data.Length); byte[] bytes = new byte[1024]; bool received = false; while (!received) { try { int num = stream.Read(bytes, 0, bytes.Length); ReceivedString = Encoding.ASCII.GetString(bytes, 0, num); } catch (ObjectDisposedException) { clientSock.Close(); } try { ReceivedString = ReceivedString.Substring(0, ReceivedString.IndexOf(';')); } catch (ArgumentOutOfRangeException) { clientSock.Close(); } Console.WriteLine(ReceivedString); received = true; ReceivedData = CommandStringTrimmer(ReceivedString); } clientSock.Close(); }
void OnReceived(Object sender, ReceivedEventArgs e) { var data = e.Data; if (data == null || data.Length < 1) { return; } BytesOfReceived += data.Length; // 处理数据委托 if (Received != null) { var e2 = new BufferEventArgs { Value = data }; Received(this, e2); if (!e2.Cancel) { return; } // 外部可能修改了数据 data = e2.Value; //if (!BufferEventArgs.Invoke(Received, data)) return null; } // 处理字符串委托 if (ReceivedString == null) { return; } var cfg = SerialPortConfig.Current; var line = ""; if (cfg.HexShow) { if (data.Length > 32) { line = "[{0}]=\r\n{1}".F(data.Length, data.ToHex("-", 32)); } else { line = "[{0}]={1}".F(data.Length, data.ToHex("-", 32)); } if (cfg.HexNewLine) { line += Environment.NewLine; } } else { line = cfg.Encoding.GetString(data); if (_stream == null) { _stream = new MemoryStream(); } else if (_stream.Length > 10 * 1024 && _stream.Position == _stream.Length) // 达到最大大小时,从头开始使用 { _stream = new MemoryStream(); } _stream.Write(data); _stream.Seek(-1 * data.Length, SeekOrigin.Current); if (_reader == null || _reader.BaseStream != _stream || _reader.CurrentEncoding != cfg.Encoding) { _reader = new StreamReader(_stream, cfg.Encoding); } line = _reader.ReadToEnd(); // 替换掉无效数据 line = line.Replace("\0", null); } ReceivedString?.Invoke(this, new StringEventArgs { Value = line }); }
public void Clear() { DragonCount = 0; ReceivedString.Clear(); }
public void Clear() { PandaCount = 0; ReceivedString.Clear(); }