public List <Device> GetDisconnectedDevices(string offlineStatus) { var devices = _mongo.Devices.AsQueryable() .Where(d => d.Status != offlineStatus) .Where(d => d.DeviceClass.OfflineTimeout != null) .Select(d => new { ID = d.ID, LastOnline = d.LastOnline, OfflineTimeout = d.DeviceClass.OfflineTimeout }).ToList(); var deviceIds = new List <int>(); var timestamp = _mongo.GetCurrentTimestamp(); foreach (var device in devices) { if (device.LastOnline == null || device.LastOnline < timestamp.AddSeconds(-device.OfflineTimeout.Value)) { deviceIds.Add(device.ID); } } return(_mongo.Devices.Find(Query <Device> .In(e => e.ID, deviceIds)).ToList()); }
public DateTime GetCurrentTimestamp() { return(_mongo.GetCurrentTimestamp()); }