Esempio n. 1
0
        public async Task <IActionResult> Importar([FromForm] IFormFile file, int multiproyecto, int mostrarCargando, int proyecto_id, int prestamoId)
        {
            try
            {
                String directorioTemporal = @Utils.getDirectorioTemporal();
                String lineaBase          = null;
                if (!Directory.Exists(directorioTemporal))
                {
                    Directory.CreateDirectory(directorioTemporal);
                }

                String     nombreArchivo = "temp_" + Guid.NewGuid();
                String     fullPath      = directorioTemporal + nombreArchivo;
                FileStream documento     = new FileStream(fullPath, FileMode.OpenOrCreate);

                if (documento.Length == 0)
                {
                    using (var stream = documento)
                    {
                        await file.CopyToAsync(stream);

                        documento.Close();
                    }
                }

                Process p = new Process();
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                String arguments = "-jar \"" + @Utils.getJartImportProject() + "\" \"1\" \"" + directorioTemporal + "\" \"" + nombreArchivo + "\" \"" + User.Identity.Name + "\" \"0\" \"" + proyecto_id + "\" \"1\" \"" + prestamoId + "\" \"" + lineaBase + "\"";
                p.StartInfo.FileName  = "java.exe";
                p.StartInfo.Arguments = arguments;
                p.Start();
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();

                Int32 proyResult;
                if (Int32.TryParse(output, out proyResult))
                {
                }

                System.IO.File.Delete(fullPath);

                bool result = ProyectoDAO.calcularCostoyFechas(proyResult);

                return(Ok(new { success = result, proyectoId = proyResult }));
            }
            catch (Exception e)
            {
                CLogger.write("2", "GanttController.class", e);
                return(BadRequest(500));
            }
        }