Esempio n. 1
0
 public IHttpActionResult BuscarTiposAnotaciones(int id)
 {
     var result = dao.Exist(id);
     if (result.IsSuccess)
     {
         var contenido = result.Value;
         var textPath = ConfigurationManager.AppSettings["textPath"].ToString();
         var filePath = Path.Combine(textPath, contenido.Contenido.FileName);
         var text = File.ReadAllText(filePath);
         var posiblesAnotaciones = new AnalizadorAnotaciones(tdDao, taDao).AnalizarPorPosiblesAnotaciones(text);
         return Ok(posiblesAnotaciones);
     }
     else
     {
         return Ok(new List<Anotacion>());
     }
 }
Esempio n. 2
0
        public Task<IHttpActionResult> Post()
        {
            var basePath = ConfigurationManager.AppSettings["basePath"].ToString();
            var textPath = ConfigurationManager.AppSettings["textPath"].ToString();

            if (Request.Content.IsMimeMultipartContent())
            {
                var streamProvider = new CustomMultipartFormDataStreamProvider(basePath);
                var file = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith<IHttpActionResult>(t =>
                {

                    if (t.IsFaulted || t.IsCanceled)
                    {
                        throw new HttpResponseException(HttpStatusCode.InternalServerError);
                    }

                    var fileInfo = streamProvider.FileData.Select(i =>
                    {
                        var info = new FileInfo(i.LocalFileName);
                        string resultado = pdfToText.Convertir(basePath, info.Name);
                        var posiblesAnotaciones = new AnalizadorAnotaciones(this.tdDao, this.taDao).AnalizarPorPosiblesAnotaciones(resultado);

                        var test = textPath + @"\" + info.Name + ".txt";

                        var archivo = new Archivo() { Ruta = info.Name };
                        var guid = Guid.NewGuid();

                        map.Add(guid, new Archivo() { Ruta = info.Name });

                        string asunto = new AnalizadorAsunto().ObtenerAsunto(resultado);

                        if (asunto.Length > 999)
                        {
                            asunto = asunto.Substring(0, 999);
                        }

                        File.WriteAllText(test, resultado);
                        return new FileDesc(archivo.Id.ToString(), basePath + @"\text" + @"\" + info.Name + ".txt", info.Length / 1024, asunto, guid, posiblesAnotaciones);
                    });

                    return Ok(fileInfo);
                });

                return file;
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
            }
        }