コード例 #1
0
ファイル: StateProvider.cs プロジェクト: Silvenga/Slight.WeMo
 public IEnumerable<WeMoDeviceState> GetAll()
 {
     using (var context = new WeMoContext())
     {
         return context.WeMoStates
             .ToList();
     }
 }
コード例 #2
0
ファイル: StateProvider.cs プロジェクト: Silvenga/Slight.WeMo
 public IEnumerable<WeMoDeviceState> GetByDeviceId(string deviceId)
 {
     using (var context = new WeMoContext())
     {
         return context.WeMoStates
             .Where(x => x.Device.DeviceId == deviceId)
             .ToList();
     }
 }
コード例 #3
0
 public void Remove(string deviceId)
 {
     using (var context = new WeMoContext())
     {
         var device = context.WeMoDevices
             .First(x => x.DeviceId == deviceId);
         context.Remove(device);
         context.SaveChanges();
     }
 }
コード例 #4
0
        public void DisableOldDevices()
        {
            using (var context = new WeMoContext())
            {
                var oldCutoff = DateTime.Now.AddMinutes(5);
                var removedDevices = context.WeMoDevices
                    .Where(x => x.LastDetected > oldCutoff);

                foreach (var device in removedDevices)
                {
                    device.Disabled = true;
                }

                context.WeMoDevices
                    .UpdateRange(removedDevices);
                context.SaveChanges();
            }

        }
コード例 #5
0
ファイル: StateProvider.cs プロジェクト: Silvenga/Slight.WeMo
        public void RecordDeviceState(string deviceId)
        {
            using (var context = new WeMoContext())
            {
                var device = context.WeMoDevices.First(x => x.DeviceId == deviceId);

                var client = new WeMoClient(device);
                var binaryState = client.GetBinaryState();

                var state = new WeMoDeviceState
                {
                    Device = device,
                    CurrentState = binaryState,
                    Timestamp = DateTime.Now
                };

                context.WeMoStates.Add(state);
                context.SaveChanges();
            }
        }
コード例 #6
0
        public WeMoDevice Update(string deviceId, string location)
        {
            using (var context = new WeMoContext())
            {
                var url = new Uri(location);
                var device = context.WeMoDevices
                    .First(x => x.DeviceId == deviceId);

                device.Host = url.Host;
                device.Port = url.Port;
                device.Location = location;
                device.Disabled = false;

                var client = new WeMoClient(device);
                client.EnumerateDeviceInfo();

                context.SaveChanges();

                return device;
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Silvenga/Slight.WeMo
        private static void Main()
        {
            Console.WriteLine("Running database migrations...");
            using (var db = new WeMoContext())
            {
                db.Database.Migrate();
            }

            var host = Debugger.IsAttached ? "localhost" : "+";
            var baseAddress = $"http://{host}:9000/";

            Console.WriteLine("Starting host...");
            using (WebApp.Start<Startup>(baseAddress))
            {
                Console.WriteLine("Starting background tasks...");
                StartBackgroundTasks();

                Console.WriteLine("Ready.");
                Console.ReadLine();
            }
        }
コード例 #8
0
        public WeMoDevice Create(string location)
        {
            using (var context = new WeMoContext())
            {
                var url = new Uri(location);
                var device = new WeMoDevice
                {
                    Host = url.Host,
                    Port = url.Port,
                    Location = location
                };

                var client = new WeMoClient(device);
                client.EnumerateDeviceInfo();

                context.WeMoDevices
                    .Add(device);
                context.SaveChanges();

                return device;
            }
        }
コード例 #9
0
 public WeMoDevice Get(string deviceId)
 {
     using (var context = new WeMoContext())
     {
         var device = context.WeMoDevices
             .FirstOrDefault(x => x.DeviceId == deviceId);
         return device;
     }
 }
コード例 #10
0
 public bool Any()
 {
     using (var context = new WeMoContext())
     {
         var any = context.WeMoDevices
             .Any();
         return any;
     }
 }
コード例 #11
0
 public bool Exists([CanBeNull] string deviceId)
 {
     using (var context = new WeMoContext())
     {
         var exists = !string.IsNullOrEmpty(deviceId)
                      && context.WeMoDevices.Any(x => x.DeviceId == deviceId);
         return exists;
     }
 }
コード例 #12
0
 public IEnumerable<WeMoDevice> GetAll()
 {
     using (var context = new WeMoContext())
     {
         var device = context.WeMoDevices
             .ToList();
         return device;
     }
 }