Ejemplo n.º 1
0
        private static BlogPost SafeGetPostFromServer(IWin32Window mainFrameWindow, string destinationBlogId, BlogPost blogPost)
        {
            try
            {
                if (BlogSettings.BlogIdIsValid(destinationBlogId))
                {
                    string entityName = blogPost.IsPage ? Res.Get(StringId.Page) : Res.Get(StringId.Post);

                    if (!VerifyBlogCredentials(destinationBlogId))
                    {
                        // warn the user we couldn't synchronize
                        ShowRecentPostNotSynchronizedWarning(mainFrameWindow, entityName);
                        return(null);
                    }

                    // get the recent post (with progress if it takes more than a predefined interval)
                    GetRecentPostOperation getRecentPostOperation = null;
                    using (RecentPostProgressForm progressForm = new RecentPostProgressForm(entityName))
                    {
                        progressForm.CreateControl();
                        getRecentPostOperation = new GetRecentPostOperation(new BlogClientUIContextImpl(progressForm), destinationBlogId, blogPost);
                        getRecentPostOperation.Start();
                        progressForm.ShowDialogWithDelay(mainFrameWindow, getRecentPostOperation, 3000);
                    }

                    // if we got the post then return it
                    if (!getRecentPostOperation.WasCancelled && getRecentPostOperation.ServerBlogPost != null)
                    {
                        return(getRecentPostOperation.ServerBlogPost);
                    }
                    // remote server didn't have a copy of the post
                    else if (getRecentPostOperation.NoPostAvailable)
                    {
                        return(null);
                    }
                    // some type of error occurred (including the user cancelled)
                    else
                    {
                        // warn the user we couldn't synchronize
                        ShowRecentPostNotSynchronizedWarning(mainFrameWindow, entityName);
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected error attempting to fetch blog-post from server: " + ex.ToString());
                return(null);
            }
        }
 private void ConnectToBlog(string blogId)
 {
     lock (_commandsLock)
     {
         if (BlogSettings.BlogIdIsValid(blogId))
         {
             using (Blog blog = new Blog(blogId))
                 ConnectToBlog(blog);
         }
         else
         {
             ClearBlogProvider();
         }
     }
 }
Ejemplo n.º 3
0
        public void CheckForNotification()
        {
            try
            {
                if ((DateTimeHelper.UtcNow >= NotificationPollingTime) && WinInet.InternetConnectionAvailable)
                {
                    // poll for notification
                    IBlogProviderButtonNotification buttonNotification = null;
                    using (new BlogClientUIContextSilentMode())
                        buttonNotification = GetButtonNotification();

                    // update notification text under control of the apply updates lock (the lock along
                    // with the check for a valid blog-id immediately below ensures that we a background
                    // notification never creates a "crufty" blog-id by writing to a BlogSettings key
                    // that has already been deleted).
                    using (BlogSettings.ApplyUpdatesLock(BlogId))
                    {
                        if (BlogSettings.BlogIdIsValid(BlogId))
                        {
                            NotificationText = buttonNotification.NotificationText;

                            // update notification image
                            ShowNotificationImage = SafeUpdateNotificationImage(buttonNotification.NotificationImage);

                            // update clear notification flag
                            ClearNotificationOnClick = buttonNotification.ClearNotificationOnClick;

                            // set next polling time
                            UpdateNotificationPollingTime(buttonNotification.PollingInterval);
                        }
                        else
                        {
                            throw new InvalidOperationException("Attempted update notification data for invalid blog-id");
                        }
                    }

                    // fire notification events
                    BlogProviderButtonNotificationSink.FireNotificationEvent(BlogId, Id);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error occurred polling for button notification: " + ex.ToString());
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///  Does this blog support post-sync? (default to true if we can't figure this out)
        /// </summary>
        /// <param name="blogId"></param>
        /// <returns></returns>
        private static bool SynchronizationSupportedForBlog(string blogId)
        {
            try
            {
                if (!BlogSettings.BlogIdIsValid(blogId))
                {
                    return(false);
                }

                // verify synchronization is supported for this blog service
                using (Blog blog = new Blog(blogId))
                    return(blog.ClientOptions.SupportsPostSynchronization);
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception getting post sync options: " + ex.ToString());
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static bool SafeDeleteRemotePost(string blogId, string postId, bool isPage)
        {
            // screen non-existent blog ids
            if (!BlogSettings.BlogIdIsValid(blogId))
            {
                return(true);
            }

            using (Blog blog = new Blog(blogId))
            {
                try
                {
                    if (blog.VerifyCredentials())
                    {
                        // try to delete the post on the remote blog
                        blog.DeletePost(postId, isPage, true);

                        // return success
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (BlogClientOperationCancelledException)
                {
                    // show no UI for operation cancelled
                    Debug.WriteLine("BlogClient operation cancelled");
                    return(false);
                }
                catch (Exception ex)
                {
                    DisplayableExceptionDisplayForm.Show(Win32WindowImpl.ForegroundWin32Window, ex);
                    return(false);
                }
            }
        }