Example #1
0
                                                          public async Task <HashSet <string> > adjuntoToText(HashSet <string> exts, Adjunto adjunto) //id del Adjunto
                                                          {
                                                              StringBuilder result = null;

                                                              try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                    var     extension     = "";
                                                                    Adjunto fil           = adjunto;// await adjuntoRepo.GetAsync(id);
                                                                    var     localFilePath = fil.RutaCompleta;



                                                                    HashSet <string> hash = null;
                                                                    if (!File.Exists(localFilePath))
                                                                    {
                                                                        return(null);
                                                                    }
                                                                    else
                                                                    {
                                                                        extension = Path.GetExtension(localFilePath);
                                                                        if (!exts.Contains(extension))
                                                                        {
                                                                            throw new Exception("documento no soportado, se esperaba alguna de las siguientes extensiones: " + string.Join(",", exts.ToArray()));
                                                                        }
                                                                    }
                                                                    extension = Path.GetExtension(localFilePath);
                                                                    ToPlainText toText = new ToPlainText();
                                                                    try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                          result = toText.GetText(localFilePath, extension);
                                                                          result = Texts.DeleteSpecialCharacteres(result);
                                                                          string[] items = Regex.Split(result.ToString(), @"\s+");
                                                                          hash = new HashSet <string>(items);
                                                                          hash = Texts.getDiferencia(hash, Texts.getStopWords());
                                                                          await this.setVocabulario(hash, dbVoca, adjunto);//guardar nuevo vocabulario en la BD
                                                                    }
                                                                    catch (Exception e) {
                                                                        return(null);
                                                                    }
                                                                    return(hash); }
                                                              catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                                                                                    throw new Exception(e.Message); }

                                                              //UtileriasArchivo util = new UtileriasArchivo();
                                                          }