public static IEnumerable <WeatherMessage> GetLatestWeatherData() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse( ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("weatherdata"); string rowKeyToUse = string.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks); TableQuery <TableWeatherMessage> query = new TableQuery <TableWeatherMessage>().Take(5); List <WeatherMessage> list = new List <WeatherMessage>(); Mapper.Initialize(cfg => cfg.CreateMap <TableWeatherMessage, WeatherMessage>()); foreach (TableWeatherMessage entity in table.ExecuteQuery(query)) { WeatherMessage wm = Mapper.Map <WeatherMessage>(entity); list.Add(wm); } return(list); }
public WeatherUpdate(WeatherMessage weatherMessage, Database database) { _database = database; Type = weatherMessage.Type; Message = weatherMessage.Message; Timestamp = weatherMessage.Timestamp; WindDirection = weatherMessage.WindDirection; WindSpeed = weatherMessage.WindSpeed; Humidity = weatherMessage.Humidity; Rain = weatherMessage.Rain; Pressure = weatherMessage.Pressure; Temperature = weatherMessage.HumidityTemperature; LightLevel = weatherMessage.LightLevel; Latitude = weatherMessage.Latitude; Longitude = weatherMessage.Longitude; Altitude = weatherMessage.Altitude; SatelliteCount = weatherMessage.SatelliteCount; GpsTimestamp = weatherMessage.GpsTimestamp; CalculateHeatIndex(); CalculateWindChill(); CalculateDewPoint(); CalculatePressureTrend(); CalculateRainLastHour(); }
private static CloudQueueMessage CreateCloudQueueMessage(LocationMessage messageParam, string content) { WeatherMessage message = CreateBlobTriggerMessage(messageParam, content); var messageJson = JsonConvert.SerializeObject(message); var cloudQueueMessage = new CloudQueueMessage(messageJson); return(cloudQueueMessage); }
public void StoreWeatherData(WeatherMessage weatherMessage) { using var connection = CreateConnection(); var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.CreateReading.sql"); connection.Query(query, weatherMessage); }
protected void OnMessageWeather(WeatherMessage ea) { if (MessageWeather != null) { MessageWeather(this, new ProtocolMessageEventArgs <WeatherMessage> { Message = ea }); } }
public override void Initialize(ServerCore server) { _server = server; _server.LoginManager.PlayerAuthorized += LoginManager_PlayerAuthorized; server.Clock.CreateNewTimer(new Clock.GameClockTimer(UtopiaTimeSpan.FromDays(1), server.Clock, PerDayTrigger)); _lastMessage = UpdateWeather(); }
private static WeatherMessage CreateBlobTriggerMessage(LocationMessage messageParam, string content) { WeatherRoot weather = (WeatherRoot)JsonConvert.DeserializeObject(content, typeof(WeatherRoot)); WeatherMessage message = new WeatherMessage(weather) { CityName = messageParam.CityName, Blob = messageParam.Blob, Guid = messageParam.Guid, }; return(message); }
private static async Task <CloudBlockBlob> GetBlobStorage(WeatherMessage message, CloudStorageAccount storageAccount) { CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference("blob-bier-weer"); await blobContainer.CreateIfNotExistsAsync(); string fileName = String.Format("{0}.png", message.Guid); CloudBlockBlob cloudBlockBlob = blobContainer.GetBlockBlobReference(fileName); cloudBlockBlob.Properties.ContentType = "image/png"; return(cloudBlockBlob); }
private void weatherLoad(string city) { /*cn.com.webxml.www.WeatherWebService w = new cn.com.webxml.www.WeatherWebService(); * s = w.getWeatherbyCityName(city); * if (s[8] == "") * { * wd.cityLabel.Text = "暂无天气信息"; * } * else * { * this.weatherButter.Image = Image.FromFile(Application.StartupPath + "\\weather\\" + s[8]); * this.weatherLabel.Text = s[5]; * wd.cityLabel.Text = s[8]; * }*/ baiduWeather weather = new baiduWeather(city); WeatherMessage weathermessage = weather.GetWeather(); String content = ""; if (weathermessage.status.Equals("success")) { WeatherModel weatherModel = weathermessage.results[0]; content = content + weatherModel.currentCity + "\n"; weather_datas = weatherModel.weather_data; content = content + weather_datas[0].date + "\n"; content = content + weather_datas[0].weather + "\n"; content = content + weather_datas[0].temperature + "\n"; content = content + weather_datas[0].wind + "\n"; wd.cityLabel.Text = content; String[] dateInfo = null; dateInfo = weather_datas[0].date.Split('('); this.weatherLabel.Text = dateInfo[1].Substring(0, dateInfo[1].Length - 1); String url = null; if (DateTime.Now.Hour < 6 || DateTime.Now.Hour > 18) { url = weather_datas[0].nightPictureUrl; } else { url = weather_datas[0].dayPictureUrl; } WebRequest webreq = WebRequest.Create(url); WebResponse webres = webreq.GetResponse(); Stream stream = webres.GetResponseStream(); this.weatherButten.Image = Image.FromStream(stream); } else { wd.cityLabel.Text = "暂无天气信息"; } }
private WeatherMessage UpdateWeather() { UtopiaTime now = _server.Clock.Now; if (TimeConfiguration.Seasons.Count == 0) { return(new WeatherMessage()); } var growing = now.Day / ((float)TimeConfiguration.DaysPerSeason / 2) <= 1; Season s1, s2; float power; var seasonIndex = now.SeasonIndex; if (growing) { var s1Index = seasonIndex - 1 < 0 ? TimeConfiguration.Seasons.Count - 1 : seasonIndex - 1; s1 = TimeConfiguration.Seasons[s1Index]; s2 = TimeConfiguration.Seasons[seasonIndex]; power = now.Day / ((float)TimeConfiguration.DaysPerSeason) + 0.5f; } else { var s2Index = seasonIndex + 1 >= TimeConfiguration.Seasons.Count ? 0 : seasonIndex + 1; s1 = TimeConfiguration.Seasons[seasonIndex]; s2 = TimeConfiguration.Seasons[s2Index]; power = now.Day / ((float)TimeConfiguration.DaysPerSeason) - 0.5f; } var temperature = Lerp(s1.Temperature, s2.Temperature, power); var moisture = Lerp(s1.Moisture, s2.Moisture, power); var msg = new WeatherMessage { MoistureOffset = moisture, TemperatureOffset = temperature }; return(msg); }
public async Task SendMessageAsync() { WeatherMessage dm = new WeatherMessage() { DeviceID = "raspberry1", PartitionKey = "raspberry1", CurrentDateTime = DateTime.Now.ToString("MMMM dd, yyyy, H:mm:ss"), RowKey = (DateTime.MaxValue.Ticks - DateTime.Now.Ticks).ToString(), Temperature = shield.Temperature.ToString(), Altitude = shield.Altitude.ToString(), Pressure = shield.Pressure.ToString(), Humidity = shield.Humidity.ToString() }; var serializedMessage = JsonConvert.SerializeObject(dm); //Debug.WriteLine("Sending message " + serializedMessage); var message = new Message(Encoding.UTF8.GetBytes(serializedMessage)); await client.SendEventAsync(message); Debug.WriteLine("Message sent."); }
public void ParseTest() { var weatherMessage = WeatherMessage.Parse("$,ws=1.80,wg=1.15,wd=180.00,r=0.01,bt=14.44,bp=1016.76,tl=597.83,st=9.68,sh=78.95,gf=1,gs=13,glt=42.764725,gln=-71.042038,ga=20.70,gth=22,gtm=20,gts=11,gdy=21,gdm=5,gdd=28,#"); Assert.AreEqual(MessageType.Data, weatherMessage.Type); Assert.AreEqual(WindDirection.South, weatherMessage.WindDirection); Assert.AreEqual(1.80M, weatherMessage.WindSpeed); Assert.AreEqual(42.764725M, weatherMessage.Latitude); Assert.AreEqual(-71.042038M, weatherMessage.Longitude); Assert.AreEqual(1016.76M, weatherMessage.Pressure); Assert.AreEqual(14.44M, weatherMessage.PressureTemperature); Assert.AreEqual(0.01M, weatherMessage.Rain); Assert.AreEqual(9.68M, weatherMessage.HumidityTemperature); Assert.AreEqual(78.95M, weatherMessage.Humidity); Assert.AreEqual(13, weatherMessage.SatelliteCount); Assert.AreEqual(20.70M, weatherMessage.Altitude); Assert.AreEqual(1.80M, weatherMessage.WindSpeed); Assert.AreEqual(597.83M, weatherMessage.LightLevel); Assert.AreEqual(DateTimeOffset.Parse("2021-05-28 22:20:11 +00:00"), weatherMessage.GpsTimestamp); }
public static async Task RunAsync([QueueTrigger("trigger-kaart-in", Connection = "AzureWebjobsStorage")] string myQueueItem, ILogger log) { WeatherMessage message = (WeatherMessage)JsonConvert.DeserializeObject(myQueueItem, typeof(WeatherMessage)); //weatherdata nodig om de locatie te bepalen WeatherRoot weatherRoot = message.Weather; Coord coordinates = weatherRoot.Coord; var storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage")); CloudBlockBlob cloudBlockBlob = await GetBlobStorage(message, storageAccount); try { string key = Environment.GetEnvironmentVariable("MapKey"); string url = String.Format("https://atlas.microsoft.com/map/static/png?subscription-key={0}&api-version=1.0¢er={1},{2}", key, coordinates.Lon, coordinates.Lat); HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(url); Stream responseContent = await response.Content.ReadAsStreamAsync(); string textToWrite = GenerateBeerText(weatherRoot); try { Stream renderedImage = WriteTextOnImage(responseContent, textToWrite); await cloudBlockBlob.UploadFromStreamAsync(renderedImage); } catch { //deze catch is bedoeld voor als de skiasharp niet meer werkt je krijgt dan een plaatje terug dat aangeeft of het te warm of te koud is string image = ""; if (weatherRoot.Main.Temp < 15) { image = "https://thumbs.dreamstime.com/z/bier-de-sneeuw-65279107.jpg"; } else { image = "https://fscomps.fotosearch.com/compc/CSP/CSP404/bier-in-woestijn-stock-fotografie__k4044056.jpg"; } using (System.Net.WebClient webClient = new System.Net.WebClient()) { using (Stream stream = webClient.OpenRead(image)) { await cloudBlockBlob.UploadFromStreamAsync(stream); } } } } catch (Exception e) { //deze catch is bedoeld voor als de azure maps service kaput is using (System.Net.WebClient webClient = new System.Net.WebClient()) { using (Stream stream = webClient.OpenRead("http://www.ajeforum.com/wp-content/uploads/2018/04/Error_Culture_Florent_Darrault2-640x478.jpg")) { string textToWrite = e.Message.ToString(); Stream renderedImage = WriteTextOnImage(stream, textToWrite); await cloudBlockBlob.UploadFromStreamAsync(renderedImage); } } } }
private void PerDayTrigger(UtopiaTime gametime) { // each day we will recalculate temperature and humidity values _lastMessage = UpdateWeather(); _server.ConnectionManager.Broadcast(_lastMessage); }
public WeatherMessage GetWeather() { WeatherMessage weatherMessage = JsonConvert.DeserializeObject <WeatherMessage>(HttpGet()); return(weatherMessage); }