/// <summary> /// Called when the send button is tapped. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Send_OnIconTapped(object sender, EventArgs e) { string comment = ui_textBox.Text; if (String.IsNullOrWhiteSpace(comment)) { App.BaconMan.MessageMan.ShowMessageSimple("\"Silence is a source of great strength.\" - Lao Tzu", "Except on reddit. Go on, say something."); return; } // Show loading ui_sendingOverlayProgress.IsActive = true; VisualStateManager.GoToState(this, "ShowOverlay", true); // Try to send the comment string response = await Task.Run(() => MiscellaneousHelper.SendRedditComment(App.BaconMan, m_itemRedditId, comment)); // If we have a post send the status to the collector bool wasSuccess = false; if (m_parentPost != null) { // Get the comment collector for this post. CommentCollector collector = CommentCollector.GetCollector(m_parentPost, App.BaconMan); // Tell the collector of the change, this will show any message boxes needed. wasSuccess = await Task.Run(() => collector.AddNewUserComment(response, m_itemRedditId)); } else { // If we are here we are a message. Validate for ourselves. // #todo, make this validation better, add capta support. Both responses to messages and post replies will have "author" if (!String.IsNullOrWhiteSpace(response) && response.Contains("author")) { wasSuccess = true; } else { wasSuccess = false; App.BaconMan.MessageMan.ShowMessageSimple("That's Not Right", "We can't send this message right now, check your Internet connection"); } } if (wasSuccess) { // Clear the reddit id so we won't open back up with the // same text m_itemRedditId = ""; // Hide the comment box. HideBox(); } else { // Hide the overlay VisualStateManager.GoToState(this, "HideOverlay", true); } }
public HostedService(ILogger <HostedService> logger, Repository repository, SettingsProvider settingsProvider, VideoCollector videoCollector, CommentCollector commentCollector, AnswerCollector answerCollector, UrlCollector urlCollector) { _logger = logger; _repository = repository; _settingsProvider = settingsProvider; _videoCollector = videoCollector; _commentCollector = commentCollector; _answerCollector = answerCollector; _urlCollector = urlCollector; }
/// <summary> /// Ensures a collector exists /// </summary> private void EnsureCollector() { if (m_commentCollector == null) { // Get the comment collector, if we don't want to show a subset don't give it the target comment m_commentCollector = new DeferredCollector <Comment>(CommentCollector.GetCollector(m_post, App.BaconMan, m_showThreadSubset ? m_targetComment : null)); // Sub to collection callbacks for the comments. m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; } }
/// <summary> /// Ensures a collector exists /// </summary> private DeferredCollector <Comment> EnsureCollector() { lock (_commentCollectorLock) { if (_commentCollector != null) { return(_commentCollector); } // Get the comment collector, if we don't want to show a subset don't give it the target comment _commentCollector = new DeferredCollector <Comment>(CommentCollector.GetCollector(_post, App.BaconMan, _showThreadSubset ? _targetComment : null)); // Sub to collection callbacks for the comments. _commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; _commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; return(_commentCollector); } }
public void CommentsTest() { Trace.Listeners.Add(new ConsoleTraceListener()); CSharp csharp = new CSharp(); CodeFile cf = csharp.Parse(System.IO.File.ReadAllText(@".\Programs\CSharp\ClassWithComments.txt"), @".\Programs\CSharp\ClassWithComments.txt"); var cc = new CommentCollector(); cf.AcceptVisitor(cc); Assert.AreEqual(3, cc.Comments.Count()); Assert.AreEqual(14, cc.Comments.First().Location.StartLineNumber); // this will be the line following the comment Assert.AreEqual(17, cc.Comments.First().Location.EndLineNumber); Assert.AreEqual(SyntaxEntityKind.Class, cc.Comments.First().Parent.Kind); Assert.AreEqual(cf.Children.First().Children.First().AssociatedComment, cc.Comments.First()); }
public void PrepareForDeletion() { // Clear out, we are going to be deleted m_post.Comments.Clear(); if (m_fullCommentList != null) { m_fullCommentList.Clear(); } // Kill the collector if (m_commentCollector != null) { m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; } m_commentCollector = null; }
/// <summary> /// Ensures a post collector has been made /// </summary> public void EnsureCommentCollector(bool makeNew = false) { lock (this) { if (makeNew && _mCommentCollector != null) { _mCommentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; _mCommentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; _mCommentCollector = null; } if (_mCommentCollector == null) { _mCommentCollector = CommentCollector.GetCollector(_mUser, App.BaconMan, _mCommentSort); _mCommentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; _mCommentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; } } }
public void OnCleanupPanel() { lock (this) { if (_mPostCollector != null) { _mPostCollector.OnCollectionUpdated -= PostCollector_OnCollectionUpdated; _mPostCollector.OnCollectorStateChange -= PostCollector_OnCollectorStateChange; _mPostCollector = null; } if (_mCommentCollector != null) { _mCommentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; _mCommentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; _mCommentCollector = null; } } }
/// <summary> /// Attempts to prefetch comments. Returns true if it is going, or false it not. /// </summary> /// <returns></returns> public bool PreFetchComments() { // Only attempt to do this once. if (m_attemptedToLoadComments) { return(false); } m_attemptedToLoadComments = true; // Do this in a background thread Task.Run(() => { // Get the comment collector, if we don't want to show a subset don't give it the target comment m_commentCollector = CommentCollector.GetCollector(m_post, App.BaconMan, m_showThreadSubset ? m_targetComment : null); // Sub to collection callbacks for the comments. m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; // Request a few comments so we will fill the screen. // If the user scrolls we will get more later. // To fix a bug where reddit doesn't give us the same // comments the first time as the next, we will // #bug #todo because of the "can't ask for more" bug we will // just ask for all of the comments here. if (!m_commentCollector.Update(false, 150)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs <Comment> args = new OnCollectionUpdatedArgs <Comment>() { ChangedItems = m_commentCollector.GetCurrentPosts(), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 }; CommentCollector_OnCollectionUpdated(null, args); } }); return(true); }
/// <summary> /// Fired when the comment sort is changed. /// </summary> public void ChangeCommentSort() { // Show loading m_post.FlipViewShowLoadingMoreComments = true; // Do this in a background thread Task.Run(() => { // Kill the current collector if (m_commentCollector != null) { m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; } m_commentCollector = null; // Get a new collector with the new sort m_commentCollector = new DeferredCollector <Comment>(CommentCollector.GetCollector(m_post, App.BaconMan)); // Sub to collection callbacks for the comments. m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; // Force our collector to update. if (!m_commentCollector.LoadAllItems(true, m_post.CurrentCommentShowingCount)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs <Comment> args = new OnCollectionUpdatedArgs <Comment>() { ChangedItems = m_commentCollector.GetCurrentItems(true), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 }; CommentCollector_OnCollectionUpdated(null, args); } }); }
/// <summary> /// Attempts to prefetch comments. Returns true if it is going, or false it not. /// </summary> /// <returns></returns> public bool PreFetchComments() { // Only attempt to do this once. if (m_attemptedToLoadComments) { return(false); } m_attemptedToLoadComments = true; // Do this in a background thread Task.Run(() => { // Get the comment collector, if we don't want to show a subset don't give it the target comment m_commentCollector = CommentCollector.GetCollector(m_post, App.BaconMan, m_showThreadSubset ? m_targetComment : null); // Sub to collection callbacks for the comments. m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; // We have to ask for all the comments here bc we can't extend. if (!m_commentCollector.Update(false, m_post.CurrentCommentShowingCount)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs <Comment> args = new OnCollectionUpdatedArgs <Comment>() { ChangedItems = m_commentCollector.GetCurrentPosts(), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 }; CommentCollector_OnCollectionUpdated(null, args); } }); return(true); }
/// <summary> /// Ensures a post collector has been made /// </summary> public void EnsureCommentCollector(bool makeNew = false) { lock (this) { if (makeNew && m_commentCollector != null) { m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; m_commentCollector = null; } if (m_commentCollector == null) { m_commentCollector = CommentCollector.GetCollector(m_user, App.BaconMan, m_commentSort); m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; } } }
/// <summary> /// Attempts to prefetch comments. Returns true if it is going, or false it not. /// </summary> /// <returns></returns> public bool PreFetchComments() { // Only attempt to do this once. if(m_attemptedToLoadComments) { return false; } m_attemptedToLoadComments = true; // Do this in a background thread Task.Run(() => { // Get the comment collector, if we don't want to show a subset don't give it the target comment m_commentCollector = CommentCollector.GetCollector(m_post, App.BaconMan, m_showThreadSubset ? m_targetComment : null); // Sub to collection callbacks for the comments. m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; // We have to ask for all the comments here bc we can't extend. if (!m_commentCollector.Update(false, m_post.CurrentCommentShowingCount)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs<Comment> args = new OnCollectionUpdatedArgs<Comment>() { ChangedItems = m_commentCollector.GetCurrentPosts(), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 }; CommentCollector_OnCollectionUpdated(null, args); } }); return true; }
/// <summary> /// Fired when the comment sort is changed. /// </summary> public void ChangeCommentSort() { // Show loading m_post.FlipViewShowLoadingMoreComments = true; // Do this in a background thread Task.Run(() => { // Kill the current collector if (m_commentCollector != null) { m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; } m_commentCollector = null; // Get a new collector with the new sort m_commentCollector = CommentCollector.GetCollector(m_post, App.BaconMan); // Sub to collection callbacks for the comments. m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; // Force our collector to update. if (!m_commentCollector.Update(true, m_post.CurrentCommentShowingCount)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs<Comment> args = new OnCollectionUpdatedArgs<Comment>() { ChangedItems = m_commentCollector.GetCurrentPosts(), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 }; CommentCollector_OnCollectionUpdated(null, args); } }); }
public void PrepareForDeletion() { // Clear out, we are going to be deleted m_post.Comments.Clear(); if(m_fullCommentList != null) { m_fullCommentList.Clear(); } // Kill the collector if (m_commentCollector != null) { m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; } m_commentCollector = null; }
/// <summary> /// Attempts to prefetch comments. Returns true if it is going, or false it not. /// </summary> /// <returns></returns> public bool PreFetchComments() { // Only attempt to do this once. if(m_attemptedToLoadComments) { return false; } m_attemptedToLoadComments = true; // Do this in a background thread Task.Run(() => { // Get the comment collector, if we don't want to show a subset don't give it the target comment m_commentCollector = CommentCollector.GetCollector(m_post, App.BaconMan, m_showThreadSubset ? m_targetComment : null); // Sub to collection callbacks for the comments. m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; // Request a few comments so we will fill the screen. // If the user scrolls we will get more later. // To fix a bug where reddit doesn't give us the same // comments the first time as the next, we will // #bug #todo because of the "can't ask for more" bug we will // just ask for all of the comments here. if (!m_commentCollector.Update(false, 150)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs<Comment> args = new OnCollectionUpdatedArgs<Comment>() { ChangedItems = m_commentCollector.GetCurrentPosts(), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 }; CommentCollector_OnCollectionUpdated(null, args); } }); return true; }
public void OnCleanupPanel() { lock (this) { if (m_postCollector != null) { m_postCollector.OnCollectionUpdated -= PostCollector_OnCollectionUpdated; m_postCollector.OnCollectorStateChange -= PostCollector_OnCollectorStateChange; m_postCollector = null; } if (m_commentCollector != null) { m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; m_commentCollector = null; } } }