/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser user) { using (ForecastService forecastService = (ForecastService)user.GetService(DfpService.v201708.ForecastService)) { // Set the line item to get a forecast for. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); try { // Get forecast for line item. AvailabilityForecastOptions options = new AvailabilityForecastOptions(); options.includeContendingLineItems = true; options.includeTargetingCriteriaBreakdown = true; AvailabilityForecast forecast = forecastService.getAvailabilityForecastById(lineItemId, options); // Display results. long matched = forecast.matchedUnits; double availablePercent = (double)(forecast.availableUnits / (matched * 1.0)) * 100; String unitType = forecast.unitType.ToString().ToLower(); Console.WriteLine("{0} {1} matched.\n{2} % {3} available.", matched, unitType, availablePercent, unitType); if (forecast.possibleUnitsSpecified) { double possiblePercent = (double)(forecast.possibleUnits / (matched * 1.0)) * 100; Console.WriteLine(possiblePercent + "% " + unitType + " possible.\n"); } Console.WriteLine("{0} contending line items.", (forecast.contendingLineItems != null) ? forecast.contendingLineItems.Length : 0); } catch (Exception e) { Console.WriteLine("Failed to get forecast by id. Exception says \"{0}\"", e.Message); } } }
public async void GetWeather() { WeatherConditions weather; var melbourneLocation = new Location() { Latitude = "-37.8136", Longitude = "144.9631" }; var serializedMelbourne = JsonConvert.SerializeObject(melbourneLocation); var cacheRepository = new CacheRepository <WeatherConditions>(_TomataboardContext); var openWeatherMapService = new OpenWeatherMapService(new StubLogger <OpenWeatherMapService>(), _openWeatherMapKeys); weather = await openWeatherMapService.Execute(serializedMelbourne); Assert.NotNull(weather); var forecastService = new ForecastService(new StubLogger <ForecastService>(), _forecastKeys); weather = await forecastService.Execute(serializedMelbourne); Assert.NotNull(weather); //var yahooWeatherService = new YahooWeatherService(new StubLogger<YahooWeatherService>(), _yahooWeatherKeys); //var provider = new WeatherProvider(new StubLogger<WeatherProvider>(), cacheRepository, forecastService,openWeatherMapService, yahooWeatherService); //weather = await provider.Execute(serializedMelbourne); Assert.NotNull(weather); }
private void GetNewForecast(string stodvaNr) { Forecast textaInfo = ForecastService.GetForecast(stodvaNr); forecastTextBox.Text = textaInfo.Content; DateTime parsed; if (DateTime.TryParse(textaInfo.Creation, out parsed)) { parsed = DateTime.Parse(textaInfo.Creation); DateTime now = DateTime.Now; TimeSpan span = now.Subtract(parsed); if (span.Hours > 0) { forecastInfoBox.Text = $"Spá skrifuð fyrir {span.Hours} klst"; } else { forecastInfoBox.Text = $"Spá skrifuð fyrir {span.Minutes} min"; } } else { forecastInfoBox.Text = $"Reynið aftur síðar"; } var validTo = textaInfo.Valid_to; var validFrom = textaInfo.Valid_from; }
public async Task <ActionResult> GetWeatherForecastByCityName(string cityName) { if (cityName.IsNullTypeOrEmpty()) { return(BadRequest("You have to post a city name to get weather forecast results..")); } Stopwatch sw = Stopwatch.StartNew(); var location = LocationService.FetchLocationInfo(cityName); if (location != null) { var weatherForecast = ForecastService.FetchForecastInfo(location.CityId, location.Lat, location.Lon); if (weatherForecast != null) { weatherForecast.CityName = location.CityName; weatherForecast.LocationQueryElapsedMilliseconds = location.QueryElapsedMilliseconds; sw.Stop(); weatherForecast.MethodQueryElapsedMilliseconds = sw.ElapsedMilliseconds; } await _hubContext.Clients.All.SendAsync("LastForecastQuery", weatherForecast); return(Ok(weatherForecast)); } return(NotFound($"Could not find any records with city name:{cityName}")); }
public void SaveForecasts_OneOfEachTypeOfForecastToSave_MapsAndCallsSaveOnClient() { // Arrange var fixture = InitializeFixture(); var client = fixture.Create <Mock <IServiceStackClient> >(); SaveForecastsRequest request = null; client .Setup(x => x.PostAsync(It.IsAny <SaveForecastsRequest>())) .ReturnsAsync(new SaveForecastsResponse()) .Callback <SaveForecastsRequest>(x => request = x); var appSettingsMock = new Mock <IAppSettings>(); var sut = new ForecastService(appSettingsMock.Object) { Client = () => client.Object }; var forecastMonth = fixture.Create <ForecastMonthDto>(); var forecastDtos = fixture .CreateMany <ForecastDto>() .ToList(); forecastMonth.ForecastDtos = forecastDtos; // Act sut.SaveForecasts(forecastMonth); // Assert Assert.That(request, Is.Not.Null); Assert.That(request.ForecastMonthDto, Is.EqualTo(forecastMonth)); Assert.That(request.ForecastMonthDto.ForecastDtos, Is.EqualTo(forecastDtos)); client.VerifyAll(); }
async Task SaveForecast() { ShowPopup = false; var user = (await authenticationStateTask).User; if (objWeatherForecast.Id == 0) { WeatherForecast objNewWeatherForecast = new WeatherForecast(); objNewWeatherForecast.Date = System.DateTime.Now; objNewWeatherForecast.Summary = objWeatherForecast.Summary; objNewWeatherForecast.TemperatureC = Convert.ToInt32(objWeatherForecast.TemperatureC); objNewWeatherForecast.TemperatureF = Convert.ToInt32(objWeatherForecast.TemperatureF); objNewWeatherForecast.UserName = user.Identity.Name; var result = ForecastService.CreateForecastAsync(objNewWeatherForecast); } else { var result = ForecastService.UpdateForecastAsync(objWeatherForecast); } forecasts = await ForecastService.GetForecastAsync(user.Identity.Name); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddMvc().AddNewtonsoftJson(); var config = new ConfigurationBuilder().AddJsonFile("appconfig.json").Build(); string apiUrl = config["Api:Url"]; string apiKey = config["Api:Key"]; IApiConfigPort apiConfig = new ApiConfigService(apiUrl, apiKey); IRequestCurrentWeather requestCurrentWeatherService = new ForecastRequestService(apiConfig); IRequestForecast requestForecastService = new ForecastRequestService(apiConfig); IGetCurrentWeather getCurrentWeatherService = new ForecastService(requestCurrentWeatherService, requestForecastService); IGetForecast getForecast = new ForecastService(requestCurrentWeatherService, requestForecastService); services.AddSingleton <IGetCurrentWeather>(provider => getCurrentWeatherService); services.AddSingleton <IGetForecast>(provider => getForecast); services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "Weather API", Description = "API for showing Weather", Version = "v1" }); }); }
public ForecastServiceTest() { _mockForecastRepository = new Mock <IForecastRepository>(); _target = new ForecastService( _mockForecastRepository.Object ); }
/// <summary> /// Run the code example. /// </summary> public void Run(DfpUser user) { // Get the ForecastService. ForecastService forecastService = (ForecastService)user.GetService(DfpService.v201611.ForecastService); // Set the line item to get a forecast for. long lineItemId1 = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); long lineItemId2 = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); try { // Get a delivery forecast for the line items. DeliveryForecastOptions options = new DeliveryForecastOptions(); options.ignoredLineItemIds = new long[] {}; DeliveryForecast forecast = forecastService.getDeliveryForecastByIds( new long[] { lineItemId1, lineItemId2 }, options); // Display results. foreach (LineItemDeliveryForecast lineItemForecast in forecast.lineItemDeliveryForecasts) { String unitType = lineItemForecast.unitType.GetType().Name.ToLower(); Console.WriteLine("Forecast for line item {0}:", lineItemForecast.lineItemId); Console.WriteLine("\t{0} {1} matched", lineItemForecast.matchedUnits, unitType); Console.WriteLine("\t{0} {1} delivered", lineItemForecast.deliveredUnits, unitType); Console.WriteLine("\t{0} {1} predicted", lineItemForecast.predictedDeliveryUnits, unitType); } } catch (Exception e) { Console.WriteLine("Failed to get forecast by id. Exception says \"{0}\"", e.Message); } }
public MainPageViewModel() { _forecastService = new ForecastService(); _citySearchService = new CitySearchService(); Items = new ObservableCollection <ForecastItem>(); PullDataFromDb(); }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the ForecastService. ForecastService forecastService = (ForecastService)user.GetService(DfpService.v201405.ForecastService); // Set the line item to get a forecast for. long lineItemId = long.Parse(_T("INSERT_LINE_ITEM_ID_HERE")); try { // Get forecast for line item. Forecast forecast = forecastService.getForecastById(lineItemId); // Display results. long matched = forecast.matchedUnits; double availablePercent = (double)(forecast.availableUnits / (matched * 1.0)) * 100; String unitType = forecast.unitType.ToString().ToLower(); Console.WriteLine("{0} {1} matched.\n{2} % {3} available.", matched, unitType, availablePercent, unitType); if (forecast.possibleUnitsSpecified) { double possiblePercent = (double)(forecast.possibleUnits / (matched * 1.0)) * 100; Console.WriteLine(possiblePercent + "% " + unitType + " possible.\n"); } Console.WriteLine("{0} contending line items.", (forecast.contendingLineItems != null)? forecast.contendingLineItems.Length : 0); } catch (Exception ex) { Console.WriteLine("Failed to get forecast by id. Exception says \"{0}\"", ex.Message); } }
private static async Task Test() { ForeCast foreCast = await ForecastService.ForecastRunAsync(); ShowProduct(foreCast); Console.ReadLine(); }
public async Task ShouldUpdateForecast_IfGeoObjectAndDateAreSame() { var repository = GetInMemoryRepository(); var fixture = new Fixture(); var forecasts = fixture.CreateMany <Forecast>(2).ToArray(); var geoObjects = forecasts.Select(x => x.GeoObject).ToArray(); await repository.AddRangeAsync(geoObjects); await repository.AddRangeAsync(forecasts); await repository.SaveChangesAsync(); var checkingForecast = forecasts.First(); checkingForecast.Precipitation += 1; checkingForecast.MaxTemperature += 1; checkingForecast.MinTemperature += 1; var sut = new ForecastService(repository); await sut.SaveParsedDataAsync(forecasts); Assert.True(repository.Query <GeoObject>().Count() == 2); Assert.True(repository.Query <Forecast>().Count() == 2); var dbCheckingForecast = repository.Query <Forecast>().First(x => x.Id == checkingForecast.Id); Assert.True(dbCheckingForecast.MaxTemperature == checkingForecast.MaxTemperature); Assert.True(dbCheckingForecast.MinTemperature == checkingForecast.MinTemperature); Assert.True(dbCheckingForecast.Precipitation == checkingForecast.Precipitation); }
private async Task GetForecast() { ForeCast foreCast = await ForecastService.ForecastRunAsync().ConfigureAwait(false); var WeatherText = new WeatherText(foreCast); ShowProduct(foreCast); }
protected override async Task OnInitializedAsync() { Forecasts = await ForecastService.GetForecastAsync(DateTime.Now); Refresh(); //NavigationManager.LocationChanged += OnLocationChanges; }
public void TestFacebookService() { var forecast = ForecastService.GetForecast(); var sunriseSunset = SunriseSunsetService.GetSunriseSunset(); var report = ReportBuilder.Build(forecast, sunriseSunset); FacebookService.PostText(report); }
public void GetCityIdsTest() { var service = new ForecastService(); var result = service.GetCityIds().Result.ToList(); Assert.IsNotNull(result, "result != null"); Assert.IsTrue(result.Any(), "result.Any()"); Assert.IsTrue(result.Any(i => i.Name.Equals("london", StringComparison.InvariantCultureIgnoreCase) && i.Id == LondonId), "result.Any()"); }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The DFP user object running the code example.</param> public override void Run(DfpUser user) { // Get the ForecastService. ForecastService forecastService = (ForecastService)user.GetService(DfpService.v201403.ForecastService); // Set the placement that the prospective line item will target. long[] targetPlacementIds = new long[] {long.Parse(_T("INSERT_PLACEMENT_ID_HERE"))}; // Set the end date time to have the line line item run till. string endDateTime = "INSERT_END_DATE_TIME_HERE (yyyyMMdd HH:mm:ss)"; // Create prospective line item. LineItem lineItem = new LineItem(); lineItem.targeting = new Targeting(); lineItem.targeting.inventoryTargeting = new InventoryTargeting(); lineItem.targeting.inventoryTargeting.targetedPlacementIds = targetPlacementIds; Size size = new Size(); size.width = 300; size.height = 250; // Create the creative placeholder. CreativePlaceholder creativePlaceholder = new CreativePlaceholder(); creativePlaceholder.size = size; lineItem.creativePlaceholders = new CreativePlaceholder[] {creativePlaceholder}; lineItem.lineItemType = LineItemType.SPONSORSHIP; lineItem.startDateTimeType = StartDateTimeType.IMMEDIATELY; lineItem.endDateTime = DateTimeUtilities.FromString(endDateTime); // Set the cost type to match the unit type. lineItem.costType = CostType.CPM; try { // Get forecast. Forecast forecast = forecastService.getForecast(lineItem); // Display results. long matched = forecast.matchedUnits; double availablePercent = (double) (forecast.availableUnits / (matched * 1.0)) * 100; String unitType = forecast.unitType.ToString().ToLower(); Console.WriteLine("{0} {1} matched.\n{2}% available.", matched, unitType, availablePercent, unitType); if (forecast.possibleUnitsSpecified) { double possiblePercent = (double) (forecast.possibleUnits / (matched * 1.0)) * 100; Console.WriteLine("{0}% {1} possible.\n", possiblePercent, unitType); } Console.WriteLine("{0} contending line items.", (forecast.contendingLineItems != null) ? forecast.contendingLineItems.Length : 0); } catch (Exception ex) { Console.WriteLine("Failed to get forecast. Exception says \"{0}\"", ex.Message); } }
public void ItShouldThrowExceptionWhenPlanNotExists() { var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.GetPlan(1)).Throws(new ForecastServiceException()); var service = new ForecastService <int>(dataService.Object); Assert.Throws(typeof(ForecastServiceException), () => service.LoadPlan(1)); }
protected override async Task OnInitializedAsync() { if (ForecastService is null) { return; } Forecasts = await ForecastService.GetForecastAsync(Now); }
public void GetForecastTest() { ForecastService forecastService = new ForecastService(); string location = "Stuttgart"; ForecastModel forecastModel = new ForecastModel(); forecastModel = forecastService.GetForecast(location); Assert.NotNull(forecastModel); }
public static void Run([TimerTrigger("0 0 4 * * *")] TimerInfo myTimer, TraceWriter log) { log.Info($"Timer trigger function executed at: {DateTime.Now}"); var forecast = ForecastService.GetForecast(); var sunriseSunset = SunriseSunsetService.GetSunriseSunset(); var report = ReportBuilder.Build(forecast, sunriseSunset); FacebookService.PostText(report); }
public void TestHelloWorld() { ForecastService service = new ForecastService(); service.HelloWorld(); Assert.AreEqual(true, true); }
public void ItShouldRunPlan() { var planId = 15; var service = new ForecastService <decimal>(new ForecastDataAccessService()); service.LoadPlan(planId); service.Run(); Thread.Sleep(30000); }
public void ItShouldThrowExceptionWhenCreatingAnExistingPlan() { var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.PlanExist("Plan")).Returns(true); var service = new ForecastService <decimal>(dataService.Object); Assert.Throws(typeof(ForecastServiceException), () => service.CreatePlan("Plan", "Plan", 1, "userName", 1, 12)); }
public void ItShouldNotVerifyIfPlanNotExists() { var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.PlanExist("Plan")).Returns(false); var service = new ForecastService <decimal>(dataService.Object); Assert.IsFalse(service.PlanExist("Plan")); }
public void ItShouldDeleteExistingPlan() { var dataService = new Mock <IForecastDataAccessService>(); dataService.Setup(x => x.DeletePlan(It.IsAny <int>())).Returns(true); var service = new ForecastService <int>(dataService.Object); Assert.IsTrue(service.DeletePlan(1)); }
/// <summary> /// For database pulling /// </summary> /// <param name="forecastService"></param> /// <param name="item">dbSet item</param> public ForecastItem(ForecastService forecastService, ForecastDbitem item) { _error = true; _forecastService = forecastService; Pinned = true; _dbId = item.ForecastDbitemId; Place = item.Place; Degrees = item.Degrees; Condition = item.Condition; ImageUrl = item.ImageUrl; }
public void ad() { ForecastService forecastService = ForecastService.getInstance(); Station s = new Station(); s.lat = "37"; s.lon = "-122"; forecastService.getForecast(s); forecastComplete += new ForecastComplete(gotForecast); }
protected override async Task OnInitAsync() { await ForecastService.GetForecastAsync(DateTime.Now); await ForecastService.GetForecastAsync(DateTime.Now); await ForecastService.GetForecastAsync(DateTime.Now); IsLoading = false; StateHasChanged(); }
public void Init() { TestUtils utils = new TestUtils(); forecastService = (ForecastService)user.GetService(DfpService.v201511.ForecastService); advertiserId = utils.CreateCompany(user, CompanyType.ADVERTISER).id; salespersonId = utils.GetSalesperson(user).id; traffickerId = utils.GetTrafficker(user).id; orderId = utils.CreateOrder(user, advertiserId, salespersonId, traffickerId).id; adUnitId = utils.CreateAdUnit(user).id; placementId = utils.CreatePlacement(user, new string[] {adUnitId}).id; lineItemId = utils.CreateLineItem(user, orderId, adUnitId).id; }