public List <AlarmList> GetAlarmList(int UserId) { tKovanContext ctx = new tKovanContext(); //List<DTOs.External.Environment> lstEnvironment = ctx.Environment.Where(x => x.UserId == UserId).ToList().Select(x => new DTOs.External.Environment { Id = x.Id, Name = x.Name }).ToList(); //return lstEnvironment; List <AlarmList> AlarmList = new List <AlarmList>(); List <DeviceList> device = ctx.Device.Where(x => x.UserId == UserId).ToList().Select(x => new DeviceList { CurrentToken = x.CurrentToken, DataSendInterval = x.DataSendInterval, EnvironmentName = x.Environment == null ? "" : x.Environment.Name, Id = x.Id, Name = x.Name, MacNo = x.MacNo, ProfileName = x.Profile == null ? "" : x.Profile.Name, UserName = x.User == null ? "" : x.User.UserName }).ToList(); foreach (DeviceList item in device) { List <TeknolojiKovaniWebApi.Models.EntityClass.Alarm> DeviceAlarm = ctx.Alarm.Include("Device").Include("Property").Where(x => x.DeviceId == item.Id).ToList(); foreach (TeknolojiKovaniWebApi.Models.EntityClass.Alarm it in DeviceAlarm) { AlarmList dAlarm = new AlarmList(); dAlarm = Utilities.Map <TeknolojiKovaniWebApi.Models.EntityClass.Alarm, AlarmList>(it, dAlarm); dAlarm.DeviceName = it.Device.Name; dAlarm.PropertyName = it.Property.DisplayName; AlarmList.Add(dAlarm); } } return(AlarmList); }
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 DTOs.Data GetReportByDeviceIdAndPropertyId(Guid DeviceId, int PropertyId) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device Device = ctx.Device.Single(x => x.Id == DeviceId); Models.EntityClass.Property Property = ctx.Property.Single(x => x.Id == PropertyId); DTOs.Data Data = new DTOs.Data(); Data.type = "line"; Data.name = Device.Name + "/" + Property.Name; Data.showInLegend = true; Data.dataPoints = new List <DTOs.DataPoint>(); List <Models.EntityClass.DeviceValue> DeviceValues = ctx.DeviceValue.Where(x => x.DeviceId == DeviceId && x.PropertyId == PropertyId).ToList(); int sayac = 0; foreach (Models.EntityClass.DeviceValue DeviceValue in DeviceValues) { DTOs.DataPoint dp = new DTOs.DataPoint(); dp.x = sayac; dp.y = DeviceValue.Value; dp.label = DeviceValue.DataDeviceTime.ToString("dd.MM.yyyy HH:mm"); Data.dataPoints.Add(dp); sayac++; } return(Data); }
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(); }
internal void UpdateEnvironment(DTOs.External.Environment environment) { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Environment eEnvironment = ctx.Environment.Single(x => x.Id == environment.Id); eEnvironment.Name = environment.Name; ctx.SaveChanges(); }
public List <DeviceList> GetDeviceList(int UserId) { tKovanContext ctx = new tKovanContext(); List <DeviceList> device = ctx.Device.Include("Environment").Include("Profile").Where(x => x.UserId == UserId).ToList().Select(x => new DeviceList { CurrentToken = x.CurrentToken, DataSendInterval = x.DataSendInterval, EnvironmentName = x.Environment == null ? "" : x.Environment.Name, Id = x.Id, Name = x.Name, MacNo = x.MacNo, ProfileName = x.Profile == null ? "" : x.Profile.Name, UserName = x.User == null ? "" : x.User.UserName }).ToList(); return(device); }
public DTOs.External.Environment GetEnvironmentById(int Id) { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Environment Environment = ctx.Environment.Where(x => x.Id == Id).FirstOrDefault(); DTOs.External.Environment eEnvironment = new DTOs.External.Environment(); eEnvironment = Utilities.Map <TeknolojiKovaniWebApi.Models.EntityClass.Environment, DTOs.External.Environment>(Environment, eEnvironment); return(eEnvironment); }
internal List <DTOs.External.Environment> GetAll(int UserId) { tKovanContext ctx = new tKovanContext(); List <DTOs.External.Environment> lstEnvironment = ctx.Environment.Where(x => x.UserId == UserId).ToList().Select(x => new DTOs.External.Environment { Id = x.Id, Name = x.Name }).ToList(); return(lstEnvironment); }
public List <PropertyRead> GetPropertyList() { tKovanContext ctx = new tKovanContext(); List <PropertyRead> PropertyReadList = ctx.Property.Select(x => new PropertyRead { Id = x.Id, Name = x.Name }).ToList(); return(PropertyReadList); }
public AlarmList GetAlarmById(int Id) { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Alarm Alarm = ctx.Alarm.Single(x => x.Id == Id); AlarmList dAlarm = new AlarmList(); dAlarm = Utilities.Map <TeknolojiKovaniWebApi.Models.EntityClass.Alarm, AlarmList>(Alarm, dAlarm); return(dAlarm); }
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); }
internal void SaveEnvironment(DTOs.External.Environment environment) { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Environment eEnvironment = new Models.EntityClass.Environment(); eEnvironment.Name = environment.Name; eEnvironment.UserId = environment.UserId; ctx.Environment.Add(eEnvironment); ctx.SaveChanges(); }
public List <PropertyRead> GetPropertyListForDevice(Guid DeviceId) { tKovanContext ctx = new tKovanContext(); List <int> propertiesId = ctx.Alarm.Where(x => x.DeviceId == DeviceId).Select(x => x.PropertyId).ToList(); List <PropertyRead> PropertyReadList = ctx.Property.Where(x => !propertiesId.Contains(x.Id)).Select(x => new PropertyRead { Id = x.Id, Name = x.Name }).ToList(); return(PropertyReadList); }
public List <DTOs.DeviceLastValue> GetAllDeviceAndLastStatus(int UserId) { tKovanContext ctx = new tKovanContext(); List <DTOs.DeviceLastValue> DeviceLastValueList = new List <DTOs.DeviceLastValue>(); List <Models.EntityClass.Device> Device = ctx.Device.Include("Profile").Include("Profile.SensorProfiles").Include("Profile.SensorProfiles.Sensor").Include("Profile.SensorProfiles.Sensor.Properties").Where(x => x.UserId == UserId).ToList(); foreach (Models.EntityClass.Device itemDevice in Device) { if (itemDevice.Profile.SensorProfiles != null) { foreach (Models.EntityClass.SensorProfile itemSensorProfile in itemDevice.Profile.SensorProfiles.ToList()) { if (itemSensorProfile.Sensor.Properties != null) { foreach (Models.EntityClass.Property itemProperty in itemSensorProfile.Sensor.Properties) { DTOs.DeviceLastValue tDeviceLastValue = new DTOs.DeviceLastValue(); tDeviceLastValue.Id = itemDevice.Id; tDeviceLastValue.DeviceName = itemDevice.Name; tDeviceLastValue.PropertyId = itemProperty.Id; tDeviceLastValue.PropertyName = itemProperty.DisplayName; Models.EntityClass.DeviceValue DeviceLastValue = ctx.DeviceValue.Where(x => x.PropertyId == itemProperty.Id && x.DeviceId == itemDevice.Id).OrderByDescending(x => x.DataDeviceTime).FirstOrDefault(); if (DeviceLastValue != null) { tDeviceLastValue.Value = DeviceLastValue.Value; tDeviceLastValue.DataDeviceTime = DeviceLastValue.DataDeviceTime; } DeviceLastValueList.Add(tDeviceLastValue); } } else { DTOs.DeviceLastValue tDeviceLastValue = new DTOs.DeviceLastValue(); tDeviceLastValue.Id = itemDevice.Id; tDeviceLastValue.DeviceName = itemDevice.Name; tDeviceLastValue.PropertyName = "Tanımlı Property Yok"; tDeviceLastValue.Value = 0; tDeviceLastValue.DataDeviceTime = new DateTime(1900, 1, 1); DeviceLastValueList.Add(tDeviceLastValue); } } } else { DTOs.DeviceLastValue tDeviceLastValue = new DTOs.DeviceLastValue(); tDeviceLastValue.Id = itemDevice.Id; tDeviceLastValue.DeviceName = itemDevice.Name; tDeviceLastValue.PropertyName = "Tanımlı Sensör Yok"; tDeviceLastValue.Value = 0; tDeviceLastValue.DataDeviceTime = new DateTime(1900, 1, 1); DeviceLastValueList.Add(tDeviceLastValue); } } return(DeviceLastValueList); }
public void ValidateToken(Guid token) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device dev = ctx.Device.FirstOrDefault(i => i.CurrentToken == token.ToString()); if (dev == null) { throw new Exception("Token invalid"); } }
public List <DTOs.Data> GetReportByDeviceId(Guid DeviceId) { List <DTOs.Data> DataList = new List <DTOs.Data>(); tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device device = ctx.Device.Include("Profile").Include("Profile.SensorProfiles").Include("Profile.SensorProfiles.Sensor").Include("Profile.SensorProfiles.Sensor.Properties").Where(x => x.Id == DeviceId).FirstOrDefault(); List <DTOs.DevicePropertyInfo> DpiList = new List <DTOs.DevicePropertyInfo>(); if (device.Profile.SensorProfiles != null) { foreach (Models.EntityClass.SensorProfile itemSensorProfile in device.Profile.SensorProfiles.ToList()) { if (itemSensorProfile.Sensor.Properties != null) { foreach (Models.EntityClass.Property itemProperty in itemSensorProfile.Sensor.Properties) { DTOs.DevicePropertyInfo Dpi = new DTOs.DevicePropertyInfo(); Dpi.DeviceId = device.Id; Dpi.DeviceName = device.Name; Dpi.PropertyId = itemProperty.Id; Dpi.PropertyName = itemProperty.Name; DpiList.Add(Dpi); } } } } foreach (DTOs.DevicePropertyInfo dpi in DpiList) { DTOs.Data Data = new DTOs.Data(); Data.type = "line"; Data.name = dpi.DeviceName + "/" + dpi.PropertyName; Data.showInLegend = true; Data.dataPoints = new List <DTOs.DataPoint>(); List <Models.EntityClass.DeviceValue> DeviceValues = ctx.DeviceValue.Where(x => x.DeviceId == DeviceId && x.PropertyId == dpi.PropertyId).ToList(); int sayac = 0; foreach (Models.EntityClass.DeviceValue DeviceValue in DeviceValues) { DTOs.DataPoint dp = new DTOs.DataPoint(); dp.x = sayac; dp.y = DeviceValue.Value; dp.label = DeviceValue.DataDeviceTime.ToString("dd.MM.yyyy HH:mm"); Data.dataPoints.Add(dp); sayac++; } DataList.Add(Data); } return(DataList); }
public PropertyRead GetProperty(string propertyName) { tKovanContext ctx = new tKovanContext(); Property prop = ctx.Property.Single(i => i.Name == propertyName); PropertyRead property = new PropertyRead() { Id = prop.Id , Name = prop.Name }; return(property); }
public List <DTOs.AlarmLogList> GetAllAlarms(int UserId) { tKovanContext ctx = new tKovanContext(); List <DTOs.AlarmLogList> AlarmLogList = new List <DTOs.AlarmLogList>(); List <Models.EntityClass.Device> Device = ctx.Device.Include("Profile").Include("Profile.SensorProfiles").Include("Profile.SensorProfiles.Sensor").Include("Profile.SensorProfiles.Sensor.Properties").Where(x => x.UserId == UserId).ToList(); foreach (Models.EntityClass.Device itemDevice in Device) { if (itemDevice.Profile.SensorProfiles != null) { foreach (Models.EntityClass.SensorProfile itemSensorProfile in itemDevice.Profile.SensorProfiles.ToList()) { if (itemSensorProfile.Sensor.Properties != null) { foreach (Models.EntityClass.Property itemProperty in itemSensorProfile.Sensor.Properties) { List <Models.EntityClass.DeviceValue> DeviceLastValues = ctx.DeviceValue.Where(x => x.PropertyId == itemProperty.Id && x.DeviceId == itemDevice.Id && ctx.Alarm.Select(i => i.Id).Contains(x.AlarmId.Value) ).OrderByDescending(x => x.DataDeviceTime) .Take(5) .ToList(); foreach (Models.EntityClass.DeviceValue DeviceLastValue in DeviceLastValues) { DTOs.AlarmLogList AlarmLog = new DTOs.AlarmLogList(); AlarmLog.Id = itemDevice.Id; AlarmLog.DeviceName = itemDevice.Name; AlarmLog.PropertyName = itemProperty.DisplayName; AlarmLog.PropertyId = itemProperty.Id; AlarmLog.Value = DeviceLastValue.Value; AlarmLog.DataDeviceTime = DeviceLastValue.DataDeviceTime; AlarmLog.AlarmId = Convert.ToInt32(DeviceLastValue.AlarmId); Models.EntityClass.Alarm Alarm = ctx.Alarm.Single(x => x.Id == AlarmLog.AlarmId); AlarmLog.Max = Alarm.Max; AlarmLog.Min = Alarm.Min; AlarmLogList.Add(AlarmLog); } } } } } } return(AlarmLogList); }
public bool DeleteEnvironment(int Id) { try { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Environment Environment = ctx.Environment.Where(x => x.Id == Id).FirstOrDefault(); ctx.Environment.Remove(Environment); ctx.SaveChanges(); return(true); } catch (Exception) { return(false); } }
internal string[] GetDeviceCommands(Guid currentDeviceId) { tKovanContext ctx = new tKovanContext(); IEnumerable <DeviceCommand> commands = ctx.DeviceCommands.Where(i => !i.Executed && i.DeviceId == currentDeviceId); foreach (DeviceCommand command in commands) { command.ExecutionTime = DateTime.Now; command.Executed = true; } ctx.SaveChanges(); return(commands.Select(i => i.Command).ToArray()); }
public bool DeleteAlarm(int Id) { try { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Alarm Alarm = ctx.Alarm.Single(x => x.Id == Id); ctx.Alarm.Remove(Alarm); ctx.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool DeleteDevice(Guid Id) { try { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Device eDevice = ctx.Device.Where(x => x.Id == Id).FirstOrDefault(); ctx.Device.Remove(eDevice); ctx.SaveChanges(); return(true); } catch (Exception) { return(false); } }
internal DTOs.External.Users Login(DTOs.External.Users User) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Users eUsers = ctx.Users.Where(x => x.UserName == User.UserName && x.Password == User.Password).FirstOrDefault(); if (eUsers != null) { User.Id = eUsers.Id; User.UserName = eUsers.UserName; User.Password = eUsers.Password; User.Email = eUsers.Email; User.PhoneNumber = eUsers.PhoneNumber; } return(User); }
public bool SaveAlarm(AlarmList AlarmList) { try { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Alarm Alarm = new Models.EntityClass.Alarm(); Alarm = Utilities.Map <AlarmList, TeknolojiKovaniWebApi.Models.EntityClass.Alarm>(AlarmList, Alarm); ctx.Alarm.Add(Alarm); ctx.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public DeviceConfig GetDeviceConfig(Guid id) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device device = ctx.Device .Include("Alarms.Property") .Include("Profile") .Include("Profile.SensorProfiles.Sensor") .Single(i => i.Id == id); return(new DeviceConfig() { Alarms = device.Alarms.Select(i => new TeknolojiKovaniWebApi.Domain.Device.DTOs.Alarm() { Id = i.Id , Level = i.Level , Max = i.Max , Min = i.Min , PinNo = i.PinNo , Property = i.Property.Name , Side = (i.AlarmType == Models.EntityClass.AlarmType.OnDevice ? "ondevice" : "onserver") } ).ToArray() , ReadInterval = device.DataReadInterval , SendInterval = device.DataSendInterval , SensorConfig = device.Profile.SensorProfiles.Select(i => new SensorConfig() { PinNumber = i.PinNumber , SensorType = (int)i.Sensor.SensorType }).ToArray() , Commands = GetDeviceCommands(device.Id) }); }
public Guid GenerateDeviceToken(GetToken token) { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Device dev = ctx.Device.FirstOrDefault(i => i.Id.ToString() == token.DeviceGuid && i.MacNo == token.Macno); if (dev != null) { Guid currentToken = Guid.NewGuid(); dev.CurrentToken = currentToken.ToString(); ctx.SaveChanges(); return(currentToken); } else { throw new Exception("Device bilgileri hatalı"); } }
internal bool SaveUsers(DTOs.External.Users User) { try { tKovanContext ctx = new tKovanContext(); Models.EntityClass.Users eUsers = new Models.EntityClass.Users(); eUsers.Email = User.Email; eUsers.Password = User.Password; eUsers.PhoneNumber = User.PhoneNumber; eUsers.UserName = User.UserName; ctx.Users.Add(eUsers); ctx.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool UpdateAlarm(AlarmList AlarmList) { try { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Alarm Alarm = ctx.Alarm.Single(x => x.Id == AlarmList.Id); Alarm.AlarmParameter = AlarmList.AlarmParameter; Alarm.AlarmType = AlarmList.AlarmType; Alarm.DeviceId = AlarmList.DeviceId; Alarm.Level = AlarmList.Level; Alarm.Max = AlarmList.Max; Alarm.Min = AlarmList.Min; Alarm.PinNo = AlarmList.PinNo; Alarm.PropertyId = AlarmList.PropertyId; ctx.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool UpdateDevice(DTOs.DeviceRead device) { try { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Device eDevice = ctx.Device.Single(x => x.Id == device.Id); eDevice.DataSendInterval = device.DataSendInterval; eDevice.EnvironmentId = device.EnvironmentId; eDevice.MacNo = device.MacNo; eDevice.Name = device.Name; eDevice.ProfileId = device.ProfileId; //eDevice.UserId = device.UserId; //eDevice.UserId = device.UserId; //ctx.Device.Add(eDevice); ctx.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool SaveDevice(DTOs.DeviceRead device) { try { tKovanContext ctx = new tKovanContext(); TeknolojiKovaniWebApi.Models.EntityClass.Device eDevice = new Models.EntityClass.Device(); //eDevice.CurrentToken = device.CurrentToken; eDevice.Id = Guid.NewGuid(); eDevice.DataSendInterval = device.DataSendInterval; eDevice.EnvironmentId = device.EnvironmentId; eDevice.MacNo = device.MacNo; eDevice.Name = device.Name; eDevice.ProfileId = device.ProfileId; eDevice.UserId = device.UserId; //eDevice.UserId = device.UserId; ctx.Device.Add(eDevice); ctx.SaveChanges(); return(true); } catch (Exception) { return(false); } }