public static BlogPost SafeRetrievePost(PostInfo postInfo, int timeoutMs)
        {
            try
            {
                // null for invalid blogs
                if (!BlogSettings.BlogIdIsValid(postInfo.BlogId))
                {
                    return(null);
                }

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

                // fire up the get post thread
                GetPostThread getPostThread = new GetPostThread(postInfo);
                Thread        thread        = ThreadHelper.NewThread(new ThreadStart(getPostThread.ThreadMain), "GetPostThread", true, false, true);
                thread.Start();

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

                // return the post if we successfully got one
                BlogPost blogPost = getPostThread.BlogPost;
                if (blogPost != null)
                {
                    // Clone in case there are ever issues sharing these accross threads
                    // (not aware of any right now)
                    return(blogPost.Clone() as BlogPost);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 2
0
        public static BlogPost SafeRetrievePost(PostInfo postInfo, int timeoutMs)
        {
            try
            {
                // null for invalid blogs
                if (!BlogSettings.BlogIdIsValid(postInfo.BlogId))
                    return null;

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

                // fire up the get post thread
                GetPostThread getPostThread = new GetPostThread(postInfo);
                Thread thread = ThreadHelper.NewThread(new ThreadStart(getPostThread.ThreadMain), "GetPostThread", true, false, true);
                thread.Start();

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

                // return the post if we successfully got one
                BlogPost blogPost = getPostThread.BlogPost;
                if (blogPost != null)
                {
                    // Clone in case there are ever issues sharing these accross threads
                    // (not aware of any right now)
                    return blogPost.Clone() as BlogPost;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }