/// <summary>
        ///     Adds everything possible to target from another source.
        ///     This may include new comments, full comments, larger text etc.
        /// </summary>
        /// <param name="target">Object to add data to.</param>
        /// <param name="otherSource">Object to use data from.</param>
        public bool AddData(EntryPage target, EntryPage otherSource)
        {
            bool updated = false;

            // Check arguments.
            if (target == null || otherSource == null)
            {
                throw new ArgumentNullException();
            }

            // Entry.
            log.DebugFormat("Updating content for entry page '{0}' from other source.", target);
            updated |= _entryHelper.UpdateWith(target.Entry, otherSource.Entry);

            // Comments.
            log.DebugFormat("Updating comments for entry page '{0}' from other source.", target);
            updated |= _repliesHelper.MergeFrom(target, otherSource);

            // CommentPages.
            if (target.CommentPages != null && !CommentPages.IsEmpty(target.CommentPages))
            {
                log.DebugFormat("Cleaning comment pages information for entry page '{0}'.", target);
                target.CommentPages = CommentPages.Empty;
                updated             = true;
            }

            return(updated);
        }
Esempio n. 2
0
        public bool AbsorbAllData(EntryPage freshSource, ILJClientData clientData, ref EntryPage dumpData)
        {
            bool appliedAnything = false;

            if (dumpData == null)
            {
                dumpData        = new EntryPage();
                appliedAnything = true;
            }

            appliedAnything |= _entryPageHelper.AddData(dumpData, freshSource);

            // TryGet all comments.
            EntryPage[] otherPages = _otherPagesLoader.LoadOtherCommentPages(freshSource.CommentPages, clientData);

            foreach (EntryPage pageX in otherPages)
            {
                appliedAnything |= _entryPageHelper.AddData(dumpData, pageX);
            }

            while (true)
            {
                IEnumerable <Comment> allFoldedComments = _repliesHelper.EnumerateRequiringFullUp(dumpData.Replies);
                IEnumerator <Comment> enumerator        = allFoldedComments.GetEnumerator();

                int     foldedCommentsLeft = 0;
                Comment c = null;

                while (enumerator.MoveNext())
                {
                    foldedCommentsLeft++;
                    if (c == null)
                    {
                        c = enumerator.Current;
                    }
                }

                // How many comments left?
                log.Info(string.Format("Folded comments left: {0}.", foldedCommentsLeft));
                if (foldedCommentsLeft == 0)
                {
                    break;
                }

                LiveJournalTarget commentTarget = LiveJournalTarget.FromString(c.Url);
                EntryPage         commentPage   = GetFrom(commentTarget, clientData);
                Comment           fullVersion   = commentPage.Replies.Comments[0];
                if (fullVersion.IsFull == false)
                {
                    // This should be a suspended user.
                    log.Info(string.Format("Comment {0} seems to be from a suspended user.", c));
                    c.IsSuspendedUser = true;
                    continue;
                }

                log.Info(string.Format("Merging comment data for comment {0}.", c));
                appliedAnything |= _repliesHelper.MergeFrom(c, fullVersion);
            }

            return(appliedAnything);
        }