static void Main(string[] args) { //Primero nos autenticamos string strUsuario = "deferarib"; string strPassword = "******"; if (CApiAuth.GetToken(strUsuario, strPassword)) { //Obtener los datos try { //Obtenemos lista var rn = new RnSegMensajeserror(); List <EntSegMensajeserror> lista = rn.ObtenerLista(); System.Console.WriteLine("Lista: " + lista.Count); System.Console.WriteLine("-------------------------------"); //EntSegMensajeserror obj = rn.ObtenerObjeto(1); //Console.WriteLine("Objeto: " + obj.accionsme); //Console.WriteLine("-------------------------------"); //obj.apiestadosme = "R. Alonzo"; //rn.Update(obj); } catch (Exception exp) { if (exp is CApiExcepcion) { var miExp = (CApiExcepcion)exp; System.Console.WriteLine(miExp.error); System.Console.WriteLine(miExp.causa); System.Console.WriteLine(miExp.accion); System.Console.WriteLine(miExp.comentario); System.Console.WriteLine(miExp.origen); } else { System.Console.WriteLine(exp); } } } System.Console.ReadKey(); }
public static void CargarError(Exception _myExp, out string mensaje, out string causa, out string accion, out string comentario, out string origen) { mensaje = ""; causa = ""; accion = ""; comentario = ""; origen = ""; try { var rn = new RnSegMensajeserror(); EntSegMensajeserror obj = new EntSegMensajeserror(); if (_myExp.GetType() == typeof(PostgresException)) { NpgsqlException sqlExp = (NpgsqlException)_myExp; string strCodigoError = sqlExp.Message.Replace("P0001: ", ""); obj = rn.ObtenerObjeto(EntSegMensajeserror.Fields.aplicacionerrorsme, "'" + strCodigoError.Substring(0, 9) + "'"); if (obj != null) { string descripcionMsg = obj.descripcionsme; string errorMsg = sqlExp.Message; while (descripcionMsg.Contains("%n")) { int indiceInicio = errorMsg.IndexOf("##"); errorMsg = ReplaceFirst(errorMsg, "##", " "); int indiceFinal = errorMsg.IndexOf("##"); if (indiceFinal < 0) { indiceFinal = errorMsg.Length; } string strVariable = errorMsg.Substring(indiceInicio, indiceFinal - indiceInicio); descripcionMsg = ReplaceFirst(descripcionMsg, "%n", strVariable); } mensaje = obj.aplicacionerrorsme + ": " + descripcionMsg; causa = obj.causasme; accion = obj.accionsme; comentario = obj.comentariosme; origen = obj.origensme; } else { mensaje = "Se ha producido un error. Revise el Detalle adjunto."; causa = sqlExp.Message; } } else { obj = rn.ObtenerObjeto(EntSegMensajeserror.Fields.aplicacionerrorsme, "'" + _myExp.Message.Substring(0, 9) + "'"); if (obj != null) { string descripcionMsg = obj.descripcionsme; string errorMsg = _myExp.Message; while (descripcionMsg.Contains("%n")) { int indiceInicio = errorMsg.IndexOf("##"); errorMsg = ReplaceFirst(errorMsg, "##", " "); int indiceFinal = errorMsg.IndexOf("##"); if (indiceFinal < 0) { indiceFinal = errorMsg.Length; } string strVariable = errorMsg.Substring(indiceInicio, indiceFinal - indiceInicio); descripcionMsg = ReplaceFirst(descripcionMsg, "%n", strVariable); } mensaje = obj.aplicacionerrorsme + ": " + descripcionMsg; causa = obj.causasme; accion = obj.accionsme; comentario = obj.comentariosme; origen = obj.origensme; } else { mensaje = _myExp.Message; causa = _myExp.StackTrace; } } } catch (Exception exp) { mensaje = _myExp.Message; causa = _myExp.StackTrace; } }