Esempio n. 1
0
        public static void encriptarArchivo(string filename)
        {
            string content_file           = Utilities.fileToString(filename);
            string encrypted_content_file = encriptar(content_file);

            Utilities.writeSingleLineToFile(filename, encrypted_content_file);
        }
Esempio n. 2
0
        public void insertarPersona(Persona per, bool iseditar = false)
        {
            char   sep  = Utils.Utilities.sep;
            string dir  = Utilities.persona_dir;
            string data = per.idpersona.ToString() + sep
                          + per.nombre + sep
                          + per.apellido + sep
                          + per.sexo + sep
                          + per.fecha_nacimiento + sep
                          + per.estado_civil + sep
                          + per.ocupacion + sep
                          + per.idbarrio.ToString() + sep
                          + per.idurbanizacion.ToString() + sep
                          + per.idseccion_dm.ToString() + sep
                          + per.idbarrio_dm.ToString() + sep
                          + per.idurbanizacion_dm.ToString() + sep
                          + per.iddistrito_municipal.ToString() + sep
                          + per.is_vivo.ToString();

            if (iseditar)
            {
                Utilities.updateFromFileById(dir, per.idpersona, data);
            }
            else
            {
                Utilities.writeSingleLineToFile(dir, data);
            }
        }
        public void insertarBarrioDM(BarrioDM ba_dm, bool is_editar = false)
        {
            char   sep  = Utils.Utilities.sep;
            string dir  = Utilities.barrio_dm_dir;
            string data = (ba_dm.Idbarrio_dm.ToString() + sep + ba_dm.iddistrito.ToString() + sep + ba_dm.nombre + sep + ba_dm.poblacion + sep + ba_dm.area + sep + ba_dm.punto_cardinal);

            if (is_editar)
            {
                Utilities.updateFromFileById(dir, ba_dm.idbarrio_dm, data);
            }
            else
            {
                Utilities.writeSingleLineToFile(dir, data);
            }
        }
        public void insertarUrbanizacionDM(UrbanizacionDM urb_dm, bool is_editar = false)
        {
            char   sep  = Utils.Utilities.sep;
            string dir  = Utilities.urbanizacion_dm_dir;
            string data = (urb_dm.idurbanizacion_dm.ToString() + sep + urb_dm.iddistrito.ToString() + sep + urb_dm.nombre + sep + urb_dm.poblacion + sep + urb_dm.area + sep + urb_dm.punto_cardinal);

            if (is_editar)
            {
                Utilities.updateFromFileById(dir, urb_dm.idurbanizacion_dm, data);
            }
            else
            {
                Utilities.writeSingleLineToFile(dir, data);
            }
        }
        public void insertarProvincia(Provincia prov, bool iseditar = false)
        {
            char   sep  = Utils.Utilities.sep;
            string dir  = Utilities.provincia_dir;
            string data = prov.Idprovincia.ToString() + sep + prov.Nombre + sep + prov.Localizacion + sep + prov.Area.ToString() + sep + prov.Punto_cardinal;

            if (iseditar)
            {
                Utilities.updateFromFileById(dir, prov.idprovincia, data);
            }
            else
            {
                Utilities.writeSingleLineToFile(dir, data);
            }
        }
Esempio n. 6
0
        public void insertarMunicipio(Municipio mun, bool is_editar = false)
        {
            char   sep  = Utils.Utilities.sep;
            string dir  = Utilities.municipio_dir;
            string data = mun.idmunicipio.ToString() + sep + mun.Idprovincia + sep + mun.Nombre + sep + mun.Localizacion + sep + mun.Area.ToString() + sep + mun.Punto_cardinal;

            if (is_editar)
            {
                Utilities.updateFromFileById(dir, mun.idmunicipio, data);
            }
            else
            {
                Utilities.writeSingleLineToFile(dir, data);
            }
        }
        public void insertarDistritoMunicipal(DistritoMunicipal dist, bool is_editar = false)
        {
            char   sep  = Utils.Utilities.sep;
            string dir  = Utilities.distrito_municipal_dir;
            string data = dist.iddistrito.ToString() + sep + dist.Idprovincia + sep + dist.Nombre + sep + dist.Localizacion + sep + dist.Area.ToString() + sep + dist.Punto_cardinal;

            if (is_editar)
            {
                Utilities.updateFromFileById(dir, dist.iddistrito, data);
            }
            else
            {
                Utilities.writeSingleLineToFile(dir, data);
            }
        }
        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);
        }