Example #1
0
        public void PreencherAlertasTeste()
        {
            AlertaQuitaGuia a1 = new AlertaQuitaGuia();

            a1.Codigo     = 20;
            a1.Descricao  = "A guia já estava quitada.";
            a1.NumeroGuia = "2600000082017";
            a1.Status     = false;

            AlertaQuitaGuia a2 = new AlertaQuitaGuia();

            a2.Codigo     = 19;
            a2.Descricao  = "A guia não foi encontrada.";
            a2.NumeroGuia = "2600000082018";
            a2.Status     = false;

            AlertaQuitaGuia a3 = new AlertaQuitaGuia();

            a3.Codigo     = 20;
            a3.Descricao  = "A guia já estava quitada.";
            a3.NumeroGuia = "2600000090300";
            a3.Status     = false;

            Alertas.Add(a1);
            Alertas.Add(a2);
            Alertas.Add(a3);
        }
Example #2
0
        public string GerarXML(int versao, string mensagem)
        {
            //Variavel que diz respeito ao ao sucesso do XML
            Boolean sucesso = true;

            //Verificar a versão do Schema
            if (versao != 1)
            {
                sucesso = false;

                return(RetornarVersaoSchemaErrado());
            }


            //CRIAR METODO PARA TRANSFORMAR A MENSAGEM EM XML E FAZER AS VALIDAÇÕES
            //AS MENSAGENS DE RETORO SÃO APENAS DE TESTES



            XmlDocument documentoXML = new XmlDocument();

            //Transformando a string recebida em arquivo XML
            try
            {
                documentoXML.LoadXml(mensagem);
                //XmlReader reader = XmlReader.Create(mensagem);
            }catch (Exception e)
            {
                sucesso = false;
                AlertaQuitaGuia alerta = new AlertaQuitaGuia();
                alerta.Codigo    = 10;
                alerta.Descricao = "XML não compativel com Schema.";
                alerta.Status    = false;
                Alertas.Add(alerta);
            }

            //Quer dizer que foi possivel converter o xml em um objeto


            //Pegando as nós das guias
            XmlNodeList nodes = documentoXML.GetElementsByTagName("Guia");
            int         count = 0;

            for (int i = 0; i < nodes.Count; i++)
            {
                count++;
                XmlNode node = nodes.Item(i);
                Guia    g    = new Guia();
                g = ConvertNode <Guia>(node);
                Guias.Add(g);
            }

            //Agora com as Guias em uma lista é possivel fazer as regras de negócio



            //PreencherAlertasTeste();

            XDocument xmlDocument  = new XDocument();
            XElement  xmlCabecalho = new XElement("Cabecalho",
                                                  new XAttribute("Versao", versao),
                                                  new XElement("Sucesso", sucesso));


            for (int i = 0; i < Alertas.Count; i++)
            {
                XElement auxElement = new XElement("Alerta",
                                                   new XElement("Codigo", Alertas[i].Codigo),
                                                   new XElement("Descricao", Alertas[i].Descricao),
                                                   new XElement("NumeroGuia", Alertas[i].NumeroGuia),
                                                   new XElement("Status", Alertas[i].Status));
                xmlCabecalho.Add(auxElement);
            }

            xmlDocument.Add(xmlCabecalho);



            StringWriter  sw = new StringWriter();
            XmlTextWriter tx = new XmlTextWriter(sw);

            xmlDocument.WriteTo(tx);

            CriarLog log = new CriarLog();

            log.EscreverLog("QuitaGuia", "Output", sw.ToString());

            return(sw.ToString());
        }