예제 #1
0
 public List <Network> GetAll()
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Networks.ToList());
     }
 }
 public List<User> GetAll(UserFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Users.Filter(filter).ToList();
     }
 }
 public List<OAuthClient> GetAll(OAuthClientFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.OAuthClients.Filter(filter).ToList();
     }
 }
 public List <DeviceClass> GetAll()
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceClasses.ToList());
     }
 }
예제 #5
0
 public List <Network> GetAll(NetworkFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Networks.Filter(filter).ToList());
     }
 }
        public void Save(AccessKey accessKey)
        {
            if (accessKey == null)
                throw new ArgumentNullException("accessKey");

            using (var context = new DeviceHiveContext())
            {
                context.AccessKeys.Add(accessKey);
                if (accessKey.ID > 0)
                {
                    context.Entry(accessKey).State = EntityState.Modified;
                    
                    foreach (var permission in accessKey.Permissions.Where(e => e.ID > 0))
                    {
                        context.Entry(permission).State = EntityState.Modified;
                    }
                    foreach (var permission in context.AccessKeyPermissions.Where(e => e.AccessKeyID == accessKey.ID))
                    {
                        if (context.Entry(permission).State == EntityState.Unchanged)
                            context.AccessKeyPermissions.Remove(permission);
                    }
                }
                
                context.SaveChanges();
            }
        }
예제 #7
0
 public List<Network> GetAll()
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Networks.ToList();
     }
 }
예제 #8
0
 public Network Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Networks.Find(id);
     }
 }
예제 #9
0
 public Network Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Networks.Find(id));
     }
 }
예제 #10
0
 public DateTime GetCurrentTimestamp()
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Database.SqlQuery <DateTime>("select sysutcdatetime()").First());
     }
 }
예제 #11
0
 public User Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Users.Find(id));
     }
 }
예제 #12
0
 public DeviceNotification Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceNotifications.Find(id));
     }
 }
예제 #13
0
 public OAuthClient Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.OAuthClients.Find(id));
     }
 }
        public void Save(AccessKey accessKey)
        {
            if (accessKey == null)
            {
                throw new ArgumentNullException("accessKey");
            }

            using (var context = new DeviceHiveContext())
            {
                context.AccessKeys.Add(accessKey);
                if (accessKey.ID > 0)
                {
                    context.Entry(accessKey).State = EntityState.Modified;

                    foreach (var permission in accessKey.Permissions.Where(e => e.ID > 0))
                    {
                        context.Entry(permission).State = EntityState.Modified;
                    }
                    foreach (var permission in context.AccessKeyPermissions.Where(e => e.AccessKeyID == accessKey.ID))
                    {
                        if (context.Entry(permission).State == EntityState.Unchanged)
                        {
                            context.AccessKeyPermissions.Remove(permission);
                        }
                    }
                }

                context.SaveChanges();
            }
        }
 public OAuthClient Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.OAuthClients.Find(id);
     }
 }
예제 #16
0
 public DeviceEquipment Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceEquipments.Find(id));
     }
 }
        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
                throw new ArgumentNullException("deviceClass");

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;

                    foreach (var equipment in deviceClass.Equipment.Where(e => e.ID > 0))
                    {
                        context.Entry(equipment).State = EntityState.Modified;
                    }
                    foreach (var equipment in context.Equipments.Where(e => e.DeviceClassID == deviceClass.ID))
                    {
                        if (context.Entry(equipment).State == EntityState.Unchanged)
                            context.Equipments.Remove(equipment);
                    }
                }
                
                context.SaveChanges();
            }
        }
예제 #18
0
 public DeviceEquipment GetByDeviceAndCode(int deviceId, string code)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceEquipments.FirstOrDefault(e => e.Device.ID == deviceId && e.Code == code));
     }
 }
예제 #19
0
 public List<User> GetAll()
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Users.ToList();
     }
 }
예제 #20
0
 public List<DeviceEquipment> GetByDevice(int deviceId)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.DeviceEquipments.Where(e => e.Device.ID == deviceId).ToList();
     }
 }
예제 #21
0
 public List <User> GetAll()
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Users.ToList());
     }
 }
예제 #22
0
 public List <OAuthClient> GetAll(OAuthClientFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.OAuthClients.Filter(filter).ToList());
     }
 }
예제 #23
0
 public List <User> GetAll(UserFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Users.Filter(filter).ToList());
     }
 }
예제 #24
0
 public List<DeviceClass> GetAll()
 {
     using (var context = new DeviceHiveContext())
     {
         return context.DeviceClasses.ToList();
     }
 }
예제 #25
0
 public User Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Users.Find(id);
     }
 }
예제 #26
0
 public DeviceEquipment Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.DeviceEquipments.Find(id);
     }
 }
예제 #27
0
        public void Save(Device device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (string.IsNullOrEmpty(device.GUID))
            {
                throw new ArgumentException("Device.GUID must have a valid value!", "device.GUID");
            }

            using (var context = new DeviceHiveContext())
            {
                if (device.Network != null)
                {
                    context.Networks.Attach(device.Network);
                }
                context.DeviceClasses.Attach(device.DeviceClass);
                context.Devices.Add(device);
                if (device.ID > 0)
                {
                    context.Entry(device).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
 public DeviceNotification Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.DeviceNotifications.Find(id);
     }
 }
 public DateTime GetCurrentTimestamp()
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Database.SqlQuery<DateTime>("select sysutcdatetime()").First();
     }
 }
        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
            {
                throw new ArgumentNullException("deviceClass");
            }

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;

                    foreach (var equipment in deviceClass.Equipment.Where(e => e.ID > 0))
                    {
                        context.Entry(equipment).State = EntityState.Modified;
                    }
                    foreach (var equipment in context.Equipments.Where(e => e.DeviceClassID == deviceClass.ID))
                    {
                        if (context.Entry(equipment).State == EntityState.Unchanged)
                        {
                            context.Equipments.Remove(equipment);
                        }
                    }
                }

                context.SaveChanges();
            }
        }
 public List<Network> GetAll(NetworkFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Networks.Filter(filter).ToList();
     }
 }
예제 #32
0
 public DeviceClass Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceClasses.Find(id));
     }
 }
예제 #33
0
 public DeviceClass Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.DeviceClasses.Find(id);
     }
 }
예제 #34
0
 public List <DeviceEquipment> GetByDevice(int deviceId)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceEquipments.Where(e => e.Device.ID == deviceId).ToList());
     }
 }
예제 #35
0
 public DeviceEquipment GetByDeviceAndCode(int deviceId, string code)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.DeviceEquipments.FirstOrDefault(e => e.Device.ID == deviceId && e.Code == code);
     }
 }
 public void Cleanup(DateTime timestamp)
 {
     using (var context = new DeviceHiveContext())
     {
         context.Database.ExecuteSqlCommand("delete from [AccessKey] where [Type] = @Type and [ExpirationDate] < @Timestamp",
                                            new SqlParameter("Type", (int)AccessKeyType.Session), new SqlParameter("Timestamp", timestamp));
     }
 }
 public void Cleanup(DateTime timestamp)
 {
     using (var context = new DeviceHiveContext())
     {
         context.Database.CommandTimeout = 300;
         context.Database.ExecuteSqlCommand("delete from [DeviceNotification] where [Timestamp] < @Timestamp", new SqlParameter("Timestamp", timestamp));
     }
 }
예제 #38
0
 public List <DeviceNotification> GetByDevice(int deviceId, DeviceNotificationFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         var query = context.DeviceNotifications.Where(e => e.Device.ID == deviceId);
         return(query.Filter(filter, FilterByGridInterval(filter == null ? null : filter.GridInterval)).ToList());
     }
 }
예제 #39
0
 public List <DeviceCommand> GetByDevice(int deviceId, DeviceCommandFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         var query = context.DeviceCommands.Where(e => e.Device.ID == deviceId);
         return(query.Filter(filter).ToList());
     }
 }
예제 #40
0
 public void Cleanup(DateTime timestamp)
 {
     using (var context = new DeviceHiveContext())
     {
         context.Database.CommandTimeout = 300;
         context.Database.ExecuteSqlCommand("delete from [DeviceNotification] where [Timestamp] < @Timestamp", new SqlParameter("Timestamp", timestamp));
     }
 }
 public List<DeviceNotification> GetByDevice(int deviceId, DeviceNotificationFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         var query = context.DeviceNotifications.Where(e => e.Device.ID == deviceId);
         return query.Filter(filter, FilterByGridInterval(filter == null ? null : filter.GridInterval)).ToList();
     }
 }
예제 #42
0
 public List <Network> GetByUser(int userId)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Networks.Where(n => context.UserNetworks
                                       .Where(un => un.UserID == userId).Select(un => un.NetworkID).Contains(n.ID)).ToList());
     }
 }
 public List<DeviceCommand> GetByDevice(int deviceId, DeviceCommandFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         var query = context.DeviceCommands.Where(e => e.Device.ID == deviceId);
         return query.Filter(filter).ToList();
     }
 }
예제 #44
0
 public List<Network> GetByUser(int userId)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Networks.Where(n => context.UserNetworks
             .Where(un => un.UserID == userId).Select(un => un.NetworkID).Contains(n.ID)).ToList();
     }
 }
 public AccessKey Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.AccessKeys
             .Include(e => e.Permissions)
             .FirstOrDefault(e => e.ID == id);
     }
 }
 public List <AccessKey> GetByUsers(int[] userIds, AccessKeyFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.AccessKeys
                .Include(e => e.Permissions)
                .Where(e => userIds.Contains(e.UserID)).Filter(filter).ToList());
     }
 }
 public List<DeviceClass> GetAll(DeviceClassFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.DeviceClasses
             .Include(e => e.Equipment)
             .Filter(filter).ToList();
     }
 }
예제 #48
0
 public void SetLastOnline(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         context.Database.ExecuteSqlCommand(
             "update [Device] set [LastOnline] = sysutcdatetime() where [ID] = @ID",
             new SqlParameter("ID", id));
     }
 }
 public List <DeviceClass> GetAll(DeviceClassFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceClasses
                .Include(e => e.Equipment)
                .Filter(filter).ToList());
     }
 }
 public DeviceClass Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.DeviceClasses
                .Include(e => e.Equipment)
                .FirstOrDefault(e => e.ID == id));
     }
 }
예제 #51
0
 public Equipment Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Equipments
             .Include(e => e.DeviceClass)
             .FirstOrDefault(e => e.ID == id);
     }
 }
예제 #52
0
 public List<Equipment> GetByDeviceClass(int deviceClassId)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Equipments
             .Include(e => e.DeviceClass)
             .Where(e => e.DeviceClass.ID == deviceClassId).ToList();
     }
 }
예제 #53
0
 public List <Equipment> GetByDeviceClass(int deviceClassId)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.Equipments
                .Include(e => e.DeviceClass)
                .Where(e => e.DeviceClass.ID == deviceClassId).ToList());
     }
 }
 public List<AccessKey> GetByUsers(int[] userIds, AccessKeyFilter filter = null)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.AccessKeys
             .Include(e => e.Permissions)
             .Where(e => userIds.Contains(e.UserID)).Filter(filter).ToList();
     }
 }
 public AccessKey Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.AccessKeys
                .Include(e => e.Permissions)
                .FirstOrDefault(e => e.ID == id));
     }
 }
 public Device Get(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.Devices
             .Include(e => e.Network)
             .Include(e => e.DeviceClass.Equipment)
             .FirstOrDefault(e => e.ID == id);
     }
 }
        public OAuthClient Get(string oauthId)
        {
            if (string.IsNullOrEmpty(oauthId))
                throw new ArgumentNullException("oauthId");

            using (var context = new DeviceHiveContext())
            {
                return context.OAuthClients.SingleOrDefault(u => u.OAuthID == oauthId);
            }
        }
 public UserNetwork Get(int userId, int networkId)
 {
     using (var context = new DeviceHiveContext())
     {
         return context.UserNetworks
             .Include(un => un.User)
             .Include(un => un.Network)
             .FirstOrDefault(un => un.UserID == userId && un.NetworkID == networkId);
     }
 }
예제 #59
0
        public Network Get(string name)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            using (var context = new DeviceHiveContext())
            {
                return context.Networks.SingleOrDefault(u => u.Name == name);
            }
        }
예제 #60
0
 public UserNetwork Get(int userId, int networkId)
 {
     using (var context = new DeviceHiveContext())
     {
         return(context.UserNetworks
                .Include(un => un.User)
                .Include(un => un.Network)
                .FirstOrDefault(un => un.UserID == userId && un.NetworkID == networkId));
     }
 }