public IEnumerable <WeMoDeviceState> GetAll() { using (var context = new WeMoContext()) { return(context.WeMoStates .ToList()); } }
public IEnumerable <WeMoDevice> GetAll() { using (var context = new WeMoContext()) { var device = context.WeMoDevices .ToList(); return(device); } }
public WeMoDevice Get(string deviceId) { using (var context = new WeMoContext()) { var device = context.WeMoDevices .FirstOrDefault(x => x.DeviceId == deviceId); return(device); } }
public bool Any() { using (var context = new WeMoContext()) { var any = context.WeMoDevices .Any(); return(any); } }
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); } }
public IEnumerable <WeMoDeviceState> GetByDeviceId(string deviceId) { using (var context = new WeMoContext()) { return(context.WeMoStates .Where(x => x.Device.DeviceId == deviceId) .ToList()); } }
public void Remove(string deviceId) { using (var context = new WeMoContext()) { var device = context.WeMoDevices .First(x => x.DeviceId == deviceId); context.Remove(device); context.SaveChanges(); } }
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(); } }
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(); } }
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); } }
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(); } }
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); } }