예제 #1
0
        public void Save(WeatherEntity weather)
        {
            var insert = @"
insert into Weather 
(AreaId,DataDate,Condition,Temperature)
values 
(@AreaId,@DataDate,@Condition,@Temperature)";

            var update = @"
update Weather 
set Condition = @Condition,
    Temperature = @Temperature
where AreaId = @AreaId
  and DataDate = @DataDate";

            var args = new SQLiteParameter[]
            {
                new SQLiteParameter("", weather.AreaId.Value),
                new SQLiteParameter("", weather.DataDate),
                new SQLiteParameter("", weather.Condition.Value),
                new SQLiteParameter("", weather.Temperature.Value),
            };

            SQLiteHelper.Excecute(insert, update, args);
        }
예제 #2
0
        public void Save(WeatherEntity weather)
        {
            string insert = @"
            insert into Weather
            (AreaId,DataDate,Condition,Tempereture)
            values
            (@AreaId,@DataDate,@Condition,@Tempereture)
            ";

            string update = @"
            update Weather
            set Condition = @Condition,
                Tempereture = @Tempereture
            where AreaId = @AreaId
            and DataDate = @DataDate
            ";

            var args = new List <SQLiteParameter>
            {
                new SQLiteParameter("@AreaId", weather.AreaID.Value),
                new SQLiteParameter("@DataDate", weather.DataDate),
                new SQLiteParameter("@Condition", weather.Condition.Value),
                new SQLiteParameter("@Tempereture", weather.Temperature.Value)
            };

            SQLiteHelper.Execute(insert, update, args.ToArray());
        }
예제 #3
0
 // UIのTextを更新する
 void Render(WeatherEntity weatherEntity)
 {
     CityNameText.text    = string.Format("都市名: {0}", weatherEntity.name);
     WeatherText.text     = string.Format("天気: {0}", weatherEntity.weather[0].main);
     TemperatureText.text = string.Format("気温: {0}", weatherEntity.main.temp - 273); // 気温(ケルビン)を摂氏に変換するため273.15を引いている
     WindForceText.text   = string.Format("風速: {0}m/s", weatherEntity.wind.speed);
 }
예제 #4
0
        private WeatherEntity GetMockEntity()
        {
            var main = new Main
            {
                Temp = Kelvin
            };

            var sys = new Sys
            {
                Sunrise = Sunrise,
                Sunset  = Sunset
            };

            var weather = new DataAccess.Entities.Weather.Weather
            {
                Main = Weathertype,
                Icon = Icon
            };

            var weatherEntity = new WeatherEntity
            {
                Name    = Location,
                Main    = main,
                Sys     = sys,
                Weather = new[] { weather }
            };

            return(weatherEntity);
        }
예제 #5
0
        public async Task <WeatherEntity> CreateWeatherAsync(WeatherEntity newWeather)
        {
            if (newWeather.Id == Guid.Empty.ToString())
            {
                newWeather.Id = Guid.NewGuid().ToString();
            }

            var dnow = DateTime.UtcNow;

            newWeather.RowVersion = dnow;

            const string sqlQuery = @"INSERT INTO weathers (
                    id,
                    AirPressure,
                    Temperature,
                    WeightValue,
                    RowVersion
                )
                VALUES (
                    @id,
                    @AirPressure,
                    @Temperature,
                    @WeightValue,
                    @RowVersion);";

            using (var db = new MySqlConnection(_options.CurrentValue.WeatherDbConnectionString))
            {
                await db.ExecuteAsync(sqlQuery, newWeather, commandType : CommandType.Text);

                return(newWeather);
            }
        }
예제 #6
0
        public static void WriteWeather(List <WeatherEntity> list, byte address, Action <string> callback)
        {
            for (int i = 0; i < list.Count; i++)
            {
                WeatherEntity weather = list[i];
                List <byte>   content = new List <byte>();
                content.AddRange(BitConverter.GetBytes(weather.WeatherName.Value).Reverse());
                content.AddRange(BitConverter.GetBytes(weather.WeatherUnit.Value).Reverse());
                content.AddRange(BitConverter.GetBytes(weather.WeatherPoint.Value).Reverse());
                byte[] byteTemp = BitConverter.GetBytes(weather.Rang);
                Array.Reverse(byteTemp, 0, 2);
                Array.Reverse(byteTemp, 2, 2);
                content.AddRange(byteTemp);
                byte[] byteFactor = new byte[12];
                byteTemp = ASCIIEncoding.ASCII.GetBytes(weather.WeatherFactor);
                for (int j = 0; j < byteTemp.Length; j++)
                {
                    byteFactor[j * 2 + 1] = byteTemp[j];
                }
                content.AddRange(byteFactor);
                byteTemp = BitConverter.GetBytes(weather.WeatherCompensation);
                Array.Reverse(byteTemp, 0, 2);
                Array.Reverse(byteTemp, 2, 2);
                content.AddRange(byteTemp);

                byte[] sendb = Command.GetWiteSendByte(address, (byte)(0x10 + weather.WeatherID), 0x10, content.ToArray());
                callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
                PLAASerialPort.Write(sendb);
            }
        }
예제 #7
0
        public async Task <WeatherEntity> RetrieveWeatherDataByCityAsync(string city)
        {
            _weatherRepo.SetInputData(city);
            var valid = _weatherRepo.ValidateInputData();

            if (valid)
            {
                var message = await _weatherRepo.GetHttpResponseMessageAsync();

                var result = await _weatherRepo.GetEntityFromJsonAsync(message);

                return(result);
            }
            else
            {
                Console.WriteLine("");
                Console.WriteLine("Error: Input data not valid!");
                Console.WriteLine("Exiting weather service!");
                Console.WriteLine("-.-");
                Console.WriteLine("Exited with error code: 789");
                Console.WriteLine("");
                var w = new WeatherEntity();
                return(w);
            }
        }
예제 #8
0
        public bool Equals(WeatherEntity anotherWeatherEntity)
        {
            if (anotherWeatherEntity == null)
            {
                return(false);
            }

            if (!City.Equals(anotherWeatherEntity.City))
            {
                return(false);
            }
            if (!Temperature.Equals(anotherWeatherEntity.Temperature))
            {
                return(false);
            }
            if (!Precipitation.Equals(anotherWeatherEntity.Precipitation))
            {
                return(false);
            }
            if (!Weather.Equals(anotherWeatherEntity.Weather))
            {
                return(false);
            }

            return(true);
        }
예제 #9
0
        public void ShowWeatherInConsoleAsync_should_throw_exception_if_weather_entity_is_null()
        {
            WeatherEntity weatherInCity = null;
            IEnumerable <WeatherEntity> weatherInCities = null;

            Assert.ThrowsAsync <ArgumentNullException>(async() => await _weatherService.ShowWeatherInConsoleAsync(weatherInCity));
            Assert.ThrowsAsync <ArgumentNullException>(async() => await _weatherService.ShowWeatherInConsoleAsync(weatherInCities));
        }
예제 #10
0
        public WeatherEntity SendRequest()
        {
            WebrequestCore core    = new WebrequestCore();
            string         appLoad = core.Get(new Uri(this.requestUrl));
            WeatherEntity  wEntity = WeatherDTO.ParserJson(appLoad, Configuration);

            return(wEntity);
        }
        public async Task <WeatherModel> GetWeatherModelAsync(string city)
        {
            WeatherEntity entity = await _repo.GetWeatherEntityByCityAsync(city);

            var model = MapFromEntity(entity);

            return(model);
        }
예제 #12
0
        private async Task <WeatherEntity> GetWeatherEntityByCityAsync(string city)
        {
            FillInputData(city);
            HttpRequestMessage message = await GetHttpResponseMessageAsync();

            WeatherEntity entity = await GetEntityFromJsonAsync(message);

            return(entity);
        }
예제 #13
0
 public bool TryAdd(WeatherEntity weather)
 {
     if (!weather.IsValid() || Find(weather) != null)
     {
         return(false);
     }
     _weather.Add(weather);
     UpdateData();
     return(true);
 }
예제 #14
0
        private static void GetCurrentWeather()
        {
            TableOperation retrieveOperation = TableOperation.Retrieve <WeatherEntity>(appId, weatherRowkey);     //retrieve Bin SMS Alter data
            TableResult    retrievedResult   = weatherTable.Execute(retrieveOperation);

            if (retrievedResult.Result != null)
            {
                weatherEntity = (WeatherEntity)retrievedResult.Result;
            }
        }
예제 #15
0
        public static List <WeatherEntity> ReadWeather(byte address, CommonConfig config, Action <string> callback)
        {
            byte[] sendb1 = Command.GetReadSendByte(address, 0x00, 0x21, 1);
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb1)));

            byte[] rbytes1 = PLAASerialPort.Read(sendb1);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes1)));

            byte count = rbytes1[4];
            List <WeatherEntity> list = new List <WeatherEntity>();

            for (byte i = 0; i < count; i++)
            {
                //Thread.Sleep(CommandUnits.CommandDelay);
                byte   high  = (byte)(0x10 + i);
                byte[] sendb = Command.GetReadSendByte(address, high, 0x10, 19);
                callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
                byte[] rbytes = PLAASerialPort.Read(sendb);
                callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));
                WeatherEntity weather = new WeatherEntity();
                weather.WeatherID = i;
                Array.Reverse(rbytes, 3, 2);
                weather.WeatherName.Value = BitConverter.ToInt16(rbytes, 3);
                weather.WeatherName.Name  = config.WeatherName.FirstOrDefault(c => c.Value == weather.WeatherName.Value).Key;
                Array.Reverse(rbytes, 5, 2);
                weather.WeatherUnit.Value = BitConverter.ToInt16(rbytes, 5);
                weather.WeatherUnit.Name  = config.WeatherUnit.FirstOrDefault(c => c.Value == weather.WeatherUnit.Value).Key;
                Array.Reverse(rbytes, 7, 2);
                weather.WeatherPoint.Value = BitConverter.ToInt16(rbytes, 7);
                weather.WeatherPoint.Name  = config.Point.FirstOrDefault(c => c.Value == weather.WeatherPoint.Value).Key;
                Array.Reverse(rbytes, 9, 2);
                Array.Reverse(rbytes, 11, 2);
                weather.Rang = BitConverter.ToSingle(rbytes, 9);
                List <byte> byteTemp = new List <byte>();
                for (int j = 13; j < 13 + 12;)
                {
                    if (rbytes[j + 1] != 0x00)
                    {
                        byteTemp.Add(rbytes[j + 1]);
                    }
                    j += 2;
                }
                weather.WeatherFactor = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());
                Array.Reverse(rbytes, 25, 2);
                Array.Reverse(rbytes, 27, 2);
                weather.WeatherCompensation = BitConverter.ToSingle(rbytes, 25);
                Array.Reverse(rbytes, 29, 2);
                Array.Reverse(rbytes, 31, 2);
                weather.CurrentWeather           = BitConverter.ToSingle(rbytes, 29);
                weather.WeatherAlertStatus.Value = rbytes[34];
                weather.WeatherAlertStatus.Name  = config.AlertStatus.FirstOrDefault(c => c.Value == rbytes[34]).Key;
                list.Add(weather);
            }
            return(list);
        }
예제 #16
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, WeatherEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #17
0
        public async Task Calculate_DateTimes_Correctly()
        {
            // Arrange
            WeatherEntity entity = GetMockEntity();

            // Act
            WeatherModel model = await _service.GetWeatherModelAsync(Location);

            // Assert
            Assert.Equal("01:01", model.Sunrise);
            Assert.Equal("17:05", model.Sunset);
        }
        public void Save()
        {
            Guard.IsNull(SelectedAreaId, "エリアを選択してください");
            var temperature = Guard.IsFloat(TemperatureText, "温度の入力に誤りがあります");

            var entity = new WeatherEntity(Convert.ToInt32(SelectedAreaId),
                                           DataDateValue,
                                           Convert.ToInt32(SelectedCondition),
                                           temperature);

            _weather.Save(entity);
        }
예제 #19
0
        public async Task Can_Retrieve_Weather_Data()
        {
            //Arrange
            string        city   = "Rzeszow";
            WeatherEntity entity = null;

            //Act
            entity = await _dataAccesService.RetrieveWeatherDataByCityAsync(city);

            //Assert
            Assert.NotNull(entity);
        }
예제 #20
0
        public IActionResult Create([FromQuery] DateTime date, [FromQuery] int temperature)
        {
            var weatherRow = new WeatherEntity {
                Temperature = temperature, Date = date
            };

            if (_repository.TryAdd(weatherRow))
            {
                return(Created("Данные успешно сохранены", weatherRow));
            }
            return(BadRequest("Не удалось сохранить"));
        }
예제 #21
0
 private static ForecastViewModel ToViewModel(this WeatherEntity entity)
 {
     return(new()
     {
         Date = entity.Date,
         Temperature = new TemperatureViewModel
         {
             Celcius = entity.Temperature,
             Farenheit = entity.Temperature.ToFarenheit()
         },
         Summary = entity.Summary
     });
 }
예제 #22
0
        public async Task Can_Retrieve_Weather_Data()
        {
            // Arrange
            WeatherEntity entity = null;
            string        city   = "London";

            // Act
            entity = await _repo.GetWeatherEntityByCityAsync(city);

            // Assert
            Assert.NotNull(entity);
            Assert.Equal(city, entity.Name);
        }
예제 #23
0
        public bool TryUpdate(WeatherEntity weather)
        {
            var weatherOld = Find(weather);

            if (weather.IsValid() && weatherOld != null)
            {
                _weather.Remove(weatherOld);
                _weather.Add(weather);
                UpdateData();
                return(true);
            }
            return(false);
        }
예제 #24
0
        public async Task SaveReport(string report)
        {
            var table = await GetTable();

            IWeatherParser <TReported> weatherParser = new TParser();

            var weather = weatherParser.Parse(report);
            WeatherEntity <TReported> weatherEntity = new WeatherEntity <TReported>(weather);


            TableOperation insertOperation = TableOperation.InsertOrReplace(weatherEntity);
            await table.ExecuteAsync(insertOperation);
        }
        private WeatherEntity PopulateDefaultWeather()
        {
            WeatherEntity defaultWeather = new WeatherEntity();

            defaultWeather.DewPoint         = "2.4°C";
            defaultWeather.Pressure         = "-";
            defaultWeather.RelativeHumidity = "32%";
            defaultWeather.SkyConditions    = "Mostly clear";
            defaultWeather.Temperature      = "18.6°C";
            defaultWeather.Visibility       = "16 km";
            defaultWeather.Wind             = "WNW 16km/h";

            return(defaultWeather);
        }
예제 #26
0
        public async Task <WeatherEntity> Post(int locationId, double temperature, double humidity)
        {
            var weather = new WeatherEntity()
            {
                LocationId  = locationId,
                Temperature = Math.Round(temperature, 1),
                Humidity    = Math.Round(humidity, 1),
                CreatedAt   = Now
            };

            Db.Weathers.Add(weather);
            await Db.SaveChangesAsync();

            return(weather);
        }
예제 #27
0
        private bool CheckIfWeatherInCityIsCorrect(string city, WeatherEntity weatherInCity)
        {
            if (weatherInCity == null)
            {
                _logger.LogError($"Tried to get weather in {city}, but received empty response");
                return(false);
            }
            if (!city.Equals(weatherInCity.City))
            {
                _logger.LogWarning($"Expected city: {city}, but was received: {weatherInCity?.City ?? "NULL"}");
                return(false);
            }

            return(true);
        }
예제 #28
0
        public async Task ShowWeatherInConsoleAsync(WeatherEntity weatherInCity)
        {
            await Task.Factory.StartNew(() =>
            {
                if (weatherInCity == null)
                {
                    _logger.LogError("Trying to show weather in city in console, but WeatherEntity is null");
                    throw new ArgumentNullException(nameof(weatherInCity), "Can't show weather in console");
                }

                Console.WriteLine("------------------------------------------------------------------");
                Console.WriteLine(weatherInCity);
                Console.WriteLine("------------------------------------------------------------------");
            }).ConfigureAwait(false);
        }
예제 #29
0
        public void Can_Map_From_Entity()
        {
            // Arrange
            WeatherEntity entity = GetMockEntity();

            // Act
            WeatherModel model = _service.MapFromEntity(entity);

            // Assert
            Assert.Equal(Location, model.Location);
            Assert.Equal(Weathertype, model.WeatherType);
            Assert.Equal(Kelvin, model.Temperature);
            Assert.Equal(Sunrise.ToString(), model.Sunrise);
            Assert.Equal(Sunset.ToString(), model.Sunset);
            Assert.Equal(Icon, model.Icon);
        }
예제 #30
0
        public async Task Calculate_Temperatures_CorrectlyAsync()
        {
            // Arrange
            WeatherEntity entity = GetMockEntity();

            // Act
            WeatherModel model = await _service.GetWeatherModelAsync(Location);

            double celsius    = model.ConvertTemperature(TemperatureUom.Celsius);
            double fahrenheit = model.ConvertTemperature(TemperatureUom.Fahrenheit);
            double kelvin     = model.ConvertTemperature(TemperatureUom.Kelvin);

            // Assert
            Assert.Equal(22, celsius);
            Assert.Equal(71.6, fahrenheit);
            Assert.Equal(295.15, kelvin);
        }