コード例 #1
0
ファイル: LogAttribute.cs プロジェクト: jmelgarejoy/SWCarCool
        // This method is executed at runtime inside your application,
        // when target methods exit with success.
        public override void OnSuccess(MethodExecutionArgs args)
        {
            try
            {
                string tramaOutput = "";
                manejadorLogEventos.Break();
                try
                {
                    tramaOutput = Helper.SerializarJsonObjecto(args.ReturnValue);
                }
                catch (Exception ex)
                {
                    tramaOutput = "ERROR AL SERIALIZAR JSON";
                    ManejadorExcepciones.PublicarExcepcion(ex, PoliticaExcepcion.ServicioWCF);
                }

                string ip = String.Empty;

                var props            = OperationContext.Current.IncomingMessageProperties;
                var endpointProperty = props[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                if (endpointProperty != null)
                {
                    ip = endpointProperty.Address;
                }

                var flagTrazasServicioWCF = ConfigurationManager.AppSettings["FlagTrazasServicioWCF"];
                if (flagTrazasServicioWCF == "S")
                {
                    try
                    {
                        // var objetoTrazabilidad = Helper.ConvertirAObjeto<ObjetoTrazabilidad>("ObjetoTrazabilidad", tramaInput);

                        manejadorLogEventos.GrabarLogMapaBD(manejadorLogEventos.inicio, manejadorLogEventos.fin, manejadorLogEventos.GetDuracion(), (manejadorLogEventos.GetDuracion() / 1000), ip, nombreUsuario, "WCF", url, tramaInput, tramaOutput, "LOG_MAPA_SERVICIO", null, null, null, null);

                        // manejadorLogEventos.GrabarLogMapaBD(manejadorLogEventos.inicio, manejadorLogEventos.fin, manejadorLogEventos.GetDuracion(), (manejadorLogEventos.GetDuracion() / 1000), ip, nombreUsuario, "WCF", url, tramaInput, tramaOutput, "LOG_MAPA_SERVICIO", null, objetoTrazabilidad != null ? objetoTrazabilidad.GuidFormulario : null, objetoTrazabilidad != null ? objetoTrazabilidad.ValorReferencial : null, objetoTrazabilidad != null ? objetoTrazabilidad.GuidEvento : null);
                    }
                    catch (Exception)
                    {
                        manejadorLogEventos.GrabarLogMapa(manejadorLogEventos.inicio.ToString(), manejadorLogEventos.fin.ToString(), manejadorLogEventos.GetDuracion().ToString(), (manejadorLogEventos.GetDuracion() / 1000).ToString(), ip, nombreUsuario, "WCF", url, tramaInput, tramaOutput);
                    }
                    //
                }
            }
            catch (Exception ex)
            {
                ManejadorExcepciones.PublicarExcepcion(ex, PoliticaExcepcion.ServicioWCF);
            }
        }
コード例 #2
0
        public void GrabarLogMapaBD(DateTime fechaInicio, DateTime FechaFin, double Duracion, Double DuracionSeg, string ip, string nombreUsuario, String TipoLlamada, string url, string tramaInput, string tramaOutput, string TipoEntrada, System.Data.SqlClient.SqlConnection conn = null, string idTrazabilidad = null, string valor1 = null, string IdEvento = null)
        {
            string cadena = "";

            if (ConfigurationManager.ConnectionStrings["cnxANTP"] != null)
            {
                cadena = ConfigurationManager.ConnectionStrings["cnxANTP"].ConnectionString;

                try
                {
                    using (TransactionScope transactionScope1 = new TransactionScope(TransactionScopeOption.RequiresNew))//(TransactionScopeOption.RequiresNew, option1))
                    {
                        using (SqlConnection conn1 = new SqlConnection(cadena))
                        {
                            try { conn1.Open(); }
                            catch { }

                            SqlCommand cm = new SqlCommand("usp_InsertLogMapa", conn1);
                            cm.CommandType = System.Data.CommandType.StoredProcedure;
                            cm.Parameters.Add("@FechaInicio", System.Data.SqlDbType.DateTime).Value = fechaInicio;
                            cm.Parameters.Add("@FechaFin", System.Data.SqlDbType.DateTime).Value    = FechaFin;
                            cm.Parameters.Add("@DuracionMS", System.Data.SqlDbType.Decimal).Value   = Duracion;
                            cm.Parameters.Add("@DuracionSeg", System.Data.SqlDbType.Decimal).Value  = DuracionSeg;


                            if (!string.IsNullOrEmpty(IdEvento))
                            {
                                cm.Parameters.Add("@IdEvento", System.Data.SqlDbType.Char).Value = IdEvento;
                            }
                            else
                            {
                                cm.Parameters.Add("@IdEvento", System.Data.SqlDbType.Char).Value = DBNull.Value;
                            }


                            // INI vj 01/09/2014 - Modificación
                            if (!string.IsNullOrEmpty(idTrazabilidad))
                            {
                                cm.Parameters.Add("@IdTrazabilidad", System.Data.SqlDbType.Char).Value = idTrazabilidad;
                            }
                            else
                            {
                                cm.Parameters.Add("@IdTrazabilidad", System.Data.SqlDbType.Char).Value = DBNull.Value;
                            }
                            if (!string.IsNullOrEmpty(valor1))
                            {
                                cm.Parameters.Add("@Valor1", System.Data.SqlDbType.VarChar).Value = valor1;
                            }
                            else
                            {
                                cm.Parameters.Add("@Valor1", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }
                            // FIN vj 01/09/2014 - Modificación

                            if (!string.IsNullOrEmpty(ip))
                            {
                                cm.Parameters.Add("@IPLocal", System.Data.SqlDbType.VarChar).Value = ip;
                            }
                            else
                            {
                                cm.Parameters.Add("@IPLocal", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(nombreUsuario))
                            {
                                cm.Parameters.Add("@Usuario", System.Data.SqlDbType.VarChar).Value = nombreUsuario;
                            }
                            else
                            {
                                cm.Parameters.Add("@Usuario", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(TipoLlamada))
                            {
                                cm.Parameters.Add("@TipoLlamada", System.Data.SqlDbType.VarChar).Value = TipoLlamada;
                            }
                            else
                            {
                                cm.Parameters.Add("@TipoLlamada", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(url))
                            {
                                cm.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = url;
                            }
                            else
                            {
                                cm.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(tramaInput))
                            {
                                cm.Parameters.Add("@JsonRequest", System.Data.SqlDbType.Text).Value = tramaInput;
                            }
                            else
                            {
                                cm.Parameters.Add("@JsonRequest", System.Data.SqlDbType.Text).Value = tramaInput;
                            }

                            if (!string.IsNullOrEmpty(tramaOutput))
                            {
                                cm.Parameters.Add("@JsonResponse", System.Data.SqlDbType.Text).Value = tramaOutput;
                            }
                            else
                            {
                                cm.Parameters.Add("@JsonResponse", System.Data.SqlDbType.Text).Value = DBNull.Value;
                            }

                            if (!string.IsNullOrEmpty(TipoEntrada))
                            {
                                cm.Parameters.Add("@TipoEntrada", System.Data.SqlDbType.VarChar).Value = TipoEntrada;
                            }
                            else
                            {
                                cm.Parameters.Add("@TipoEntrada", System.Data.SqlDbType.VarChar).Value = DBNull.Value;
                            }

                            cm.ExecuteNonQuery();

                            try { conn1.Close(); }
                            catch { }
                        }

                        transactionScope1.Complete();
                    }
                }
                catch (Exception ex)
                {
                    var manejadorLogEventos = new ManejadorLogEventos();
                    manejadorLogEventos.GrabarLogMapa(
                        fechaInicio.ToString(),
                        FechaFin.ToString(),
                        Duracion.ToString(),
                        DuracionSeg.ToString(),
                        ip,
                        nombreUsuario,
                        TipoLlamada,
                        url,
                        ex.Message,
                        ex.ToString(),
                        "Error en GrabarLogMapaBD");
                }
            }
            else
            {
                var manejadorLogEventos = new ManejadorLogEventos();
                manejadorLogEventos.GrabarLogMapa(fechaInicio.ToString(), FechaFin.ToString(), Math.Round(Duracion, 2).ToString(), Math.Round(DuracionSeg, 2).ToString(), ip, nombreUsuario, TipoLlamada, url, tramaInput, tramaOutput, IdEvento != null ? IdEvento : "");
            }
        }