本文整理汇总了C#中Google.GData.Client.Service.Query方法的典型用法代码示例。如果您正苦于以下问题:C# Service.Query方法的具体用法?C# Service.Query怎么用?C# Service.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google.GData.Client.Service
的用法示例。
在下文中一共展示了Service.Query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectUserBlog
/** Lists the user's blogs and returns the URI for posting new entries
* to the blog which the user selected.
*/
static Uri SelectUserBlog(Service service)
{
Console.WriteLine("\nPlease select a blog on which to post.");
FeedQuery query = new FeedQuery();
// Retrieving a list of blogs
query.Uri = new Uri("http://www.blogger.com/feeds/default/blogs");
AtomFeed feed = service.Query(query);
// Publishing a blog post
Uri blogPostUri = null;
if (feed != null)
{
foreach (AtomEntry entry in feed.Entries)
{
// Print out the title of the Blog
Console.WriteLine(" Blog name: " + entry.Title.Text);
Console.Write(" Post to this blog? (y/n): ");
if (Console.ReadLine().Equals("y"))
{
// find the href in the link with a rel pointing to the blog's feed
for (int i = 0; i < entry.Links.Count; i++)
{
if (entry.Links[i].Rel.Equals("http://schemas.google.com/g/2005#post"))
{
blogPostUri = new Uri(entry.Links[i].HRef.ToString());
Console.WriteLine(" Your new posts will be sent to " + blogPostUri.AbsoluteUri.ToString());
}
}
return blogPostUri;
}
}
}
return blogPostUri;
}
示例2: Main
static void Main(string[] args)
{
Console.WriteLine("Suchwort:");
string searchTerm = Console.ReadLine();
string uriSearchTerm = HttpUtility.UrlEncode(searchTerm);
string url = "http://gdata.youtube.com/feeds/videos?q=" + uriSearchTerm;
Console.WriteLine("Connection to YouTube - Searching: " + searchTerm);
FeedQuery query = new FeedQuery("");
Service service = new Service("youtube", "sample");
query.Uri = new Uri(url);
query.StartIndex = 0;
query.NumberToRetrieve = 20;
AtomFeed resultFeed = service.Query(query);
foreach (AtomEntry entry in resultFeed.Entries)
{
Console.WriteLine("Title: " + entry.Title.Text);
Console.WriteLine("Link: " + entry.AlternateUri.Content);
Console.WriteLine("Tags:");
foreach (AtomCategory cat in entry.Categories)
{
Console.Write(cat.Term + ", ");
}
Console.WriteLine();
}
Console.ReadLine();
}
示例3: GetGoogleCalendar
public AtomFeed GetGoogleCalendar()
{
Service service = new Service();
FeedQuery query = new FeedQuery();
query.Uri = new Uri(publicCalendarUrl);
return service.Query(query);
}
示例4: ListUserBlogs
/** Lists the user's blogs. */
static void ListUserBlogs(Service service)
{
Console.WriteLine("\nRetrieving a list of blogs");
FeedQuery query = new FeedQuery();
// Retrieving a list of blogs
query.Uri = new Uri("http://www.blogger.com/feeds/default/blogs");
AtomFeed feed = null;
feed = service.Query(query);
foreach (AtomEntry entry in feed.Entries)
{
Console.WriteLine(" Blog title: " + entry.Title.Text);
}
}
示例5: GetFeed
public static AtomFeed GetFeed(string url = "", int start = 0, int num_results = 0)
{
FeedQuery query = new FeedQuery("");
Google.GData.Client.Service service = new Google.GData.Client.Service();
query.Uri = new Uri(url);
if (start > 0) {
query.StartIndex = start;
}
if (num_results > 0) {
query.NumberToRetrieve = num_results;
}
AtomFeed feed = service.Query(query);
return feed;
}
示例6: DefaultHostDeleteAll
//////////////////////////////////////////////////////////////////////
/// <summary>deletes all entries in defhost feed</summary>
//////////////////////////////////////////////////////////////////////
[Test] public void DefaultHostDeleteAll()
{
Tracing.TraceMsg("Entering DefaultHostDeleteAll");
FeedQuery query = new FeedQuery();
Service service = new Service();
service.RequestFactory = this.factory;
query.Uri = new Uri(this.defaultHost);
AtomFeed returnFeed = service.Query(query);
foreach (AtomEntry entry in returnFeed.Entries )
{
entry.Delete();
}
}
示例7: CalendarXHTMLTest
[Test] public void CalendarXHTMLTest()
{
Tracing.TraceMsg("Entering CalendarXHTMLTest");
FeedQuery query = new FeedQuery();
Service service = new Service();
if (this.defaultCalendarUri != null)
{
if (this.userName != null)
{
service.Credentials = new GDataCredentials(this.userName, this.passWord);
}
service.RequestFactory = this.factory;
query.Uri = new Uri(this.defaultCalendarUri);
AtomFeed calFeed = service.Query(query);
String strTitle = "Dinner time" + Guid.NewGuid().ToString();
if (calFeed != null)
{
// get the first entry
Tracing.TraceMsg("Created calendar entry");
String xhtmlContent = "<div><b>this is an xhtml test text</b></div>";
AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1);
Tracing.TraceMsg("Created calendar entry");
entry.Title.Text = strTitle;
entry.Content.Type = "xhtml";
Tracing.TraceMsg("Created calendar entry");
entry.Content.Content = xhtmlContent;
AtomEntry newEntry = calFeed.Insert(entry);
Tracing.TraceMsg("Created calendar 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("xhtml"));
Assert.IsTrue(sameGuy.Content.Content.Equals(xhtmlContent));
}
service.Credentials = null;
}
}
示例8: GoogleAuthenticationTest
/////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/// <summary>runs an authentication test</summary>
//////////////////////////////////////////////////////////////////////
[Test] public void GoogleAuthenticationTest()
{
Tracing.TraceMsg("Entering GoogleAuthenticationTest");
FeedQuery query = new FeedQuery();
Service service = new Service();
int iCount;
if (this.defaultCalendarUri != null)
{
if (this.userName != null)
{
service.Credentials = new GDataCredentials(this.userName, this.passWord);
}
service.RequestFactory = this.factory;
query.Uri = new Uri(this.defaultCalendarUri);
AtomFeed calFeed = service.Query(query);
ObjectModelHelper.DumpAtomObject(calFeed,CreateDumpFileName("AuthenticationTest"));
iCount = calFeed.Entries.Count;
String strTitle = "Dinner time" + Guid.NewGuid().ToString();
if (calFeed != null && calFeed.Entries.Count > 0)
{
// get the first entry
AtomEntry entry = calFeed.Entries[0];
entry = ObjectModelHelper.CreateAtomEntry(1);
entry.Title.Text = strTitle;
AtomEntry newEntry = calFeed.Insert(entry);
iCount++;
Tracing.TraceMsg("Created calendar 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");
}
calFeed = service.Query(query);
Assert.AreEqual(iCount, calFeed.Entries.Count, "Feed should have one more entry, it has: " + calFeed.Entries.Count);
if (calFeed != null && calFeed.Entries.Count > 0)
{
// look for the one with dinner time...
foreach (AtomEntry entry in calFeed.Entries)
{
Tracing.TraceMsg("Entrie title: " + entry.Title.Text);
if (String.Compare(entry.Title.Text, strTitle)==0)
{
entry.Content.Content = "Maybe stay until breakfast";
entry.Update();
Tracing.TraceMsg("Updated entry");
}
}
}
calFeed = service.Query(query);
Assert.AreEqual(iCount, calFeed.Entries.Count, "Feed should have one more entry, it has: " + calFeed.Entries.Count);
if (calFeed != null && calFeed.Entries.Count > 0)
{
// look for the one with dinner time...
foreach (AtomEntry entry in calFeed.Entries)
{
Tracing.TraceMsg("Entrie title: " + entry.Title.Text);
if (String.Compare(entry.Title.Text, strTitle)==0)
{
entry.Delete();
iCount--;
Tracing.TraceMsg("deleted entry");
}
}
}
calFeed = service.Query(query);
Assert.AreEqual(iCount, calFeed.Entries.Count, "Feed should have the same count again, it has: " + calFeed.Entries.Count);
service.Credentials = null;
}
}
示例9: CalendarStressTest
[Test] public void CalendarStressTest()
{
Tracing.TraceMsg("Entering CalendarStressTest");
FeedQuery query = new FeedQuery();
Service service = new Service();
if (this.defaultCalendarUri != null)
{
if (this.userName != null)
{
service.Credentials = new GDataCredentials(this.userName, this.passWord);
}
service.RequestFactory = this.factory;
query.Uri = new Uri(this.defaultCalendarUri);
AtomFeed calFeed = service.Query(query);
if (calFeed != null)
{
for (int i = 0; i<127; i++)
{
AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1);
entry.Title.Text = "Entry number: " + i;
calFeed.Insert(entry);
}
}
calFeed = service.Query(query);
int iCount = 0;
while (calFeed != null && calFeed.Entries.Count > 0)
{
iCount += calFeed.Entries.Count;
// just query the same query again.
if (calFeed.NextChunk != null)
{
query.Uri = new Uri(calFeed.NextChunk);
calFeed = service.Query(query);
}
else
{
calFeed = null;
}
}
Assert.AreEqual(127, iCount, "Feed should have 127 entries, it has: " + iCount);
service.Credentials = null;
}
}
示例10: ListEntryComments
static void ListEntryComments(Service service, Uri commentUri)
{
if (commentUri != null)
{
Console.WriteLine("\nRetrieving all blog post comments");
// Retrieve all comments on a blog entry
FeedQuery query = new FeedQuery();
Console.WriteLine(" Query URI: " + commentUri.ToString());
query.Uri = commentUri;
AtomFeed feed = service.Query(query);
foreach (AtomEntry entry in feed.Entries)
{
Console.WriteLine(" Comment Title: " + entry.Title.Text);
}
}
}
示例11: GetFeed
private static AtomFeed GetFeed(string url, int start, int number)
{
System.Diagnostics.Trace.Write("Conectando youtube at " + url);
FeedQuery query = new FeedQuery("");
Service service = new Service("youtube", "exampleCo");
query.Uri = new Uri(url);
query.StartIndex = start;
query.NumberToRetrieve = number;
AtomFeed myFeed = service.Query(query);
return myFeed;
}
示例12: DefaultHostInsertAndStay
/////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/// <summary>creates a number or rows </summary>
//////////////////////////////////////////////////////////////////////
[Test] public void DefaultHostInsertAndStay()
{
Tracing.TraceMsg("Entering DefaultHostInsertAndStay");
int iCount=0;
FeedQuery query = new FeedQuery();
Service service = new Service();
service.RequestFactory = this.factory;
query.Uri = new Uri(this.defaultHost);
AtomFeed returnFeed = service.Query(query);
AtomEntry entry;
iCount = returnFeed.Entries.Count;
// now we have all we need.
for (int i = 0; i < this.iIterations; i++)
{
Tracing.TraceMsg("DefaultHostInsertAndStay: inserting entry #: " + i);
entry = ObjectModelHelper.CreateAtomEntry(i);
entry = returnFeed.Insert(entry);
}
Tracing.TraceMsg("DefaultHostInsertAndStay: inserted lot's of entries");
// done doing the inserts...
// now query the guy again.
returnFeed = service.Query(query);
Assert.AreEqual(iCount+this.iIterations, returnFeed.Entries.Count, "feed should have " + this.iIterations + " more entries now");
}
示例13: GetFeedUriFromQuery
private static String GetFeedUriFromQuery(BlogDescriptor blogDescriptor)
{
var query = new gClient.FeedQuery(blogDescriptor.Address);
var service = new gClient.Service("blogger", GoogleSucks.GetApplicationName())
{
Credentials = new gClient.GDataCredentials(blogDescriptor.Username, blogDescriptor.Password)
};
var bloggerFeed = service.Query(query);
var feeds = new List<gClient.AtomEntry>();
while (bloggerFeed != null && bloggerFeed.Entries.Count > 0)
{
foreach (gClient.AtomEntry entry in bloggerFeed.Entries)
feeds.Add(entry);
if (bloggerFeed.NextChunk != null)
{
query.Uri = new Uri(bloggerFeed.NextChunk);
bloggerFeed = service.Query(query);
}
else
{
bloggerFeed = null;
}
}
foreach (gClient.AtomEntry entry in feeds)
if (entry != null)
foreach (gClient.AtomLink link in entry.Links)
if (link.Rel == gClient.BaseNameTable.ServiceFeed)
return link.HRef.ToString();
return null;
}
示例14: BloggerPublicFeedTest
/////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/// <summary>tests if we can access a public feed</summary>
//////////////////////////////////////////////////////////////////////
[Test] public void BloggerPublicFeedTest()
{
Tracing.TraceMsg("Entering BloggerPublicFeedTest");
FeedQuery query = new FeedQuery();
Service service = new Service(this.ServiceName, 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");
}
}
}
}
示例15: BloggerStressTest
/////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/// <summary>runs an authentication test</summary>
//////////////////////////////////////////////////////////////////////
[Test] public void BloggerStressTest()
{
Tracing.TraceMsg("Entering Blogger GoogleStressTest");
FeedQuery query = new FeedQuery();
Service service = new Service(this.ServiceName, 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< 100; 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);
}
}
}
}