protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var temp = new TempratureModel(); while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); await Task.Delay(1000, stoppingToken); } }
public async Task <AddTempratureResponse> Handle(AddTempratureCommand request, CancellationToken cancellation) { var id = Guid.NewGuid().ToString(); TempratureModel temprature = new TempratureModel { Id = id, timeStamp = DateTime.Now.ToString("dd_MMM_yyyy_HH_mm_ss"), value = request.value }; await _tempratureRepo.addAsync(temprature); return(new AddTempratureResponse(id)); }
public async Task <TempratureModel> addAsync(TempratureModel temprature) { if (temprature == null) { throw new ArgumentNullException("temprature was null"); } else { temprature.Id = Guid.NewGuid().ToString(); string jsonString = JsonSerializer.Serialize(temprature); var content = new StringContent(temprature.ToString(), Encoding.UTF8, "application/json"); var result = await client.PostAsync("https://localhost:44371/api/Temprature/PostTemprature", content); Console.WriteLine("Status Code: " + result.StatusCode); return(temprature); } }
public static async Task <string> SendMessageAsync(DeviceClient deviceClient) { var data = new TempratureModel { Temperature = rnd.Next(20, 30).ToString(), Humidity = rnd.Next(40, 50).ToString() }; var json = JsonConvert.SerializeObject(data); var payload = new Microsoft.Azure.Devices.Client.Message(Encoding.UTF8.GetBytes(json)); await deviceClient.SendEventAsync(payload); Console.WriteLine($"Message sent: {json}"); return(json); }
private void HandleMessageReceived(MqttApplicationMessage message) { Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###"); Console.WriteLine($"+ Topic = {message.Topic}"); Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(message.Payload)}"); Console.WriteLine($"+ QoS = {message.QualityOfServiceLevel}"); Console.WriteLine($"+ Retain = {message.Retain}"); Console.WriteLine(); string payload = Encoding.UTF8.GetString(message.Payload); Console.WriteLine(payload); TempratureModel tempratureModel = new TempratureModel(); tempratureModel.Id = Guid.NewGuid().ToString(); tempratureModel.timeStamp = DateTime.Now.ToString("MMM_dd_yyyy_HH_mm_ss"); tempratureModel.value = payload; context.tempratures.Add(tempratureModel); context.SaveChanges(); Console.WriteLine("Temprature added"); }
public async Task <TempratureModel> addAsync(TempratureModel temprature) { if (temprature == null) { throw new ArgumentNullException("temprature was null"); } else { try { await _meterContext.AddAsync(temprature); await _meterContext.SaveChangesAsync(); return(temprature); } catch (Exception e) { throw new Exception(e.Message); } } }
public GetLastTempratureResponse(TempratureModel temprature) { _temprature = temprature; }
public async void addScantoDB(TempratureModel temprature) { await repository.addAsync(temprature); }
public void saveTemprature(TempratureModel temprature) { addScantoDB(temprature); }