internal void SaveValue(DTOs.External.DeviceValue value) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.DeviceValue deviceValue = new Models.EntityClass.DeviceValue(); deviceValue = Utilities.Map <TeknolojiKovaniWebApi.Domain.Values.DTOs.External.DeviceValue, TeknolojiKovaniWebApi.Models.EntityClass.DeviceValue>(value, deviceValue); deviceValue.DataServerTime = DateTime.UtcNow.AddHours(3); deviceValue.DataDeviceTime = DateTime.UtcNow.AddHours(3); ProfileDomain profileDomain = new ProfileDomain(); PropertyRead property = profileDomain.GetProperty(value.PropertyName); deviceValue.PropertyId = property.Id; DeviceDomain deviceDomain = new DeviceDomain(); DeviceRead device = deviceDomain.GetDevice(value.DeviceId); deviceValue.EnvironmentId = device.EnvironmentId.Value; deviceValue.UserId = device.UserId; ctx.DeviceValue.Add(deviceValue); ctx.SaveChanges(); }
public IHttpActionResult FireAlarm(FireAlarm alarm) { AlarmDomain alarmDomain = new AlarmDomain(); DeviceRead currentDevice = StaticContext.GetCurrentDevice(); if (currentDevice == null) { throw new UnauthorizedAccessException("Device token required"); } ValuesDomain valuesDomain = new ValuesDomain(); DeviceValue val = new DeviceValue(); val = Utilities.Map <FireAlarm, DeviceValue>(alarm, val); val.DeviceId = currentDevice.Id; val.AlarmId = alarm.AlarmId; valuesDomain.SaveValue(val); if (alarm.Side == "onserver") { AlarmFireDto alarmDto = new AlarmFireDto(); alarmDto = Utilities.Map <FireAlarm, AlarmFireDto>(alarm, alarmDto); alarmDomain.FireAlarm(alarmDto); } return(Ok()); }
public void DeleteDeviceRead(DeviceRead device) { lock (locker) { database.Delete(device); } }
public DeviceRead GetDevice(Guid id) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device device = ctx.Device.Single(i => i.Id == id); DeviceRead deviceRead = new DeviceRead() { CurrentToken = device.CurrentToken , DataSendInterval = device.DataSendInterval , EnvironmentId = device.EnvironmentId , Id = device.Id , MacNo = device.MacNo , Name = device.Name , ProfileId = device.ProfileId , UserId = device.UserId }; return(deviceRead); }
public DeviceRead GetDeviceById(Guid Id) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device device = ctx.Device.Single(x => x.Id == Id); DeviceRead oDevice = new DeviceRead(); oDevice = Utilities.Map <Models.EntityClass.Device, DeviceRead>(device, oDevice); return(oDevice); }
public IHttpActionResult SaveValue(string propertyName, DeviceValue value) { DeviceRead currentDevice = StaticContext.GetCurrentDevice(); value.DeviceId = currentDevice.Id; value.PropertyName = propertyName; ValuesDomain valuesDomain = new ValuesDomain(); valuesDomain.SaveValue(value); return(Ok()); }
public Task RunAsync(SimulationStrategy strategy, CancellationToken cancellationToken) { return(strategy.RunAsync((value) => { var reading = new DeviceReading(DateTime.UtcNow, value, _channel, string.Empty, _unit); var eventProps = new Dictionary <string, string>(); eventProps["ProjectId"] = "Foo"; var @event = new DeviceRead(_deviceId, reading, "console-sim", string.Empty, eventProps, DateTime.UtcNow); _sender.SendAsync(@event, cancellationToken); }, cancellationToken)); }
public static Guid GetCurrentDeviceId() { DeviceRead device = GetCurrentDevice(); if (device == null) { throw new Exception("Device token required"); } else { return(device.Id); } }
public void SaveDeviceRead(DeviceRead deviceRead) { lock (locker) { if (deviceRead.Id == 0) { database.Insert(deviceRead); } else { database.Update(deviceRead); } } }
public static DeviceRead GetCurrentDevice() { string token = HttpContext.Current.Request.Headers["token"]; if (string.IsNullOrEmpty(token)) { return(null); } else { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device dev = ctx.Device.FirstOrDefault(i => i.CurrentToken == token.ToString()); DeviceRead res = null; if (dev != null) { res = Utilities.Map <Models.EntityClass.Device, DeviceRead>(dev, res); } return(res); } }
void OnScanResult(IScanResult result) { //Guid a; if (result.Device.Name == "TaggenBeacon") { var frameData = result.AdvertisementData.ServiceData.FirstOrDefault(); if (frameData == null) { return; } if (frameData.Count() != 22) { return; } if ((frameData[0] != 0xAA) && (frameData[1] != 0xFE) && (frameData[2] != 0x00)) { return; } StringBuilder eddystoneNamespace = new StringBuilder(20); for (int i = 4; i < 14; i++) { eddystoneNamespace.AppendFormat("{0:x2}", frameData[i]); } StringBuilder eddystoneInstance = new StringBuilder(12); for (int i = 14; i < 20; i++) { eddystoneInstance.AppendFormat("{0:x2}", frameData[i]); } var instanceStr = eddystoneInstance.ToString(); var stretcher = App.Database.GetByInstance(instanceStr); if (stretcher != null) // Apenas salva uma leitura caso esse dispositivo exista no Dojot { // Atualiza a maca e a ambulancia: App.Database.UpdateDojotDevice(stretcher); DeviceRead deviceRead = App.Database.GetDeviceReadByInstance(instanceStr); if (deviceRead == null) { deviceRead = new DeviceRead(); deviceRead.Instance = instanceStr; } deviceRead.RSSI = result.Rssi; deviceRead.LastReadOn = DateTime.Now; Log($"Leu o beacon { deviceRead.Instance }, em { deviceRead.LastReadOn.ToString() }"); App.Database.SaveDeviceRead(deviceRead); } } }