public CongressComunication GetCongressComunication(CongressComunication congressComunication)
 {
     return(context.CongressComunications.FirstOrDefault(cc =>
                                                         cc.Title == congressComunication.Title &&
                                                         cc.Year == congressComunication.Year &&
                                                         cc.Url == congressComunication.Url &&
                                                         cc.Congress == congressComunication.Congress &&
                                                         cc.Edition == congressComunication.Edition &&
                                                         cc.Place == congressComunication.Place &&
                                                         cc.InitialPage == congressComunication.InitialPage &&
                                                         cc.FinalPage == congressComunication.FinalPage));
 }
        public override bool Equals(object obj)
        {
            CongressComunication other = obj as CongressComunication;

            if (other == null)
            {
                return(false);
            }

            bool a = Congress == null ? other.Congress == null : Congress.Equals(other.Congress);
            bool b = Edition == null ? other.Edition == null : Edition.Equals(other.Edition);
            bool c = Place == null ? other.Place == null : Place.Equals(other.Place);
            bool d = InitialPage == null ? other.InitialPage == null : InitialPage.Equals(other.InitialPage);
            bool e = FinalPage == null ? other.FinalPage == null : FinalPage.Equals(other.FinalPage);
            bool f = base.Equals(obj);

            return(a && b && c && d && e && f);
        }
        private void ShowResults(SearchAnswer searchAnswer, bool searchArticle, bool searchBook, bool searchCongress)
        {
            if (searchAnswer == null)
            {
                richTextBoxArticles.ForeColor = Color.Red;
                richTextBoxArticles.Text      = "There was a problem with the answer of the warehouse.";

                return;
            }

            richTextBoxArticles.ForeColor = Color.Black;
            richTextBoxBooks.ForeColor    = Color.Black;
            richTextBoxCongressComunications.ForeColor = Color.Black;

            if (searchArticle)
            {
                string text = "";

                for (int i = 0; i < searchAnswer.Articles.Count; i++)
                {
                    Article a = searchAnswer.Articles[i];

                    text += $"{i + 1}.- {a.Title}\n";
                    text += $"Year: {a.Year}\n";
                    text += a.Url == null ? "" : $"Url: {a.Url}\n";
                    text += a.InitialPage == null && a.FinalPage == null ? "" : $"Pages: {a.InitialPage} - {a.FinalPage}\n";
                    text += a.Exemplar == null ? "" : $"Volume: {a.Exemplar.Volume}\n";
                    text += a.Exemplar == null ? "" : $"Number: {a.Exemplar.Number}\n";
                    text += a.Exemplar == null ? "" : $"Month: {a.Exemplar.Month}\n";
                    text += a.Exemplar == null ? "" : $"Journal: {a.Exemplar.Journal.Name}\n";
                    text += PrepareAuthors(a.People);
                    text += "\n";
                }

                richTextBoxArticles.Text = text == "" ? "No articles found." : text;

                if (tabControlResults.TabPages.Contains(tabs[0]))
                {
                    tabControlResults.TabPages.Remove(tabs[0]);
                }

                tabControlResults.TabPages.Add(tabs[0]);
            }
            else
            {
                tabControlResults.TabPages.Remove(tabs[0]);
            }

            if (searchBook)
            {
                string text = "";

                for (int i = 0; i < searchAnswer.Books.Count; i++)
                {
                    Book b = searchAnswer.Books[i];

                    text += $"{i + 1}.- {b.Title}\n";
                    text += $"Year: {b.Year}\n";
                    text += b.Url == null ? "" : $"Url: {b.Url}\n";
                    text += b.Editorial == null ? "" : $"Editorial: {b.Editorial}\n";
                    text += PrepareAuthors(b.People);
                    text += "\n";
                }

                richTextBoxBooks.Text = text == "" ? "No books found." : text;

                if (tabControlResults.TabPages.Contains(tabs[1]))
                {
                    tabControlResults.TabPages.Remove(tabs[1]);
                }

                tabControlResults.TabPages.Add(tabs[1]);
            }
            else
            {
                tabControlResults.TabPages.Remove(tabs[1]);
            }

            if (searchCongress)
            {
                string text = "";

                for (int i = 0; i < searchAnswer.CongressComunications.Count; i++)
                {
                    CongressComunication cc = searchAnswer.CongressComunications[i];

                    text += $"{i + 1}.- {cc.Title}\n";
                    text += $"Year: {cc.Year}\n";
                    text += cc.Url == null ? "" : $"Url: {cc.Url}\n";
                    text += cc.Congress == null ? "" : $"Congress: {cc.Congress}\n";
                    text += cc.Edition == null ? "" : $"Edition: {cc.Edition}\n";
                    text += cc.Place == null ? "" : $"Place: {cc.Place}\n";
                    text += cc.InitialPage == null && cc.FinalPage == null ? "" : $"Pages: {cc.InitialPage} - {cc.FinalPage}\n";
                    text += PrepareAuthors(cc.People);
                    text += "\n";
                }

                richTextBoxCongressComunications.Text = text == "" ? "No congress comunications found." : text;

                if (tabControlResults.TabPages.Contains(tabs[2]))
                {
                    tabControlResults.TabPages.Remove(tabs[2]);
                }

                tabControlResults.TabPages.Add(tabs[2]);
            }
            else
            {
                tabControlResults.TabPages.Remove(tabs[2]);
            }

            string PrepareAuthors(ICollection <Person> people)
            {
                if (people.Count == 0)
                {
                    return("");
                }

                string text = "Authors: ";

                foreach (Person person in people)
                {
                    text += person.Name + " " + person.Surnames + ", ";
                }

                return(text.Substring(0, text.Length - 2) + "\n");
            }
        }
Exemple #4
0
        public (int, List <string>) ExtractData <T>(string extractorName, string json)
        {
            List <Article> articlesToSave = new List <Article>();
            List <Book>    booksToSave    = new List <Book>();
            List <CongressComunication> congressComunicationsToSave = new List <CongressComunication>();
            List <string> errorList = new List <string>();

            logger.LogInformation(extractorName + "extractor: Preparing the json...");

            string preparedJson = PrepareJson(json);

            if (preparedJson == null)
            {
                string errorMessage = extractorName + "extractor: There was a problem preparing the json.";

                logger.LogInformation(errorMessage);
                errorList.Add(errorMessage);

                return(0, errorList);
            }

            logger.LogInformation(extractorName + "extractor: Converting the json to the schema...");

            List <T> publications = JsonConvert.DeserializeObject <List <T> >(preparedJson);

            logger.LogInformation(extractorName + "extractor: " + publications.Count() + " publications received. Creating them...");

            foreach (T publication in publications)
            {
                try
                {
                    if (IsArticle(publication))
                    {
                        Article article = CreateArticle(publication);

                        if (!articlesToSave.Contains(article) && databaseAccess.GetArticle(article) == null)
                        {
                            articlesToSave.Add(article);
                        }
                    }
                    else if (IsBook(publication))
                    {
                        Book book = CreateBook(publication);

                        if (!booksToSave.Contains(book) && databaseAccess.GetBook(book) == null)
                        {
                            booksToSave.Add(book);
                        }
                    }
                    else if (IsCongressComunication(publication))
                    {
                        CongressComunication conference = CreateCongressComunication(publication);

                        if (!congressComunicationsToSave.Contains(conference) && databaseAccess.GetCongressComunication(conference) == null)
                        {
                            congressComunicationsToSave.Add(conference);
                        }
                    }
                    else
                    {
                        errorList.Add("The publication type is not supported.");
                    }
                }
                catch (Exception e)
                {
                    errorList.Add(e.Message);
                }
            }

            logger.LogInformation(extractorName + "extractor: Saving the publications into the database...");

            databaseAccess.SaveArticles(articlesToSave);
            databaseAccess.SaveBooks(booksToSave);
            databaseAccess.SaveCongressComunications(congressComunicationsToSave);

            return(articlesToSave.Count + booksToSave.Count + congressComunicationsToSave.Count, errorList);
        }