Beispiel #1
0
        public static String getXmlPost()
        {
            Sis_informador theSis_informador = new Sis_informador("03107", "OK", "1", "2019_01_18 11_53_55");

            List <Sis_alerta> theListSis_alerta = new List <Sis_alerta>();

            Sis_alerta theSis_alerta = new Sis_alerta("BAAMONDE", "2");

            theSis_alerta.listAlertas.Add(new Alerta("51", "eth1 conexion eliminada", "2019_01_21 16_43_34"));
            //theSis_alerta.listAlertas.Add(new Alerta("52", "eth2 conexion eliminada", "2012_01_21 16_43_34"));
            theListSis_alerta.Add(theSis_alerta);

            /*
             * Sis_alerta theSis_alerta1 = new Sis_alerta("BAAMONDE", "1");
             * theSis_alerta1.listAlertas.Add(new Alerta("51", "eth1 conexion eliminada", "2019_01_21 16_43_34"));
             * theSis_alerta1.listAlertas.Add(new Alerta("52", "eth2 conexion eliminada", "2012_01_21 16_43_34"));
             * theListSis_alerta.Add(theSis_alerta1);
             */

            mensaje theMensaje = new mensaje(theSis_informador);

            theMensaje.sis_alerta = theListSis_alerta;



            XmlSerializer xmlSerializer = new XmlSerializer(theMensaje.GetType());

            using (StringWriter textWriter = new StringWriter())
            {
                xmlSerializer.Serialize(textWriter, theMensaje);
                return(textWriter.ToString());
            }
        }
Beispiel #2
0
        private static string SerializeXml(mensaje theMensaje)
        {
            XmlSerializer ser = new XmlSerializer(typeof(mensaje));

            // Using a MemoryStream to store the serialized string as a byte array,
            // which is "encoding-agnostic"
            using (MemoryStream ms = new MemoryStream())
                // Few options here, but remember to use a signature that allows you to
                // specify the encoding
                using (XmlTextWriter tw = new XmlTextWriter(ms, Encoding.UTF8))
                {
                    tw.Formatting = System.Xml.Formatting.Indented;
                    ser.Serialize(tw, theMensaje);
                    // Now we get the serialized data as a string in the desired encoding

                    String rpta = Encoding.UTF8.GetString(ms.ToArray());

                    string path = @"d:\alertasSiam.txt";

                    // This text is added only once to the file.
                    if (!File.Exists(path))
                    {
                        // Create a file to write to.
                        //string createText = "Hello and Welcome" + Environment.NewLine;
                        File.WriteAllText(path, rpta);
                    }
                    return(rpta);
                }
        }
Beispiel #3
0
        public static mensaje getMensaje()
        {
            Sis_informador theSis_informador = new Sis_informador("03107", "OK", "1", "2019_01_18 11_53_55");

            List <Sis_alerta> theListSis_alerta = new List <Sis_alerta>();

            Sis_alerta theSis_alerta = new Sis_alerta("BAAMONDE", "1");

            theSis_alerta.listAlertas.Add(new Alerta("51", "eth1 conexion eliminada", "2019_01_21 16_43_34"));
            theListSis_alerta.Add(theSis_alerta);
            mensaje theMensaje = new mensaje(theSis_informador);

            theMensaje.sis_alerta = theListSis_alerta;

            return(theMensaje);
        }