Exemplo n.º 1
0
        public static async Task Push(ISerialConnection connection, RealTimePayload realTimePayLoad)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.MaxResponseContentBufferSize = 256000;
            var                 serviceUri             = new Uri(@"http://obdmicroservice20180827101800.azurewebsites.net/api/realtimepayloads");
            StringContent       realTimePayLoadContent = new StringContent(JsonConvert.SerializeObject(realTimePayLoad), System.Text.Encoding.UTF8, "application/json");
            HttpResponseMessage response = await httpClient.PostAsync(serviceUri, realTimePayLoadContent);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] RealTimePayload realTimePayload)
        {
            if (ModelState.IsValid)
            {
                _context.Add(realTimePayload);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(GetAll)));
            }
            return(this.Ok(realTimePayload));
        }
Exemplo n.º 3
0
        public static async Task Push(ISerialConnection connection, RealTimePayload realTimePayLoad)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.MaxResponseContentBufferSize = 256000;
            var                 serviceUri             = new Uri(@"http://obdmicroservice20180827101800.azurewebsites.net/api/realtimepayloads");
            StringContent       realTimePayLoadContent = new StringContent(JsonConvert.SerializeObject(realTimePayLoad), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await httpClient.PostAsync(serviceUri, realTimePayLoadContent);

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine($"Speed: {realTimePayLoad.Speed} : RPM: {realTimePayLoad.Rpm} : Fuel Level: {realTimePayLoad.FuelLevel}");
            }
            else
            {
                Console.WriteLine("FAILED");
            }
        }
Exemplo n.º 4
0
        private void ContinuousPush(int speepTime, Func <bool> cancellationCriateria)
        {
            Task.Factory.StartNew(async() =>
            {
                while (cancellationCriateria())
                {
                    RealTimePayload realTimePayLoad = await GetRealTimePayload(dev);

                    if (realTimePayLoad.Rpm != 0)
                    {
                        await Push(this.serialConnection, realTimePayLoad);
                    }

                    if (!isCancellationRequested)
                    {
                        await Task.Delay(speepTime);
                    }
                }

                isCancellationRequested = false;
            });
        }