Example #1
0
 public IEnumerable <WeMoDeviceState> GetAll()
 {
     using (var context = new WeMoContext())
     {
         return(context.WeMoStates
                .ToList());
     }
 }
Example #2
0
 public IEnumerable <WeMoDevice> GetAll()
 {
     using (var context = new WeMoContext())
     {
         var device = context.WeMoDevices
                      .ToList();
         return(device);
     }
 }
Example #3
0
 public WeMoDevice Get(string deviceId)
 {
     using (var context = new WeMoContext())
     {
         var device = context.WeMoDevices
                      .FirstOrDefault(x => x.DeviceId == deviceId);
         return(device);
     }
 }
Example #4
0
 public bool Any()
 {
     using (var context = new WeMoContext())
     {
         var any = context.WeMoDevices
                   .Any();
         return(any);
     }
 }
Example #5
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);
     }
 }
Example #6
0
 public IEnumerable <WeMoDeviceState> GetByDeviceId(string deviceId)
 {
     using (var context = new WeMoContext())
     {
         return(context.WeMoStates
                .Where(x => x.Device.DeviceId == deviceId)
                .ToList());
     }
 }
Example #7
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();
     }
 }
Example #8
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();
            }
        }
Example #9
0
        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();
            }
        }
Example #10
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);
            }
        }
Example #11
0
        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();
            }
        }
Example #12
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);
            }
        }