private bool ToggleBookmark(ThreadMetadata thread, BookmarkAction action, int timeout = CoreConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS) { //Logger.AddEntry(string.Format("ToggleBookmarkAsync - ThreadID: {0}, Action: {1}", thread.ID, action)); string url = String.Format("{0}/{1}", CoreConstants.BASE_URL, CoreConstants.BOOKMARK_THREAD_URI); //Logger.AddEntry(string.Format("ToggleBookmarkAsync - Bookmark url: {0}", url)); // create request and request data var request = InitializePostRequest(url); var signal = new AutoResetEvent(false); var result = request.BeginGetRequestStream(callback => ProcessToggleBookmarkAsyncGetRequest(callback, signal, action, thread), request); // wait for processing signal.WaitOne(); // begin the response process request = result.AsyncState as HttpWebRequest; result = request.BeginGetResponse(callback => { signal.Set(); }, request); signal.WaitOne(timeout); // process response and return success status bool success = ProcessToggleBookmarkAsyncGetResponse(result); return success; }
public static bool ClearMarkedPosts(ThreadMetadata thread, int timeout = CoreConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS) { // create request HttpWebRequest request = AwfulWebRequest.CreateFormDataPostRequest( "http://forums.somethingawful.com/showthread.php", "application/x-www-form-urlencoded"); // begin request stream creation and wait... var signal = new AutoResetEvent(false); var result = request.BeginGetRequestStream(callback => SendClearMarkedPostRequest(callback, signal, thread), request); signal.WaitOne(); // begin response stream and wait... request = result.AsyncState as HttpWebRequest; result = request.BeginGetResponse(callback => { signal.Set(); }, request); signal.WaitOne(timeout); if (!result.IsCompleted) throw new TimeoutException(); // process the response and return status bool success = ProcessClearMarkedPostResponse(result); return success; }
public MessagePostModel(ThreadMetadata thread) : base() { this.thread = thread; this.submit = SubmitPostAsync; this.Title = "New Reply"; this.Subtitle = thread.Title; }
private string FormatSubtext2(ThreadMetadata metadata) { //ShowPostCount = !metadata.IsNew; ShowPostCount = true; if (metadata.IsNew) { return(string.Format("{0} {1}", PageCount, PageCount == 1 ? "page" : "pages")); } else if (metadata.NewPostCount == ThreadMetadata.NO_UNREAD_POSTS_POSTCOUNT) { return("no new posts"); } else if (metadata.NewPostCount == 1) { return("1 new post"); } else { return(string.Format("{0} new posts", metadata.NewPostCount)); } }
private SAThreadViewEventArgs CreateViewmodel(Uri parameter) { // try and parse a thread page from the html ThreadPageMetadata page = MetadataExtensions.ThreadPageFromUri(parameter); // since we have a page, create thread metadata from it ThreadMetadata thread = new ThreadMetadata() { ThreadID = page.ThreadID, Title = page.ThreadTitle, PageCount = page.LastPage }; // create binding wrappers Data.ThreadDataSource threadSource = new Data.ThreadDataSource(thread); Data.ThreadPageDataObject pageSource = new Data.ThreadPageDataObject(page); // create viewmodel ViewModels.ThreadViewModel viewmodel = new ViewModels.ThreadViewModel(); int pageIndex = pageSource.PageNumber - 1; viewmodel.UpdateModel(threadSource); viewmodel.Pages[pageIndex] = pageSource; // set the current page to page source viewmodel.SelectedItem = viewmodel.Pages[pageIndex]; viewmodel.SelectedIndex = pageIndex; return(new SAThreadViewEventArgs(viewmodel)); }
protected override object DoWork(LoadPageCommandArgs value) { // load the page ThreadPageMetadata page = value.LoadPage(value.State); if (page == null) { throw new Exception("There was an error loading the requested page."); } else { this._pageCache.AddPage(page); } UpdateStatus("Rendering..."); ThreadPageDataObject dataObject = new ThreadPageDataObject(page); this._currentThread = MetadataExtensions.FromPageMetadata(page); this._ratingCommand.ThreadId = page.ThreadID; this._rating = 0; this._currentThreadPage = dataObject; if (TotalPages != page.LastPage) { this._items = new ThreadPageSlideViewList(page.LastPage); SynchronizeSlideView = true; } return(dataObject); }
private void FormatRatingView(ThreadMetadata metadata) { this.Rating = metadata.Rating; this.ShowRating = this.Rating != 0; switch (this.Rating) { // unrated case case 0: this.ShowRating = false; break; case 1: this.RatingColor = App.THREAD_RATING_COLOR_1; break; case 2: this.RatingColor = App.THREAD_RATING_COLOR_2; break; case 3: this.RatingColor = App.THREAD_RATING_COLOR_3; break; case 4: this.RatingColor = App.THREAD_RATING_COLOR_4; break; case 5: this.RatingColor = App.THREAD_RATING_COLOR_5; break; } }
public ThreadDataSource(ThreadMetadata data) : base() { if (data != null) { SetMetadata(data); } }
public void LoadLastPost(ThreadMetadata thread) { LoadPageCommandArgs args = new LoadPageCommandArgs(); args.LoadPage = LoadLastPostDelegate; args.State = thread; Execute(args); }
public void CreateNew(string threadId) { ThreadMetadata thread = new ThreadMetadata() { ThreadID = threadId }; this.Request = thread.CreateReplyRequest(); }
protected override object DoWork(int parameter) { var thread = new ThreadMetadata() { ThreadID = ThreadId }; return(thread.Rate(parameter)); }
public void LoadPageNumber(ThreadMetadata thread, int pageNumber) { this.CurrentThread = thread; LoadPageCommandArgs args = new LoadPageCommandArgs(); args.LoadPage = LoadPageNumberDelegate; args.State = pageNumber; Execute(args); }
public MessagePostModel(IThreadForm form, ThreadMetadata thread) : base() { this.thread = thread; this.form = form; this.isEdit = true; this.message = form.Message; this.submit = SubmitFormAsync; this.Title = "Edit Post"; this.Subtitle = thread.Title; }
private bool ToggleBookmarksWork(bool isBookmarked, ThreadMetadata thread) { if (!isBookmarked) { return(Data.MainDataSource.Instance.CurrentUser.Metadata.AddToUserBookmarks(thread)); } else { return(Data.MainDataSource.Instance.CurrentUser.Metadata.RemoveFromUserBookmarks(thread)); } }
public static ThreadDataSource FromThreadId(string threadId) { ThreadMetadata data = new ThreadMetadata() { ThreadID = threadId }; ThreadDataSource thread = new ThreadDataSource(); thread._data = data; thread.ThreadID = data.ThreadID; return(thread); }
public ThreadPageMetadata GetPage(ThreadMetadata thread, int pageNumber) { ThreadPageMetadata page = null; string threadId = thread.ThreadID; if (this.ContainsKey(threadId) && this[threadId].ContainsKey(pageNumber)) { page = this[threadId][pageNumber]; } return(page); }
public void SetMetadata(ThreadMetadata data) { this._data = data; this.Title = data.Title; this.IsSticky = data.IsSticky; this.ThreadID = data.ThreadID; this.PageCount = data.PageCount; this.Subtitle = FormatSubtext1(data); this.Description = FormatSubtext2(data); FormatRatingView(data); FormatImage(data.IconUri); }
public static ThreadMetadata ParseThread(HtmlNode node) { ThreadMetadata thread = new ThreadMetadata() .ParseThreadID(node) .ParseThreadSeen(node) .ParseThreadTitleAndUrl(node) .ParseThreadAuthor(node) .ParseReplies(node) .ParseRating(node) .ParseSticky(node) .ParseColorCategory(node) .ParseIconUri(node); thread.LastUpdated = DateTime.Now; return thread; }
private void ProcessToggleBookmarkAsyncGetRequest(IAsyncResult asyncResult, AutoResetEvent signal, BookmarkAction action, ThreadMetadata data) { //Logger.AddEntry("ToggleBookmarkAsync - Initializingweb request..."); HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest; StreamWriter writer = new StreamWriter(request.EndGetRequestStream(asyncResult)); var postData = String.Format("{0}&{1}={2}", action == BookmarkAction.Add ? CoreConstants.BOOKMARK_ADD : CoreConstants.BOOKMARK_REMOVE, CoreConstants.THREAD_ID, data.ThreadID); //Logger.AddEntry(string.Format("ToggleBookmarkAsync - PostData: {0}", postData)); writer.Write(postData); writer.Close(); signal.Set(); }
public void UpdateModel(ThreadViewPageState state) { var thread = Data.MainDataSource.Instance.FindThreadByID(state.ThreadID); if (thread == null) { ThreadMetadata metadata = new ThreadMetadata(); metadata.ThreadID = state.ThreadID; metadata.Title = state.Title; metadata.PageCount = state.PageCount; thread = new Data.ThreadDataSource(metadata); } this.Thread = thread; int index = state.PageNumber - 1; var page = this.Pages[index]; page.Html = state.Html; page.Posts = state.Posts; this.IsReady = true; }
public static bool RemoveBookmark(ThreadMetadata data) { return ThreadBookmarkTask.Bookmark(data, BookmarkAction.Remove); }
public static bool Rate(ThreadMetadata data, int rating) { var url = string.Format("http://forums.somethingawful.com/threadrate.php?vote={0}&threadid={1}", rating, data.ThreadID); return RunURLTask(url); }
internal ThreadReplyRequest(ThreadMetadata thread) { this.Thread = thread; }
public static bool Bookmark(ThreadMetadata thread, BookmarkAction action) { return instance.ToggleBookmark(thread, action); }
public static Uri Reply(ThreadMetadata data, string message) { return ThreadReplyTask.Reply(data, message); }
private string FormatSubtext1(ThreadMetadata metadata) { return(string.Format("by {0}", metadata.Author)); }
public static bool AddBookmark(ThreadMetadata data) { return ThreadBookmarkTask.Bookmark(data, BookmarkAction.Add); }
private void LoadFromQuery() { var query = NavigationContext.QueryString; if (query.ContainsKey("link")) { string value = query["link"]; try { this.threadSlideView.ControlViewModel.LoadPageFromUri(new Uri(value)); } catch (Exception ex) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Critical, ex); NavigationService.GoBack(); } } else if (query.ContainsKey("id") && query.ContainsKey("nav")) { string ThreadID = query["id"]; ThreadMetadata thread = new ThreadMetadata() { ThreadID = ThreadID }; switch (query["nav"]) { case "unread": this.threadSlideView.ControlViewModel.LoadFirstUnreadPost(thread); break; case "last": this.threadSlideView.ControlViewModel.LoadLastPost(thread); break; case "page": int pageNumber = -1; int.TryParse(query["pagenumber"], out pageNumber); this.threadSlideView.ControlViewModel.LoadPageNumber(thread, pageNumber); break; } } }
private static void SendClearMarkedPostRequest(IAsyncResult result, AutoResetEvent signal, ThreadMetadata data) { HttpWebRequest request = result.AsyncState as HttpWebRequest; using (StreamWriter writer = new StreamWriter(request.EndGetRequestStream(result))) { string postData = string.Format("json=1&action=resetseen&threadid={0}", data.ThreadID); writer.Write(postData); writer.Close(); } signal.Set(); }
public static Uri Reply(ThreadMetadata thread, string text) { return instance.ReplyToThread(thread, text); }
private Uri ReplyToThread(ThreadMetadata thread, string text) { var threadID = thread.ThreadID; ThreadReplyData? data = GetReplyData(threadID, text); if (data.HasValue) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug,"ThreadReplyService"); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Begin Reply data..."); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "ThreadID: " + data.Value.THREADID); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Begin Text..."); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, data.Value.TEXT); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "...End Text."); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Form key: " + data.Value.FORMKEY); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Form cookie: " + data.Value.FORMCOOKIE); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "...End reply data."); return InitiateReply(data.Value); } else { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Critical, "ThreadReplyService - ReplyAsync failed on null ThreadReplyData."); return null; } }
public void CreateNew(string threadId) { ThreadMetadata thread = new ThreadMetadata() { ThreadID = threadId }; this.Request = thread.CreateReplyRequest(); }