示例#1
0
        private CrawlPostGroup_Post MapFromCrawlPostDTOToCrawlPostGroup_Post(CrawlPostDTO source)
        {
            CrawlPostGroup_Post des = new CrawlPostGroup_Post();

            try
            {
                des.Message               = source.Message;
                des.Fb_Id                 = source.Fb_Id;
                des.Picture               = source.Picture;
                des.Link                  = source.Link;
                des.Name                  = source.Name;
                des.Caption               = source.Caption;
                des.Description           = source.Description;
                des.CrawlPostGroup_Action = source.Actions.Select(x => new CrawlPostGroup_Action
                {
                    Name = x.Name,
                    Link = x.Link
                }).ToList();
                des.CrawlPostGroup_Privacy = new List <CrawlPostGroup_Privacy>
                {
                    mapFromCrawlPostGroupPrivacyTOCrawlPostPrivacyDTO(source.Privacy)
                };

                des.CrawlPostGroup_Comment = source.Comments.Data.Select(x => new CrawlPostGroup_Comment()
                {
                    CreatedTime = DateTime.Parse(x.CreatedTimeFromApi),
                    Message     = x.Message,
                    CanRemove   = x.CanRemove,
                    LikeCount   = x.LikeCount,
                    UserLike    = x.UserLikes,
                    Fb_Id       = x.Fb_Id
                }).ToList();
                des.Type            = source.Type;
                des.StatusType      = source.StatusType;
                des.CreatedTime     = source.CreatedTime;
                des.UpdatedTime     = source.UpdatedTime;
                des.IsHidden        = source.IsHidden;
                des.IsExpired       = source.IsExpired;
                des.TimeCreatedInDb = DateTime.Now;
                des.TimeUpdatedInDb = DateTime.Now;
                return(des);
            }
            catch (Exception e)
            {
            }
            return(des);
        }
示例#2
0
        private async Task UpdatePostDetail(FbToolEntities db, CrawlPostGroup_Post dbPostInDb)
        {
            try
            {
                var postDetailInDb = db.CrawlPostGroup_PostDetail.FirstOrDefault(x => x.CrawlPostGroup_PostId == dbPostInDb.Id);
                //string cookie =
                //    "sb=srBAX2Yf70eNGh8YE48Rh9uV; datr=MbZAX5ch9yeZ8S7kWRJ-avy4; c_user=100001578994326; dpr=1.25; spin=r.1002600685_b.trunk_t.1598977068_s.1_v.2_; xs=44%3A-H2B8TYHbDoigw%3A2%3A1598151193%3A19558%3A6330%3A%3AAcUH9rZg5FSLhbO4I8oVAqiKtPcc_0fH95G7F6NZ2i0; fr=1nKtY59ZJSUFo6uYR.AWUxrD6u02zOlIw2BoY3euBzJOI.BfQLCy.TG.F9K.0.0.BfToJd.AWWJZZlx; wd=574x722; presence=EDvF3EtimeF1598981783EuserFA21B01578994326A2EstateFDt3F_5b_5dElm3FnullEutc3F1598981783875G598981783915CEchF_7bCC";
                var tempPostDetail = await PostGroupHelper.GetPostDetailDTOAsync(dbPostInDb.Fb_Id, ListHelper <TokenCookie> .GetRandomItemInListObject(Constant.LIST_TOKEN_COOKIE).Cookie);

                //string cookie = ListHelper.GetRandomItemInList(Constant.LIST_COOKIE);
                //var tempPostDetail = await PostGroupHelper.GetPostDetailDTOAsync(dbPostInDb.Fb_Id, cookie);
                if (postDetailInDb != null)
                {
                    db.Entry(postDetailInDb).CurrentValues.SetValues(tempPostDetail);
                    postDetailInDb.TimeUpdatedInDb = DateTime.Now;
                }
                else
                {
                    var newPostDetail = new CrawlPostGroup_PostDetail();
                    newPostDetail.TimeCreatedInDb       = DateTime.Now;
                    newPostDetail.CrawlPostGroup_PostId = dbPostInDb.Id;
                    newPostDetail.Name = tempPostDetail.Name;
                    newPostDetail.UID  = tempPostDetail.UID;
                    newPostDetail.ReactionTotalCount = tempPostDetail.ReactionTotalCount;
                    newPostDetail.LikeCount          = tempPostDetail.LikeCount;
                    newPostDetail.LoveCount          = tempPostDetail.LoveCount;
                    newPostDetail.WowCount           = tempPostDetail.WowCount;
                    newPostDetail.SupportCount       = tempPostDetail.SupportCount;
                    newPostDetail.HahaCount          = tempPostDetail.HahaCount;
                    newPostDetail.SadCount           = tempPostDetail.SadCount;
                    newPostDetail.AngryCount         = tempPostDetail.AngryCount;
                    newPostDetail.ShareCount         = tempPostDetail.ShareCount;
                    newPostDetail.CommentCount       = tempPostDetail.CommentCount;
                    db.CrawlPostGroup_PostDetail.Add(newPostDetail);
                }
                db.SaveChanges();
            }
            catch (Exception e)
            {
                InvokeControlHelper.AppendRichTextboxV2(rtbInfoGetToken, $"Exception UpdatePostDetail.PostId = {dbPostInDb?.Id}. Exception = {e.Message}, InnerException ={e.InnerException?.Message}", Color.Red);
            }
        }
示例#3
0
        private async Task AddOrUpdatePostGroup(CrawlPostDTO model)
        {
            using (var db = new FbToolEntities())
            {
                var test     = db.Chat_Fb_FunnyStory.ToList();
                var postInDb = db.CrawlPostGroup_Post.Where(x => x.Fb_Id == model.Fb_Id).Include(x => x.CrawlPostGroup_Action).FirstOrDefault();
                if (postInDb == null)
                {
                    postInDb = new CrawlPostGroup_Post();
                    postInDb.TimeCreatedInDb = DateTime.Now;
                    db.CrawlPostGroup_Post.Add(postInDb);
                    db.SaveChanges();
                    InvokeControlHelper.AppendRichTextboxV2(rtbCrawlGroupPostInfo, $"Thêm mới Post với Id = {model.Fb_Id}", Color.Blue);
                }
                if (postInDb != null)
                {
                    db.Entry(postInDb).CurrentValues.SetValues(model);
                    postInDb.TimeUpdatedInDb = DateTime.Now;
                    #region Action
                    foreach (var action in postInDb.CrawlPostGroup_Action.ToList())
                    {
                        if (!model.Actions.Any(c => c.Name == action.Name))
                        {
                            db.CrawlPostGroup_Action.Remove(action);
                        }
                    }
                    // Update and Insert children
                    foreach (var actionDto in model.Actions)
                    {
                        var existingChildAction = postInDb.CrawlPostGroup_Action
                                                  .Where(c => c.Name == actionDto.Name)
                                                  .FirstOrDefault();

                        if (existingChildAction != null)
                        {
                            // Update child
                            db.Entry(existingChildAction).CurrentValues.SetValues(actionDto);
                        }
                        else
                        {
                            // Insert child
                            var newChild = new CrawlPostGroup_Action
                            {
                                Name = actionDto.Name,
                                Link = actionDto.Link
                            };
                            postInDb.CrawlPostGroup_Action.Add(newChild);
                        }
                    }
                    #endregion

                    #region Privacy
                    var existingChildPrivacy = postInDb.CrawlPostGroup_Privacy.FirstOrDefault();
                    if (existingChildPrivacy != null)
                    {
                        // Update child
                        db.Entry(existingChildPrivacy).CurrentValues.SetValues(model.Privacy);
                    }
                    else
                    {
                        // Insert child
                        var newChild = new CrawlPostGroup_Privacy()
                        {
                            Value       = model.Privacy.Value,
                            Description = model.Privacy.Description,
                            Friends     = model.Privacy.Friends,
                            Allow       = model.Privacy.Allow,
                            Deny        = model.Privacy.Deny
                        };
                        postInDb.CrawlPostGroup_Privacy.Add(newChild);
                    }
                    #endregion

                    #region Comment
                    foreach (var comment in postInDb.CrawlPostGroup_Comment.ToList())
                    {
                        if (!model.Comments.Data.Any(c => c.Fb_Id == comment.Fb_Id))
                        {
                            db.CrawlPostGroup_Comment.Remove(comment);
                        }
                    }
                    // Update and Insert children
                    if (model.Comments?.Data?.Count > 0)
                    {
                        foreach (var commentDto in model.Comments?.Data)
                        {
                            var existingChildComment = postInDb.CrawlPostGroup_Comment
                                                       .Where(c => c.Fb_Id == commentDto.Fb_Id)
                                                       .FirstOrDefault();

                            if (existingChildComment != null)
                            {
                                // Update child
                                db.Entry(existingChildComment).CurrentValues.SetValues(commentDto);
                            }
                            else
                            {
                                // Insert child
                                var newChild = new CrawlPostGroup_Comment()
                                {
                                    CreatedTime = DateTimeHelper.ConvertStringFromApiFacebookToDateTime(commentDto.CreatedTimeFromApi),
                                    Message     = commentDto.Message,
                                    CanRemove   = commentDto.CanRemove,
                                    LikeCount   = commentDto.LikeCount,
                                    UserLike    = commentDto.UserLikes,
                                    Fb_Id       = commentDto.Fb_Id
                                };
                                postInDb.CrawlPostGroup_Comment.Add(newChild);
                            }
                        }
                    }
                    #endregion
                }
                db.SaveChanges();
                InvokeControlHelper.AppendRichTextboxV2(rtbCrawlGroupPostInfo, $"Update thành công bài Post với Id = {model.Fb_Id}", Color.Green);
                await UpdatePostDetail(db, postInDb);

                InvokeControlHelper.AppendRichTextboxV2(rtbCrawlGroupPostInfo, $"Update thành công Detail bài Post với Id = {model.Fb_Id}", Color.Green);
                Thread.Sleep(100);
            }
        }