예제 #1
0
        public Nodo <Productos> LeerNodo(string pathArch, int posi, CifradoS cif)
        {
            Nodo <Productos> nodo = new Nodo <Productos>();

            using (var stream = new FileStream(pathArch, FileMode.Open))
            {
                //int posi = encabezado.FixedSizeText + tamnodo * encabezado.Raiz;

                stream.Seek(posi, SeekOrigin.Begin);
                byte[] lectura = new byte[nodo.FixedSizeText];
                stream.Read(lectura, 0, nodo.FixedSizeText);
                cif.ConvertirAscci(lectura); //Obtengo los codigos Ascci del buffer
                cif.InicioDesCifrado();      //inicio el cifrado del buffer
                string datos = Encoding.UTF8.GetString(cif.escribir, 0, cif.escribir.Length);
                nodo.LlenarNodo(datos);
                posi = posi + nodo.FixedSizeText;
                for (int i = 0; i < nodo.Values.Length; i++)
                {
                    Productos aux = new Productos();
                    stream.Seek(posi + (aux.FixedSizeText * i), SeekOrigin.Begin);
                    lectura = new byte[aux.FixedSizeText];
                    stream.Read(lectura, 0, aux.FixedSizeText);
                    cif.ConvertirAscci(lectura); //Obtengo los codigos Ascci del buffer
                    cif.InicioDesCifrado();      //inicio el cifrado del buffer
                    datos = Encoding.UTF8.GetString(cif.escribir, 0, cif.escribir.Length);
                    aux.LLenarProducto(datos);
                    nodo.Values[i] = aux;
                }
                stream.Close();
            }
            return(nodo);
        }
예제 #2
0
        public void EscribirNodo(string pathArch, int pos, Nodo <Productos> nodo, CifradoS cif)
        {
            Productos vacio = new Productos();

            vacio.Id     = -1;
            vacio.Nombre = "";
            vacio.Precio = 00.00;
            using (var stream = new FileStream(pathArch, FileMode.Open))
            {
                stream.Seek(pos, SeekOrigin.Begin);
                string escribir = nodo.ToFixedSizeString();
                stream.Write(Encoding.ASCII.GetBytes(escribir), 0, nodo.FixedSizeText);
                for (int i = 0; i < nodo.Values.Length; i++)
                {
                    if (nodo.Values[i] != null)
                    {
                        escribir = nodo.Values[i].ToFixedSizeString();
                        cif.ConvertirAscci(Encoding.ASCII.GetBytes(escribir)); //Obtengo los codigos Ascci del buffer
                        cif.InicioCifrado();                                   //inicio el cifrado del buffer
                        stream.Seek(pos + nodo.FixedSizeText + (i * nodo.Values[i].FixedSizeText), SeekOrigin.Begin);
                        stream.Write(cif.escribir, 0, escribir.Length);
                    }
                    else
                    {
                        escribir = vacio.ToFixedSizeString();
                        cif.ConvertirAscci(Encoding.ASCII.GetBytes(escribir)); //Obtengo los codigos Ascci del buffer
                        cif.InicioCifrado();                                   //inicio el cifrado del buffer
                        stream.Seek((pos + nodo.FixedSizeText + (i * escribir.Length)), SeekOrigin.Begin);
                        stream.Write(cif.escribir, 0, escribir.Length);
                    }
                }
                stream.Close();
            }
        }
예제 #3
0
 public void EscribirEncabezado(string pathArch, CifradoS cif)
 {
     using (var stream = new FileStream(pathArch, FileMode.OpenOrCreate))
     {
         stream.Seek(0, SeekOrigin.Begin);
         string escribir = ToFixedSizeString();
         cif.ConvertirAscci(Encoding.ASCII.GetBytes(escribir)); //Obtengo los codigos Ascci del buffer
         cif.InicioDesCifrado();                                //inicio el cifrado del buffer
         stream.Write(cif.escribir, 0, cif.escribir.Length);
         stream.Close();
     }
 }
예제 #4
0
        public Encabezado LeerEncabezado(string pathArch, CifradoS cif)
        {
            Encabezado encabezado = new Encabezado();

            using (var stream = new FileStream(pathArch, FileMode.Open))
            {
                stream.Seek(0, SeekOrigin.Begin);
                byte[] lectura = new byte[encabezado.FixedSizeText];
                stream.Read(lectura, 0, encabezado.FixedSizeText);
                cif.ConvertirAscci(lectura); //Obtengo los codigos Ascci del buffer
                cif.InicioDesCifrado();      //inicio el cifrado del buffer
                string datos = Encoding.UTF8.GetString(cif.escribir, 0, cif.escribir.Length);
                encabezado.LLenarEncabezado(datos);
                stream.Close();
            }
            return(encabezado);
        }
예제 #5
0
        public Productos LeerProducto(string pathArch, int posi, CifradoS cif)
        {
            Productos aux = new Productos();

            using (var stream = new FileStream(pathArch, FileMode.Open))
            {
                stream.Seek(posi, SeekOrigin.Begin);
                byte[] lectura = new byte[aux.FixedSizeText];

                stream.Read(lectura, 0, aux.FixedSizeText);
                cif.ConvertirAscci(lectura); //Obtengo los codigos Ascci del buffer
                cif.InicioDesCifrado();      //inicio el cifrado del buffer
                string datos = Encoding.UTF8.GetString(cif.escribir, 0, cif.escribir.Length);
                aux.LLenarProducto(datos);



                stream.Close();
            }
            return(aux);
        }
예제 #6
0
파일: Nodo.cs 프로젝트: luciale/Proyecto
        public static Nodo <Productos> Insert_NewFather(Nodo <T> nodo_actual, Productos[] sortedList, int medio, List <int> list, string pathArch, int nodo_a, CifradoS cif)
        {
            Productos auxp = new Productos();

            int pos_nodos = Data.Instance.encabezado.FixedSizeText;
            Nodo <Productos> actual_father = new Nodo <Productos>();

            actual_father.Values[0] = sortedList[medio];

            Nodo <Productos> nodo_aux = new Nodo <Productos>();

            for (int x = 0; x < medio; x++)
            {
                nodo_aux.Values[x] = sortedList[x];
            }
            Nodo <Productos> nodo_aux1 = new Nodo <Productos>();
            int x_aux = 0;

            for (int x = medio + 1; x < sortedList.Length; x++)
            {
                nodo_aux1.Values[x_aux] = sortedList[x];
                x_aux++;
            }
            //ORdenar hijos si la lista no es vacia

            if (list != null)
            {
                //Ordenar los hijos
                List <int>       list_aux         = new List <int>();       //lista auxiliar para guardar hijos actuales
                List <Productos> list_aux_valores = new List <Productos>(); //lista auxiliar para guardar el primer valor de cada hijo
                for (int x = 0; x < nodo_actual.Children.Length; x++)
                {
                    if (nodo_actual.Children[x] != -1)
                    {
                        list_aux.Add(nodo_actual.Children[x]);
                        //IR A CADA UNO DE LOS HIJOS A TOMAR LOS VALORES
                        for (int i = 0; i < nodo_actual.Children.Length; i++)
                        {
                            Productos aux = new Productos();
                            pos_nodos = Data.Instance.encabezado.FixedSizeText + nodo_actual.Children[x] * (nodo_actual.FixedSizeText + aux.FixedSizeText * nodo_actual.Values.Length);

                            aux = aux.LeerProducto(pathArch, pos_nodos + nodo_actual.FixedSizeText, cif);
                            list_aux_valores.Add(aux);
                        }
                    }
                }
                for (int x = 0; x < list.Count; x++)
                {
                    list_aux.Add(list[x]);
                    Productos aux = new Productos();
                    pos_nodos = Data.Instance.encabezado.FixedSizeText + list[x] * (nodo_actual.FixedSizeText + aux.FixedSizeText * nodo_actual.Values.Length);

                    aux = aux.LeerProducto(pathArch, pos_nodos + nodo_actual.FixedSizeText, cif);
                    list_aux_valores.Add(aux);
                    list_aux_valores.Add(aux);
                }
                //Ordenamos los primeros valores de cada hijo
                var sortedList1 = GenericComparation <T> .SortedList(list_aux_valores.ToArray(), Productos.CompareByName);

                nodo_aux.Children = new int[Data.Instance.grado];
                //asignamos los hijos de nodo_aux
                int hijos = sortedList1.Length / 2;
                for (int x = 0; x < hijos; x++)
                {
                    for (int y = 0; y < list_aux.Count; y++)
                    {
                        Nodo <Productos> n = new Nodo <Productos>();

                        pos_nodos = Data.Instance.encabezado.FixedSizeText + list_aux[y] * (nodo_actual.FixedSizeText + auxp.FixedSizeText * nodo_actual.Values.Length);

                        n = auxp.LeerNodo(pathArch, pos_nodos, );
                        if (n.Values[0].Equals(sortedList1[x]))
                        {
                            nodo_aux.Children[x] = list_aux[x];
                            pos_nodos            = Data.Instance.encabezado.FixedSizeText + nodo_aux.Children[x] * (nodo_actual.FixedSizeText + auxp.FixedSizeText * nodo_actual.Values.Length);
                            n        = auxp.LeerNodo(pathArch, pos_nodos, cif);
                            n.father = Data.Instance.encabezado.Disponible;
                            auxp.EscribirNodo(pathArch, pos_nodos, n, cif);
                        }
                    }
                }


                nodo_aux1.Children = new int[Data.Instance.grado];
                //asignamos los hijos de nodo_aux1
                for (int x = hijos; x < sortedList1.Length; x++)
                {
                    for (int y = 0; y < list_aux.Count; y++)
                    {
                        Nodo <Productos> n = new Nodo <Productos>();

                        pos_nodos = Data.Instance.encabezado.FixedSizeText + list_aux[y] * (nodo_actual.FixedSizeText + auxp.FixedSizeText * nodo_actual.Values.Length);

                        n = auxp.LeerNodo(pathArch, pos_nodos, cif);
                        if (list_aux[y].Equals(sortedList1[x]))
                        {
                            nodo_aux1.Children[x] = list_aux[x];
                            nodo_aux1.Children[x] = list_aux[x];
                            pos_nodos             = Data.Instance.encabezado.FixedSizeText + nodo_aux1.Children[x] * (nodo_actual.FixedSizeText + auxp.FixedSizeText * nodo_actual.Values.Length);
                            n        = auxp.LeerNodo(pathArch, pos_nodos, cif);
                            n.father = Data.Instance.encabezado.Disponible;
                            auxp.EscribirNodo(pathArch, pos_nodos, n, cif);
                        }
                    }
                }
            }


            nodo_aux.father  = Data.Instance.encabezado.Disponible;
            nodo_aux1.father = Data.Instance.encabezado.Disponible;

            pos_nodos = Data.Instance.encabezado.FixedSizeText + nodo_aux.Children[Data.Instance.encabezado.Disponible] * (nodo_actual.FixedSizeText + auxp.FixedSizeText * nodo_actual.Values.Length);

            actual_father.Children[0] = nodo_a;

            actual_father.Children[1] = Data.Instance.encabezado.Disponible + 1;
            actual_father.father      = -1;
            auxp.EscribirNodo(pathArch, pos_nodos, actual_father, cif);
            Data.Instance.encabezado.Grado = Data.Instance.encabezado.Grado + 2;
            return(actual_father);
        }