public async Task GetImageRoot() { var networkHelper = new NetworkHelper(); //Check Internet connection with Bing & Flickr image service if (!networkHelper.HasInternetAccess) { return; } BingImageRoot = await GetImagesTask(LanguageCode); BingHelper b = new BingHelper(); foreach (BingImage bingImage in BingImageRoot.images) { var appropriateLink = b.GenerateImageLink(bingImage.urlbase); var isLinkValid = await HttpService.GetHeadTask(appropriateLink, false); if (isLinkValid) { bingImage.AppropriateLink = appropriateLink; } } for (int i = BingImageRoot.images.Count - 1; i >= 0; i--) { if (string.IsNullOrEmpty(BingImageRoot.images[i].AppropriateLink)) { BingImageRoot.images.RemoveAt(i); } } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "custom/{latitude}/{longitude}")] HttpRequest req, [CosmosDB(Constants.CosmosDbName, Constants.MyLocationsCollection, CreateIfNotExists = true, ConnectionStringSetting = "AzureCosmosDBConnectionString", SqlQuery = "SELECT * FROM locations hospital WHERE ST_DISTANCE(hospital.location, {{ 'type': 'Point', 'coordinates':[ {latitude},{longitude}]}}) < 16000" )] IEnumerable <Hospital> hospitals, double latitude, double longitude, ILogger log) { List <Location> locationResults = new List <Location>(); try { WayPoint userLocation = new WayPoint { Longitude = longitude, Latitude = latitude }; BingHelper bh = new BingHelper(); string mapUrl; string distance; foreach (Hospital h in hospitals) { WayPoint wp = new WayPoint { Latitude = h.Location.Coordinates[0], Longitude = h.Location.Coordinates[1] }; mapUrl = await bh.GetMapImageUrl(userLocation, wp); distance = await bh.GetRouteDistance(userLocation, wp); Location l = new Location() { Address = h.Address, Name = h.Name, Telephone = h.PhoneNumber, Point = h.Location, MapUri = mapUrl, Distance = distance }; locationResults.Add(l); } } catch (Exception ex) { return(new BadRequestObjectResult(ex)); } return(new OkObjectResult(locationResults)); }
public override void ViewDidLoad() { base.ViewDidLoad(); helper = new BingHelper(); ImageCollection.WeakDataSource = this; // Perform any additional setup after loading the view, typically from a nib. }
public async Task <IList <Attachment> > CreateResourceCards(string apiKey, IList <DataAnalyticProject.Resource> resources) { apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"]; var attachments = new List <Attachment>(); foreach (var resource in resources) { var heroCard = new HeroCard { Title = resource.Name, Subtitle = resource.Address, Text = $"Resources Available : Medicine {resource.Medicine}, Shelter {resource.Shelter}, Food {resource.Food}, Clothes {resource.Clothes}" }; attachments.Add(heroCard.ToAttachment()); if (resource.Address != null) { var helper = new BingHelper(); double lat = Convert.ToDouble(resource.Lat); double lon = Convert.ToDouble(resource.Lon); var locations = await helper.GetLocationsByPointAsync(apiKey, lat, lon); var location = locations.Locations.FirstOrDefault(); if (location != null) { var image = new CardImage(helper.GetLocationMapImageUrl(apiKey, location)); var action = new CardAction() { Value = $"https://www.bing.com/maps?cp={lat}~{lon}&lvl=14&v=2&sV=2&form=S00027", Type = "openUrl", Title = "Open in maps" }; heroCard.Images = new[] { image }; } } } return(attachments); }
public async Task MessageRecievedAsync(IDialogContext context, IAwaitable <LuisResult> input) { var x = await input; string query = x.Query; PypestreamHackathon.Helpers.BingHelper bingHelper = new BingHelper(); var bingSearchResults = await bingHelper.GetSearchResults(query, 5); List <string> rez = new List <string>(); foreach (var searchResult in bingSearchResults) { rez.Add(searchResult.Title); } string searchResultsString = String.Join(string.Empty, rez); // Add carosel here...time provided context.Done(searchResultsString); }
public async Task <IActionResult> GetWallpaperAsync() { var userContext = await GetUserContextAsync(); var result = await _userServices.GetConfigAsync(userContext.Id); if (result.WallpaperSource == WallpaperSource.Upload) { result.WallpaperUrl = Appsetting.FileUrl + result.WallpaperUrl; } if (result.IsBing) { result.WallpaperSource = WallpaperSource.Bing; result.WallpaperUrl = await BingHelper.GetEverydayBackgroundImageAsync(); } return(Json(new ResponseModel <dynamic> { IsSuccess = true, Message = "初始化壁纸成功", Model = result })); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "near/{latitude}/{longitude}/{distance:int=16000}")] HttpRequest req, [CosmosDB(Constants.CosmosDbName, Constants.MyLocationsCollection, CreateIfNotExists = true, ConnectionStringSetting = "AzureCosmosDBConnectionString", SqlQuery = "SELECT * FROM locations l WHERE ST_DISTANCE(l.location, {{ 'type': 'Point', 'coordinates':[ {latitude},{longitude}]}}) < {distance}" )] IEnumerable <dynamic> destinations, double latitude, double longitude, ILogger log) { log.LogInformation("Location Lookup Started"); List <dynamic> resultList = new List <dynamic>(); try { int returnCount; string countParam = req.Query["count"]; if (!string.IsNullOrWhiteSpace(countParam) && countParam.CompareTo("all") == 0) { returnCount = destinations.Count(); } else { int.TryParse(countParam, out returnCount); if (returnCount < 1) { returnCount = int.Parse(Environment.GetEnvironmentVariable("DefaultReturnCount")); } } WayPoint userLocation = new WayPoint { Longitude = longitude, Latitude = latitude }; BingHelper bh = new BingHelper(); foreach (dynamic d in destinations.Take(returnCount)) { var location = d["location"]["coordinates"]; if (location != null) { WayPoint wp = new WayPoint { Latitude = location[0], Longitude = location[1] }; d.MapUri = await bh.GetMapImageUrl(userLocation, wp); d.Distance = await bh.GetRouteDistance(userLocation, wp); resultList.Add(d); } } } catch (Exception ex) { return(new BadRequestObjectResult(ex)); } log.LogInformation("Location Lookup Complete"); return(new OkObjectResult(resultList)); }