public IEnumerable <Comments> GetComments(TorrentMovie movie) { Log.Information($"GetComments to {movie.title}{Environment.NewLine}{movie.movieId} " + $"{Environment.NewLine}{movie.pathDownLoad} started{DateTime.Now}{Environment.NewLine}"); IEnumerable <string> TextCommFromHtmlNodes = new List <string>(); List <Comments> comments = new List <Comments>(); var urls = GetPaths(movie.pathDownLoad);//Getting paths from panel of navugation foreach (var url in urls) { try { TextCommFromHtmlNodes = GetTextCommFromHtmlNodes(url); } catch (Exception ex) { Log.Error($"Get nodes form {url} was fail with exception:{Environment.NewLine}{ex.Message}"); return(null); } foreach (var coment in TextCommFromHtmlNodes) { comments.Add(new Comments() { commentIndex = 0, commentText = coment, movieId = movie }); } } return(comments); }
public async Task <bool> SaveCommens(TorrentMovie movie) { Log.Information($"CommentService.SaveCommtnts.SaveComments() start at {DateTime.Now}{Environment.NewLine}"); //var movies = _unitOfWork.torrentMove.AsQueryable(); //int counter = 0; //int numberCommentsToRenewal = 11; try { /* foreach (var movie in movies) * {*/ var commentsMovie = _commetsGetter.GetComments(movie); if (commentsMovie == null || commentsMovie.Count() == movie.amountOfComments)//if anount of comments not change, continue, else remove old comments and add new comments { Log.Information($"CommentService.SaveCommtnts.SaveComments().GetComments(movie){Environment.NewLine}" + $"Amount of comments not change or GetComments(movie) equal null{Environment.NewLine}{movie.title}{Environment.NewLine}{movie.movieId} " + $"{Environment.NewLine}{movie.pathDownLoad} {DateTime.Now}{Environment.NewLine}"); } else { /*counter++; * if (counter == numberCommentsToRenewal) { break; }*/ if (movie.amountOfComments != 0) { try { var oldComments = _unitOfWork.comments.Where(x => x.movieId.Id.ToString().Equals(movie.Id.ToString())).ToList(); _unitOfWork.comments.Remove(oldComments); } catch (Exception) { Log.Information($"CommentService.SaveCommtnts.SaveComments()..Remove(oldComments){Environment.NewLine}Comments missing in DB to {movie.title}{Environment.NewLine}{movie.movieId} " + $"{Environment.NewLine}{movie.pathDownLoad}{DateTime.Now}{Environment.NewLine}"); } } _unitOfWork.comments.AddRange(commentsMovie); movie.amountOfComments = commentsMovie.Count(); /*}*/ } _unitOfWork.Save(); Log.Information($"Finish SaveComments() at {DateTime.Now}{Environment.NewLine}"); return(true); } catch (Exception ex) { Log.Error($"(CommentService.SaveCommentsToDb.SaveCommens()){Environment.NewLine}Get and Save comment was fail with exception:at {DateTime.Now}{Environment.NewLine}{ex.Message}"); return(false); } }
public void GetCommentIndex(TorrentMovie movie) { Log.Information($"CommentService.CommentHanlder.GetCommentIndex() started at {DateTime.Now}{ Environment.NewLine}"); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() started at {DateTime.Now}{ Environment.NewLine}"); try { Dictionary <string, int> dictFromLemms = new Dictionary <string, int>(); Dictionary <string, string> DictionaryAffin = _afinn.GetDictionary(); int countAffinWordInText = 0; int IndexWordsFromText = 0; int CommentIndex = 0; var comments = _unitOfWork.comments.Where(x => x.movieId.Id.ToString().Equals(movie.Id.ToString())); if (comments != null) { string commentsString = Regex.Replace(BuildSringFromComments(comments), @"\s{2}", " "); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() work with movie {movie.title}{ Environment.NewLine}{movie.Id}"); Log.Information($"CommentService.CommentHanlder.GetCommentIndex() work with movie {movie.title}{ Environment.NewLine}{movie.Id}"); dictFromLemms = _lemmatization.GetDictFromLemms(commentsString); if (dictFromLemms != null) { foreach (var wordFromText in dictFromLemms) { if (DictionaryAffin.ContainsKey(wordFromText.Key)) { int AffinWordValue = Convert.ToInt32(DictionaryAffin[wordFromText.Key]) + 5;//remove negative values IndexWordsFromText += AffinWordValue * wordFromText.Value; countAffinWordInText += wordFromText.Value; } } if (countAffinWordInText != 0) { int downloadsToInt = movie.downloads; CommentIndex = Convert.ToInt32(Math.Round((double)IndexWordsFromText / countAffinWordInText, 3) * 10) + movie.amountOfComments; movie.commentIndex = CommentIndex; } else { movie.commentIndex = movie.amountOfComments; } } else { movie.commentIndex = movie.amountOfComments; } } else { Log.Information($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}" + $"DB not contain comments by movie {movie.title}{ Environment.NewLine} "); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}" + $"DB not contain comments by movie {movie.title}{ Environment.NewLine} "); movie.commentIndex = 0; } _unitOfWork.Save(); Log.Information($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}"); System.Diagnostics.Debug.WriteLine($"CommentService.CommentHanlder.GetCommentIndex() finish at {DateTime.Now}{ Environment.NewLine}"); } catch (Exception ex) { Log.Error($"CommentService.CommentHanlder.GetCommentIndex() worked with error {DateTime.Now}" + $"{Environment.NewLine}{ex}{Environment.NewLine}"); } }