Exemplo 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);
            }
        }
Exemplo n.º 2
0
        public void ApplyUpdates(IBlogSettingsDetectionContext settingsContext)
        {
            using (MetaLock(APPLY_UPDATES_LOCK))
            {
                if (BlogSettings.BlogIdIsValid(_id))
                {
                    if (settingsContext.ManifestDownloadInfo != null)
                    {
                        ManifestDownloadInfo = settingsContext.ManifestDownloadInfo;
                    }

                    if (settingsContext.ClientType != null)
                    {
                        ClientType = settingsContext.ClientType;
                    }

                    if (settingsContext.FavIcon != null)
                    {
                        FavIcon = settingsContext.FavIcon;
                    }

                    if (settingsContext.Image != null)
                    {
                        Image = settingsContext.Image;
                    }

                    if (settingsContext.WatermarkImage != null)
                    {
                        WatermarkImage = settingsContext.WatermarkImage;
                    }

                    if (settingsContext.Categories != null)
                    {
                        Categories = settingsContext.Categories;
                    }

                    if (settingsContext.Keywords != null)
                    {
                        Keywords = settingsContext.Keywords;
                    }

                    if (settingsContext.ButtonDescriptions != null)
                    {
                        ButtonDescriptions = settingsContext.ButtonDescriptions;
                    }

                    if (settingsContext.OptionOverrides != null)
                    {
                        OptionOverrides = settingsContext.OptionOverrides;
                    }

                    if (settingsContext.HomePageOverrides != null)
                    {
                        HomePageOverrides = settingsContext.HomePageOverrides;
                    }
                }
                else
                {
                    throw new InvalidOperationException("Attempted to apply updates to invalid blog-id");
                }
            }
        }