elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  hacer que un programa basado en archivos de texto funcione solo con strings
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: hacer que un programa basado en archivos de texto funcione solo con strings  (Leído 1,620 veces)
dr4

Desconectado Desconectado

Mensajes: 3


Ver Perfil
hacer que un programa basado en archivos de texto funcione solo con strings
« en: 19 Mayo 2015, 15:22 pm »

Muy buenas! tengo una cosa que me está dando mucho quebradero de cabeza, os comento:

Tengo un programilla en visual studio funcionando que coge datos de 2 bases de datos,las convierte en archivos en xml,las compara y por ultimo las sincroniza, funciona perfectamente pero ahora quisiera hacer lo mismo pero sin crear ningún archivo, que todo el proceso ocurra internamente en el programa, os paso el código que tengo del programa funcionando (del método que hace todo el proceso de xml), y el código del nuevo, el problema ahora mismo me salta a la hora de comparar los dos strings y no descarto que lo que viene luego tampoco vaya a funcionar:



PROGRAMA FUNCIONANDO:

Código
  1.  
  2.  
  3.  
  4.  
  5.  
  6.        public static void CompareXml()
  7.        {
  8.  
  9.  
  10.            XmlWriter writexml;
  11.  
  12.  
  13.  
  14.                writexml = XmlWriter.Create("C:\\sharecompare.xml");
  15.  
  16.  
  17.            string xmlString1 = "C:\\share2Copy.xml";
  18.            string xmlString2 = "C:\\share1.xml";
  19.            string xmlString3 = "C:\\sharecomparefinal.xml";
  20.            string xmlString4 = "C:\\sharecompare.xml";
  21.  
  22.  
  23.  
  24.            XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |
  25.                                             XmlDiffOptions.IgnoreNamespaces |
  26.                                             XmlDiffOptions.IgnorePrefixes);
  27.            bool bIdentical = xmldiff.Compare(xmlString2, xmlString1, false, writexml);
  28.  
  29.  
  30.            writexml.Close();
  31.  
  32.            FileStream patchedFile = new FileStream(xmlString3, FileMode.Create, FileAccess.Write);
  33.  
  34.            XmlPatch xmlPatch = new XmlPatch();
  35.  
  36.  
  37.            try
  38.            {
  39.              //  XmlTextReader diffgramReader = new XmlTextReader("C:\\sharecompare.xml");
  40.               // xmlpatch.Patch(sourceDoc, diffgramReader);
  41.                xmlPatch.Patch(new XmlTextReader(xmlString2), patchedFile, new XmlTextReader(xmlString4));
  42.  
  43.  
  44.            }
  45.            catch (Exception ex)
  46.            {
  47.                Console.WriteLine("HA habido un ERROR: "+ex.Message);
  48.  
  49.            }
  50.  
  51.            patchedFile.Close();
  52.            Console.WriteLine("The patched document or fragment has been saved to " + xmlString3);
  53.  
  54.        }
  55.  
  56.  
  57.  






INTENTO CONVERTIRLO EN UN PROGRAMA QUE FUNCIONE SIN CREAR ARCHIVOS. xml1 y xml2 son strings y cogen bien el xml de las bases de datos,el problema viene a la hora de intentar comparar los dos strings y sacar un tercer string con el resultado en formato xml:




Código
  1. public static void CompareXml()
  2.        {
  3.            DShare Obj=new DShare();
  4.  
  5.            XmlWriter writexml;
  6.  
  7.            StringWriter sw = new StringWriter();
  8.  
  9.  
  10.  
  11.  
  12.            writexml = XmlWriter.Create(sw);
  13.  
  14.  
  15.            string xmlString1 = Obj.Xml2;
  16.            string xmlString2 = Obj.Xml1;
  17.            string xmlString3 = Obj.Xmlfinal;
  18.            string xmlString4 = sw.ToString();
  19.  
  20.  
  21.            string str = sw.ToString();//
  22.  
  23.  
  24.  
  25.            XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder |
  26.                                             XmlDiffOptions.IgnoreNamespaces |
  27.                                             XmlDiffOptions.IgnorePrefixes);
  28.            bool bIdentical = xmldiff.Compare(xmlString2, xmlString1, false, writexml);
  29.  
  30.  
  31.            writexml.Close();
  32.  
  33.            MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(xmlString3));
  34.            //FileStream patchedFile = new FileStream(xmlString3, FileMode.Create, FileAccess.Write);
  35.  
  36.            XmlPatch xmlPatch = new XmlPatch();
  37.  
  38.  
  39.            try
  40.            {
  41.                //  XmlTextReader diffgramReader = new XmlTextReader("C:\\sharecompare.xml");
  42.                // xmlpatch.Patch(sourceDoc, diffgramReader);
  43.                xmlPatch.Patch(new XmlTextReader(xmlString2), ms, new XmlTextReader(xmlString4));
  44.  
  45.  
  46.            }
  47.            catch (Exception ex)
  48.            {
  49.                Console.WriteLine("HA habido un ERROR: " + ex.Message);
  50.  
  51.            }
  52.  
  53.            ms.Close();
  54.           // patchedFile.Close();
  55.  
  56.            Console.WriteLine("The patched document or fragment has been saved to " + xmlString3);
  57.        }
  58.  


« Última modificación: 19 Mayo 2015, 15:57 pm por Eleкtro » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines