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

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


  Mostrar Mensajes
Páginas: 1 ... 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 [48] 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ... 238
471  Foros Generales / Foro Libre / Re: [Humor] A todos nos ha pasado... en: 16 Agosto 2014, 12:02 pm


Y lo mejor es pensar que hay gente a la que le pasa... :xD :xD



Otra de LOL...

472  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 8 Agosto 2014, 21:07 pm
Bueno, como siempre se agradecen sugerencias... Acabo de editar el código y sí, ese indentador no es mio, y la verdad es que tampoco me preocupe mucho, como vi que funciono la primera vez pues no le presté mucha atención...

Ahora como verás me he pasado poniendo usings, pero bueno >:D
473  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 8 Agosto 2014, 17:11 pm
Muy buenas, después de estar bastante tiempo sin subir nada aquí tengo una cosita interesante :P

Creo que algunas de estas utilidades están ya presentes dentro de lo que es la super colección de Elektro, pero bueno supongo que un indentador XML nunca se ha visto por aquí así que aquí va:

Código
  1. Imports System.IO
  2. Imports System.Xml
  3. Imports System.Xml.Serialization
  4.  
  5. Public Class XMLTools
  6.  
  7.    Public Shared Function Serialize(Of T)(value As T, Optional ByVal indented As Boolean = False) As String
  8.        If value Is Nothing Then
  9.            Throw New Exception("XMLSerializer - The value passed is null!")
  10.            Return ""
  11.        End If
  12.        Try
  13.  
  14.            Dim xmlserializer As New XmlSerializer(GetType(T))
  15.            Dim serializeXml As String = ""
  16.  
  17.            Using stringWriter As New StringWriter()
  18.  
  19.                Using writer As XmlWriter = XmlWriter.Create(stringWriter)
  20.                    xmlserializer.Serialize(writer, value)
  21.                    serializeXml = stringWriter.ToString()
  22.                End Using
  23.  
  24.                If indented Then
  25.                    serializeXml = Beautify(serializeXml)
  26.                End If
  27.  
  28.            End Using
  29.  
  30.            Return serializeXml
  31.        Catch ex As Exception
  32.            Throw New Exception(ex.Message)
  33.            Return ""
  34.        End Try
  35.    End Function
  36.  
  37.    Public Shared Function Deserialize(Of T)(value As String) As T
  38.  
  39.        Try
  40.            Dim returnvalue As New Object()
  41.            Dim xmlserializer As New XmlSerializer(GetType(T))
  42.            Dim reader As TextReader = New StringReader(value)
  43.  
  44.            returnvalue = xmlserializer.Deserialize(reader)
  45.  
  46.            reader.Close()
  47.            Return DirectCast(returnvalue, T)
  48.        Catch ex As Exception
  49.            Throw New Exception(ex.Message)
  50.            Return Nothing
  51.        End Try
  52.  
  53.    End Function
  54.  
  55.    Public Shared Sub SerializeToFile(Of T)(value As T, filePath As String, Optional ByVal indented As Boolean = False)
  56.        If value Is Nothing Then
  57.            Throw New Exception("XMLSerializer - The value passed is null!")
  58.        End If
  59.        Try
  60.            Dim xmlserializer As New XmlSerializer(GetType(T))
  61.            Using fileWriter As StreamWriter = New StreamWriter(filePath)
  62.                If indented Then
  63.                    Using stringWriter As New StringWriter()
  64.                        Using writer As XmlWriter = XmlWriter.Create(stringWriter)
  65.                            xmlserializer.Serialize(writer, value)
  66.                            fileWriter.WriteLine(Beautify(stringWriter.ToString()))
  67.                        End Using
  68.                    End Using
  69.                Else
  70.                    Using writer As XmlWriter = XmlWriter.Create(fileWriter)
  71.                        xmlserializer.Serialize(writer, value)
  72.                    End Using
  73.                End If
  74.            End Using
  75.  
  76.        Catch ex As Exception
  77.            Throw New Exception(ex.Message)
  78.        End Try
  79.    End Sub
  80.  
  81.    Public Shared Function DeserializeFromFile(Of T)(filePath As String) As T
  82.  
  83.        Try
  84.            Dim returnvalue As New Object()
  85.            Dim xmlserializer As New XmlSerializer(GetType(T))
  86.            Using reader As TextReader = New StreamReader(filePath)
  87.                returnvalue = xmlserializer.Deserialize(reader)
  88.            End Using
  89.            Return DirectCast(returnvalue, T)
  90.        Catch ex As Exception
  91.            Throw New Exception(ex.Message)
  92.            Return Nothing
  93.        End Try
  94.  
  95.    End Function
  96.  
  97.    Public Shared Function Beautify(obj As Object) As String
  98.        Dim doc As New XmlDocument()
  99.        If obj.[GetType]() Is GetType(String) Then
  100.            If Not [String].IsNullOrEmpty(DirectCast(obj, String)) Then
  101.                Try
  102.                    doc.LoadXml(DirectCast(obj, String))
  103.                Catch ex As Exception
  104.                    Throw New Exception("XMLIndenter - Wrong string format! [" + ex.Message & "]")
  105.                    Return ""
  106.                End Try
  107.            Else
  108.                Throw New Exception("XMLIndenter - String is null!")
  109.                Return ""
  110.            End If
  111.        ElseIf obj.[GetType]() Is GetType(XmlDocument) Then
  112.            doc = DirectCast(obj, XmlDocument)
  113.        Else
  114.            Throw New Exception("XMLIndenter - Not supported type!")
  115.            Return ""
  116.        End If
  117.        Dim returnValue As String = ""
  118.        Using w As New MemoryStream()
  119.            Using writer As New XmlTextWriter(w, Encoding.Unicode)
  120.                writer.Formatting = Formatting.Indented
  121.                doc.WriteContentTo(writer)
  122.  
  123.                writer.Flush()
  124.                w.Seek(0L, SeekOrigin.Begin)
  125.  
  126.                Using reader As New StreamReader(w)
  127.                    returnValue = reader.ReadToEnd()
  128.                End Using
  129.            End Using
  130.        End Using
  131.    End Function
  132.  
  133. End Class

Un saludo.
474  Foros Generales / Dudas Generales / Re: dudas internet en: 24 Mayo 2014, 12:22 pm
A lo mejor es eso lo que te consume mucho ancho de banda ;)
475  Foros Generales / Sugerencias y dudas sobre el Foro / Re: chat de elhacker.net en: 11 Mayo 2014, 11:14 am
jajaja Que va, solo lo digo por si queréis hablar con más gente ;) También podría haber mandado os links del IRC y TS3 pero no me los se... :rolleyes:
476  Foros Generales / Sugerencias y dudas sobre el Foro / Re: chat de elhacker.net en: 10 Mayo 2014, 21:03 pm
EHN tiene IRC, TS3, hasta un grupo que cree yo por Skype...

Si queréis meteros, pues mi Skype es "ikillnukes" ;)
477  Foros Generales / Sugerencias y dudas sobre el Foro / Re: ¿error del foro? en: 10 Mayo 2014, 21:02 pm
Antes el de UNDER también salia repetido :rolleyes:
478  Foros Generales / Sugerencias y dudas sobre el Foro / Re: Hacker. Net en: 10 Mayo 2014, 20:58 pm
Cuando sea ENH-DEV 2014... :-X
479  Informática / Hardware / Re: ¿Portátil o torre? en: 1 Mayo 2014, 00:05 am
Según cuanta potencia necesites, en general, no siempre las torres suelen tener más potencia y duran más... Si vas a hacer cosas en 3D una torre es la mejor opción.

Un saludo.
480  Foros Generales / Dudas Generales / Re: navegar sin imagenes en: 24 Abril 2014, 15:02 pm
Un gif es una superposición de imágenes animadas, por tanto, es razonable... :silbar:
Páginas: 1 ... 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 [48] 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ... 238
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines