Example #1
0
        /// <summary>
        /// Delete the device in HomeSeer.  Clear the set INI settings.  Delete the thread.
        /// </summary>
        /// <param name="refIdStr">The device reference identifier (as string) for HomeSeer.</param>
        /// <returns><c>true</c> if device was found and deleted, <c>false</c> otherwise.</returns>
        public bool DeleteDevice(string refIdStr)
        {
            int  refId;
            bool success = true;

            // delete the device from HomeSeer
            if (!Int32.TryParse(refIdStr, out refId))
            {
                success = false;
            }
            else
            {
                Scheduler.Classes.DeviceClass hsDevice = (Scheduler.Classes.DeviceClass)hs.GetDeviceByRef(refId);
                if ((hsDevice == null) || (!hs.DeleteDevice(refId)))
                {
                    success = false;
                }
            }

            // delete the info from the INI file
            hs.ClearINISection("Camera" + refIdStr, INI_File);

            // delete the thread
            HikAlarmThreadManager.DeleteDevice(refId);

            return(success);
        }
Example #2
0
        /// <summary>
        /// Updates the device parameters in the INI file.  It is necessary to restart the thread for the new values to take effect.
        /// </summary>
        /// <param name="refIdStr">The device reference identifier (as string) for HomeSeer.</param>
        /// <param name="ipAddress">The ip address.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns><c>true</c> if the update was successful, <c>false</c> otherwise.</returns>
        public bool UpdateDevice(string refIdStr, string ipAddress, string username, string password)
        {
            int refId;

            if (!Int32.TryParse(refIdStr, out refId))
            {
                return(false);
            }

            Scheduler.Classes.DeviceClass hsDevice = (Scheduler.Classes.DeviceClass)hs.GetDeviceByRef(refId);
            if (hsDevice == null)
            {
                return(false);
            }

            // save the settings
            hs.SaveINISetting("Camera" + refIdStr, "IpAddress", ipAddress, INI_File);
            hs.SaveINISetting("Camera" + refIdStr, "Username", username, INI_File);
            if (password != "")
            {
                hs.SaveINISetting("Camera" + refIdStr, "Password", password, INI_File);
            }

            HikAlarmThreadManager.DeleteDevice(refId);
            HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password);

            return(true);
        }