public ActionController(ProtocolResolver pResolverParam, int clienteId) { pResolver = pResolverParam; this.clientId = clienteId; listActions = new Dictionary <string, Action>(); CreateActions(); TagAction = pResolver.GetTagProtocol(); action = new Action(); action = GetActionByTag(); }
public void ProtocolResolvesCorrectly(string minProtocol, string maxProtocol, string clientProtocol, string expectedProtocol) { var request = new Mock <IRequest>(); var queryStrings = new NameValueCollection(); var minProtocolVersion = new Version(minProtocol); var maxProtocolVersion = new Version(maxProtocol); var protocolResolver = new ProtocolResolver(minProtocolVersion, maxProtocolVersion); queryStrings.Add("clientProtocol", clientProtocol); request.Setup(r => r.QueryString).Returns(new NameValueCollectionWrapper(queryStrings)); var version = protocolResolver.Resolve(request.Object); Assert.Equal(version, new Version(expectedProtocol)); }
public void ProtocolResolvesCorrectly(string minProtocol, string maxProtocol, string clientProtocol, string expectedProtocol) { var minProtocolVersion = new Version(minProtocol); var maxProtocolVersion = new Version(maxProtocol); var protocolResolver = new ProtocolResolver(minProtocolVersion, maxProtocolVersion); var queryStrings = new Dictionary <string, string> { { "clientProtocol", clientProtocol } }; var context = new TestContext("/negotite", queryStrings); var version = protocolResolver.Resolve(context.MockRequest.Object); Assert.Equal(version, new Version(expectedProtocol)); }
//recebe os dados private void WaitData(IAsyncResult ar) { try { if (ativo) { int size = this.socket.EndReceive(ar); // se o tamanho do buffer for maior que zero, escreve na tela os bytes recebidos if (size > 0) { Array.Resize(ref this.buffer, size); sb.Append(Encoding.UTF8.GetString(buffer, 0, size)); _sProtocolReceiver = sb.ToString(); sb.Clear(); //implementado controle de erros com o valor do _sProtocolReceiver recebido aqui if (ProtocoloRecebidoOK(_sProtocolReceiver)) { ProtocolResolver pResolver = new ProtocolResolver(_sProtocolReceiver); ActionController actionController = new ActionController(pResolver, this.clientId); actionController.ExecAction(); } else { Server._sProtocolResponse = erroProt; } if (_sProtocolReceiver != null) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Receiver: {0}", _sProtocolReceiver); Console.ResetColor(); Send(socket, Server._sProtocolResponse); } else { socket.BeginReceive(buffer, 0, BufferSize, 0, new AsyncCallback(WaitData), socket); } Console.WriteLine($"{_sProtocolReceiver}"); } else { //atualizar a lista do servidor retirando esse cliente da lista //evento disparado sempre que um cliente disconecta this.ClienteDisconecta(this, new EventArgs()); Close(); } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{ex.Message} \n {ex.StackTrace}"); } finally { if (ativo) { try { buffer = new Byte[4000]; this.socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, WaitData, null); } catch (Exception e) { Console.WriteLine(e.Message); } } } }