public async Task <IActionResult> PutSensorRecord([FromRoute] long id, [FromBody] SensorRecord sensorRecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sensorRecord.Id)
            {
                return(BadRequest());
            }

            _context.Entry(sensorRecord).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SensorRecordExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async void StopTimer()
        {
            // pag di enabled, return lng
            if (!IsEnabled)
            {
                return;
            }

            // enabled, so pwede i-stop
            IsEnabled = false;

            // get time when stopped
            Logger.Log("Stop Timer");
            stopTime    = DateTime.Now;
            stopTimeStr = stopTime.ToLongTimeString();
            activity.SetStopTime(stopTimeStr);

            // pagkastop write ulit last
            await WriteEntries();

            // create model TODO
            SensorRecord record = new SensorRecord()
            {
                Filename  = currentFilename,
                ClientId  = cliSession.ClientId,
                StartTime = startTime,
                StopTime  = stopTime
            };

            Logger.Debug(record);

            // save to db
            var response = await cliService.AddSensorRecord(record);
        }
        public void ViewRecordClicked(object sender, int position)
        {
            Logger.Log($"ViewRecordClicked - {position}");

            SensorRecord record = records[position];

            view.LaunchViewRecord(record);
        }
Exemplo n.º 4
0
        private string ConvertRecordToSQLCommand(SensorRecord record)
        {
            string commandText = $"INSERT INTO {databaseTableName} (Name, Description, SignalAmplitude, SignalFrequency," +
                                 $" DesiredContent, Type, IsGrounded) " +
                                 $"VALUES ('{record.Name}','{record.ImageLocation}','{record.Description}','{record.SignalAmplitude}','{record.SignalFrequency}'," +
                                 $"'{record.DesiredContent}','{record.Type}','{record.IsGrounded}');";

            return(commandText);
        }
Exemplo n.º 5
0
        public void LaunchViewRecord(SensorRecord record)
        {
            Logger.Log("LaunchViewRecord");
            FragmentTransaction ft       = Activity.SupportFragmentManager.BeginTransaction();
            Fragment            fragment = new ClientViewSensorRecordView(record);

            ft.Replace(Resource.Id.fragment_container, fragment);
            ft.AddToBackStack(null);
            ft.Commit();
        }
Exemplo n.º 6
0
        private SensorRecord ConvertSQLRowToRecord(SqlDataReader sqlReader)
        {
            SensorRecord record = new SensorRecord();

            record.Name            = sqlReader["Name"].ToString();
            record.Description     = sqlReader["Description"].ToString();
            record.DesiredContent  = sqlReader["DesiredContent"].ToString();
            record.SignalAmplitude = sqlReader["SignalAmplitude"].ToString();
            record.SignalFrequency = sqlReader["SignalFrequency"].ToString();
            record.Type            = sqlReader["Type"].ToString();
            record.IsGrounded      = sqlReader["IsGrounded"].ToString();
            return(record);
        }
Exemplo n.º 7
0
        public void GenerateSystemByName(string name)
        {
            // Open Card Database
            SensorDatabase database = new SensorDatabase();

            database.OpenConnection();
            // Request CardRecord from Database
            SensorRecord record = database.RequestSensorByName(name);

            database.CloseConnection();
            // Map CardRecord to CardBaseModel
            PopulateSystemFromRecord(record);
        }
Exemplo n.º 8
0
        public async Task <List <ApiResponse> > AddSensorRecord(SensorRecord record)
        {
            string url      = ApiUri.AddSensorRecord.ToUrl();
            string filename = record.Filename;

            IFileService fileService = new FileService(FileDirectory.SensorRecord);
            string       content     = await fileService.ReadToEndAsStringAsync(filename);

            byte[] bytesContent = content.ToBytesArray();

            var response = await httpService.PostMultipartFormDataContent
                           <IEnumerable <ApiResponse>, SensorRecord>(url, record, bytesContent, filename);

            return(response.ToList());
        }
Exemplo n.º 9
0
        // Request a single sensor by name
        public SensorRecord RequestSensorByName(string name)
        {
            SensorRecord sensor      = new SensorRecord();
            string       commandText = $"SELECT * FROM {databaseTableName} WHERE Name='{name}'";
            SqlCommand   command     = new SqlCommand(commandText, databaseConnection);

            // Read the account that matches the Username request
            using (SqlDataReader sqlReader = command.ExecuteReader())
            {
                while (sqlReader.Read())
                {
                    // Store all gameElement data from the acquired SQL record in the GameElementRecord object
                    sensor = (ConvertSQLRowToRecord(sqlReader));
                }
            }
            return(sensor);
        }
Exemplo n.º 10
0
 public void PopulateSystemFromRecord(SensorRecord record)
 {
     Name            = record.Name;
     Description     = $"\"{record.Description}\"";
     DesiredContent  = record.DesiredContent;
     SignalAmplitude = Convert.ToDecimal(record.SignalAmplitude);
     if (record.SignalFrequency != "DC")
     {
         SignalFrequency = Convert.ToInt32(record.SignalFrequency);
     }
     else
     {
         SignalFrequency = 0;
     }
     SensorType = record.Type;
     IsGrounded = (record.IsGrounded == "Yes");
 }
Exemplo n.º 11
0
        public ClientViewSensorRecordPresenter(IClientViewSensorRecordView view, SensorRecord record)
        {
            this.view   = view;
            this.record = record;

            fileService = fileService ?? new FileService(FileDirectory.SensorRecord);
            cliService  = cliService ?? new ClientService();

            entriesPiezo = new List <Entry>();
            entriesAccel = new List <Tuple <Entry, Entry, Entry> >();

            displayPiezo = new LinkedList <Entry>();
            displayAx    = new LinkedList <Entry>();
            displayAy    = new LinkedList <Entry>();
            displayAz    = new LinkedList <Entry>();

            InitLineChart();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Call writing measurement
        /// </summary>
        public long SetMeasure(SensorRecord sensorRecord)
        {
            var controller = "SensorRecords";

            string url = string.Format("http://{0}/{1}/{2}", _controllerServer, _restAPI, controller);
            var    uri = new Uri(url);

            _logger.Info(string.Format("Call Rest API - {0}/Post", url));

            var PostData = JsonConvert.SerializeObject(sensorRecord);

            var response = _httpClient.PostAsync(uri, new StringContent(PostData, Encoding.UTF8, _contentType));

            string jsonResult         = response.Result.Content.ReadAsStringAsync().Result;
            var    sensorRecordResult = JsonConvert.DeserializeObject <SensorRecord>(jsonResult);

            return(sensorRecordResult.Id);
        }
        public async Task <IActionResult> PostSensorRecord([FromBody] SensorRecord sensorRecord)
        {
            _logger.LogInformation("SensorRecords: SensorId:{0},  Value:{1} - Start ", sensorRecord.SensorId, sensorRecord.Value);

            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(sensorRecord);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            sensorRecord.DateTime = DateTime.Now;
            _context.SensorRecords.Add(sensorRecord);
            await _context.SaveChangesAsync();

            _logger.LogInformation("SensorRecords - End");

            return(CreatedAtAction("GetSensorRecord", new { id = sensorRecord.Id }, sensorRecord));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Start process of Collector
        /// </summary>
        public void Run()
        {
            _logger.Info("Run Collector - start");

            //Collector Initialize
            Initialize();

            // Registration to controller and synchronize ID
            RegisterCollectorInController();

            while (true)
            {
                // Read values from sensors
                foreach (var sensor in sensors)
                {
                    try
                    {
                        _logger.Info(string.Format("Sensor {0} before measure", sensor.ToString()));
                        var measureValue = sensor.Measure(sensor.Type);
                        _logger.Info(string.Format("Sensor {0} , Value {1}", sensor.ToString(), measureValue));

                        var sensorRecord = new SensorRecord();

                        sensorRecord.CollectorId = id;
                        sensorRecord.SensorId    = sensor.Id;
                        sensorRecord.Unit        = sensor.Unit;
                        sensorRecord.Value       = measureValue;
                        sensorRecord.DateTime    = System.DateTime.Now;

                        _communicator.SetMeasure(sensorRecord);
                    }
                    catch (System.Exception e)
                    {
                        _logger.Error(string.Format("Measure Error - Sensor ID {0}, Error: {1}", sensor.Id, e.Message), e);
                    }
                    Thread.Sleep(readingFrequency * 1000);
                }
            }
            ;
        }
Exemplo n.º 15
0
        public void AddSensorRecordTest()
        {
            string filename = randAlpha() + ".rec";
            string content  = "00:00:00.000,69,0.69,69.99,99.69";

            SensorRecord record = new SensorRecord()
            {
                ClientId  = 9,
                Filename  = filename,
                StartTime = DateTime.Now,
                StopTime  = DateTime.Now
            };

            string url = ApiUri.AddSensorRecord.ToUrl();

            HttpService httpService = new HttpService();
            var         task        = httpService.PostMultipartFormDataContent
                                      <IEnumerable <ApiResponse>, SensorRecord>(url, record, content.ToBytesArray(), filename);

            task.Wait();
            var res = task.Result;

            Assert.AreEqual(res.First().Code.ToString(), "UpdateSuccess");
        }
 public ClientViewSensorRecordView(SensorRecord record)
 {
     presenter = new ClientViewSensorRecordPresenter(this, record);
 }
Exemplo n.º 17
0
        // Add a new sensor
        public void AddNewSensor(SensorRecord sensor)
        {
            string commandText = ConvertRecordToSQLCommand(sensor);

            ExecuteSqlSendCommand(commandText);
        }