public async Task GetBingImageUrlTest() { string bingMapsKey = Configuration["BingMapsAPI"]; System.Console.WriteLine("BingMapsKey: " + bingMapsKey); BingMapService service = new BingMapService(bingMapsKey); DailyChallengeEntry entry = await service.GetLocationDetails("Nevada", null); Assert.IsTrue(entry.latitude != 0 && entry.longitude != 0); }
/// <summary> /// Get SchoolsViewModel /// </summary> public async Task <SchoolsViewModel> GetSchoolsViewModelAsync(UserContext userContext) { var currentUser = userContext.IsStudent ? await educationServiceClient.GetStudentAsync() as SectionUser : await educationServiceClient.GetTeacherAsync() as SectionUser; var schools = (await educationServiceClient.GetSchoolsAsync()) .OrderBy(i => i.Name) .ToArray(); BingMapService mapServices = new BingMapService(); for (var i = 0; i < schools.Count(); i++) { var address = string.Format("{0}/{1}/{2}", schools[i].State, HttpUtility.HtmlEncode(schools[i].City), HttpUtility.HtmlEncode(schools[i].Address)); if (!string.IsNullOrEmpty(schools[i].Address)) { var longitudeAndLatitude = await mapServices.GetLongitudeAndLatitudeByAddress(address); if (longitudeAndLatitude.Count() == 2) { schools[i].Latitude = longitudeAndLatitude[0].ToString(); schools[i].Longitude = longitudeAndLatitude[1].ToString(); } } else { if (string.IsNullOrEmpty(schools[i].Zip)) { schools[i].Address = "-"; } } } var mySchools = schools .Where(i => i.SchoolId == currentUser.SchoolId) .ToArray(); var myFirstSchool = mySchools.FirstOrDefault(); var grade = userContext.IsStudent ? currentUser.EducationGrade : myFirstSchool?.EducationGrade; var sortedSchools = mySchools .Union(schools.Except(mySchools)); return(new SchoolsViewModel(sortedSchools) { IsStudent = userContext.IsStudent, UserId = currentUser.UserId, EducationGrade = grade, UserDisplayName = currentUser.DisplayName, MySchoolId = currentUser.SchoolId, BingMapKey = Constants.BingMapKey }); }
public async Task <object> OpenModal() { //var client = new ServiceReference1.NoneyaWebServiceClient(); //var environmentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(); //var userDetails = await client.GetUserInformationAsync(environmentUserName); //first let's call the Bing service var address = await BingMapService.GetAddresses(); RetrievedAddress = address.resourceSets.FirstOrDefault().resources.FirstOrDefault().address; return(JsRuntime.InvokeAsync <object>("BingMap.OpenModalOnSearch")); }
private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var command = stepContext.Result.ToString(); if (command.ToLower().Contains("choose image")) { int imageIndex = await GetImageIndex(stepContext); BingImageService imageService = new BingImageService(); DailyChallengeImage image = await tableService.getDailyChallengeImage(); BingMapService mapService = new BingMapService(Configuration["BingMapsAPI"]); Logger.LogInformation("Image Text: " + image.ImageText); DailyChallengeEntry challengeEntry = await mapService.GetLocationDetails(image.ImageText, Logger); if (challengeEntry == null) { Logger.LogError("Unable to retrieve details of image"); throw new Exception("Unable to retrieve details from Google"); } Logger.LogInformation("Image Response: " + challengeEntry.imageResponse); Logger.LogInformation("Longitude: " + challengeEntry.longitude); Logger.LogInformation("Latitude: " + challengeEntry.latitude); Logger.LogInformation("Latitude: " + challengeEntry.distanceFrom); var dailyChallenge = await tableService.GetDailyChallenge(); dailyChallenge.photoUrl = image.Url; dailyChallenge.text = image.ImageText; dailyChallenge.latitude = challengeEntry.latitude; dailyChallenge.longitude = challengeEntry.longitude; dailyChallenge.extractedLocation = challengeEntry.imageResponse; dailyChallenge.entries = new List <DailyChallengeEntry>(); dailyChallenge.publishedTime = DateTime.Now; dailyChallenge.currentStatus = DailyChallengeStatus.Guessing; await tableService.SaveDailyChallenge(dailyChallenge); IMessageActivity reply = MessageFactory.Attachment(new List <Attachment>()); reply.Attachments.Add(AttachmentHelper.ImageChosen(dailyChallenge.photoUrl)); var activity = (Activity)reply; await stepContext.Context.SendActivityAsync((Activity)reply); return(await stepContext.EndDialogAsync(cancellationToken)); //return await stepContext.ReplaceDialogAsync(nameof(ChallengeGuesserDialog), promptOptions, cancellationToken); } else if (command.ToLower().Contains("try another image")) { int imageIndex = await IncrementAndReturnImageIndex(); } else if (command.ToLower().Contains("switch to google")) { try { var reply = MessageFactory.Attachment(new List <Attachment>()); var attachment = await GetGoogleImageChoiceAttachment(); await UpdateImageSource(ImageSource.Google); reply.Attachments.Add(attachment); } catch (Exception exp) { Logger.LogError(exp, $"Could not set Google Image: {exp.Message} - {exp.StackTrace}", null); throw exp; } } else if (command.ToLower().Contains("switch to bing")) { var reply = MessageFactory.Attachment(new List <Attachment>()); int imageIndex = await GetImageIndex(stepContext); await UpdateImageSource(ImageSource.Bing); var attachment = await GetBingImageChoiceAttachment(imageIndex); // reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments.Add(attachment); } else { await stepContext.Context.SendActivityAsync(MessageFactory.Text("Sorry, not sure about that"), cancellationToken); } return(await stepContext.BeginDialogAsync(nameof(MainDialog), null, cancellationToken)); }
private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { BingMapService mapService = new BingMapService(Configuration["BingMapsAPI"]); string guessText = stepContext.Result.ToString(); DailyChallengeInfo info = await tableService.GetLatestInfo(); if (guessText.ToLower().Contains("check results")) { DailyChallenge dailyChallenge = await tableService.GetDailyChallenge(); await CheckResults(stepContext, cancellationToken, dailyChallenge, info); return(await stepContext.EndDialogAsync(cancellationToken)); } else { TelemetryClient.TrackTrace("Checking for guess: " + guessText, Severity.Information, null); try { DailyChallengeEntry entry = await mapService.GetLocationDetails(guessText, Logger); if (entry == null) { var locationSplit = stepContext.Result.ToString().Split(' '); if (locationSplit.Length > 1) { var searchText = guessText.Substring(guessText.IndexOf(' ')); entry = await mapService.GetLocationDetails(searchText, Logger); } } if (entry == null) { await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Sorry, bing maps couldn't identify the location '{stepContext.Result.ToString()}'. Please try again."), cancellationToken); return(await stepContext.EndDialogAsync()); } else { DailyChallenge dailyChallenge = await tableService.GetDailyChallenge(); if (dailyChallenge.entries != null) { var matchingEntries = dailyChallenge.entries.Where <DailyChallengeEntry>(e => e.imageResponse == entry.imageResponse); if (matchingEntries.Count() > 0) { await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Sorry, someone has beaten you to suggesting '{stepContext.Result.ToString()}'. Please try again."), cancellationToken); // This line caused a bit of a meltdown so changing to end dialogue //return await stepContext.BeginDialogAsync(nameof(ChallengeGuesserDialog), null, cancellationToken); return(await stepContext.EndDialogAsync()); } } double distanceFromResult = DistanceMeasureHelper.GetDistanceFromResult(entry.latitude, entry.longitude, dailyChallenge.latitude, dailyChallenge.longitude); entry.distanceFrom = distanceFromResult; entry.userName = stepContext.Context.Activity.From.Name; entry.userId = stepContext.Context.Activity.From.Id; dailyChallenge.entries.Add(entry); await tableService.SaveDailyChallenge(dailyChallenge); IMessageActivity reply = MessageFactory.Attachment(new List <Attachment>()); DailyChallengeEntriesStatus currentStatus = await CheckWhetherAllEntriesReceived(stepContext, cancellationToken, dailyChallenge, info); reply.Attachments.Add(AttachmentHelper.AwaitingGuesses(currentStatus.userCount, dailyChallenge.photoUrl, currentStatus.usersWithEntryCount, entry.userName, entry.imageResponse)); await stepContext.Context.SendActivityAsync((Activity)reply); return(await stepContext.EndDialogAsync(null, cancellationToken)); } } catch (Exception exp) { TelemetryClient.TrackTrace("Error loading results: " + exp.Message + exp.StackTrace, Severity.Error, null); throw exp; } } }