Esempio n. 1
0
        private async void Timer_Tick(ThreadPoolTimer timer)
        {
            try
            {
                //perform inventory scan and read available RFID tags
                var tagInventory = await _reader.PerformInventoryScan();

                if (tagInventory.Count() > 0)
                {
                    //assemble readings in the expected structure
                    List <TrackerReadingModel> readings = new List <TrackerReadingModel>();
                    foreach (var tag in tagInventory)
                    {
                        TrackerReadingModel reading = new TrackerReadingModel();
                        reading.IpAddress = _ipAddress;
                        reading.TagId     = BitConverter.ToString(tag);
                        reading.Reading   = DateTime.Now;
                        readings.Add(reading);
                    }

                    //send reading data to the cloud service
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri("http://YOURBASEURL.COM/");
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var response = await client.PostAsJsonAsync("api/reading/add-multi-readings", readings);
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: Logging of exception
            }
        }
Esempio n. 2
0
        private async void Timer_Tick(ThreadPoolTimer timer)
        {
            try
            {
                //perform inventory scan and read available RFID tags
                var tagInventory = await _reader.PerformInventoryScan();
                if(tagInventory.Count() > 0)
                {
                    //assemble readings in the expected structure
                    List<TrackerReadingModel> readings = new List<TrackerReadingModel>();
                    foreach(var tag in tagInventory)
                    {
                        TrackerReadingModel reading = new TrackerReadingModel();
                        reading.IpAddress = _ipAddress;
                        reading.TagId = BitConverter.ToString(tag);
                        reading.Reading = DateTime.Now;
                        readings.Add(reading);
                    }

                    //send reading data to the cloud service
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri("http://YOURBASEURL.COM/");
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var response = await client.PostAsJsonAsync("api/reading/add-multi-readings", readings);
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: Logging of exception
            }
        }
Esempio n. 3
0
        // Checks individual tags as they pass over
        private async void Timer_Tick(ThreadPoolTimer timer)
        {
            try
            {
                //perform inventory scan and read available RFID tags
                var tagInventory = await reader.PerformInventoryScan();

                if (tagInventory.Count() > 0)
                {
                    //assemble readings in the expected structure
                    List <TrackerReadingModel> readings = new List <TrackerReadingModel>();
                    foreach (var tag in tagInventory)
                    {
                        TrackerReadingModel reading = new TrackerReadingModel();
                        //                       reading.IpAddress = ipAddress;
                        reading.TagId   = BitConverter.ToString(tag);
                        reading.Reading = DateTime.Now;
                        readings.Add(reading);
                    }

                    //// Debugging
                    //foreach (var reading in readings)
                    //{
                    //    // Debug to make sure we're getting all the readings here.
                    //    System.Diagnostics.Debug.WriteLine(reading.TagId);
                    //}
                    //System.Diagnostics.Debug.WriteLine("");

                    string output = JsonConvert.SerializeObject(readings);
                    //send reading data to the web server
                    using (var client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var response = await client.PostAsync("http://127.0.0.1:1338", new StringContent(output.ToString(), Encoding.UTF8, "application/json"));
                    }


                    //var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:1338");
                    //httpWebRequest.ContentType = "application/json";
                    //httpWebRequest.Method = "POST";
                    //Stream stream = httpWebRequest.GetRequestStream();

                    //using (var streamWriter = new StreamWriter(stream))
                    //{
                    //    System.Diagnostics.Debug.Write(output);
                    //    streamWriter.Write(output);
                    //}
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Esempio n. 4
0
        public HttpResponseMessage PostTrackerReadingModel(TrackerReadingModel trackerReadingModel)
        {
            TrackerReadingRepository repo = new TrackerReadingRepository();
            bool ok = repo.AddReading(trackerReadingModel);

            if (ok)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }