public static List<String> filterPersona(Dictionary<string, object> dic) { string columns = ""; List<string> result = new List<string>(); List<string> parameters = (List<string>)dic["parameters"]; //Console.WriteLine("\n**** Parametros ****\n"); //Utilities.printCollection(parameters); List<int> columns_position_infile = new List<int>(); result = Utilities.readFileByList(Utilities.persona_dir); if (parameters[0] == "*") { return result; } else { if (parameters.Contains("idpersona")) { columns_position_infile.Add(0); } if (parameters.Contains("nombre")) { columns_position_infile.Add(1); } if (parameters.Contains("apellido")) { columns_position_infile.Add(2); } if (parameters.Contains("sexo")) { columns_position_infile.Add(3); } if (parameters.Contains("fecha_nacimiento")) { columns_position_infile.Add(4); } if (parameters.Contains("estado_civil")) { columns_position_infile.Add(5); } if (parameters.Contains("ocupacion")) { columns_position_infile.Add(6); } if (parameters.Contains("idbarrio")) { columns_position_infile.Add(7); } if (parameters.Contains("idurbanizacion")) { columns_position_infile.Add(8); } if (parameters.Contains("idseccion_dm")) { columns_position_infile.Add(9); } if (parameters.Contains("idbarrio_dm")) { columns_position_infile.Add(10); } if (parameters.Contains("idurbanizacion_dm")) { columns_position_infile.Add(11); } if (parameters.Contains("idistrito_municipal")) { columns_position_infile.Add(12); } if (parameters.Contains("isvivo")) { columns_position_infile.Add(13); } //Console.WriteLine("\n**** Elementos ****\n\n"); //Utilities.printCollection(columns_position_infile); //Console.WriteLine("\n**** Find elementos ****\n\n"); result = Utilities.readFileByListSpecified(Utilities.persona_dir, columns_position_infile); } return result; }
private static void ReceiveCallBack(IAsyncResult AR) { string action; Socket socket = (Socket)AR.AsyncState; int received = socket.EndReceive(AR); byte[] databuf = new byte[received]; Array.Copy(_buffer, databuf, received); // receiving text from client string request = Encoding.ASCII.GetString(databuf); // desencriptar peticion encriptada enviada por el cliente request = Encrypt.desencriptar(request); string response = string.Empty; // si esta autenticado, puedo hacer request if (is_authenticated == true) { // request format action,query action = request.Split('[')[0]; request = request.Split('[')[1]; if (action == "query") { List <string> lista = new List <string>(); // enviar data a cliente if (request.ToLower() != "") { //response = DateTime.Now.ToLongTimeString(); // make request and return Console.WriteLine("Petition : " + request); response = Utilities.executeQueryReturnString(request); } else { response = "Invalid Request"; } } if (action == "signup") { Utilities.writeSingleLineToFile(Utilities.user_dir, request); response = "exito"; } } else { // si no está autenticado, autenticalo List <string> users = new List <string>(); users = Utilities.readFileByList(Utilities.user_dir); if (users.Contains(request)) { Console.WriteLine("Client with Code " + request + " Logged in Succesfully"); is_authenticated = true; response = "authenticated"; } else { Console.WriteLine("Client login Failed"); response = "password error"; } } // encriptar respuesta para enviar de enviarsela al cliente encriptada response = Encrypt.encriptar(response); byte[] data = Encoding.ASCII.GetBytes(response); socket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallBack), socket); // receive again after send socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallBack), socket); }