public GetGeocodeDataProcessor BuildGetProcessor(string connString, string apiKey, string outputFile) { var db = new DatabaseReader(connString); var googleMaps = new GoogleMapService(apiKey); return(new GetGeocodeDataProcessor(db, googleMaps, outputFile)); }
public async Task GetPlaces(string place) { GooglePlaceAutoCompleteResult result = await GoogleMapService.GetPlaces(place); if (result != null && result.Status == "OK") { Places = new ObservableCollection <GooglePlaceAutoCompletePrediction>(result.AutoCompletePlaces); } }
private async Task <Attachment> GetGoogleImageChoiceAttachment() { GoogleMapService mapService = new GoogleMapService(Configuration["GoogleMapsAPI"]); HeroCard heroCard = null; try { DailyChallengeImage image = await mapService.GetRandomLocation(); await tableService.SaveDailyChallengeImage(image); heroCard = new HeroCard { Title = "Today's Daily Challenge", Subtitle = image.ImageRegion, Text = "Click to choose the image for today or try another image.", Images = new List <CardImage> { new CardImage(image.Url) }, Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, "Choose image", value: "Choose image"), new CardAction(ActionTypes.ImBack, "Try another Google image", value: "Try another image"), new CardAction(ActionTypes.ImBack, "Switch to Bing", value: "Switch to Bing") } }; } catch (Exception exp) { if (exp.Message == "Sorry, couldn't find a suitable image. Try again shortly.") { heroCard = new HeroCard { Title = "Today's Daily Challenge", Subtitle = "Not found", Text = "After trying 50 different locations, Google couldn't find a suitable image.", Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, "Try another Google image", value: "Try another image"), new CardAction(ActionTypes.ImBack, "Switch to Bing", value: "Switch to Bing") } }; } else if (exp.Message == "Over Google query limit") { heroCard = new HeroCard { Title = "Today's Daily Challenge", Subtitle = "Not found", Text = "The Google Maps Search Service is on a low level and has exceeeded it's usage. Please wait a few minutes and try again or switch to Bing.", Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, "Try another Google image", value: "Try another image"), new CardAction(ActionTypes.ImBack, "Switch to Bing", value: "Switch to Bing") } }; } else { throw exp; } } return(heroCard.ToAttachment()); }
public async Task <GooglePlace> GetPlaceDetails(string placeId) { return(await GoogleMapService.GetPlaceDetails(placeId)); }
public GetGeocodeDataProcessor(DatabaseReader db, GoogleMapService svc, string outputFile) { _db = db ?? throw new ArgumentNullException(nameof(db)); _svc = svc ?? throw new ArgumentNullException(nameof(svc)); _outputFile = outputFile ?? throw new ArgumentNullException(nameof(outputFile)); }
public List<VMonitorVehicle> GetMonitorVehicleList(string vehicleCode, EnumMapType mapType) { List<VMonitorVehicle> list = DACFacade.Movo.VehicleDAC.SelectListByVehicleCodes(vehicleCode, mapType); list = list.OrderBy(p => p.OrderByType).ToList(); LatLon latlon = null; GoogleMapService gms = new GoogleMapService(); foreach (var item in list) { if (item.Lng.HasValue && item.Lat.HasValue) { if (mapType == EnumMapType.GoogleCN) { latlon = gms.LatLonToMar(new LatLon { Longitude = item.Lng.Value, Latitude = item.Lat.Value }); if (latlon != null) { item.Lng = latlon.Longitude; item.Lat = latlon.Latitude; } } } } return list; }
public List<VMonitorVehicle> GetWithMonitorVehicleList(EnumMapType mapType, List<Guid> vehicleCodes) { List<VMonitorVehicle> list = DACFacade.Movo.VehicleDAC.SelectListByVehicleCodes(vehicleCodes, mapType); LatLon latlon = null; GoogleMapService gms = new GoogleMapService(); foreach (var item in list) { if (item.ExpireTime.HasValue && item.ExpireTime.Value.Date < DateTime.Now.Date) { item.IsOverdue = true; } if (item.AlarmType != null) { item.IsWarning = true; } if (item.Lng.HasValue && item.Lat.HasValue) { switch (mapType) { case EnumMapType.GoogleCN: latlon = gms.LatLonToMar(new LatLon { Longitude = item.Lng.Value, Latitude = item.Lat.Value }); break; case EnumMapType.BaiduMap: latlon = gms.LatLonToMar(new LatLon { Longitude = item.Lng.Value, Latitude = item.Lat.Value }); break; } if (latlon != null) { item.Lng = latlon.Longitude; item.Lat = latlon.Latitude; } } } return list; }
public List<VMonitorVehicle> GetMonitorVehicleList(string userCode, string tenantCode, EnumMapType mapType, string vehGroupID, bool? isMonitorVehicles,out string rightTabHtmlAll, out string rightTabHtmlOnline, out int onlineNum) { onlineNum = 0; rightTabHtmlAll = string.Empty; rightTabHtmlOnline = string.Empty; List<VMonitorVehicle> list = DACFacade.Movo.VehicleDAC.SelectListByVehicleCodes(userCode, tenantCode, mapType, vehGroupID); list = list.OrderBy(p => p.OrderByType).ToList(); LatLon latlon = null; GoogleMapService gms = new GoogleMapService(); StringBuilder sbTabHtmlAll = new StringBuilder(); StringBuilder sbTabHtmlOnline = new StringBuilder(); foreach (var item in list) { EFortifyAlertsetting fortifyAlertsetting = DACFacade.Gps.FortifyAlertSettingDAC.SelectByVehicleCode(new Guid(item.VehicleCode)); //设防按钮 string fortifysHtml = string.Empty; if (fortifyAlertsetting != null && fortifyAlertsetting.Enable) { item.IsFortify = true; fortifysHtml = "<a href='#' class='al-lock' onclick='MonitorUnFortify(\"{0}\");'>取消设防</a>"; } else { fortifysHtml = "<a href='#' class='al-unlock' onclick='MonitorFortify(\"{0}\");'>设防</a>"; } //obd按钮 string obdHtml = string.Empty; if (item.MachineType == 1) { obdHtml = "<a href='#' class='aLinkMonitor al-obd' onclick='OpenMonitorOBDInfo(\"{0}\")'>OBD</a>"; } if (item.Lng.HasValue && item.Lat.HasValue) { if (mapType == EnumMapType.GoogleCN) { latlon = gms.LatLonToMar(new LatLon { Longitude = item.Lng.Value, Latitude = item.Lat.Value }); if (latlon != null) { item.Lng = latlon.Longitude; item.Lat = latlon.Latitude; } } } string _cssName = (item.Lng.HasValue && item.Lat.HasValue ? string.Empty : " c9"); string checkHtml = "<div "; if (isMonitorVehicles != null && isMonitorVehicles.Value) { checkHtml = "<div style='padding-top: 8px;padding-left: 4px; float: left;'><input id='chkVehicle_{0}' type='checkbox'></div><div style='width: auto;' "; } if (item.IsOverdue) // 过期 { //item.OrderByType = 3; sbTabHtmlAll.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='true' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam red'><span>{1}</span>过期</p><p class='car-fun{7}'>跟踪<a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' onclick='MonitorZoomIn();'>放大</a></p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName); if (item.StateName != "OffLine") { onlineNum++; sbTabHtmlOnline.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='true' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam red'><span>{1}</span>过期</p><p class='car-fun{7}'>跟踪<a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' onclick='MonitorZoomIn();'>放大</a></p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName); } } else if (item.IsStop) // 停用 { //item.OrderByType = 4; sbTabHtmlAll.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam red'><span>{1}</span>停用</p><p class='car-fun{7}'>跟踪<a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' onclick='MonitorZoomIn();'>放大</a></p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); if (item.StateName != "OffLine") { onlineNum++; sbTabHtmlOnline.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='true' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam red'><span>{1}</span>停用</p><p class='car-fun{7}'>跟踪<a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' onclick='MonitorZoomIn();'>放大</a></p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); } } else if (item.StateName == EnumVehicleState.Run.ToString()) // 行驶 { //item.OrderByType = 1; sbTabHtmlAll.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam gre'><span>{1}</span>行驶</p><p class='car-fun{7}'>" + obdHtml + "<a href='#' class='aLinkMonitor al-fol' onclick='OpenMonitorTrack(\"{0}\")'>跟踪</a><a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' class='al-mag' onclick='MonitorZoomIn();'>放大</a>" + fortifysHtml + "</p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); onlineNum++; sbTabHtmlOnline.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam gre'><span>{1}</span>行驶</p><p class='car-fun{7}'>" + obdHtml + "<a href='#' class='aLinkMonitor al-fol' onclick='OpenMonitorTrack(\"{0}\")'>跟踪</a><a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' class='al-mag' onclick='MonitorZoomIn();'>放大</a>" + fortifysHtml + "</p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); } else if (item.StateName == EnumVehicleState.Stop.ToString()) // 停止 { //item.OrderByType = 2; sbTabHtmlAll.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam gre'><span>{1}</span>停止</p><p class='car-fun{7}'>" + obdHtml + "<a href='#' class='aLinkMonitor al-fol' onclick='OpenMonitorTrack(\"{0}\")'>跟踪</a><a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' class='al-mag' onclick='MonitorZoomIn();'>放大</a>" + fortifysHtml + "</p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); onlineNum++; sbTabHtmlOnline.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam gre'><span>{1}</span>停止</p><p class='car-fun{7}'>" + obdHtml + "<a href='#' class='aLinkMonitor al-fol' onclick='OpenMonitorTrack(\"{0}\")'>跟踪</a><a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' class='al-mag' onclick='MonitorZoomIn();'>放大</a>" + fortifysHtml + "</p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); } else if (item.StateName == EnumVehicleState.OffLine.ToString()) // 离线 { //item.OrderByType = 5; sbTabHtmlAll.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam{7}'><span>{1}</span>离线</p><p class='car-fun{7}'>" + obdHtml + "<a href='#' class='aLinkMonitor al-fol' onclick='OpenMonitorTrack(\"{0}\")'>跟踪</a><a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' class='al-mag' onclick='MonitorZoomIn();'>放大</a>" + fortifysHtml + "</p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); } else if (item.StateName == EnumVehicleState.Warning.ToString()) //报警 { //item.OrderByType = 1; sbTabHtmlAll.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam gre'><span>{1}</span>报警</p><p class='car-fun{7}'>" + obdHtml + "<a href='#' class='aLinkMonitor al-fol' onclick='OpenMonitorTrack(\"{0}\")'>跟踪</a><a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' class='al-mag' onclick='MonitorZoomIn();'>放大</a>" + fortifysHtml + "</p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); onlineNum++; sbTabHtmlOnline.AppendFormat("<li id='LiVehicle_{0}' VehicleCode='{0}' LicenceNumber='{1}' IsOverdue='{8}' IsStop={2} Lon='{3}' Lat='{4}'>" + checkHtml + " class='car-img'><img id='ImgVehicle_{0}' src='/Content/WeChat/images/Cars/IconCar/{5}_{6}_West.png'/></div><p class='car-nam gre'><span>{1}</span>报警</p><p class='car-fun{7}'>" + obdHtml + "<a href='#' class='aLinkMonitor al-fol' onclick='OpenMonitorTrack(\"{0}\")'>跟踪</a><a class='al-tra' href='#' onclick=\"PlayHistoricalTrack('{0}');\">历史轨迹</a><a href='#' class='al-mag' onclick='MonitorZoomIn();'>放大</a>" + fortifysHtml + "</p></li>", item.VehicleCode, item.LicenceNumber, item.IsStop, item.Lng, item.Lat, item.IconTypeName, item.StateName, _cssName, item.IsOverdue); } } if (sbTabHtmlAll.Length > 0) rightTabHtmlAll = sbTabHtmlAll.ToString(); if (sbTabHtmlOnline.Length > 0) rightTabHtmlOnline = sbTabHtmlOnline.ToString(); return list; }
/// <summary> /// Initializes an instance of BookingController, complete with mocked repositories and services. /// </summary> /// <param name="shouldHaveAccommodations">If true, the mocked repository will always return an accommodation. If false, always throws a KeyNotFoundException instead.</param> /// <returns>An instance of BookingController with mocked services.</returns> private BookingController GetController(bool shouldHaveAccommodations) { //Mock accommodation repo var accommodationRepo = new Mock <IAccommodationRepository>(); var reviewRepo = new EFReviewRepository(null, accommodationRepo.Object); var accommodationManager = new AccommodationManager(accommodationRepo.Object, reviewRepo); if (shouldHaveAccommodations) { //Setup fake accommodation var accommodation = new Accommodation() { Id = 1, MaxPersons = 4, Name = "Test Accommodation" }; accommodationRepo.Setup(r => r.GetAccommodation(It.IsAny <long>())).Returns(accommodation); } else { //If there are no accommodations, always throw a KeyNotFoundException accommodationRepo.Setup(r => r.GetAccommodation(It.IsAny <long>())).Throws(new KeyNotFoundException()); } //Setup fake countries var countries = new List <Country>() { new Country() { Id = 1, CountryCode = "NED", Name = "Netherlands", }, new Country() { Id = 2, CountryCode = "USA", Name = "United States", }, new Country() { Id = 3, CountryCode = "NOR", Name = "Norway", }, }; //Mock country repo var countryRepo = new Mock <ICountryRepository>(); var countryManager = new CountryManager(countryRepo.Object); countryRepo.Setup(r => r.Countries).Returns(countries); //Setup fake google API options var fakeApiOptions = new GoogleApiServiceOptions() { ClientApiKey = "Testkey" }; //Mock google api options var googleOpts = new Mock <IOptions <GoogleApiServiceOptions> >(); googleOpts.Setup(g => g.Value).Returns(fakeApiOptions); var googleOptsManager = new GoogleMapService(googleOpts.Object); var sessionMock = new Mock <ISession>(); byte[] emptyJsonObjectString = Encoding.ASCII.GetBytes("{}"); sessionMock.Setup(s => s.TryGetValue(It.IsAny <string>(), out emptyJsonObjectString)); sessionMock.Setup(s => s.Set(It.IsAny <string>(), It.IsAny <byte[]>())); //Set up a default HTTP context so the session can be mocked var httpContext = new DefaultHttpContext(); httpContext.Session = sessionMock.Object; //Setup controller var controller = new BookingController(accommodationManager, countryManager, googleOptsManager); controller.ControllerContext = new ControllerContext() { HttpContext = httpContext, RouteData = new RouteData() }; return(controller); }