private IEnumerable<BloggerEntry> FindBlogs()
		{
			BloggerQuery query = new BloggerQuery();
            BloggerService service = new BloggerService("BloggerSampleApp.NET");

            if (UserName != null && UserName.Length > 0)
            {
                service.Credentials = new GDataCredentials(UserName, Password);
            }

            query.Uri = new Uri(BloggerFeedUrl);


            BloggerFeed bloggerFeed = service.Query(query);
			
			List<BloggerEntry> blogs = new List<BloggerEntry>();

            while (bloggerFeed != null && bloggerFeed.Entries.Count > 0)
            {
                foreach (BloggerEntry entry in bloggerFeed.Entries) 
                {
                    blogs.Add(entry); 
                }
                // do the chunking...
                if (bloggerFeed.NextChunk != null) 
                {
                    query.Uri = new Uri(bloggerFeed.NextChunk); 
                    bloggerFeed = service.Query(query);
                }
                else 
                {
                    bloggerFeed = null; 
                }
            }
			
			return blogs;
		}
        private void AddEntry_Click(object sender, System.EventArgs e)
        {
            addentry dlg = new addentry();
            if (dlg.ShowDialog() == DialogResult.OK &&
                dlg.Entry.Length > 0) 
            {
                // now add this to the feed.

                BloggerEntry entry = new BloggerEntry();

                entry.Content.Content = dlg.Entry;
                entry.Content.Type = "html"; 
                entry.Title.Text = dlg.EntryTitle;


                string userName =    this.UserName.Text;
                string passWord =    this.Password.Text;

                BloggerService service = new BloggerService("BloggerSampleApp.NET");

                if (userName != null && userName.Length > 0)
                {
                    service.Credentials = new GDataCredentials(userName, passWord);
                }

                service.Insert(new Uri(this.feedUri), entry); 

                RefreshFeed(this.feedUri);
            }
        }
        private void RefreshFeed(string bloggerURI) 
        {
            string userName =    this.UserName.Text;
            string passWord =    this.Password.Text;

            // Suppress repainting the TreeView until all the objects have been created.
            this.FeedView.BeginUpdate(); 
            // Clear the TreeView each time the method is called.
            this.FeedView.Nodes.Clear(); 

            if (this.feedUri != null)
            {
                BloggerQuery query = new BloggerQuery();
                BloggerService service = new BloggerService("BloggerSampleApp.NET");

                if (userName != null && userName.Length > 0)
                {
                    service.Credentials = new GDataCredentials(userName, passWord);
                }

                // only get event's for today - 1 month until today + 1 year

                query.Uri = new Uri(bloggerURI);

                // set wait cursor before...
                Cursor.Current = Cursors.WaitCursor; 
            

                BloggerFeed bloggerFeed = service.Query(query);

                // Reset the cursor to the default for all controls.
                Cursor.Current = Cursors.Default;



                // now populate the calendar
                while (bloggerFeed != null && bloggerFeed.Entries.Count > 0)
                {
                    foreach (BloggerEntry entry in bloggerFeed.Entries) 
                    {
                        int iIndex = this.FeedView.Nodes.Add(new TreeNode(entry.Title.Text)); 
                        if (iIndex >= 0) 
                        {
                            AtomPerson author = entry.Authors[0];
                            this.FeedView.Nodes[iIndex].Nodes.Add(new TreeNode("by: " + author.Name));
                            this.FeedView.Nodes[iIndex].Nodes.Add(new TreeNode("published: " + entry.Published.ToString())); 
                            if (entry.Content.Content.Length > 50) 
                            {
                                this.FeedView.Nodes[iIndex].Nodes.Add(new TreeNode(entry.Content.Content.Substring(0, 50)+"....")); 
                            } 
                            else 
                            {
                                this.FeedView.Nodes[iIndex].Nodes.Add(new TreeNode(entry.Content.Content)); 
                            }

                        }
                    }

                    // do the chunking...
                    if (bloggerFeed.NextChunk != null) 
                    {
                        query.Uri = new Uri(bloggerFeed.NextChunk); 
                        bloggerFeed = service.Query(query);
                    }
                    else
                    {
                        bloggerFeed = null;
                    }
                }
            }

            // Reset the cursor to the default for all controls.
            Cursor.Current = Cursors.Default;
            // stop repainting the TreeView.
            this.FeedView.EndUpdate();
        }
        private void RefreshFeedList()
        {
            string bloggerURI  = this.BloggerURI.Text;
            string userName =    this.UserName.Text;
            string passWord =    this.Password.Text;

            BloggerQuery query = new BloggerQuery();
            BloggerService service = new BloggerService("BloggerSampleApp.NET");

            if (userName != null && userName.Length > 0)
            {
                service.Credentials = new GDataCredentials(userName, passWord);
            }

            // only get event's for today - 1 month until today + 1 year

            query.Uri = new Uri(bloggerURI);

            Cursor.Current = Cursors.WaitCursor; 

            // start repainting
            this.FeedChooser.BeginUpdate(); 

            BloggerFeed bloggerFeed = service.Query(query);
            // Display a wait cursor while the TreeNodes are being created.

            this.FeedChooser.DisplayMember = "Title"; 

            while (bloggerFeed != null && bloggerFeed.Entries.Count > 0)
            {
                foreach (BloggerEntry entry in bloggerFeed.Entries) 
                {
                    int iIndex = this.FeedChooser.Items.Add(new ListEntry(entry)); 
                }
                // do the chunking...
                if (bloggerFeed.NextChunk != null) 
                {
                    query.Uri = new Uri(bloggerFeed.NextChunk); 
                    bloggerFeed = service.Query(query);
                }
                else 
                {
                    bloggerFeed = null; 
                }
            }

            if (this.FeedChooser.Items.Count > 0) 
            {
                this.FeedChooser.Items.Insert(0, "Choose the feed..."); 
            }
            else 
            {
                 this.FeedChooser.Items.Insert(0, "No feeds for this user..."); 
            }
            
            
            // Reset the cursor to the default for all controls.
            Cursor.Current = Cursors.Default;
            // End repainting the combobox
            this.FeedChooser.EndUpdate();
        
            
        }
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void BloggerStressTest()
        {
            Tracing.TraceMsg("Entering Blogger GoogleStressTest");

            FeedQuery query = new FeedQuery();
            BloggerService service = new BloggerService(this.ApplicationName);

            if (this.bloggerURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.bloggerURI);
                AtomFeed blogFeed = service.Query(query);

                ObjectModelHelper.DumpAtomObject(blogFeed,CreateDumpFileName("AuthenticationTest")); 

                if (blogFeed != null)
                {
                    for (int i=0; i< 30; i++)
                    {
                        AtomEntry entry = ObjectModelHelper.CreateAtomEntry(i); 
                        entry.Categories.Clear();
                        entry.Title.Text = "Title " + i; 
                        entry.Content.Content = "Some text...";
                        entry.Content.Type = "html"; 

                        blogFeed.Insert(entry); 
                    }
                }
            }

        }
        public void BloggerETagTest()
        {
            Tracing.TraceMsg("Entering BloggerETagTest");

            BloggerQuery query = new BloggerQuery();
            BloggerService service = new BloggerService(this.ApplicationName);
            service.ProtocolMajor = 2;

            string title = "V1" + Guid.NewGuid().ToString();

            service.RequestFactory = this.factory;

            query.Uri = new Uri(this.bloggerURI);

            // insert a new entry in version 1

            AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1); 
            entry.Categories.Clear();
            entry.Title.Text = title;
            entry.IsDraft = true;

            BloggerEntry returnedEntry = service.Insert(new Uri(this.bloggerURI), entry) as BloggerEntry;

            Assert.IsTrue(returnedEntry.ProtocolMajor == service.ProtocolMajor);
            Assert.IsTrue(entry.IsDraft);
            Assert.IsTrue(returnedEntry.IsDraft);
            Assert.IsTrue(returnedEntry.Etag != null);

            string etagOld = returnedEntry.Etag; 

            returnedEntry.Content.Content = "This is a test";

            BloggerEntry newEntry = returnedEntry.Update() as BloggerEntry; 

            Assert.IsTrue(newEntry.Etag != null);
            Assert.IsTrue(newEntry.Etag != etagOld);
        }
        public void BloggerVersion2Test()
        {
            Tracing.TraceMsg("Entering BloggerVersion2Test");

            BloggerQuery query = new BloggerQuery();
            BloggerService service = new BloggerService(this.ApplicationName);

            string title = "V1" + Guid.NewGuid().ToString();

            service.ProtocolMajor = 1; 

            service.RequestFactory = this.factory;
            query.Uri = new Uri(this.bloggerURI);

            // insert a new entry in version 1

            AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1); 
            entry.Categories.Clear();
            entry.Title.Text = title;
            entry.IsDraft = true;
            entry.ProtocolMajor = 12;



            AtomEntry returnedEntry = service.Insert(new Uri(this.bloggerURI), entry);
            Assert.IsTrue(returnedEntry.ProtocolMajor == service.ProtocolMajor);
            Assert.IsTrue(entry.IsDraft);
            Assert.IsTrue(returnedEntry.IsDraft);

            BloggerFeed feed = service.Query(query);
            Assert.IsTrue(feed.ProtocolMajor == service.ProtocolMajor);
            if (feed != null)
            {
                Assert.IsTrue(feed.TotalResults >= feed.Entries.Count, "totalresults should be >= number of entries");
                Assert.IsTrue(feed.Entries.Count > 0, "We should have some entries");
            }

            service.ProtocolMajor = 2;
            feed = service.Query(query);
            Assert.IsTrue(feed.ProtocolMajor == service.ProtocolMajor);

            if (feed != null)
            {
                Assert.IsTrue(feed.Entries.Count > 0, "We should have some entries");
                Assert.IsTrue(feed.TotalResults >= feed.Entries.Count, "totalresults should be >= number of entries");

                foreach (BloggerEntry e in feed.Entries)
                {
                    if (e.Title.Text == title)
                    {
                        Assert.IsTrue(e.ProtocolMajor == 2);
                        Assert.IsTrue(e.IsDraft);
                    }
                }
            }


        }
        public void BloggerPublicFeedTest()
        {
            Tracing.TraceMsg("Entering BloggerPublicFeedTest");

            FeedQuery query = new FeedQuery();
            BloggerService service = new BloggerService(this.ApplicationName);

            String publicURI = (String) this.externalHosts[0];

            if (publicURI != null)
            {
                service.RequestFactory = this.factory; 

                query.Uri = new Uri(publicURI);
                AtomFeed feed = service.Query(query);

                 if (feed != null)
                 {
                       // look for the one with dinner time...
                    foreach (AtomEntry entry in feed.Entries)
                    {
                        Assert.IsTrue(entry.ReadOnly, "The entry should be readonly");
                    }
                 }
            }

        }
        public void BloggerHTMLTest()
        {
            Tracing.TraceMsg("Entering BloggerHTMLTest");

            FeedQuery query = new FeedQuery();
            BloggerService service = new BloggerService(this.ApplicationName);

            if (this.bloggerURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.bloggerURI);
                AtomFeed feed = service.Query(query);

                String strTitle = "Dinner time" + Guid.NewGuid().ToString(); 

                if (feed != null)
                {
                    // get the first entry
                    String htmlContent = "<div>&lt;b&gt;this is an html test text&lt;/b&gt;</div>"; 
                    AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1); 
                    entry.Categories.Clear();
                    entry.Title.Text = strTitle;
                    entry.Content.Type = "html";
                    entry.Content.Content = htmlContent;

                    AtomEntry newEntry = feed.Insert(entry); 
                    Tracing.TraceMsg("Created blogger entry");

                    // try to get just that guy.....
                    FeedQuery singleQuery = new FeedQuery();
                    singleQuery.Uri = new Uri(newEntry.SelfUri.ToString()); 
                    AtomFeed newFeed = service.Query(singleQuery);
                    AtomEntry sameGuy = newFeed.Entries[0]; 

                    Assert.IsTrue(sameGuy.Title.Text.Equals(newEntry.Title.Text), "both titles should be identical"); 
                    Assert.IsTrue(sameGuy.Content.Type.Equals("html"));
                    String input = HttpUtility.HtmlDecode(htmlContent); 
                    String output = HttpUtility.HtmlDecode(sameGuy.Content.Content); 
                    Assert.IsTrue(input.Equals(output), "The input string should be equal the output string"); 

                }

                service.Credentials = null; 
            }
        }
Exemple #10
0
        public void GoogleAuthenticationTest()
        {
            Tracing.TraceMsg("Entering Blogger AuthenticationTest");

            BloggerQuery query = new BloggerQuery();
            BloggerService service = new BloggerService(this.ApplicationName);

            int iCount; 

            if (this.bloggerURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.bloggerURI);
                BloggerFeed blogFeed = service.Query(query);

                ObjectModelHelper.DumpAtomObject(blogFeed,CreateDumpFileName("AuthenticationTest")); 
                iCount = blogFeed.Entries.Count; 

                String strTitle = "Dinner time" + Guid.NewGuid().ToString(); 

                if (blogFeed != null && blogFeed.Entries.Count > 0)
                {
                    BloggerEntry entry = ObjectModelHelper.CreateAtomEntry(1) as BloggerEntry;
                    // blogger does not like labels yet.
                    entry.Categories.Clear(); 
                    entry.Title.Text = strTitle;
                    entry.Categories.Clear();
                    entry.IsDraft = true; 
                    entry.Updated = Utilities.EmptyDate;
                    entry.Published = Utilities.EmptyDate; 
                    BloggerEntry newEntry = blogFeed.Insert(entry); 
                    iCount++; 
                    Tracing.TraceMsg("Created blogger entry");

                    // try to get just that guy.....
                    BloggerQuery singleQuery = new BloggerQuery();
                    singleQuery.Uri = new Uri(newEntry.SelfUri.ToString()); 

                    BloggerFeed newFeed = service.Query(singleQuery);

                    BloggerEntry sameGuy = newFeed.Entries[0] as BloggerEntry;

                    Tracing.TraceMsg("retrieved blogger entry");

                    Assert.IsTrue(sameGuy.Title.Text.Equals(newEntry.Title.Text), "both titles should be identical"); 
                    Assert.IsTrue(sameGuy.IsDraft); 

                }

                blogFeed = service.Query(query);

                Assert.AreEqual(iCount, blogFeed.Entries.Count, "Feed should have one more entry, it has: " + blogFeed.Entries.Count); 

                if (blogFeed != null && blogFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (AtomEntry entry in blogFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text); 
                        if (String.Compare(entry.Title.Text, strTitle)==0)
                        {
                            entry.Content.Content = "Maybe stay until breakfast";
                            entry.Content.Type = "text";
                            entry.Update();
                            Tracing.TraceMsg("Updated entry");
                        }
                    }
                }

                blogFeed = service.Query(query);

                Assert.AreEqual(iCount, blogFeed.Entries.Count, "Feed should have one more entry, it has: " + blogFeed.Entries.Count); 

                if (blogFeed != null && blogFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (AtomEntry entry in blogFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text); 
                        if (String.Compare(entry.Title.Text, strTitle)==0)
                        {
                            entry.Delete();
                            iCount--; 
                            Tracing.TraceMsg("deleted entry");
                        }
                    }
                }


                blogFeed = service.Query(query);
                Assert.AreEqual(iCount, blogFeed.Entries.Count, "Feed should have the same count again, it has: " + blogFeed.Entries.Count); 

                service.Credentials = null; 

            }

        }
Exemple #11
0
        private void AddEntry_Click(object sender, System.EventArgs e)
        {
            addentry dlg = new addentry();
            if (dlg.ShowDialog() == DialogResult.OK &&
                dlg.Entry.Length > 0)
            {
                // now add this to the feed.

                BloggerEntry entry = new BloggerEntry();

                entry.Content.Content = dlg.Entry;
                entry.Content.Type = "html";
                entry.Title.Text = dlg.EntryTitle;
                string sLables = dlg.txtLabel.Text;
                string[] arrLabels = sLables.Split(',');
                for(int i=0;i<arrLabels.Length;i++)
                {
                    AtomCategory cat = new AtomCategory();
                    cat.Scheme = new Uri("http://www.blogger.com/atom/ns#");
                    cat.Term = arrLabels[i].ToString();
                    entry.Categories.Add(cat);
                }

                string userName =    this.UserName.Text;
                string passWord =    this.Password.Text;

                BloggerService service = new BloggerService("ChessBank");

                if (userName != null && userName.Length > 0)
                {
                    service.Credentials = new GDataCredentials(userName, passWord);
                }

                service.Insert(new Uri(this.feedUri), entry);

                RefreshFeed(this.feedUri);
            }
        }
Exemple #12
0
        private static IEnumerable<Publication> LoadPublications(string url, bool retrieveAllPost)
        {
            url = url.Trim();

            var publications = new List<Publication>();

            var bloggerService = new BloggerService(Factory.GoogleApplicationName);
            var query = new BloggerQuery(url);

            try
            {
                var feed = bloggerService.Query(query);

                if (retrieveAllPost && feed.TotalResults > feed.Entries.Count)
                {
                    query.NumberToRetrieve = feed.TotalResults;
                    feed = bloggerService.Query(query);
                }

                foreach (BloggerEntry entry in feed.Entries)
                {
                    var blog = Factory.CreateBlog(entry);
                    publications.Add(blog);
                }

                return publications;
            }
            catch
            {
                return new List<Publication>();
            }
        }
Exemple #13
0
        public virtual Publication GetSinglePublication(string id)
        {
            try
            {
                var query = new BloggerQuery(String.Format("http://www.blogger.com/feeds/{0}/posts/default/{1} ", GoogleAccount.BlogId, id));

                var bloggerService = new BloggerService(Factory.GoogleApplicationName);
                var feed = bloggerService.Query(query);
                var postEntry = (BloggerEntry)feed.Entries.FirstOrDefault();
                return Factory.CreateBlog(postEntry);
            }
            catch
            {
                return null;
            }
        }