//static HttpClient hc = new HttpClient(); public static async Task SendTelemetry(TelemetryModel data) { using (var hc = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(data), System.Text.Encoding.UTF8, "application/json"); await hc.PostAsync(ConfigurationManager.AppSettings["TelemetryApiUrl"], content); } }
public async Task SaveTelemetryAsync() { TelemetryModel telemetry = new TelemetryModel { Zones = Zones.Where(x => !x.Timestamp.IsStale()).ToList(), Channels = Channels, Timestamp = DateTime.Now }; Repository rep = new Repository(); await rep.AddTelemetryAsync(telemetry); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } TelemetryModel = await _context.TelemetryModel.FindAsync(id); if (TelemetryModel != null) { _context.TelemetryModel.Remove(TelemetryModel); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } TelemetryModel = await _context.TelemetryModel .Include(t => t.Car).FirstOrDefaultAsync(m => m.IdTel == id); if (TelemetryModel == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> PostMqttOnDemandAsync() { IPHostEntry hostInfo = Dns.Resolve(Dns.GetHostName()); TelemetryModel model = new TelemetryModel() { deviceid = Guid.NewGuid().ToString(), timestamp = DateTime.Now, tempValue = 23.7, rssi = "100", snr = "5", }; var onDemandMessageWasSent = await _awsIoTProcessor.OnDemandMessageAsync(_environment.WebRootPath, _jsonSerializer.SerializeObject(model)); return(Ok(onDemandMessageWasSent)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } TelemetryModel = await _context.TelemetryModel .Include(t => t.Car).FirstOrDefaultAsync(m => m.IdTel == id); if (TelemetryModel == null) { return(NotFound()); } ViewData["CarIdCar"] = new SelectList(_context.CarModel, "IdCar", "IdCar"); return(Page()); }
public IActionResult CreateTelemetry([FromBody] TelemetryModel telemetry) { try { if (telemetry == null) { return(BadRequest("Telemetry record is empty")); } var user = _serviceProvider.GetUserService().GetUser(telemetry.Email); if (user == null || !user.LicenceKeyId.HasValue) { return(NotFound("User not found or inactive")); } var telemetryRecord = _serviceProvider.GetTelemetryService().CreateOrUpdateTelemetryRecord(user.Id, telemetry.OsVersion, telemetry.NetFxVersion); var clientIp = Request.Headers["CF-Connecting-IP"].FirstOrDefault() ?? Request.Headers["X-Forwarded-For"].FirstOrDefault(); if (string.IsNullOrEmpty(clientIp)) { clientIp = "127.0.0.1"; } var resultReader = _dataConnection.ExecuteReader($"SELECT COUNT(*) FROM telemetryIps WHERE telemetryId = {user.Id} AND ip = '{clientIp}'"); var result = 0; if (resultReader.HasRows) { resultReader.Read(); result = resultReader.GetInt32(0); resultReader.Close(); } if (result == 0) { _dataConnection.ExecuteNonQuery($"INSERT INTO telemetryIps(telemetryId,ip) VALUES({telemetryRecord},'{clientIp}')"); } return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public override void BuildPayload() { string deviceIdString = SerialNumberValue; string rssiString = RssiValue; string snrString = SnrValue; string buttonStatus = CommandTypeValue; double tempValue = Convert.ToDouble(TempValue); double batValue = Convert.ToDouble(BatValue); TelemetryModel model = new TelemetryModel() { deviceid = deviceIdString, correlationId = Guid.NewGuid(), timestamp = DateTime.Now, buttonStatus = buttonStatus, batValue = batValue, tempValue = tempValue, rssi = rssiString, snr = snrString, }; Message = _jsonSerializer.SerializeObject(model); }
// send vitals as a json to mongoDB // from: https://www.stevejgordon.co.uk/sending-and-receiving-json-using-httpclient-with-system-net-http-json //public static async Task PostJsonHttpClient(string uri, HttpClient httpClient) public static async Task PostJsonHttpClient() { // HttpClient httpClient = Data.api; // api post request url string url = "http://localhost:3002/api/event"; //string url = "http://127.0.0.1:3002/api/vital"; //string url = "http://127.0.0.1:3002/api/temp"; //string url = "http://127.0.0.1:3002/api/oxygen"; //string url = "http://127.0.0.1:3002/api/heartrate"; // var postVitals = new TelemetryModel { HEART_BPM = 60 }; // var postResponse = await httpClient.PostAsJsonAsync(url, postVitals); // postResponse.EnsureSuccessStatusCode(); }
private string InitTelemetryModel(Session session, string captchaMode, string bookDate, Version appVersion, Guid uniqueId, double timeTakenToBook, string source) { var telemetryModel = new TelemetryModel { UniqueId = uniqueId, AppVersion = appVersion.ToString().Trim(), Source = source.Trim(), BookedOn = DateTime.ParseExact(bookDate, "dd-MM-yyyy HH:mm:ss", new CultureInfo("en-US")), TimeTakenToBookInSeconds = timeTakenToBook, CaptchaMode = captchaMode.Trim(), Latitude = Convert.ToInt32(session.Lat), Longitude = Convert.ToInt32(session.Long), PINCode = Convert.ToInt32(session.Pincode), District = session.DistrictName.Trim(), State = session.StateName.Trim(), BeneficiaryCount = beneficiaries.Count, MinimumAge = Convert.ToInt32(_configuration["CoWinAPI:MinAgeLimit"]), MaximumAge = Convert.ToInt32(_configuration["CoWinAPI:MaxAgeLimit"]), }; var telemetryMetadata = JsonConvert.SerializeObject(telemetryModel); return(telemetryMetadata); }
private void GetAvailableSlots(CovidVaccinationCenters covidVaccinationCenters) { List <Center> vaccinationCentres = covidVaccinationCenters.Centers; if (_vaccinationCentresToSearch.Count != 0 && Convert.ToBoolean(_configuration["CoWinAPI:IsSearchToBeDoneForVaccinationCentreName"]) == true) { vaccinationCentres = covidVaccinationCenters.Centers.Where(x => _vaccinationCentresToSearch.Any(centrename => centrename == x.Name.ToUpper().Trim())).ToList(); } if (vaccinationCentres.Count == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"[WARNING] Sorry! No Vaccination Centers available for your search criteria"); Console.ResetColor(); return; } foreach (var cvc in vaccinationCentres) { foreach (var session in cvc.Sessions) { if (IsFiltrationCriteriaSatisfied(cvc, session)) { if (session.Slots.Count > 0) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"[INFO] HURRAY! Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Center : {cvc.Name}"); Console.ResetColor(); DisplaySlotInfo(cvc, session); } // Processing of Slot Booking in Reverse Order so that chances are higher to get the slot for (int i = session.Slots.Count - 1; i >= 0; i--) { var stopwatch = new Stopwatch(); stopwatch.Start(); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"[INFO] Trying to Book Appointment for CVC: {cvc.Name} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Slot: {session.Slots[i]}"); Console.ResetColor(); string captcha = new Captcha(_configuration).GetCurrentCaptchaDetails(); IS_BOOKING_SUCCESSFUL = BookAvailableSlot(session.SessionId, session.Slots[i], captcha); if (IS_BOOKING_SUCCESSFUL == true) { stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; var captchaMode = Convert.ToBoolean(_configuration["CoWinAPI:Auth:AutoReadCaptcha"]) == true ? "AI AutoCaptcha" : "Manual Captcha"; var bookDate = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"); var appVersion = new VersionChecker(_configuration).GetCurrentVersionFromSystem(); var uniqueId = Guid.NewGuid(); var timeTakenToBook = ts.TotalSeconds; var source = System.Runtime.InteropServices.OSPlatform.Windows.ToString(); var telemetryModel = new TelemetryModel { UniqueId = uniqueId, AppVersion = appVersion.ToString().Trim(), Source = source.Trim(), BookedOn = DateTime.ParseExact(bookDate, "dd-MM-yyyy HH:mm:ss", new CultureInfo("en-US")), TimeTakenToBookInSeconds = timeTakenToBook, CaptchaMode = captchaMode.Trim(), Latitude = Convert.ToInt32(cvc.Lat), Longitude = Convert.ToInt32(cvc.Long), PINCode = Convert.ToInt32(cvc.Pincode), District = cvc.DistrictName.Trim(), State = cvc.StateName.Trim(), BeneficiaryCount = beneficiaries.Count, MinimumAge = Convert.ToInt32(_configuration["CoWinAPI:MinAgeLimit"]), MaximumAge = Convert.ToInt32(_configuration["CoWinAPI:MaxAgeLimit"]), }; var telemetryMetadata = JsonConvert.SerializeObject(telemetryModel); new Telemetry(_configuration).SendStatistics(telemetryMetadata); new Notifier().Notify($"*SLOT BOOKED SUCCESSFULLY +1* \n\n" + $"*LocalAppVersion* : `{ appVersion }`\n" + $"*BookedOn* : `{ bookDate }`\n" + $"*TimeTakenToBook* : `{ timeTakenToBook } seconds`\n" + $"*CaptchaMode* : `{captchaMode}`\n" + $"*Latitude* : `{ cvc.Lat}`\n" + $"*Longitude* : `{ cvc.Long}`\n" + $"*PINCode* : `{cvc.Pincode}`\n" + $"*District* : `{ cvc.DistrictName}`\n" + $"*State* : `{ cvc.StateName}`\n" + $"*BeneficiaryCount* : `{ beneficiaries.Count}`\n" + $"*AgeGroup* : `{_configuration["CoWinAPI:MinAgeLimit"]} - {_configuration["CoWinAPI:MaxAgeLimit"]}`\n" + $"*Source* : `{ source }`\n" + $"*UniqueId* : `{ uniqueId }`\n"); return; } stopwatch.Stop(); } } else { Console.WriteLine($"[INFO] Sorry! No Slots Available for search criteria: Age {_configuration["CoWinAPI:MinAgeLimit"]}-{_configuration["CoWinAPI:MaxAgeLimit"]} - PIN: {cvc.Pincode} - District: {cvc.DistrictName} - Date: {session.Date} - Center : {cvc.Name}"); Console.ResetColor(); } } } }
public async Task AddTelemetryAsync(TelemetryModel telemetry) { var collection = DB.GetCollection <TelemetryModel>("Telemetry"); await collection.InsertOneAsync(telemetry); }