Example #1
0
        /// <summary>
        /// Clears all HTTP authentication credentials that were added as part of handling
        /// <see cref="IRequestHandler.GetAuthCredentials(IWebBrowser, IBrowser, string, bool, string, int, string, string, IAuthCallback)"/>.
        /// </summary>
        /// <param name="requestContext">request context</param>
        /// <returns>A task that represents the ClearHttpAuthCredentials operation.
        /// Result indicates if the credentials cleared successfully.</returns>
        public static Task <bool> ClearHttpAuthCredentialsAsync(this IRequestContext requestContext)
        {
            var handler = new TaskCompletionCallback();

            requestContext.ClearHttpAuthCredentials(handler);

            return(handler.Task);
        }
Example #2
0
        /// <summary>
        /// Flush the backing store (if any) to disk.
        /// </summary>
        /// <param name="cookieManager">cookieManager instance</param>
        /// <returns>A task that represents the FlushStore operation. Result indicates if the flush completed successfully.
        /// Will return false if the cookikes cannot be accessed.</returns>
        public static Task <bool> FlushStoreAsync(this ICookieManager cookieManager)
        {
            var handler = new TaskCompletionCallback();

            if (cookieManager.FlushStore(handler))
            {
                return(handler.Task);
            }

            //returns null if cookies cannot be accessed.
            return(Task.FromResult(false));
        }
        /// <summary>
        /// Gets the cookie manager associated with the <see cref="IRequestContext"/>. Once the cookie manager
        /// storage has been initialized the method will return.
        /// </summary>
        /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
        /// <param name="requestContext">The <see cref="IRequestContext"/> instance this method extends.</param>
        /// <returns>returns <see cref="ICookieManager"/> if the store was successfully loaded otherwise null. </returns>
        public static async Task <ICookieManager> GetCookieManagerAsync(this IRequestContext requestContext)
        {
            if (requestContext == null)
            {
                throw new Exception("RequestContext is null, unable to obtain cookie manager");
            }

            var callback = new TaskCompletionCallback();

            var cookieManager = requestContext.GetCookieManager(callback);

            var success = await callback.Task;

            return(success ? cookieManager : null);
        }