private void OnCommandBing_OldAPI(string Source, string Query, string RestrictURL)
{
try
{
XDocument Document;
XElement SearchResult;
string Title;
string Description;
string Url;
Document = XDocument.Load(String.Format("http://api.bing.net/xml.aspx?AppId={0}&Sources=Web&Version=2.0&Market=en-US&Web.count=1&XmType=ElementBased&Web.Offset=0&Query={1}", Uri.EscapeDataString(BingAppID), Uri.EscapeDataString(Query)));
SearchResult = (from XElement E in Document.Descendants(BingAPINamespace + "WebResult") select E).FirstOrDefault();
if (SearchResult == null)
{
// Console.WriteLine("No results found");
SendMessage(SendType.Message, Source, "No results.");
return;
}
// Console.WriteLine(Document.ToString());
Title = (string)(from XElement E in SearchResult.Descendants(BingAPINamespace + "Title") select E).FirstOrDefault();
Description = (string)(from XElement E in SearchResult.Descendants(BingAPINamespace + "Description") select E).FirstOrDefault();
Url = (string)(from XElement E in SearchResult.Descendants(BingAPINamespace + "Url") select E).FirstOrDefault();
//
// If we were to restrict the results to those just under a
// certain URL, fake no results if the first one did not match.
//
if (RestrictURL != null && !Url.StartsWith(RestrictURL))
{
SendMessage(SendType.Message, Source, "No results.");
return;
}
SendMessage(SendType.Message, Source, String.Format("{0}: {1} - {2}", Title, Url, Description));
}
catch (Exception)
{
SendMessage(SendType.Message, Source, String.Format("Unable to retrieve search results for {0}.", Query));
}
}