Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds or removes a NZB bookmark for your account.
        /// </summary>
        /// <param name="action">Add or delete</param>
        /// <param name="nzbId">NZB ID</param>
        /// <returns>Result code</returns>
        internal BookmarkCode Bookmark(BookmarkAction action, int nzbId)
        {
            var page = string.Format("bookmarks.php?id={0}&action={1}", nzbId, action.ToString().ToLower());

            var response = ResponseParser.ParseSearchResponse <IBookmarksResponse>(
                MakeQuery(page)).SingleOrDefault();

            if (response == null)
            {
                return(BookmarkCode.Unknown);
            }

            var bookmarkCode = response.Result.Split(':').Last().Replace("_", string.Empty);

            return(bookmarkCode.ToEnumSafe <BookmarkCode>());
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        public void ToggleBookmarkAsync(ThreadData thread, BookmarkAction action, Action<Awful.Core.Models.ActionResult> result)
        {
            Awful.Core.Event.Logger.AddEntry(string.Format("ToggleBookmarkAsync - ThreadID: {0}, Action: {1}", thread.ID, action));

            string url = String.Format("{0}/{1}", Globals.Constants.SA_BASE, Globals.Constants.BOOKMARK_THREAD);

            Awful.Core.Event.Logger.AddEntry(string.Format("ToggleBookmarkAsync - Bookmark url: {0}", url));

            AutoResetEvent bookmarkSignal = new AutoResetEvent(false);
            bool bookmarkSuccess = false;

            Action<IAsyncResult> ProccessBookmarkGetRequestStream = null;
            Action<IAsyncResult> ProccessBookmarkBeginGetResponse = null;
            ProccessBookmarkGetRequestStream = (asyncResult) =>
            {
                try
                {
                    Awful.Core.Event.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 ? Globals.Constants.ADD_BOOKMARK : Globals.Constants.REMOVE_BOOKMARK,
                        Globals.Constants.THREAD_ID,
                        thread.ID);

                    Awful.Core.Event.Logger.AddEntry(string.Format("ToggleBookmarkAsync - PostData: {0}", postData));

                    writer.Write(postData);
                    writer.Close();
                    bookmarkSuccess = true;

                    Awful.Core.Event.Logger.AddEntry("ToggleBookmarkAsync - Web request initialization successful.");
                }

                catch (Exception)
                {
                    Awful.Core.Event.Logger.AddEntry("ToggleBookmarkAsync - Web request initialization failed.");
                    bookmarkSuccess = false;
                }
                bookmarkSignal.Set();
            };

            ProccessBookmarkBeginGetResponse = (asyncResult) =>
            {
                Awful.Core.Event.Logger.AddEntry("ToggleBookmarkAsync - Start Get Response...");
                HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
                HttpWebResponse response = request.EndGetResponse(asyncResult) as HttpWebResponse;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Awful.Core.Event.Logger.AddEntry("ToggleBookmarkAsync - Start Get Response successful.");
                    Awful.Core.Event.Logger.AddEntry(string.Format("ToggleBookmarkAsync - Repsonse url: {0}", response.ResponseUri));
                    bookmarkSuccess = true;
                }
                else
                {
                    Awful.Core.Event.Logger.AddEntry("ToggleBookmarkAsync - Start Get Response failed.");
                    bookmarkSuccess = false;
                }

                bookmarkSignal.Set();
            };

            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
            {
                var request = state as HttpWebRequest;
                var callback = new AsyncCallback(ProccessBookmarkGetRequestStream);
                var dispatch = Deployment.Current.Dispatcher;

                request.BeginGetRequestStream(callback, request);
                bookmarkSignal.WaitOne();
                if (!bookmarkSuccess)
                {
                    dispatch.BeginInvoke(() => { result(Awful.Core.Models.ActionResult.Failure); });
                    return;
                }
                callback = new AsyncCallback(ProccessBookmarkBeginGetResponse);
                request.BeginGetResponse(callback, request);
                bookmarkSignal.WaitOne();
                if (!bookmarkSuccess)
                {
                    dispatch.BeginInvoke(() => { result(Awful.Core.Models.ActionResult.Failure); });
                    return;
                }

                dispatch.BeginInvoke(() => { result(Awful.Core.Models.ActionResult.Success); });
                return;
            }),
                InitializePostRequest(url));
        }
Ejemplo n.º 7
0
 public BookmarkMessage(BookmarkAction action, ClrDumpObject clrDumpObject)
 {
     Action        = action;
     ClrDumpObject = clrDumpObject;
 }
Ejemplo n.º 8
0
 public static bool Bookmark(ThreadMetadata thread, BookmarkAction action)
 {
     return instance.ToggleBookmark(thread, action);
 }
Ejemplo n.º 9
0
 public static bool Bookmark(ThreadMetadata thread, BookmarkAction action)
 {
     return(instance.ToggleBookmark(thread, action));
 }
Ejemplo n.º 10
0
 public BookmarkMessage(BookmarkAction action, ClrDumpObject clrDumpObject)
 {
     Action = action;
     ClrDumpObject = clrDumpObject;
 }