Example #1
0
        public void RegistrarTiempoEjecucion(RequestLogEvento request, object data = null)
        {
            try
            {
                if (!isStopped)
                {
                    Break();
                }
                string json = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.None, new IsoDateTimeConverter()
                {
                    DateTimeFormat = "dd.MM.yyyy HH:mm:ss"
                });                                                                                                                                                     // HH:mm:ss

                string mensaje = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}",
                                               request.NombreMaquina
                                               , request.DireccionIP
                                               , request.NombreUsuario
                                               , request.Formulario
                                               , request.NombreEvento
                                               , inicio
                                               , fin
                                               , GetDuracion(), json);

                (new ManejadorLog()).RegistrarTiempoEjecucion(mensaje);
            }
            catch (Exception ex)
            {
                ManejadorExcepciones.PublicarExcepcion(ex, PoliticaExcepcion.Framework);
            }

            //Cursor.Current = Cursors.Default;
        }
Example #2
0
        // This method is executed at runtime inside your application,
        // before target methods.
        public override void OnEntry(MethodExecutionArgs args)
        {
            try
            {
                manejadorLogEventos = new ManejadorLogEventos();

                url = OperationContext.Current.IncomingMessageHeaders.To.AbsoluteUri;
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("+ Entering ");

                if (args.Arguments != null && args.Arguments.Count > 0)
                {
                    tramaInput = Helper.SerializarJsonObjecto(args.Arguments[0]);


                    // nombreUsuario = getUsuario(args.Arguments[0]);
                    nombreUsuario = Usuario;
                }
                args.MethodExecutionTag = stringBuilder;
            }
            catch (Exception ex)
            {
                ManejadorExcepciones.PublicarExcepcion(ex, PoliticaExcepcion.ServicioWCF);
            }
        }
Example #3
0
        //private string getUsuario(object argumento)
        //{
        //    try
        //    {

        //        return req.UsuarioSeguridadDTO.CuentaUsuarioRed;
        //    }
        //    catch
        //    {
        //        return "";
        //    }
        //}


        public override void OnException(MethodExecutionArgs args)
        {
            try
            {
                manejadorLogEventos.Break();
                string tramaOutput = Helper.SerializarJsonObjecto(args.ReturnValue);

                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
                    {
                        manejadorLogEventos.GrabarLogMapaBD(manejadorLogEventos.inicio, manejadorLogEventos.fin, manejadorLogEventos.GetDuracion(), (manejadorLogEventos.GetDuracion() / 1000), ip, nombreUsuario, "WCF-ERROR", url, tramaInput, tramaOutput, "LOG_MAPA_SERVICIO");
                    }
                    catch (Exception)
                    {
                        manejadorLogEventos.GrabarLogMapa(manejadorLogEventos.inicio.ToString(), manejadorLogEventos.fin.ToString(), manejadorLogEventos.GetDuracion().ToString(), (manejadorLogEventos.GetDuracion() / 1000).ToString(), ip, nombreUsuario, "WCF-ERROR", url, tramaInput, tramaOutput);
                    }
                }
            }
            catch (Exception ex)
            {
                ManejadorExcepciones.PublicarExcepcion(ex, PoliticaExcepcion.ServicioWCF);
            }
        }
Example #4
0
        // 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);
            }
        }
Example #5
0
        public Y DeserializarJSON <T, Y>(T request, string url, string GuidProceso = null, string GuidEvento = null, string soapAction = "", bool consultaSap = false)
        {
            object vnull          = null;
            Y      resultServicio = (Y)(vnull);

            ManejadorLogEventos manejadorLogEventosMAPA       = new ManejadorLogEventos();
            ManejadorLogEventos manejadorLogEventosLOGERRORES = new ManejadorLogEventos();
            String Request  = "";
            String Response = "";
            var    flagTrazasServicioWCF     = ConfigurationManager.AppSettings["FlagTrazasServicioWCF"];
            var    flagTrazasServicioBrocker = ConfigurationManager.AppSettings["FlagTrazasServicioBrocker"];

            try
            {
                var RESTProxy = new MyWebClient();
                if (!string.IsNullOrEmpty(soapAction))
                {
                    RESTProxy.Headers["SOAPAction"] = soapAction;
                }
                RESTProxy.Headers["Content-type"] = "application/json";

                MemoryStream ms             = new MemoryStream();
                Stream       stream         = ms;
                bool         SeEjecutadeWeb = true;
                bool         conrequest     = true;
                if (request.ToString() == string.Empty)
                {
                    try
                    {
                        stream         = RESTProxy.OpenRead(url);
                        SeEjecutadeWeb = true;
                    }
                    catch
                    {
                        SeEjecutadeWeb = false;
                        ms             = new MemoryStream(new UTF8Encoding().GetBytes(""));
                    }
                    conrequest = false;
                }
                else
                {
                    if (consultaSap)
                    {
                        Request = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.None, new IsoDateTimeConverter()
                        {
                            DateTimeFormat = "dd.MM.yyyy"
                        });                                                                                                                                           // HH:mm:ss

                        ms          = new MemoryStream(new UTF8Encoding().GetBytes(Request));
                        ms.Position = 0;
                    }
                    else
                    {
                        var serializerToUpload = new DataContractJsonSerializer(typeof(T));
                        serializerToUpload.WriteObject(ms, request);
                        ms.Position = 0;

                        Request = Encoding.UTF8.GetString(ms.ToArray());
                    }

                    if (consultaSap && flagTrazasServicioWCF == "S")
                    {
                        manejadorLogEventosLOGERRORES.GuardarTrama2(manejadorLogEventosLOGERRORES.inicio, "REQUEST", url, Helper.LocalIPAddress(), Environment.UserName, Request);
                    }
                }


                //


                if (SeEjecutadeWeb == false || conrequest == true)
                {
                    System.Net.ServicePointManager.Expect100Continue = false;
                    var dc   = System.Text.Encoding.UTF8.GetString(RESTProxy.UploadData(url, "POST", ms.ToArray())).ToCharArray();
                    var data = System.Text.Encoding.UTF8.GetBytes(dc);

                    Stream stream_response;
                    stream_response          = new MemoryStream(data);
                    stream_response.Position = 0;
                    var sr_response = new StreamReader(stream_response);
                    sr_response.ReadToEnd();

                    Response = Encoding.UTF8.GetString(data.ToArray());
                    if (consultaSap && flagTrazasServicioBrocker == "S")
                    {
                        manejadorLogEventosLOGERRORES.Break();
                        manejadorLogEventosLOGERRORES.GuardarTrama2(manejadorLogEventosLOGERRORES.fin, "RESPONSE", url, Helper.LocalIPAddress(), Environment.UserName, Response);
                    }
                    stream = new MemoryStream(data);
                }



                if (consultaSap)
                {
                    StreamReader sReader = new StreamReader(stream);
                    Response = sReader.ReadToEnd();

                    resultServicio = (Y)JsonConvert.DeserializeObject(Response, typeof(Y), new JsonSerializerSettings()
                    {
                        NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                    });

                    manejadorLogEventosMAPA.Break();
                    if (flagTrazasServicioBrocker == "S")
                    {
                        manejadorLogEventosMAPA.GrabarLogMapaBD(manejadorLogEventosMAPA.inicio, manejadorLogEventosMAPA.fin, manejadorLogEventosMAPA.GetDuracion(), (manejadorLogEventosMAPA.GetDuracion() / 1000), Helper.LocalIPAddress(), "", "BROKER", url, Request, Response, "LOG_MAPA_BROKER", null, GuidProceso, null, GuidEvento);
                    }
                }
                else
                {
                    var obj = new DataContractJsonSerializer(typeof(Y));
                    resultServicio = (Y)obj.ReadObject(stream);

                    manejadorLogEventosMAPA.Break();
                    if (flagTrazasServicioWCF == "S")
                    {
                        manejadorLogEventosMAPA.GrabarLogMapaBD(manejadorLogEventosMAPA.inicio, manejadorLogEventosMAPA.fin, manejadorLogEventosMAPA.GetDuracion(), (manejadorLogEventosMAPA.GetDuracion() / 1000), Helper.LocalIPAddress(), "", "PROXY", url, Request, Response, "LOG_MAPA_WCF", null, GuidProceso, null, GuidEvento);
                    }
                }
            }
            catch (Exception ex)
            {
                ManejadorExcepciones.PublicarExcepcion(ex, PoliticaExcepcion.Framework);

                if (flagTrazasServicioBrocker == "S")
                {
                    manejadorLogEventosMAPA.Break();
                    manejadorLogEventosMAPA.GrabarLogMapaBD(manejadorLogEventosMAPA.inicio, manejadorLogEventosMAPA.fin, manejadorLogEventosMAPA.GetDuracion(), (manejadorLogEventosMAPA.GetDuracion() / 1000), Helper.LocalIPAddress(), "", "PROXY", url, Request, ex.Message, "LOG_MAPA_WCF", null, GuidProceso, null, GuidEvento);
                }
            }
            return(resultServicio);
        }