Exemplo n.º 1
0
        bool IDeserializa.Xml(out Lapiz unLapiz)
        {
            bool retorno = false;

            unLapiz = null;

            XmlTextReader xr  = null;
            XmlSerializer ser = null;

            try
            {
                xr      = new XmlTextReader(this.Path);
                ser     = new XmlSerializer(typeof(Lapiz));
                unLapiz = (Lapiz)ser.Deserialize(xr);
                retorno = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (xr != null)
                {
                    xr.Close();
                }
            }


            return(retorno);
        }
Exemplo n.º 2
0
        bool IDeserializa.Xml(out Lapiz lapiz)
        {
            bool ret = false;

            try
            {
                //PARA DESERIALIZAR
                //INSTANCIO UN TEXTREADER CON UN STREAMREADER, LE PASO EL PATH
                using (StreamReader tr = new StreamReader(this.Path))
                {
                    //INSTANCIO UN XMLSERIALIZER CON EL TIPO QUE VA A DESERIALIZAR
                    XmlSerializer sr = new XmlSerializer(typeof(Lapiz));
                    //USO EL METODO DESERIALIZE, PASANDOLE COMO PARAMETRO EL TEXTREADER
                    //PERO LO TENGO QUE CASTEAR AL TIPO, SE LO ASIGNO AL OBJETO LAPIZ QUE
                    //DEBERIA RECIBIR COMO PARAMETRO OUT
                    lapiz = (Lapiz)sr.Deserialize(tr);
                    ret   = true;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(ret);
        }
Exemplo n.º 3
0
        bool IDeserializa.Xml(out Lapiz l)
        {
            l = null;
            bool rta = false;

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(Lapiz));
                XmlTextReader sr = new XmlTextReader(this.Path);
                l = (Lapiz)xs.Deserialize(sr);
                sr.Close();
                rta = true;
            }
            catch (Exception)
            {
            }
            return(rta);
        }
Exemplo n.º 4
0
        public bool ProbarElementos(Boligrafo b, Lapiz l)
        {
            this.listaBoligrafo = new List <Boligrafo>();
            this.listaLapiz     = new List <Lapiz>();

            listaBoligrafo.Add(b);
            listaLapiz.Add(l);

            foreach (var item in listaBoligrafo)
            {
                if (item.UnidadesDeEscritura > 0)
                {
                    item.UnidadesDeEscritura -= 1;
                }

                if (item.UnidadesDeEscritura <= 0)
                {
                    item.Recargar(10);
                }
            }

            foreach (var item in listaLapiz)
            {
                if (((IAcciones)item).UnidadesDeEscritura > 0)
                {
                    ((IAcciones)item).UnidadesDeEscritura -= 1;
                }

                if (((IAcciones)item).UnidadesDeEscritura <= 0)
                {
                    ((IAcciones)item).Recargar(10);
                }
            }

            if (listaBoligrafo != null && listaLapiz != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        bool IDeserializa.Xml(out Lapiz l)
        {
            l = null;
            bool ret = true;

            try
            {
                using (StreamReader sr = new StreamReader(Path))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(Lapiz));

                    l = (Lapiz)ser.Deserialize(sr);
                }
            }
            catch (Exception e)
            {
                ret = false;
            }
            return(ret);
        }
Exemplo n.º 6
0
        bool IDeserializa.Xml(out Lapiz lapiz)
        {
            bool rta = true;

            try
            {
                using (XmlTextReader xmlTR = new XmlTextReader(this.Path))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(Lapiz));
                    lapiz = (Lapiz)ser.Deserialize(xmlTR);
                }
            }
            catch (Exception)
            {
                lapiz = new Lapiz();
                rta   = false;
            }


            return(rta);
        }
Exemplo n.º 7
0
        bool IDeserializa.Xml(out Lapiz unLapiz)
        {
            bool retorno = false;

            unLapiz = null;

            try
            {
                XmlSerializer xml = new XmlSerializer(typeof(Lapiz));
                TextReader    tr  = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Rivola.Agustin.lapiz.xml");
                unLapiz = (Lapiz)xml.Deserialize(tr);
                tr.Close();
                retorno = true;
            }
            catch (Exception)
            {
            }


            return(retorno);
        }
Exemplo n.º 8
0
        bool IDeserializa.Xml(out Lapiz l)
        {
            bool ret = false;

            l = default(Lapiz);
            try
            {
                using (XmlTextReader reader = new XmlTextReader(this.Path))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Lapiz));
                    l = (Lapiz)xs.Deserialize(reader);
                }
                ret = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Falló la deserialización. Razones: " + e.Message);
            }

            return(ret);
        }
Exemplo n.º 9
0
        bool IDeserializa.Xml(out Lapiz l)
        {
            bool          Flag = false;
            XmlSerializer ser  = new XmlSerializer(typeof(Lapiz));
            Lapiz         aux  = new Lapiz();

            try
            {
                using (StreamReader reader = new StreamReader(this.Path))
                {
                    aux  = (Lapiz)ser.Deserialize(reader);
                    Flag = true;
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                l = aux;
            }

            return(Flag);
        }