/// <summary> /// Called by InControl when a new device should be tracked locally. /// </summary> /// <param name="haDevice"></param> /// <returns></returns> public HaDevice trackDevice(HaDeviceDto haDevice) { // InControl will call this every time it starts up. It'll call it for each device it currently knows about. // We should use the data passed in to create an HaDevice and track it in our localDevices list. // Then return that new HaDevice back to InControl. var newDevice = new HaDevice(); // Grab some of the other values and set them in our local device newDevice.providerDeviceId = haDevice.uniqueName; newDevice.deviceId = haDevice.deviceId; newDevice.name = haDevice.deviceName; // Our devices always start at level unless there's a value set in the database saving its state newDevice.level = 0; // See if the device has a value saved in the database for it's initial level try { var savedStateRaw = base.getDeviceMetadata(newDevice.deviceId, PRIOR_STATE); if (savedStateRaw != null) { double savedValue = 0; if (double.TryParse(savedStateRaw, out savedValue)) { newDevice.level = savedValue; } } } catch { } // Add the device to our local list localDevices.Add(newDevice); return newDevice; }
/// <summary> /// Called when the server pulls a saved device from the db. /// </summary> /// <param name="dbDevice"></param> /// <returns></returns> public HaDevice trackDevice(HaDeviceDto dbDevice) { var haDev = new CameraDevice() { deviceId = dbDevice.deviceId, providerDeviceId = dbDevice.uniqueName, deviceName = dbDevice.deviceName }; try { // See if there is meta data available for snapshot/mjpg url's var snapShotUrl = getDeviceMetadata(haDev.deviceId, META_SNAPSHOT_URL); var mjpegUrl = getDeviceMetadata(haDev.deviceId, META_MJPEG_URL); if (!string.IsNullOrEmpty(snapShotUrl)) { haDev.liveStreamUrl = mjpegUrl; haDev.snapShotUrl = snapShotUrl; Thread t = new Thread(() => { setupMetaPropertiesForOtherCam(haDev, snapShotUrl, mjpegUrl); }); t.IsBackground = true; t.Start(); } else { // Foscam only // Get the ip, username and password from the devicename try { var split = dbDevice.uniqueName.Split('|'); haDev.ip = split[0].Replace("http://", ""); haDev.userName = split[1]; haDev.password = split[2]; } catch { } haDev.liveStreamUrl = string.Format("http://{0}{1}", haDev.ip, replaceStringValues(LIVESTREAM_URL, haDev)); Thread t = new Thread(() => { setupMetaProperties(haDev); }); t.IsBackground = true; t.Start(); } } catch { } localDevices.Add(haDev); return haDev; }
/// <summary> /// /// </summary> /// <param name="haDevice"></param> /// <returns></returns> public HaDevice trackDevice(HaDeviceDto haDevice) { // Nofies the controller of a new device to be tracked. Adds the new device to the local list. var newDevice = new HaDevice(); // Our devices always start at level 0. newDevice.level = 0; // Grab some of the other values and set them in our local device newDevice.providerDeviceId = haDevice.uniqueName; newDevice.deviceId = haDevice.deviceId; newDevice.name = haDevice.deviceName; // Add the device to our local list localDevices.Add(newDevice); return newDevice; }