Versión Copiada del tfs
This commit is contained in:
107
tsExcepcion.vb
Normal file
107
tsExcepcion.vb
Normal file
@@ -0,0 +1,107 @@
|
||||
Imports System
|
||||
Imports System.Runtime.Serialization
|
||||
Imports Microsoft.VisualBasic
|
||||
Imports Microsoft.VisualBasic.CompilerServices
|
||||
|
||||
|
||||
|
||||
<Serializable>
|
||||
Public Class tsExcepcion
|
||||
Inherits ApplicationException
|
||||
Public Enum ModoBusquedaEnum As Long
|
||||
EnTodaLaCadena
|
||||
DesdeExcepcionSiguiente
|
||||
SoloEnExcepcionActual
|
||||
End Enum
|
||||
|
||||
Private pCodigo As String
|
||||
|
||||
Private pDatosExtra As String
|
||||
|
||||
Public ReadOnly Property Codigo As String
|
||||
Get
|
||||
Return pCodigo
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property DatosExtra As String
|
||||
Get
|
||||
Return pDatosExtra
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub New(message As String, Optional argCodigo As String = Nothing, Optional argDatosExtra As String = Nothing)
|
||||
MyBase.New(message)
|
||||
pCodigo = argCodigo
|
||||
pDatosExtra = argDatosExtra
|
||||
End Sub
|
||||
|
||||
Public Sub New(message As String, innerException As Exception, Optional argCodigo As String = Nothing, Optional argDatosExtra As String = Nothing)
|
||||
MyBase.New(message, innerException)
|
||||
pCodigo = argCodigo
|
||||
pDatosExtra = argDatosExtra
|
||||
End Sub
|
||||
|
||||
Protected Sub New(info As SerializationInfo, context As StreamingContext)
|
||||
MyBase.New(info, context)
|
||||
pCodigo = info.GetString("pCodigo")
|
||||
pDatosExtra = info.GetString("pDatosExtra")
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub GetObjectData(info As SerializationInfo, context As StreamingContext)
|
||||
MyBase.GetObjectData(info, context)
|
||||
info.AddValue("pCodigo", pCodigo)
|
||||
info.AddValue("pDatosExtra", pDatosExtra)
|
||||
End Sub
|
||||
|
||||
Public Shared Function Buscar(excepcion As Exception, patronCodigo As String, Optional modoBusqueda As ModoBusquedaEnum = ModoBusquedaEnum.EnTodaLaCadena) As tsExcepcion
|
||||
Try
|
||||
If excepcion Is Nothing Then
|
||||
Throw New tsExcepcion("'excepcion' es Nothing.")
|
||||
End If
|
||||
|
||||
If Not [Enum].IsDefined(GetType(ModoBusquedaEnum), modoBusqueda) Then
|
||||
Throw New tsExcepcion("Modo de búsqueda incorrecto: " & Conversions.ToString(modoBusqueda))
|
||||
End If
|
||||
|
||||
Dim ex = excepcion
|
||||
If modoBusqueda = ModoBusquedaEnum.DesdeExcepcionSiguiente Then
|
||||
ex = ex.InnerException
|
||||
End If
|
||||
|
||||
Dim num = 1
|
||||
Do
|
||||
If ex Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
If TypeOf ex Is tsExcepcion Then
|
||||
Dim text = CType(ex, tsExcepcion).Codigo
|
||||
If Equals(text, Nothing) Then
|
||||
text = ""
|
||||
End If
|
||||
|
||||
If LikeOperator.LikeString(text, patronCodigo, CompareMethod.Binary) Then
|
||||
Return CType(ex, tsExcepcion)
|
||||
End If
|
||||
End If
|
||||
|
||||
ex = ex.InnerException
|
||||
If modoBusqueda = ModoBusquedaEnum.SoloEnExcepcionActual Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
num = num + 1
|
||||
Loop While num <= 1000000
|
||||
Throw New tsExcepcion("Bucle cuasi-infinito.")
|
||||
Catch ex2 As Exception
|
||||
ProjectData.SetProjectError(ex2)
|
||||
Dim ex3 = ex2
|
||||
Throw New tsExcepcion("Buscando tsExcepcion con código: " & patronCodigo & vbCrLf & ex3.Message, ex3)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Shared Function Es(excepcion As Exception, patronCodigo As String, Optional modoBusqueda As ModoBusquedaEnum = ModoBusquedaEnum.EnTodaLaCadena) As Boolean
|
||||
Return Buscar(excepcion, patronCodigo, modoBusqueda) IsNot Nothing
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user