コード例 #1
0
ファイル: DeviceDomain.cs プロジェクト: asc793/teknolojiKovan
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: DeviceDomain.cs プロジェクト: asc793/teknolojiKovan
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: DeviceDomain.cs プロジェクト: asc793/teknolojiKovan
        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)
            });
        }
コード例 #6
0
ファイル: DeviceDomain.cs プロジェクト: asc793/teknolojiKovan
 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);
     }
 }