Esempio n. 1
0
        public void Iniciar(IList <string> parametrosApp)
        {
            string mensaje = string.Empty;
            var    window  = SimpleInyectorEngine.Get <frmDescargas>();

            if (parametrosApp.Count == 2)
            {
                window.txtUrlJson.Text    = parametrosApp[0];
                window.txtDestino.Text    = parametrosApp[1];
                window.DescargaAutomatica = true;
            }
            else if (parametrosApp.Count == 1)
            {
                mensaje = "No se han especificado todos los parámetros: falta la ruta del Json o la ruta de la descarga";
            }
            else if (parametrosApp.Count > 2)
            {
                mensaje = "Demasiados parámetros";
            }

            if (!string.IsNullOrEmpty(mensaje))
            {
                MessageBox.Show(mensaje);
                throw new Exception("Error en los parametros");
            }
            else
            {
                window.Show();
            }
        }
Esempio n. 2
0
        private async void RecuperarDescarga()
        {
            try
            {
                string mensaje = string.Empty;

                ControlesProgeso controles = SimpleInyectorEngine.Get <ControlesProgeso>();
                controles.pbarProgeso   = pbarProgeso;
                controles.txtProcesando = txtProcesando;

                txtDestino.Text = string.Empty;
                txtUrlJson.Text = string.Empty;

                Resultado resultado = await _downloadManager.RecuperaErrores(controles, chkErrores.IsChecked.Value);

                mensaje = $"Estado de la recuparacion:\nTotal de ficheros a recuperar: {resultado.Procesados}\nFicheros recuperados: {resultado.Correctos}\nFicheros con error: {resultado.Fallidos}\nEstado: {(resultado.ProcesoCorrecto ? "Recuparacion correcta" : "Recuperación con errorres")}";
                MessageBox.Show(mensaje);
                if (resultado.ProcesoCorrecto)
                {
                    _downloadManager.BorraFicheroRecuperacion();
                    btnRecuperar.IsEnabled = false;
                }
                else
                {
                    btnRecuperar.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Error no controlado al recuperar la descarga", ex);
            }
        }
Esempio n. 3
0
        private async Task <Resultado> Descarga(EstructuraFicheros estructura)
        {
            Resultado      ret             = SimpleInyectorEngine.Get <Resultado>();
            IList <string> filesToDownload = GetFilesToDownload(estructura);

            if (filesToDownload != null)
            {
                _controlesProgeso.pbarProgeso.Minimum = 0;
                _controlesProgeso.pbarProgeso.Maximum = filesToDownload.Count();
                _controlesProgeso.pbarProgeso.BeginAnimation(RangeBase.ValueProperty, null);
                _saveFiles.FicheroProcesadoEvent += saveFiles_FicheroProcesadoEvent;
                if (estructura != null)
                {
                    if (_directorio.CrearEstructuraDirectorios(estructura))
                    {
                        ret = await _saveFiles.Save(filesToDownload, estructura, _conErrores);

                        if (!ret.ProcesoCorrecto)
                        {
                            _serializacion.Serializa(estructura);
                        }
                    }
                }
                _saveFiles.FicheroProcesadoEvent -= saveFiles_FicheroProcesadoEvent;
            }
            return(ret);
        }
Esempio n. 4
0
        private async void Descarga()
        {
            string           mensaje   = string.Empty;
            Resultado        resultado = null;
            MessageBoxButton botones   = MessageBoxButton.OK;

            try
            {
                ControlesProgeso controles = SimpleInyectorEngine.Get <ControlesProgeso>();
                controles.pbarProgeso   = pbarProgeso;
                controles.txtProcesando = txtProcesando;

                btnInicio.IsEnabled = false;
                resultado           = await _downloadManager.DownloadManagerStart(txtUrlJson.Text.Trim(), txtDestino.Text.Trim(), controles, chkErrores.IsChecked.Value);

                mensaje = $"Estado de la descarga:\nTotal de ficheros a descargar: {resultado.Procesados}\nFicheros descargados: {resultado.Correctos}\nFicheros con error: {resultado.Fallidos}\nEstado: {(resultado.ProcesoCorrecto ? "Descarga correcta" : "Descarga con errorres")}";
                if (!resultado.ProcesoCorrecto)
                {
                    btnRecuperar.IsEnabled = true;
                    botones  = MessageBoxButton.YesNo;
                    mensaje += $"\n¿ Recuperar la descarga ?";
                }
            }
            catch (Exception ex) when(ex.GetType() != typeof(Exception))
            {
                _logger.Error(ex.Message, ex);
                mensaje             = ex.Message;
                btnInicio.IsEnabled = true;
            }
            catch (Exception ex)
            {
                _logger.Error($"Error no controlado", ex);
                mensaje = ex.Message;
            }
            finally
            {
                if (!string.IsNullOrEmpty(mensaje))
                {
                    MessageBoxResult result = MessageBox.Show(mensaje, "", botones);
                    if (result == MessageBoxResult.Yes)
                    {
                        RecuperarDescarga();
                    }
                }
            }
        }
Esempio n. 5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            try
            {
                ConfiguracionInyector.Configura();
                _logger.Debug("Se inicia la aplicación");

                //throw new Exception("Su aplicación ha sufrido un fallo catastrófico, le tengo que pedir que abandone la fragua");
                var inicio = SimpleInyectorEngine.Get <IniciaApp>();
                inicio.Iniciar(e.Args.ToList());
            }
            catch (Exception ex)
            {
                _logger.Fatal("Error en la carga de la aplicación\n" + ex.Message + "\n" + ex.StackTrace);
                Application.Current.Shutdown();
            }
        }
Esempio n. 6
0
        public EstructuraFicheros ParseJson(JObject json)
        {
            try
            {
                _estructura = SimpleInyectorEngine.Get <EstructuraFicheros>();
                Parsea(json, n =>
                {
                    if (n.First != null && n.First.Type == JTokenType.Property && ((JProperty)n.First).Name.Equals("md5"))
                    {
                        _path_actual = Regex.Replace(n.Path, @" ?\[.*?\]", string.Empty).Replace(".", @"\");

                        if (!_path_actual.Equals(_path) && !string.IsNullOrEmpty(_path))
                        {
                            _estructura.AddFicheros(_path, _ficheros);
                            _ficheros = new List <IDictionary <string, string> >();
                        }
                        _path        = _path_actual;
                        _propiedades = new Dictionary <string, string>();
                        foreach (JProperty prop in n.Children())
                        {
                            _propiedades.Add(prop.Name, (string)prop.Value);
                        }
                        _ficheros.Add(_propiedades);
                    }
                    else if (n.First.Last.Type == JTokenType.Array && !n.First.Last.HasValues)
                    {
                        string path_vacio = Regex.Replace(n.First.Last.Path, @" ?\[.*?\]", string.Empty).Replace(".", @"\");
                        _estructura.AddFicheros(path_vacio, null);
                    }
                });
                if (!_estructura.GetEstructura().ContainsKey(_path))
                {
                    _estructura.AddFicheros(_path, _ficheros);
                }
            }
            catch (Exception ex)
            {
                _estructura = null;
                _logger.Error($"Error al parsear el json\n{json.ToString()}");
                throw ex;
            }

            return(_estructura);
        }
Esempio n. 7
0
        public async Task <Resultado> Save(IList <string> filesToDownload, EstructuraFicheros estructura, bool conErrores)
        {
            _resultado = SimpleInyectorEngine.Get <Resultado>();

            Uri    aux_uri = new Uri(estructura.UrlJson, UriKind.Absolute);
            string url     = aux_uri.AbsoluteUri.Replace(aux_uri.AbsolutePath, "") + "/" + "getfile?file=";

            //pbar.Maximum = filesToDownload.Count();
            //pbar.Minimum = 0;
            //pbar.BeginAnimation(RangeBase.ValueProperty, null);

            IList <string> ficheros_ok = await GetFicherosFromApi(estructura.Root, url, filesToDownload, conErrores);

            estructura.LimpiaEstructura(ficheros_ok);

            _resultado.Procesados      = filesToDownload.Count();
            _resultado.Correctos       = _resultado.Procesados - _resultado.Fallidos;
            _resultado.ProcesoCorrecto = _resultado.Correctos == _resultado.Procesados;

            return(_resultado);
        }
Esempio n. 8
0
        public async Task <Resultado> DownloadManagerStart(string urlJson, string rutaDestino, ControlesProgeso controlesProgeso, bool conErrores)
        {
            _controlesProgeso = controlesProgeso;
            _conErrores       = conErrores;
            if (!rutaDestino.EndsWith(@"\"))
            {
                rutaDestino += @"\";
            }
            JObject json = _jsonManager.GetJson(urlJson);

            if (json != null)
            {
                EstructuraFicheros estructura = _jsonManager.ParseJson(json);
                estructura.UrlJson = urlJson;
                estructura.Root    = rutaDestino;
                return(await Descarga(estructura));
            }
            else
            {
                return(SimpleInyectorEngine.Get <Resultado>());
            }
        }