Exemplo n.º 1
0
        /// <summary>
        /// Publishes posts to the destination blog.
        /// </summary>
        /// <history>
        /// Sean Patterson   11/15/2010   [Created]
        /// </history>
        public void WriteXMLPosts()
        {
            Services     blogService = new Services();
            Post         resultPost;
            StreamWriter swLog;
            WorkerArgs   args = new WorkerArgs();

            string LogFile = App.sourceBlog.serviceType + "_" +
                             App.destBlog.serviceType + "_Migration-" +
                             DateTime.Now.ToString("yyyy_MM_dd_hhMMss") + ".csv";

            // Load document.
            swLog = new StreamWriter(LogFile);
            swLog.WriteLine("Source Id, Source Link, Destination Id, " +
                            "Destination Link");

            swLog.Flush();

            try
            {
                args.status = "Migrating posts from " + App.sourceBlog.serviceType +
                              " to " + App.destBlog.serviceType;
                migrationWorker.ReportProgress(15, args);

                if (App.rewritePosts)
                {
                    args.status = "Rewriting original posts ENABLED.";
                    migrationWorker.ReportProgress(15, args);
                }
                else
                {
                    args.status = "Rewriting original posts DISABLED.";
                    migrationWorker.ReportProgress(15, args);
                }

                foreach (Post blogPost in App.sourceBlog.blogPosts)
                {
                    if (App.sourceBlog.postsToMigrate.
                        Contains(Convert.ToInt32(blogPost.postid)))
                    {
                        args.status = "Writing Post: " + blogPost.title;
                        migrationWorker.ReportProgress(20, args);

                        resultPost = blogService.InsertPost
                                         (App.destBlog.serviceUrl, App.destBlog.blogId,
                                         App.destBlog.username, App.destBlog.password,
                                         blogPost);

                        swLog.WriteLine(blogPost.postid.ToString() + "," + blogPost.link + "," +
                                        resultPost.postid.ToString() + "," + resultPost.link);

                        swLog.Flush();

                        if (App.rewritePosts)
                        {
                            Post   updatePost = blogPost;
                            string newUrl     = "<a href='" + resultPost.link + "'>" + resultPost.link + "</a>";
                            string newMessage = App.rewriteMessage.Replace("[URL]", newUrl);
                            updatePost.description = newMessage;

                            blogService.UpdatePost(App.sourceBlog.serviceUrl,
                                                   App.sourceBlog.username,
                                                   App.sourceBlog.password,
                                                   updatePost);
                        }
                    }
                }
                swLog.Close();
            }
            catch (Exception ex)
            {
                swLog.Flush();
                swLog.Close();
                MessageBox.Show("An error occurred migrating blog posts:" +
                                Environment.NewLine + Environment.NewLine +
                                ex.ToString() +
                                Environment.NewLine + Environment.NewLine +
                                "Please verify your settings and try migrating " +
                                "posts again.", "Error Migrating Posts",
                                MessageBoxButton.OK, MessageBoxImage.Error);

                migrationWorker.CancelAsync();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Publishes posts to the destination blog from a BlogML object.
        /// </summary>
        /// <history>
        /// Sean Patterson   11/15/2010   [Created]
        /// </history>
        public void ImportXMLPosts()
        {
            Services     blogService = new Services();
            Post         resultPost;
            Post         newPost;
            StreamWriter swLog;
            Generator    myGenerator = new Generator();

            BlogML.categoryRefType currCatRef;
            string categoryName;

            BlogML.postType currPost;
            List <string>   categoryList;
            WorkerArgs      args = new WorkerArgs();

            string LogFile = App.sourceBlog.serviceType + "_" +
                             App.destBlog.serviceType + "_Migration-" +
                             DateTime.Now.ToString("yyyy_MM_dd_hhMMss") + ".csv";

            // Load document.
            swLog = new StreamWriter(LogFile);
            swLog.WriteLine("Source Id, Source Link, Destination Id, " +
                            "Destination Link");

            swLog.Flush();

            try
            {
                args.status = "Migrating posts from " + App.sourceBlog.serviceType +
                              " to " + App.destBlog.serviceType;
                migrationWorker.ReportProgress(15, args);

                for (int i = 0; i <= App.sourceBlog.blogData.posts.Length - 1; i++)
                {
                    currPost = App.sourceBlog.blogData.posts[i];

                    if (App.sourceBlog.postsToMigrate.Contains(Convert.ToInt32(currPost.id)))
                    {
                        args.status = "Writing Post: " + string.Join(" ", currPost.title.Text);
                        migrationWorker.ReportProgress(20, args);

                        newPost             = new Post();
                        newPost.title       = string.Join(" ", currPost.title.Text);
                        newPost.dateCreated = currPost.datecreated;
                        newPost.userid      = App.destBlog.username;
                        newPost.postid      = currPost.id;
                        newPost.description = currPost.content.Value;
                        newPost.link        = App.sourceBlog.rootUrl + currPost.posturl;

                        // Post Tags/Categories (currently only categories are implemented with BlogML
                        if (currPost.categories != null)
                        {
                            categoryList = new List <string>();

                            for (int j = 0; j <= currPost.categories.Length - 1; j++)
                            {
                                currCatRef   = currPost.categories[j];
                                categoryName = myGenerator.GetCategoryById
                                                   (App.sourceBlog.blogData,
                                                   Convert.ToInt32(currCatRef.@ref));
                                categoryList.Add(categoryName);
                            }

                            newPost.categories = categoryList.ToArray();
                        }

                        resultPost = blogService.InsertPost
                                         (App.destBlog.serviceUrl, App.destBlog.blogId,
                                         App.destBlog.username, App.destBlog.password,
                                         newPost);

                        swLog.WriteLine(newPost.postid.ToString() + "," + newPost.link + "," +
                                        resultPost.postid.ToString() + "," + resultPost.link);

                        swLog.Flush();

                        // Rewrite posts can still be done "live" even if a BlogML
                        // file is being imported provided the serviceUrl details
                        // are provided.
                        if (App.rewritePosts)
                        {
                            Post   updatePost = newPost;
                            string newUrl     = "<a href='" + resultPost.link + "'>" + resultPost.link + "</a>";
                            string newMessage = App.rewriteMessage.Replace("[URL]", newUrl);
                            updatePost.description = newMessage;

                            blogService.UpdatePost(App.sourceBlog.serviceUrl,
                                                   App.sourceBlog.username,
                                                   App.sourceBlog.password,
                                                   updatePost);
                        }
                    }
                }

                swLog.Close();
            }
            catch (Exception ex)
            {
                swLog.Flush();
                swLog.Close();
                MessageBox.Show("An error occurred migrating blog posts:" +
                                Environment.NewLine + Environment.NewLine +
                                ex.ToString() +
                                Environment.NewLine + Environment.NewLine +
                                "Please verify your settings and try migrating " +
                                "posts again.", "Error Migrating Posts",
                                MessageBoxButton.OK, MessageBoxImage.Error);

                migrationWorker.CancelAsync();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Migrates the posts from the source to destination server.
        /// </summary>
        /// <param name="sender">Migrate button click event.</param>
        /// <param name="e">Button click event arguments.</param>
        /// <history>
        /// Sean Patterson    11/4/2010   [Created]
        /// </history>
        private void btnMigrate_Click(object sender, RoutedEventArgs e)
        {
            WorkerArgs myArgs = new WorkerArgs();
             myArgs.processToRun = "migrateposts";
             myArgs.status = "Migrate posts action selected.";

             try
             {
            App.sourceBlog.postsToMigrate.Clear();

            foreach (PostData item in lsvAllPosts.SelectedItems)
            {
               App.sourceBlog.postsToMigrate.Add(item.postid);
            }

            if (chkUpdateSource.IsChecked == true)
            {
               App.rewritePosts = true;
               App.rewriteMessage = txtUpdateSource.Text;
            }
            else
            {
               App.rewritePosts = false;
               App.rewriteMessage = null;
            }

            if (App.sourceBlog.postsToMigrate.Count > 0)
            {
               migrationWorker.RunWorkerAsync(myArgs);
            }
            else
            {
               MessageBox.Show("Please specify at least one post to migrate.",
                               "No Posts Specified.", MessageBoxButton.OK,
                               MessageBoxImage.Exclamation);
            }
             }
             catch (XmlRpcFaultException fex)
             {
               MessageBox.Show("XML-RPC error migrating posts: " +
                               Environment.NewLine + Environment.NewLine +
                               fex.ToString() + "Please check your settings and " +
                               "try again.", "Migration Result",
                               MessageBoxButton.OK, MessageBoxImage.Information);
             }
             catch (Exception ex)
             {
            MessageBox.Show("General error migrating posts: " +
                            Environment.NewLine + Environment.NewLine +
                            ex.ToString() + "Please check your settings and " +
                            "try again.", "Migration Result",
                            MessageBoxButton.OK, MessageBoxImage.Information);
             }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles btnGetAllPosts click event.
        /// </summary>
        /// <param name="sender">Get All Posts button click event.</param>
        /// <param name="e">Click event arguments.</param>
        /// <history>
        /// Sean Patterson    11/4/2010   [Created]
        /// </history>
        private void btnGetAllPosts_Click(object sender, RoutedEventArgs e)
        {
            WorkerArgs myArgs = new WorkerArgs();
             myArgs.processToRun = "getallposts";
             myArgs.status = "Get all posts action selected.";

             try
             {
               allPostsWorker.RunWorkerAsync(myArgs);
             }
             catch (XmlRpcFaultException fex)
             {
               // Flush out old records to prevent accidental writes.
               if (App.sourceBlog.blogPosts.Count > 0)
               {
                  App.sourceBlog.blogPosts.Clear();
               }

               App.sourceBlog.blogData = null;

               if (PostCollection.Count > 0)
               {
                  PostCollection.Clear();
               }

               lblEntriesCount.Content = "[0 Total]";

               MessageBox.Show("XML-RPC error migrating posts: " +
                              Environment.NewLine + Environment.NewLine +
                              fex.ToString() + "Please check your settings and " +
                              "try again.", "Migration Result",
                              MessageBoxButton.OK, MessageBoxImage.Error);
             }
             catch (Exception ex)
             {
               // Flush out old records to prevent accidental writes.
               if (App.sourceBlog.blogPosts.Count > 0)
               {
                  App.sourceBlog.blogPosts.Clear();
               }

               App.sourceBlog.blogData = null;

               if (PostCollection.Count > 0)
               {
                  PostCollection.Clear();
               }

               lblEntriesCount.Content = "[0 Total]";

               MessageBox.Show("General error migrating posts: " +
                              Environment.NewLine + Environment.NewLine +
                              ex.ToString() + "Please check your settings and " +
                              "try again.", "Migration Result",
                              MessageBoxButton.OK, MessageBoxImage.Information);
             }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Publishes posts to the destination blog from a BlogML object.
        /// </summary>
        /// <history>
        /// Sean Patterson   11/15/2010   [Created]
        /// </history>
        public void ImportXMLPosts()
        {
            Services blogService = new Services();
               Post resultPost;
               Post newPost;
               StreamWriter swLog;
               Generator myGenerator = new Generator();
               BlogML.categoryRefType currCatRef;
               string categoryName;
               BlogML.postType currPost;
               List<string> categoryList;
               WorkerArgs args = new WorkerArgs();

               string LogFile = App.sourceBlog.serviceType + "_" +
                            App.destBlog.serviceType + "_Migration-" +
                            DateTime.Now.ToString("yyyy_MM_dd_hhMMss") + ".csv";

               // Load document.
               swLog = new StreamWriter(LogFile);
               swLog.WriteLine("Source Id, Source Link, Destination Id, " +
                           "Destination Link");

               swLog.Flush();

               try
               {
              args.status = "Migrating posts from " + App.sourceBlog.serviceType +
                            " to " + App.destBlog.serviceType;
              migrationWorker.ReportProgress(15, args);

              for (int i = 0; i <= App.sourceBlog.blogData.posts.Length - 1; i++)
              {
                 currPost = App.sourceBlog.blogData.posts[i];

                 if (App.sourceBlog.postsToMigrate.Contains(Convert.ToInt32(currPost.id)))
                 {
                    args.status = "Writing Post: " + string.Join(" ", currPost.title.Text);
                    migrationWorker.ReportProgress(20, args);

                    newPost = new Post();
                    newPost.title = string.Join(" ", currPost.title.Text);
                    newPost.dateCreated = currPost.datecreated;
                    newPost.userid = App.destBlog.username;
                    newPost.postid = currPost.id;
                    newPost.description = currPost.content.Value;
                    newPost.link = App.sourceBlog.rootUrl + currPost.posturl;

                    // Post Tags/Categories (currently only categories are implemented with BlogML
                    if (currPost.categories != null)
                    {
                       categoryList = new List<string>();

                       for (int j = 0; j <= currPost.categories.Length - 1; j++)
                       {
                          currCatRef = currPost.categories[j];
                          categoryName = myGenerator.GetCategoryById
                                                     (App.sourceBlog.blogData,
                                                      Convert.ToInt32(currCatRef.@ref));
                          categoryList.Add(categoryName);
                       }

                       newPost.categories = categoryList.ToArray();
                    }

                    resultPost = blogService.InsertPost
                                               (App.destBlog.serviceUrl, App.destBlog.blogId,
                                                App.destBlog.username, App.destBlog.password,
                                                newPost);

                    swLog.WriteLine(newPost.postid.ToString() + "," + newPost.link + "," +
                                    resultPost.postid.ToString() + "," + resultPost.link);

                    swLog.Flush();

                    // Rewrite posts can still be done "live" even if a BlogML
                    // file is being imported provided the serviceUrl details
                    // are provided.
                    if (App.rewritePosts)
                    {
                       Post updatePost = newPost;
                       string newUrl = "<a href='" + resultPost.link + "'>" + resultPost.link + "</a>";
                       string newMessage = App.rewriteMessage.Replace("[URL]", newUrl);
                       updatePost.description = newMessage;

                       blogService.UpdatePost(App.sourceBlog.serviceUrl,
                                              App.sourceBlog.username,
                                              App.sourceBlog.password,
                                              updatePost);
                    }
                 }
              }

              swLog.Close();
               }
               catch (Exception ex)
               {
              swLog.Flush();
              swLog.Close();
              MessageBox.Show("An error occurred migrating blog posts:" +
                              Environment.NewLine + Environment.NewLine +
                              ex.ToString() +
                              Environment.NewLine + Environment.NewLine +
                              "Please verify your settings and try migrating " +
                              "posts again.", "Error Migrating Posts",
                              MessageBoxButton.OK, MessageBoxImage.Error);

              migrationWorker.CancelAsync();
               }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Publishes posts to the destination blog.
        /// </summary>
        /// <history>
        /// Sean Patterson   11/15/2010   [Created]
        /// </history>
        public void WriteXMLPosts()
        {
            Services blogService = new Services();
               Post resultPost;
               StreamWriter swLog;
               WorkerArgs args = new WorkerArgs();

               string LogFile = App.sourceBlog.serviceType + "_" +
                            App.destBlog.serviceType + "_Migration-" +
                            DateTime.Now.ToString("yyyy_MM_dd_hhMMss") + ".csv";

               // Load document.
               swLog = new StreamWriter(LogFile);
               swLog.WriteLine("Source Id, Source Link, Destination Id, " +
                           "Destination Link");

               swLog.Flush();

               try
               {
              args.status = "Migrating posts from " + App.sourceBlog.serviceType +
                              " to " + App.destBlog.serviceType;
              migrationWorker.ReportProgress(15, args);

              if (App.rewritePosts)
              {
                 args.status = "Rewriting original posts ENABLED.";
                 migrationWorker.ReportProgress(15, args);
              }
              else
              {
                 args.status = "Rewriting original posts DISABLED.";
                 migrationWorker.ReportProgress(15, args);
              }

              foreach (Post blogPost in App.sourceBlog.blogPosts)
              {

                 if (App.sourceBlog.postsToMigrate.
                         Contains(Convert.ToInt32(blogPost.postid)))
                 {
                    args.status = "Writing Post: " + blogPost.title;
                    migrationWorker.ReportProgress(20, args);

                    resultPost = blogService.InsertPost
                                             (App.destBlog.serviceUrl, App.destBlog.blogId,
                                              App.destBlog.username, App.destBlog.password,
                                              blogPost);

                    swLog.WriteLine(blogPost.postid.ToString() + "," + blogPost.link + "," +
                                    resultPost.postid.ToString() + "," + resultPost.link);

                    swLog.Flush();

                    if (App.rewritePosts)
                    {
                       Post updatePost = blogPost;
                       string newUrl = "<a href='" + resultPost.link + "'>" + resultPost.link + "</a>";
                       string newMessage = App.rewriteMessage.Replace("[URL]", newUrl);
                       updatePost.description = newMessage;

                       blogService.UpdatePost(App.sourceBlog.serviceUrl,
                                              App.sourceBlog.username,
                                              App.sourceBlog.password,
                                              updatePost);
                    }
                 }
              }
              swLog.Close();
               }
               catch (Exception ex)
               {
              swLog.Flush();
              swLog.Close();
              MessageBox.Show("An error occurred migrating blog posts:" +
                              Environment.NewLine + Environment.NewLine +
                              ex.ToString() +
                              Environment.NewLine + Environment.NewLine +
                              "Please verify your settings and try migrating " +
                              "posts again.", "Error Migrating Posts",
                              MessageBoxButton.OK, MessageBoxImage.Error);

              migrationWorker.CancelAsync();
               }
        }
        private void btnRewrite_Click(object sender, RoutedEventArgs e)
        {
            WorkerArgs myArgs = new WorkerArgs();

             if (cmbRewriteService.SelectedIndex > -1)
             {
            ComboBoxItem itemDest = (ComboBoxItem)cmbRewriteService.SelectedItem;

            switch (itemDest.Tag.ToString())
            {
               case "SS":
                  App.rewriteBlog.serviceUrl = "http://www.squarespace.com/process/service/PostInterceptor";
                  break;

               case "WP":
                  App.rewriteBlog.serviceUrl = txtRewriteBlogUrl.Text + "/xmlrpc.php";
                  break;

               case "ASPNet":
                  App.rewriteBlog.serviceUrl = "http://weblogs.asp.net/metablog.ashx";
                  break;

               case "OTHER":
                  App.rewriteBlog.serviceUrl = txtRewriteServiceUrl.Text;
                  break;
            }

            App.rewriteBlog.blogId = txtRewriteBlogId.Text;
            App.rewriteBlog.rootUrl = txtRewriteBlogUrl.Text;
            App.rewriteBlog.username = txtRewriteUser.Text;
            App.rewriteBlog.password = txtRewritePassword.Text;
            App.rewriteBlog.blogFile = txtRewriteFile.Text;

            App.itemsToRewrite.Clear();
            foreach (LogData logItem in lsvLogEntries.SelectedItems)
            {
               App.itemsToRewrite.Add(logItem);
            }

            App.rewriteMessage = txtUpdateSource.Text;

            myArgs.processToRun = "rewrite";
            myArgs.status = "Starting rewrite process...";
            rewriteWorker.RunWorkerAsync(myArgs);
             }
             else
             {
            MessageBox.Show("Please specify a service type.",
                            "Rewrite Sources Error.",
                            MessageBoxButton.OK, MessageBoxImage.Error);
             }
        }