Esempio n. 1
0
        /// <summary>
        /// Perform a blog operation with a timeout. If the operation could not be completed for any reason (including
        /// an invalid blog, no credentials, a network error, or a timeout) then null is returned.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="blogId"></param>
        /// <param name="operation"></param>
        /// <param name="timeoutMs"></param>
        /// <returns></returns>
        public static object PerformBlogOperationWithTimeout(string blogId, BlogClientOperation operation, int timeoutMs, bool verifyCredentials)
        {
            try
            {
                // null for invalid blogs
                if (!BlogSettings.BlogIdIsValid(blogId))
                {
                    return(null);
                }

                // null if the user can't authenticate
                if (verifyCredentials)
                {
                    using (Blog blog = new Blog(blogId))
                    {
                        if (!blog.VerifyCredentials())
                        {
                            return(null);
                        }
                    }
                }

                // fire up the thread
                BlogClientOperationThread operationThread = new BlogClientOperationThread(blogId, operation);
                Thread thread = ThreadHelper.NewThread(new ThreadStart(operationThread.ThreadMain), "BlogClientOperationThread", true, false, true);
                thread.Start();

                // wait for it to complete
                thread.Join(timeoutMs);

                // return the result
                return(operationThread.Result);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception occurred performing BlogOperation: " + ex.ToString());
                return(null);
            }
        }
Esempio n. 2
0
 public BlogClientOperationThread(string blogId, BlogClientOperation operation)
 {
     _blogId    = blogId;
     _operation = operation;
 }
Esempio n. 3
0
 public static object PerformBlogOperationWithTimeout(string blogId, BlogClientOperation operation, int timeoutMs)
 {
     return(PerformBlogOperationWithTimeout(blogId, operation, timeoutMs, true));
 }
 public BlogClientOperationThread(string blogId, BlogClientOperation operation)
 {
     _blogId = blogId;
     _operation = operation;
 }
        /// <summary>
        /// Perform a blog operation with a timeout. If the operation could not be completed for any reason (including
        /// an invalid blog, no credentials, a network error, or a timeout) then null is returned.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="blogId"></param>
        /// <param name="operation"></param>
        /// <param name="timeoutMs"></param>
        /// <returns></returns>
        public static object PerformBlogOperationWithTimeout(string blogId, BlogClientOperation operation, int timeoutMs, bool verifyCredentials)
        {
            try
            {
                // null for invalid blogs
                if (!BlogSettings.BlogIdIsValid(blogId))
                    return null;

                // null if the user can't authenticate
                if (verifyCredentials)
                {
                    using (Blog blog = new Blog(blogId))
                    {
                        if (!blog.VerifyCredentials())
                            return null;
                    }
                }

                // fire up the thread
                BlogClientOperationThread operationThread = new BlogClientOperationThread(blogId, operation);
                Thread thread = ThreadHelper.NewThread(new ThreadStart(operationThread.ThreadMain), "BlogClientOperationThread", true, false, true);
                thread.Start();

                // wait for it to complete
                thread.Join(timeoutMs);

                // return the result
                return operationThread.Result;
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception occurred performing BlogOperation: " + ex.ToString());
                return null;
            }
        }
 public static object PerformBlogOperationWithTimeout(string blogId, BlogClientOperation operation, int timeoutMs)
 {
     return PerformBlogOperationWithTimeout(blogId, operation, timeoutMs, true);
 }