/// <summary>
        /// Add a new camera device to the HomeSeer configuration.
        /// </summary>
        /// <param name="name">The name for the HomeSeer device.</param>
        /// <param name="ipAddress">The IP address for the camera.</param>
        /// <param name="username">The username to use for the camera.</param>
        /// <param name="password">The password to use for the camera.</param>
        private void AddCameraButton(string name, string ipAddress, string username, string password)
        {
            if ((name == "") || (ipAddress == "") || (username == "") || (password == ""))
            {
                return;
            }

            int refId = plugin.CreateDeviceFromConfig(name, ipAddress, username, password);

            NameValueCollection cameraList = HikAlarmThreadManager.CameraNameList();

            UpdateDropList("ListBoxCameras", ref cameraList, SelectedValue: refId.ToString());
            ChangeCameraSelection(refId.ToString());
        }
Example #2
0
        /// <summary>
        /// Called when HomeSeer is not longer using the plugin.
        /// This call will be made if a user disables a plugin from the interfaces configuration page and when HomeSeer is shut down.
        /// </summary>
        public override void ShutdownIO()
        {
            // debug
            hs.WriteLog(IFACE_NAME, "Entering ShutdownIO");

            // shut everything down here
            HikAlarmThreadManager.Shutdown();

            // perform any base class shutdown
            base.ShutdownIO();

            // debug
            hs.WriteLog(IFACE_NAME, "Completed ShutdownIO");
        }
Example #3
0
        /// <summary>
        /// If a device is owned by your plug-in (interface property set to the name of the plug-in) and the device's status_support property is set to True,
        /// then this procedure will be called in your plug-in when the device's status is being polled, such as when the user clicks "Poll Devices" on the device status page.
        /// Normally your plugin will automatically keep the status of its devices updated.
        /// There may be situations where automatically updating devices is not possible or CPU intensive.
        /// In these cases the plug-in may not keep the devices updated. HomeSeer may then call this function to force an update of a specific device.
        /// This request is normally done when a user displays the status page, or a script runs and needs to be sure it has the latest status.
        /// </summary>
        /// <param name="dvref">Reference Id for the device</param>
        /// <returns>IPlugInAPI.PollResultInfo</returns>
        public override IPlugInAPI.PollResultInfo PollDevice(int dvref)
        {
            double status = -1;

            IPlugInAPI.PollResultInfo pollResult = new IPlugInAPI.PollResultInfo();

            if (HikAlarmThreadManager.GetDeviceStatus(dvref, out status))
            {
                pollResult.Result = IPlugInAPI.enumPollResult.OK;
                pollResult.Value  = status;
            }
            else
            {
                pollResult.Result = IPlugInAPI.enumPollResult.Device_Not_Found;
                pollResult.Value  = 0;
            }

            return(pollResult);
        }
Example #4
0
        /// <summary>
        /// Initialize the plugin and associated hardware/software, start any threads
        /// </summary>
        /// <param name="port">The COM port for the plugin if required.</param>
        /// <returns>Warning message or empty for success.</returns>
        public override string InitIO(string port)
        {
            // initialize everything here, return a blank string only if successful, or an error message
            try
            {
                Scheduler.Classes.clsDeviceEnumeration EN = (Scheduler.Classes.clsDeviceEnumeration)hs.GetDeviceEnumerator();
                if (EN == null)
                {
                    throw new Exception(IFACE_NAME + " failed to get a device enumerator from HomeSeer.");
                }
                do
                {
                    Scheduler.Classes.DeviceClass dv = EN.GetNext();
                    if ((dv != null) &&
                        (dv.get_Interface(hs) != null) &&
                        (dv.get_Interface(hs).Trim() == IFACE_NAME))
                    {
                        //Console.WriteLine("Found device: refId = {0}", dv.get_Ref(hs));
                        int    refId     = dv.get_Ref(hs);
                        string ipAddress = hs.GetINISetting("Camera" + refId, "IpAddress", "", INI_File);
                        string username  = hs.GetINISetting("Camera" + refId, "Username", "", INI_File);
                        string password  = hs.GetINISetting("Camera" + refId, "Password", "", INI_File);
                        Console.WriteLine("Camera: RefId: {0}, IpAddress: {1}, Username: {2}, Password: {3}", refId, ipAddress, username, password);

                        HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password);
                    }
                } while (!EN.Finished);
            }
            catch (Exception ex)
            {
                hs.WriteLog(IFACE_NAME + " Error", "Exception in Find_Create_Devices/Enumerator: " + ex.Message);
            }

            // Create and register the web pages - only need one for configuration
            configPage = new HikAlarmConfig(this);
            RegisterWebPage(configPage.Name);

            return("");
        }
        /// <summary>
        /// Builds the web page body for the configuration page.
        /// The page has separate forms so that only the data in the appropriate form is returned when a button is pressed.
        /// </summary>
        private string BuildWebPageBody()
        {
            StringBuilder       stb        = new StringBuilder();
            NameValueCollection cameraList = HikAlarmThreadManager.CameraNameList();
            bool   allowEdit     = (cameraList.Count > 0);
            string editIpAddress = "";
            string editUsername  = "";
            string editPassword  = "";

            if (allowEdit)
            {
                plugin.GetDeviceParameters(cameraList.Get(0), ref editIpAddress, ref editUsername, ref editPassword);
                editPassword = "******";
            }

            try
            {
                stb.Append("<table width='1000' cellpadding='0' cellspacing='0' border='0'>");

                // Help button
                stb.Append(" <tr>");
                stb.Append("  <td></td>");
                stb.Append("  <td align='right'>");
                //stb.Append("   <a href='HikAlaramCheck%20Help%20File\\HikAlarmCheck-Help.htm'>Help Page</a>");
                stb.Append("  </td>");
                stb.Append(" </tr>");

                // Add new item section
                stb.Append(" <tr>");
                stb.Append("  <td colspan='2'>");
                stb.Append(PageBuilderAndMenu.clsPageBuilder.FormStart("frmAddCamera", "AddCamera", "Post"));
                stb.Append("   <table width='1000' cellpadding='0' cellspacing='0' style='border-right: black thin solid; border-top: black thin solid; border-left: black thin solid; border-bottom: black thin solid;'>");
                stb.Append("    <tr><td style='background-color: #Cdcdcd; text-align: center;'><br /></td></tr>");
                stb.Append("    <tr>");
                stb.Append("     <td align='center' style='background-color: #f5f5f5;'>");
                stb.Append("      <table width='100%'>");
                stb.Append("       <col width='100'><col width='100'>");
                stb.Append("       <tr><td><strong>Add New Camera:</strong></td></tr>");
                stb.Append("       <tr><td>Name:</td><td>" + BuildTextBox("TextBoxName") + "</td></tr>");
                stb.Append("       <tr><td>Ip Address:</td><td>" + BuildTextBox("TextBoxIpAddress") + "</td></tr>");
                stb.Append("       <tr><td>Username:</td><td>" + BuildTextBox("TextBoxUsername") + "</td></tr>");
                stb.Append("       <tr><td>Password:</td><td>" + BuildTextBox("TextBoxPassword") + "</td></tr>");
                stb.Append("       <tr><td></td><td>" + BuildButton("Add Camera", "ButAddCamera") + "</td></tr>");
                stb.Append("      </table>");
                stb.Append("     </td>");
                stb.Append("    </tr>");
                stb.Append("   </table>");
                stb.Append(PageBuilderAndMenu.clsPageBuilder.FormEnd());
                stb.Append("  </td>");
                stb.Append(" </tr>");

                // Select item to edit
                stb.Append(" <tr>");
                stb.Append("  <td colspan='2'>");
                stb.Append(PageBuilderAndMenu.clsPageBuilder.FormStart("frmEditCamera", "EditCamera", "Post"));
                stb.Append("   <table width='1000' cellpadding='0' cellspacing='0' style='border-right: black thin solid; border-top: none; border-left: black thin solid; border-bottom: black thin solid;'>");
                stb.Append("    <tr><td style='background-color: #Cdcdcd; text-align: center;'><br /></td></tr>");
                stb.Append("    <tr>");
                stb.Append("     <td align='center' style='background-color: #f5f5f5;'>");
                stb.Append("      <table width='100%'>");
                stb.Append("       <col width='100'><col width='100'>");
                stb.Append("       <tr><td><strong>Edit Camera:</strong></td><td>" + BuildDropList("ListBoxCameras", ref cameraList) + "</td></tr>");
                stb.Append("       <tr><td>Ip Address:</td><td>" + BuildTextBox("TextBoxIpAddressEdit", editIpAddress, allowEdit) + "</td></tr>");
                stb.Append("       <tr><td>Username:</td><td>" + BuildTextBox("TextBoxUsernameEdit", editUsername, allowEdit) + "</td></tr>");
                stb.Append("       <tr><td>Password:</td><td>" + BuildTextBox("TextBoxPasswordEdit", editPassword, allowEdit) + "</td></tr>");
                stb.Append("       <tr><td></td>");
                stb.Append("        <td align='left'>");
                stb.Append("         <table width='20%'>");
                stb.Append("          <col width='30'><col width='30'>");
                stb.Append("          <tr><td>" + BuildButton("Save", "ButSaveCamera", allowEdit) + "</td><td>" + BuildButton("Delete", "ButDeleteCamera", allowEdit) + "</td></tr>");
                stb.Append("         </table>");
                stb.Append("        </td>");
                stb.Append("      </table>");
                stb.Append("     </td>");
                stb.Append("    </tr>");
                stb.Append("   </table>");
                stb.Append(PageBuilderAndMenu.clsPageBuilder.FormEnd());
                stb.Append("  </td>");
                stb.Append(" </tr>");

                // End of table
                stb.Append("</table>");

                return(stb.ToString());
            }
            catch (Exception)
            {
            }
            return(null);
        }