Пример #1
0
        public Proveedor consultarPadronRest(string cuit)
        {
            log.Info("Cuit Ingresado " + cuit);
            cuit = Funciones.ConvertToCUIT(cuit);

            Certificacion[] certificaciones = new Certificacion[0];
            Proveedor       proveedor       = new Proveedor();
            IT_Mensaje      mensaje         = new IT_Mensaje();

            string usuarioProxy = ConfigurationManager.AppSettings["CPA_Proxy_Usuario"];
            string passwdProxy  = ConfigurationManager.AppSettings["CPA_Proxy_Passwd"];
            string domainProxy  = ConfigurationManager.AppSettings["CPA_Proxy_Dominio"];

            string WSApiEndpoint  = ConfigurationManager.AppSettings["WS_ApiEndpoint"];
            string WSApiParameter = ConfigurationManager.AppSettings["WS_ApiParameter"];
            Uri    WSUriApi       = new Uri(WSApiEndpoint + "?" + WSApiParameter + "=" + cuit);

            var client = new RestClient(WSApiEndpoint);

            client.Proxy = Funciones.CrearProxy();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 |
                                                   SecurityProtocolType.Tls | SecurityProtocolType.Tls11;

            ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            mensaje.Consulta = cuit;
            mensaje.Mensaje  = string.Empty;

            var request = new RestRequest("?" + WSApiParameter + "=" + cuit, Method.GET);

            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            string content = string.Empty;

            log.Info("Invocacion al Endpoint de Renappo " + WSApiEndpoint + " con el siguiente parametro y valor " + WSApiParameter + "=" + cuit);
            timer.Start();
            var response = client.Execute(request);

            timer.Stop();
            long tiempo = timer.ElapsedMilliseconds / 1000;

            log.Info("Tiempo Renappo - invocacion: " + tiempo + "segundos");

            timer.Restart();
            if (response != null && !string.IsNullOrEmpty(response.Content) && response.StatusCode == HttpStatusCode.OK)
            {
                log.Info("Respuesta Renappo - Servicio : " + Environment.NewLine + JValue.Parse(response.Content)?.ToString(Newtonsoft.Json.Formatting.Indented));

                log.Info("Parseando el la respuesta previamente obtenida");
                certificaciones = JsonConvert.DeserializeObject <Certificacion[]>(response.Content);
            }
            else
            {
                mensaje.Tipo = "E";
                log.Info(
                    "Respuesta Renappo - Servicio : " +
                    Environment.NewLine +
                    "Estado - " + response?.StatusCode +
                    Environment.NewLine +
                    "Descripcion" + response?.StatusDescription);
            }

            if (certificaciones != null && certificaciones.Any())
            {
                if (certificaciones.Any(x => x.Fallo))
                {
                    mensaje.Mensaje       = certificaciones.FirstOrDefault(x => x.Fallo)?.Mensaje;
                    mensaje.Tipo          = "E";
                    proveedor.Detalle     = null;
                    proveedor.Actividades = null;
                }
                else
                {
                    string mensajeVacio = "No se pudo obtener información";
                    mensaje.Tipo = "S";

                    IT_Detalle          detalle     = new IT_Detalle();
                    List <IT_Actividad> actividades = new List <IT_Actividad>();

                    foreach (var certificacion in certificaciones)
                    {
                        detalle.RazonSocial        = !string.IsNullOrEmpty(certificacion.RazonSocial) ? certificacion.RazonSocial : mensajeVacio;
                        detalle.Intermediario      = !string.IsNullOrEmpty(certificacion.Medio) ? certificacion.Medio : mensajeVacio;
                        detalle.Habilitado         = !string.IsNullOrEmpty(certificacion.Habilitado) ? certificacion.Habilitado : mensajeVacio;
                        detalle.FechaVigenciaDesde = Funciones.ConvertToFechaFormato(Funciones.ConvertToFechaVigencia(certificacion.FechaVigencia, Parametros.FechaVigencia.Desde), null);
                        detalle.FechaVigenciaHasta = Funciones.ConvertToFechaFormato(Funciones.ConvertToFechaVigencia(certificacion.FechaVigencia, Parametros.FechaVigencia.Hasta), null);

                        #region Tarifario
                        if (!string.IsNullOrEmpty(certificacion.Tarifario))
                        {
                            var tarifario = SubirArchivoRest(certificacion.Tarifario);
                            if (tarifario != null && !tarifario.Error && !string.IsNullOrEmpty(tarifario.Id))
                            {
                                detalle.Tarifario = tarifario.Id;
                            }
                            else
                            {
                                mensaje.Tipo      = "W";
                                mensaje.Mensaje   = mensaje.Mensaje + tarifario.Detalle + "; ";
                                detalle.Tarifario = null;
                            }
                        }
                        else
                        {
                            detalle.Tarifario = mensajeVacio;
                        }
                        #endregion

                        #region Cobertura Geografica
                        if (!string.IsNullOrEmpty(certificacion.CoberturaGeografica))
                        {
                            var cobertura = SubirArchivoRest(certificacion.CoberturaGeografica);
                            if (cobertura != null && !cobertura.Error && !string.IsNullOrEmpty(cobertura.Id))
                            {
                                detalle.CoberturaGeografica = cobertura.Id;
                            }
                            else
                            {
                                mensaje.Tipo                = "W";
                                mensaje.Mensaje             = mensaje.Mensaje + cobertura.Detalle + "; ";
                                detalle.CoberturaGeografica = null;
                            }
                        }
                        else
                        {
                            detalle.CoberturaGeografica = mensajeVacio;
                        }
                        #endregion

                        if (!string.IsNullOrEmpty(certificacion.Certificado))
                        {
                            log.Info("Parseando el campo certificado para obtener la/s actividad/es del Proveedor");
                            var elementos = XElement.Parse(certificacion.Certificado);

                            if (elementos.HasElements)
                            {
                                foreach (var elemento in elementos.Elements())
                                {
                                    var elementosTexto = elemento.Descendants()?.Where(x => x.FirstNode != null && x.FirstNode.NodeType == XmlNodeType.Text);

                                    if (elementosTexto != null && elementosTexto.Any())
                                    {
                                        var actividad = new IT_Actividad();
                                        actividad.Actividad   = elementosTexto?.FirstOrDefault(x => x.Parent.Value.Contains("CERTIFICADO HABILITANTE") && x.Name == "strong").Value;
                                        actividad.Fecha       = Funciones.ConvertToFechaFormato(elementosTexto?.FirstOrDefault(x => x.Value.Contains("Fecha:"))?.Value, "Fecha:");
                                        actividad.Vencimiento = Funciones.ConvertToFechaFormato(elementosTexto?.FirstOrDefault(x => x.Value.Contains("Vencimiento:"))?.Value, "Vencimiento:");
                                        actividad.Certificado = elementosTexto?.FirstOrDefault(x => x.Value.Contains("RENAPPO")).Value.Trim() ?? mensajeVacio;

                                        actividades.Add(actividad);
                                    }
                                }
                            }
                            proveedor.Actividades = actividades.ToArray();
                        }
                        else
                        {
                            log.Info("No se pudo obtener la/s actividad/es del Proveedor");
                        }
                    }
                    proveedor.Detalle = detalle;
                }
            }

            proveedor.Mensaje = mensaje;

            timer.Stop();
            tiempo = timer.ElapsedMilliseconds / 1000;
            log.Info("Tiempo Servicio - procesamiento: " + tiempo + "segundos");

            return(proveedor);
        }
Пример #2
0
        public Proveedor consultarPadron(string cuit)
        {
            log.Info("Cuit Ingresado " + cuit);
            cuit = Funciones.ConvertToCUIT(cuit);

            Certificacion[] certificaciones = new Certificacion[0];
            Proveedor       proveedor       = new Proveedor();

            string usuarioProxy = ConfigurationManager.AppSettings["CPA_Proxy_Usuario"];
            string passwdProxy  = ConfigurationManager.AppSettings["CPA_Proxy_Passwd"];
            string domainProxy  = ConfigurationManager.AppSettings["CPA_Proxy_Dominio"];

            string WSApiEndpoint  = ConfigurationManager.AppSettings["WS_ApiEndpoint"];
            string WSApiParameter = ConfigurationManager.AppSettings["WS_ApiParameter"];
            Uri    WSUriApi       = new Uri(WSApiEndpoint + "?" + WSApiParameter + "=" + cuit);

            log.Debug("Seteando PROXY.");
            string urlProxy = ConfigurationManager.AppSettings["CPA_Proxy_URL"];

            WebProxy Proxy = new WebProxy(new Uri(urlProxy));

            Proxy.BypassProxyOnLocal    = false;
            Proxy.UseDefaultCredentials = false;
            Proxy.Credentials           = new NetworkCredential(usuarioProxy, passwdProxy, domainProxy);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 |
                                                   SecurityProtocolType.Tls | SecurityProtocolType.Tls11;

            ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });

            log.Info("Invocacion al Endpoint de Renappo " + WSApiEndpoint + " con el siguiente parametro y valor " + WSApiParameter + "=" + cuit);
            //HttpWebRequest request = Funciones.GenerarRequest(WSApiEndpoint + "?" + WSApiParameter + "=" + cuit);
            HttpWebRequest request = WebRequest.Create(WSUriApi) as HttpWebRequest;

            request.ContentType = "text/html; charset=utf-8";
            //request.ContentType = "application/x-www-form-urlencoded";
            //request.Accept = "application/json";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
            request.Method = WebRequestMethods.Http.Get;
            //request.KeepAlive = true;
            request.UserAgent       = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36";
            request.PreAuthenticate = true;
            //request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
            request.Proxy = Proxy;
            //request.Credentials = CredentialCache.DefaultCredentials;

            string content = string.Empty;

            WebResponse response = (HttpWebResponse)request.GetResponse();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                content = reader.ReadToEnd();
            }

            if (!string.IsNullOrEmpty(content) && content.Length > 0 && !content.StartsWith("[{"))
            {
                throw new Exception(content);
            }

            log.Info("Respuesta del Endpoint " + WSApiEndpoint + ": " + Environment.NewLine + content);

            log.Info("Parseando el la respuesta previamente obtenida");
            certificaciones = JsonConvert.DeserializeObject <Certificacion[]>(content);

            if (certificaciones != null && certificaciones.Any())
            {
                if (certificaciones.Any(x => x.Fallo))
                {
                    throw new Exception(certificaciones.FirstOrDefault(x => x.Fallo)?.Mensaje);
                }

                IT_Detalle          detalle     = new IT_Detalle();
                List <IT_Actividad> actividades = new List <IT_Actividad>();

                foreach (var certificacion in certificaciones)
                {
                    detalle.RazonSocial        = certificacion.RazonSocial;
                    detalle.Intermediario      = certificacion.Medio;
                    detalle.Habilitado         = certificacion.Habilitado;
                    detalle.FechaVigenciaDesde = Funciones.ConvertToFechaFormato(Funciones.ConvertToFechaVigencia(certificacion.FechaVigencia, Parametros.FechaVigencia.Desde), null);
                    detalle.FechaVigenciaHasta = Funciones.ConvertToFechaFormato(Funciones.ConvertToFechaVigencia(certificacion.FechaVigencia, Parametros.FechaVigencia.Hasta), null);

                    detalle.Tarifario           = SubirArchivo(certificacion.Tarifario);
                    detalle.CoberturaGeografica = SubirArchivo(certificacion.CoberturaGeografica);

                    if (!string.IsNullOrEmpty(certificacion.Certificado))
                    {
                        log.Info("Parseando el campo certificado para obtener la/s actividad/es del Proveedor");
                        var elementos = XElement.Parse(certificacion.Certificado);

                        if (elementos.HasElements)
                        {
                            foreach (var elemento in elementos.Elements())
                            {
                                var elementosTexto = elemento.Descendants()?.Where(x => x.FirstNode != null && x.FirstNode.NodeType == XmlNodeType.Text);

                                var actividad = new IT_Actividad();
                                actividad.Actividad   = elementosTexto?.FirstOrDefault(x => x.Parent.Value.Contains("CERTIFICADO HABILITANTE") && x.Name == "strong").Value;
                                actividad.Fecha       = Funciones.ConvertToFechaFormato(elementosTexto?.FirstOrDefault(x => x.Value.Contains("Fecha:"))?.Value, "Fecha:");
                                actividad.Vencimiento = Funciones.ConvertToFechaFormato(elementosTexto?.FirstOrDefault(x => x.Value.Contains("Vencimiento:"))?.Value, "Vencimiento:");
                                actividad.Certificado = elementosTexto?.FirstOrDefault(x => x.Value.Contains("RENAPPO")).Value.Trim();

                                actividades.Add(actividad);
                            }
                        }
                    }
                }

                proveedor.Detalle     = detalle;
                proveedor.Actividades = actividades.ToArray();
            }

            return(proveedor);
        }