public async Task <Command> GetApiWaitCommand(string id) { Command cmd = null; _isWait = true; int timeCount = 0; //while (cmd == null && timeCount <= ServerCommands.TimeOutApiRequest) //{ // cmd = _waitCommandsList.First(c => c.Id == id); // await Task.Delay(100); // timeCount++; //} do { var data = _sr?.ReadLine(); var dataDescomp = await StringCompressionAsync.DecompressString(data); cmd = await SerializerAsync.DeserializeJson <Command>(dataDescomp); if (cmd != null && !cmd.IsWait) { DelegateAction del; if (!string.IsNullOrEmpty(cmd.Id) && _srvsCmdsBuffer.TryGetValue(cmd.Id, out del)) { del.server[0] = dataDescomp; del.Exec(); } else if (_srvsCmdsBuffer.TryGetValue(ServerCommands.BroadCastId, out del)) { del.server[0] = dataDescomp; del.Exec(); } } } while (cmd != null && !cmd.IsWait); _isWait = false; return(cmd); }
private async void Read(Object source, ElapsedEventArgs e) { try { // _timerRead.Enabled = false; if (!_isWait && _clientSocket?.Client?.Available > 0) { _hearthBitCount = 0; var data = _sr?.ReadLine(); string dataDescomp = await StringCompressionAsync.DecompressString(data); try { var bt = await SerializerAsync.DeserializeJson <Command>(dataDescomp); if (bt != null) { if (!bt.Cmd.Equals(ServerCommands.HearthBit)) { //_bufferRead.Enqueue(dataDescomp); // ConsoleEx.WriteLine("Olha o que eu coloquei aqui: " +dataDescomp); DelegateAction del; if (!string.IsNullOrEmpty(bt.Id) && _srvsCmdsBuffer.TryGetValue(bt.Id, out del)) { del.server[0] = dataDescomp; del.Exec(); } else if (_srvsCmdsBuffer.TryGetValue(ServerCommands.BroadCastId, out del)) { del.server[0] = dataDescomp; del.Exec(); } } } else { _bufferRead.Enqueue(dataDescomp); } } catch (Exception ex) { ConsoleEx.WriteError("Read", ex); //Dispose(); } } } catch (Exception exception) { ConsoleEx.WriteError("erro do Read:", exception); //Dispose(); } finally { // _timerRead.Enabled = true; } }