/// <summary>
        /// This section searches for the top 5 photos of the selected car from Bing using year, make, model and trim as the parameters
        /// We create a Bing container and pass the assigned key for credentials
        /// </summary>
        /// <param name="year"></param>
        /// <param name="make"></param>
        /// <param name="model"></param>
        /// <param name="trim"></param>
        /// <returns></returns>

        private string[] GetImages(string year, string make, string model, string trim)
        {
            // This is the query - or you could get it from args.
            string query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.
            string rootUri       = "https://api.datamarket.azure.com/Bing/Search";
            var    bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.



            var accountKey = "i52CgTJWkEZb7wR4q0/XNKItRAQrkaUAFZuijkBao+k=";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential("accountKey", accountKey);

            // Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null).AddQueryOption("$top", 5);
            //imageQuery = imageQuery.AddQueryOption("$top", 5);
            var imageResults = imageQuery.Execute();

            //extract the properties needed for the images
            List <string> images = new List <string>();

            foreach (var result in imageResults)
            {
                images.Add(result.MediaUrl);
            }
            return(images.ToArray());
        }
示例#2
0
        private string[] GetImages(string year, string make, string model, string trim)
        {
            string query = year + " " + make + " " + model + " " + trim;

            //Create a Bing container
            string rootUri       = "https://api.datamarket.azure.com/Bing/Search";
            var    bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            var accountkey = "deKmywQL9zTT0DV30aJYSxVGmLCQj279OtHw0QcYDyU";

            //Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(accountkey, accountkey);

            //Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);

            imageQuery = imageQuery.AddQueryOption("$top", 5);
            var imageResults = imageQuery.Execute();
            //extract the properties needed for the images
            List <string> images = new List <string>();

            foreach (var result in imageResults)
            {
                images.Add(result.MediaUrl);
            }
            return(images.ToArray());
        }
示例#3
0
        public static BingSearchViewModel ImageSearch(string query, string callback)
        {
            string accountKey = WebConfigurationManager.AppSettings["BingKey"];
            string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl));
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);

            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
            imageQuery = imageQuery.AddQueryOption("$top", 12);
            var imageResults = imageQuery.Execute();

            var model = new BingSearchViewModel();
            if (callback != null && callback.Length > 0)
            {
                model.Callback = callback;
            }
            foreach (var result in imageResults)
            {
                model.Results.Add(new BingSearchImageResult() {
                    ImageURL = result.MediaUrl,
                    ThumbnailURL = result.Thumbnail.MediaUrl,
                    ThumbnailWidth = result.Thumbnail.Width,
                    ThumbnailHeight = result.Thumbnail.Height,
                });
            }
            return model;
        }
		private MessageHandlerResult GetImage(string query, IPluginContext context)
		{
			try
			{
				var bingContainer = new Bing.BingSearchContainer(new Uri(BingApiUri))
					                    {
						                    Credentials =
							                    new NetworkCredential(BingApi, BingApi)
					                    };

				var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
				var imageResults = imageQuery.Execute();

				if (imageResults != null)
				{
					var imageList = imageResults.ToList();
					if (imageList.Count > 0)
					{
						var index = context.RandomProvider.Next(imageList.Count);
						var url = imageList[index].MediaUrl;

						return this.Handled(this.Message(url));
					}
				}

				var response = context.TextProcessor.FormatPluginResponse("Really? Do you kiss ${SOMEONE}'s mum with that mouth?", context);
				return this.Handled(this.Message(response));
			}
			catch (Exception ex)
			{
				Log.ErrorException("Unable to search for images on bing.", ex);
				return this.Handled(this.Message("Uh Oh..."));
			}
		}
示例#5
0
        public static List<KeyValuePair<string, string>> Search(string key)
        {
            List<KeyValuePair<string, string>> op = new List<KeyValuePair<string, string>>();

            // Create a Bing container
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.
            var accountKey = "mzyAdEQ7iPEwvJ0XWUHhYt5ypb9wmCpenCfvE7sfDsI";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);

            // Build the query.
            var imageQuery = bingContainer.Image(key, null, null, null, null, null, null);
            var imageResults = imageQuery.Execute();

            foreach (var result in imageResults)
            {
                op.Add(new KeyValuePair<string, string>(result.Title, result.MediaUrl));
            }

            return op;
        }
示例#6
0
        /// <summary>
        /// 検索ボタンクリック
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            // This is the query - or you could get it from args.
            string query = txtSearch.Text.Trim();

            // Create a Bing container.
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.
            var accountKey = "SOKyLs1uETTMXQzh+mnSmFLXzRFrGYZTFaaN2UzPkQs";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);

            // Build the query.
            if (rdbWeb.Checked)
            {
                var webQuery = bingContainer.Web(query, null, null, null, null, null, null, null);
                webQuery = webQuery.AddQueryOption("$top", 10);
                var webResults = webQuery.Execute();

                grdResult.DataSource = webResults;
                grdResult.DataBind();
            }
            else
            {
                var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
                var imageResults = imageQuery.Execute();
                grdResult.DataSource = imageResults;
                grdResult.DataBind();
            }
        }
        /// <summary>
        /// Search for image only.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnImageSearch_Click(object sender, EventArgs e)
        {
            Repeater rptResult = new Repeater();
            string   query     = tbQueryString.Text;

            // Create a Bing container.
            string rootUrl       = "https://api.datamarket.azure.com/Bing/Search";
            var    bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl));

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey);

            // Build the query, limiting to 10 results.
            var imageQuery =
                bingContainer.Image(query, null, market, null, null, null, null);

            imageQuery = imageQuery.AddQueryOption("$top", 50);

            // Run the query and display the results.
            var           imageResults = imageQuery.Execute();
            StringBuilder searchResult = new StringBuilder();
            Label         lblResults   = new Label();

            foreach (Bing.ImageResult iResult in imageResults)
            {
                searchResult.Append(string.Format("Image Title: <a href={1}>{0}</a><br />Image Url: {1}<br /><br />",
                                                  iResult.Title,
                                                  iResult.MediaUrl));
            }
            lblResults.Text = searchResult.ToString();
            Panel1.Controls.Add(lblResults);
        }
示例#8
0
        public static List <KeyValuePair <string, string> > Search(string key)
        {
            List <KeyValuePair <string, string> > op = new List <KeyValuePair <string, string> >();

            // Create a Bing container
            string rootUri       = "https://api.datamarket.azure.com/Bing/Search";
            var    bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));


            // Replace this value with your account key.
            var accountKey = "mzyAdEQ7iPEwvJ0XWUHhYt5ypb9wmCpenCfvE7sfDsI";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);


            // Build the query.
            var imageQuery   = bingContainer.Image(key, null, null, null, null, null, null);
            var imageResults = imageQuery.Execute();

            foreach (var result in imageResults)
            {
                op.Add(new KeyValuePair <string, string>(result.Title, result.MediaUrl));
            }

            return(op);
        }
示例#9
0
        public async Task <IHttpActionResult> GetCarData(string model_year = "", string make = "", string model_name = "", string model_trim = "")
        {
            HttpResponseMessage response;
            var content   = "";
            var singleCar = await db.GetCar(model_year, make, model_name, model_trim);

            var car = new carViewModel
            {
                Car = singleCar,
                //Car = db.GetCars(year, make, model, trim),
                Recalls = content,
                Images  = ""
            };


            //Get recall Data

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + model_year + "/make/"
                                                     + make + "/model/" + model_name + "?format=json");

                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return(InternalServerError(e));
                }
            }

            car.Recalls = content;


            //////////////////////////////   My Bing Search   //////////////////////////////////////////////////////////

            string query = model_year + " " + make + " " + model_name + " " + model_trim;

            string rootUri = "https://api.datamarket.azure.com/Bing/Search";

            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            var accountKey = ConfigurationManager.AppSettings["BingAPIKey"];;

            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);


            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);

            var imageResults = imageQuery.Execute().ToList();


            car.Images = imageResults.First().MediaUrl;

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////

            return(Ok(car));
        }
示例#10
0
 /// <summary>
 /// Bing 画像検索を行い、取得した画像URLのシーケンスをIObservableとして返却します
 /// </summary>
 /// <param name="searchWord">検索文字列</param>
 /// <param name="accountKey">Bing Search アカウントキー</param>
 /// <param name="skip">スキップする検索結果の件数</param>
 /// <param name="top">取得する検索結果の件数</param>
 /// <returns>画像検索結果</returns>
 public static IObservable<Bing.ImageResult> SearchImageAsObservable(string searchWord, string accountKey, int skip, int top,IScheduler scheduler)
 {
     return Observable.Start(() =>
     {
         var bing = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));
         bing.Credentials = new NetworkCredential("accountKey", accountKey);
         var query = bing.Image(searchWord, null, null, null, null, null, null);
         query = query.AddQueryOption("$skip", skip);
         query = query.AddQueryOption("$top", top);
         return query.Execute();
     },scheduler).SelectMany(ie => ie);
 }
示例#11
0
        /// <summary>
        /// Documentation under IChronozoomSVC
        /// </summary>
        BaseJsonResult <IEnumerable <Bing.ImageResult> > IBingSearchAPI.GetImages(string query, string top, string skip)
        {
            return(ApiOperation <BaseJsonResult <IEnumerable <Bing.ImageResult> > >(delegate(User user, Storage storage)
            {
                var searchResults = new List <Bing.ImageResult>();

                if (string.IsNullOrEmpty(BingAccountKey) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"]))
                {
                    BingAccountKey = ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"];
                }

#if RELEASE
                if (user == null)
                {
                    // Setting status code to 403 to prevent redirection to authentication resource if status code is 401.
                    SetStatusCode(HttpStatusCode.Forbidden, ErrorDescription.UnauthorizedUser);
                    return new BaseJsonResult <IEnumerable <Bing.ImageResult> >(searchResults);
                }
#endif

                int resultsCount = int.TryParse(top, out resultsCount) ? resultsCount : BingDefaultSearchLimit;
                int offset = int.TryParse(skip, out offset) ? offset : BingDefaultOffset;

                try
                {
                    var bingContainer = new Bing.BingSearchContainer(new Uri(BingAPIRootUrl));
                    bingContainer.Credentials = new NetworkCredential(BingAccountKey, BingAccountKey);

                    var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
                    imageQuery = imageQuery.AddQueryOption("$top", resultsCount);
                    imageQuery = imageQuery.AddQueryOption("$skip", offset);

                    var imageResults = imageQuery.Execute();

                    foreach (var result in imageResults)
                    {
                        searchResults.Add(result);
                    }
                }
                catch (ArgumentNullException)
                {
                    SetStatusCode(HttpStatusCode.BadRequest, ErrorDescription.NullSearchQuery);
                }
                catch (Exception ex)
                {
                    SetStatusCode(HttpStatusCode.InternalServerError, ex.Message);
                }

                return new BaseJsonResult <IEnumerable <Bing.ImageResult> >(searchResults);
            }));
        }
示例#12
0
        /// <summary>
        /// Image Search
        /// </summary>
        /// <param name="query">Query String</param>
        /// <param name="longitude">Longitude</param>
        /// <param name="latitude">Latitude</param>
        /// <returns>Results</returns>
        public IEnumerable <ImageResult> Search(string query, double?longitude = null, double?latitude = null)
        {
            var results = this.QueryLocal(query);

            if (null == results || 0 == results.Count())
            {
                results = results ?? new List <ImageResult>();
                var bingContainer = new Bing.BingSearchContainer(new Uri(RootUri))
                {
                    Credentials = new NetworkCredential(AccountKey, AccountKey),
                };

                var imageQuery = bingContainer.Image(query, null, null, "Strict", latitude, longitude, "Size:Large+Style:Photo");

                var entries = new List <BingQueryEntry>();
                var images  = imageQuery.Execute();
                foreach (var image in images)
                {
                    if (null != image)
                    {
                        var result = new ImageResult(image);
                        results.Add(result);

                        var entry = new BingQueryEntry()
                        {
                            PartitionKey = query.ToLowerInvariant(),
                            RowKey       = Guid.NewGuid().ToString(),
                            Url          = result.Url,
                            ThumbnailUrl = result.ThumbnailUrl,
                        };

                        entries.Add(entry);
                    }
                }

                this.SaveLocal(entries);
            }

            return(results);
        }
示例#13
0
        static void MakeRequest()
        {
            string query       = "Chairs";
            string res_img_dir = SaveDir + query + "/";

            // create directory
            Directory.CreateDirectory(res_img_dir);

            string rootUrl       = "https://api.datamarket.azure.com/Bing/Search";
            var    bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl));

            string market = "en-us";

            bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey);

            // build query
            var imageQuery = bingContainer.Image(query, null, market, null, null, null, null);

            imageQuery = imageQuery.AddQueryOption("$top", 50);
            imageQuery = imageQuery.AddQueryOption("$skip", 50);

            // run query: MUST ADD TOLIST()!
            var imageResults = imageQuery.Execute().ToList();

            Console.WriteLine("{0} results for query " + query + ":", imageResults.Count());

            // download searched images
            System.Net.WebClient _WebClient = new System.Net.WebClient();
            int cnt = 0;

            foreach (var result in imageResults)
            {
                cnt++;
                Console.WriteLine("{0}: {1}\n{2}\n", cnt, result.Title, result.MediaUrl);
                int    filenamestart = result.MediaUrl.LastIndexOf('/') + 1;
                int    filenameend   = result.MediaUrl.LastIndexOf('.') - 1;
                string filename      = result.MediaUrl.Substring(filenamestart, filenameend - filenamestart + 1);
                _WebClient.DownloadFile(result.MediaUrl, res_img_dir + filename + ".jpg");
            }
        }
示例#14
0
        static void MakeRequest()
        {
            string query = "Chairs";
            string res_img_dir = SaveDir + query + "/";
            // create directory
            Directory.CreateDirectory(res_img_dir);

            string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl));

            string market = "en-us";

            bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey);

            // build query
            var imageQuery = bingContainer.Image(query, null, market, null, null, null, null);
            imageQuery = imageQuery.AddQueryOption("$top", 50);
            imageQuery = imageQuery.AddQueryOption("$skip", 50);

            // run query: MUST ADD TOLIST()!
            var imageResults = imageQuery.Execute().ToList();

            Console.WriteLine("{0} results for query " + query + ":", imageResults.Count());

            // download searched images
            System.Net.WebClient _WebClient = new System.Net.WebClient();
            int cnt = 0;
            foreach(var result in imageResults)
            {
                cnt++;
                Console.WriteLine("{0}: {1}\n{2}\n", cnt, result.Title, result.MediaUrl);
                int filenamestart = result.MediaUrl.LastIndexOf('/') + 1;
                int filenameend = result.MediaUrl.LastIndexOf('.') - 1;
                string filename = result.MediaUrl.Substring(filenamestart, filenameend - filenamestart + 1);
                _WebClient.DownloadFile(result.MediaUrl, res_img_dir + filename + ".jpg");
            }
        }
示例#15
0
        /* This class will get images for year, make, and model */
        private string[] GetImages(string year, string make, string model, string trim)
        {
            // This is the query - or you could get it from args.
            string query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";

            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.
            var accountKey = "B7fUsZ3RushD0tSHsGmJfD2UywS5m4cpIlJ9v5Uca/M=";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential("accountKey", accountKey);

            // Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);

            imageQuery = imageQuery.AddQueryOption("$top", 5);
            var imageResults = imageQuery.Execute();

            //extract the properties need for the images
            List<string> images = new List<string>();

           
            //for each results in this collection
            foreach (var result in imageResults)
            {
                if (UrlCtrl.IsUrl(result.MediaUrl))
                {
                    images.Add(result.MediaUrl);
                  
                }
                else
                {
                    continue;
                }
                
            }
            //matching and converting into strings.
            return images.ToArray();
        }
        async Task doSearch(ImageSearchQuery state, int imageOffset)
        {
            if (String.IsNullOrEmpty(state.Query) || String.IsNullOrWhiteSpace(state.Query))             
            {
                return;
            }

            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));
           
            // Configure bingContainer to use your credentials.

            bingContainer.Credentials = new NetworkCredential(BingAccountKey.accountKey, BingAccountKey.accountKey);           

            // Build the query.
            String imageFilters = null;

            if (!state.Size.Equals(size[0]))
            {
                imageFilters = "Size:" + state.Size;
            }

            if (!state.Layout.Equals(layout[0]))
            {
                if (imageFilters != null) imageFilters += "+";

                imageFilters += "Aspect:" + state.Layout;
            }

            if (!state.Type.Equals(type[0]))
            {
                if (imageFilters != null) imageFilters += "+";

                imageFilters += "Style:" + state.Type;
            }

            if (!state.People.Equals(type[0]))
            {
                if (imageFilters != null) imageFilters += "+";

                imageFilters += "Face:" + state.People;
            }

            if (!state.Color.Equals(type[0]))
            {
                if (imageFilters != null) imageFilters += "+";

                imageFilters += "Color:" + state.Color;
            }
               
            var imageQuery = bingContainer.Image(Query, null, null, state.SafeSearch, state.GeoTag.LatDecimal, state.GeoTag.LonDecimal, imageFilters);
            imageQuery = imageQuery.AddQueryOption("$top", 50);
            imageQuery = imageQuery.AddQueryOption("$skip", imageOffset);
                        
            IEnumerable<Bing.ImageResult> imageResults = 
                await Task.Factory.FromAsync<IEnumerable<Bing.ImageResult>>(imageQuery.BeginExecute(null, null), imageQuery.EndExecute);
                               
            if (imageOffset == 0)
            {
                MediaState.clearUIState(Query, DateTime.Now, MediaStateType.SearchResult);
            }

            List<MediaItem> results = new List<MediaItem>();

            int relevance = imageOffset;

            MediaState.UIMediaCollection.EnterReadLock();

            foreach (var image in imageResults)
            {
                MediaItem item = new ImageResultItem(image, relevance);

                if (MediaState.UIMediaCollection.Contains(item)) continue;

                results.Add(item);

                relevance++;
            }

            MediaState.UIMediaCollection.ExitReadLock();

            MediaState.addUIState(results);
                                                                
        }
        private void searchButton_Click(object sender, RoutedEventArgs e)
        {
            if (searchBox.Text != "")
            {
                currentSearch++;
                progressBar.Visibility = Visibility.Visible;
                grid1.RowDefinitions.Clear();
                grid1.Children.Clear();

                var accountKey = "XXQj7RFCzyb5w0QR0xhLd3g3pFCu4zRuBKhwJ/25Vh0=";

                 AppSettings settings = new AppSettings();

                var bingContainer = new Bing.BingSearchContainer(
                    new Uri("https://api.datamarket.azure.com/Bing/Search/"));
                bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
                bingContainer.UseDefaultCredentials = false;

                var imageQuery = bingContainer.Image(searchBox.Text, null, "en-US", null, null, null, "Size:Medium");
                imageQuery = imageQuery.AddQueryOption("$top", settings.bingMaxResults);
                imageQuery.BeginExecute(new AsyncCallback(this.ImageResultLoadedCallback), imageQuery);
            }
            else
            {
                progressBar.Visibility = Visibility.Collapsed;
                MessageBox.Show("No results");
            }
        }
示例#18
0
        /// <summary>
        /// This section searches for the top 5 photos of the selected car from Bing using year, make, model and trim as the parameters
        /// We create a Bing container and pass the assigned key for credentials
        /// </summary>
        /// <param name="year"></param>
        /// <param name="make"></param>
        /// <param name="model"></param>
        /// <param name="trim"></param>
        /// <returns></returns>

        private string[] GetImages(string year, string make, string model, string trim)
        {
            // This is the query - or you could get it from args.
            string query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.
            var accountKey = "i52CgTJWkEZb7wR4q0/XNKItRAQrkaUAFZuijkBao+k=";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential("accountKey", accountKey);

            // Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
                imageQuery = imageQuery.AddQueryOption("$top", 5);
            var imageResults = imageQuery.Execute();

            //extract the properties needed for the images
            List<string> images = new List<string>();
            foreach (var result in imageResults)
            {
                images.Add(result.MediaUrl);
            }
            return images.ToArray();

        }
        private string[] GetImages (string year, string make, string model, string trim)
        {
            // This is the query - or you could get it from args.
            string query = "";
            if (trim == null)
                query = year + " " + make + " " + model;
            else
                query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.
            var accountKey = "ZMMsPNe6jZ6qK372fUwv7eaneomhgGw3jxLrwr0w2nk=";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential("accountKey", accountKey);

            // Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
            imageQuery = imageQuery.AddQueryOption("$top", 6);
            var imageResults = imageQuery.Execute();

            //extract the properties needed for the images

            List<string> images = new List<string>();

            foreach (var result in imageResults)
            {
                if( UrlCtrl.IsUrl(result.MediaUrl))
                {
                    images.Add(result.MediaUrl);
                }
            }
            return images.ToArray();
        }
示例#20
0
        private string[] GetImages(string year, string make, string model)
        {
           string query = year + " " + make + " " + model;

           string rootUri = "https://api.datamarket.azure.com/Bing/Search";

           var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

           var accountKey = "/7AIpfB3zsaqbfg8L/DsttX/YgDqetIK7xv3iZo+hKw=";

           bingContainer.Credentials = new NetworkCredential("accountKey", accountKey);

           var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);

           imageQuery = imageQuery.AddQueryOption("$top", 5);

           var imageResults = imageQuery.Execute();

           List<string> imageURLs = new List<string>();

           foreach (var result in imageResults)
           {
              // check for http response code 200 before adding
              if (UrlCtrl.IsUrl(result.MediaUrl))
              {
                 imageURLs.Add(result.MediaUrl);
              }
           }

           return imageURLs.ToArray();
        }
示例#21
0
        async Task doSearch(ImageSearchQuery state, int imageOffset)
        {
            if (String.IsNullOrEmpty(state.Query) || String.IsNullOrWhiteSpace(state.Query))
            {
                return;
            }

            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Configure bingContainer to use your credentials.

            bingContainer.Credentials = new NetworkCredential(BingAccountKey.accountKey, BingAccountKey.accountKey);

            // Build the query.
            String imageFilters = null;

            if (!state.Size.Equals(size[0]))
            {
                imageFilters = "Size:" + state.Size;
            }

            if (!state.Layout.Equals(layout[0]))
            {
                if (imageFilters != null)
                {
                    imageFilters += "+";
                }

                imageFilters += "Aspect:" + state.Layout;
            }

            if (!state.Type.Equals(type[0]))
            {
                if (imageFilters != null)
                {
                    imageFilters += "+";
                }

                imageFilters += "Style:" + state.Type;
            }

            if (!state.People.Equals(type[0]))
            {
                if (imageFilters != null)
                {
                    imageFilters += "+";
                }

                imageFilters += "Face:" + state.People;
            }

            if (!state.Color.Equals(type[0]))
            {
                if (imageFilters != null)
                {
                    imageFilters += "+";
                }

                imageFilters += "Color:" + state.Color;
            }

            var imageQuery = bingContainer.Image(Query, null, null, state.SafeSearch, state.GeoTag.LatDecimal, state.GeoTag.LonDecimal, imageFilters);

            imageQuery = imageQuery.AddQueryOption("$top", 50);
            imageQuery = imageQuery.AddQueryOption("$skip", imageOffset);

            IEnumerable <Bing.ImageResult> imageResults =
                await Task.Factory.FromAsync <IEnumerable <Bing.ImageResult> >(imageQuery.BeginExecute(null, null), imageQuery.EndExecute);

            if (imageOffset == 0)
            {
                MediaState.clearUIState(Query, DateTime.Now, MediaStateType.SearchResult);
            }

            List <MediaItem> results = new List <MediaItem>();

            int relevance = imageOffset;

            MediaState.UIMediaCollection.EnterReadLock();

            foreach (var image in imageResults)
            {
                MediaItem item = new ImageResultItem(image, relevance);

                if (MediaState.UIMediaCollection.Contains(item))
                {
                    continue;
                }

                results.Add(item);

                relevance++;
            }

            MediaState.UIMediaCollection.ExitReadLock();

            MediaState.addUIState(results);
        }
示例#22
0
        private string[] GetImages(string year, string make, string model, string trim)
        {
            string query = string.Concat(year, " ", make, " ", model, " ", trim);

            // Create a Bing container.
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // My account key.
            var accountKey = "SFqfTsHuISE5EHYum81ONhrG5Eji5oaqZqGmv2QwjjM=";

            // Configure bingContainer to use my credentials.
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
        
            var imageResults = bingContainer.Image(query, null, null, null, null, null, null)// Build the query but do not executy the query
                                .AddQueryOption("$top", 5)//limit images returned to 5
                                .Execute();//execute the query         
            List<string> images = new List<string>();
            foreach (var results in imageResults)
            {
                images.Add(results.Thumbnail.MediaUrl);
            }
            return images.ToArray();
        }
示例#23
0
        /// <summary>
        /// Documentation under IChronozoomSVC
        /// </summary>
        BaseJsonResult<IEnumerable<Bing.ImageResult>> IBingSearchAPI.GetImages(string query, string top, string skip)
        {
            return ApiOperation<BaseJsonResult<IEnumerable<Bing.ImageResult>>>(delegate(User user, Storage storage)
            {
                var searchResults = new List<Bing.ImageResult>();

                if (string.IsNullOrEmpty(BingAccountKey) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"]))
                {
                    BingAccountKey = ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"];
                }

            #if RELEASE
                if (user == null)
                {
                    // Setting status code to 403 to prevent redirection to authentication resource if status code is 401.
                    SetStatusCode(HttpStatusCode.Forbidden, ErrorDescription.UnauthorizedUser);
                    return new BaseJsonResult<IEnumerable<Bing.ImageResult>>(searchResults);
                }
            #endif

                int resultsCount = int.TryParse(top, out resultsCount) ? resultsCount : BingDefaultSearchLimit;
                int offset = int.TryParse(skip, out offset) ? offset : BingDefaultOffset;

                try
                {
                    var bingContainer = new Bing.BingSearchContainer(new Uri(BingAPIRootUrl));
                    bingContainer.Credentials = new NetworkCredential(BingAccountKey, BingAccountKey);

                    var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
                    imageQuery = imageQuery.AddQueryOption("$top", resultsCount);
                    imageQuery = imageQuery.AddQueryOption("$skip", offset);

                    var imageResults = imageQuery.Execute();

                    foreach (var result in imageResults)
                    {
                        searchResults.Add(result);
                    }
                }
                catch (ArgumentNullException)
                {
                    SetStatusCode(HttpStatusCode.BadRequest, ErrorDescription.NullSearchQuery);
                }
                catch (Exception ex)
                {
                    SetStatusCode(HttpStatusCode.InternalServerError, ex.Message);
                }

                return new BaseJsonResult<IEnumerable<Bing.ImageResult>>(searchResults);
            });
        }
示例#24
0
        private string[] GetImages(string year, string make, string model, string trim)
        {
            // This is the query - or you could get it from args.

            string query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.

            string rootUri = "https://api.datamarket.azure.com/Bing/Search";

            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.

            var accountKey = "gfVShPxSX5M5xEOjsZCXHyVdHx8xm4g0RK2BpLUx1zw=";

            // Configure bingContainer to use your credentials.

            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);

            // Build the query.

            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
            imageQuery = imageQuery.AddQueryOption("$top", 5);

            var imageResults = imageQuery.Execute();

            //extract the properties needed for the images
            //check to make sure that each picture is valid
            List<string> images = new List<string>();
            foreach (var result in imageResults)
            {
                    WebRequest webRequest = WebRequest.Create(result.MediaUrl);
                    webRequest.Timeout = 1200; // miliseconds
                    webRequest.Method = "HEAD";
                    WebResponse res = null;
                try
                {               
                    res = webRequest.GetResponse();
                    images.Add(result.MediaUrl);
                }

                catch
                {

                }

                finally
                {
                    if (res != null)
                    {
                        res.Close();
                    }
                }
            }
            return images.ToArray();
        }
示例#25
0
        private string[] GetImages(string year, string make, string model)
        {
            string query = string.Concat(year," ", make, " ", model);
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));
            var accountKey = "SFqfTsHuISE5EHYum81ONhrG5Eji5oaqZqGmv2QwjjM=";
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);

            var imageResults = bingContainer.Image(query, null, null, null, null, null, null).AddQueryOption("$top", 5).Execute();
            List<string> images = new List<string>();
            foreach (var results in imageResults)
            {
                images.Add(results.Thumbnail.MediaUrl);
            }
            return images.ToArray();
        }
示例#26
0
        // Next, we need to retrieve image URLs that match our car selections. We will need to set up our
        // Azure accounts to work with the Bing Search API to do so. https://datamarket.azure.com

        private string[] GetImages(string year, string make, string model, string trim)
        {
            // This is the query - or you could get it from args.

            string query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.

            string rootUri = "https://api.datamarket.azure.com/Bing/Search";

            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));       // BingSearchContainer is a proprietary way to access the Bing api

            // Replace this value with your account key.

            var accountKey = "/7AIpfB3zsaqbfg8L/DsttX/YgDqetIK7xv3iZo+hKw=";

            // Configure bingContainer to use your credentials.

            bingContainer.Credentials = new NetworkCredential("accountKey", accountKey);

            // Build the query.

            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);

            imageQuery = imageQuery.AddQueryOption("$top", 5);  // caps the image urls to only 5 (the top 5 results). otherwise it's 50 by default

            var imageResults = imageQuery.Execute();

            // extract the properties needed for the images
            List<string> imageURLs = new List<string>();

            foreach (var result in imageResults)
            {
                imageURLs.Add(result.MediaUrl);
            }

            return imageURLs.ToArray();
        }