示例#1
0
        /// <summary>
        /// Save the settings
        /// </summary>
        /// <param name="values"></param>
        internal static void save(string values, string newLicense = "")
        {
            try
            {
                settingsContent = settingsContent.Replace("&", "&amp;");
                XmlDocument xmlDoc = new XmlDocument();
                //Load the XML string into the xmlDoc variable
                xmlDoc.LoadXml(settingsContent);

                string aoiSetting   = "";
                string emailSetting = "";
                string licenseInfo  = "";
                string autoRestart  = "";
                string camInfo      = "";

                //Make sure that we have something to save for the default AOI settings
                var aoi = xmlDoc.GetElementsByTagName("defaultVideoStreamControlSettings");
                if (aoi.Count > 0)
                {
                    aoiSetting = aoi[0].OuterXml;
                }
                else
                {
                    aoiSetting = defaultAOI.toXML();
                }

                //Make sure that we have something to save for the default email settings
                var tempEmail = xmlDoc.GetElementsByTagName("emailConfiguration");
                if (tempEmail.Count > 0)
                {
                    emailSetting = tempEmail[0].OuterXml;
                }
                else
                {
                    emailSetting = email.toXML();
                }

                //Only care if this it is not returned with the email settings
                if (!emailSetting.Contains("<automaticCameraRestart>"))
                {
                    //Make sure that we have something to save for the default email settings
                    var tempAuto = xmlDoc.GetElementsByTagName("automaticCameraRestart");
                    if (tempEmail.Count > 0)
                    {
                        autoRestart += tempAuto[0].OuterXml;
                    }
                    else
                    {
                        autoRestart += "<automaticCameraRestart><stream_timeout>5</stream_timeout><camera_restart_interval>5</camera_restart_interval><camera_restart_attempts>10</camera_restart_attempts></automaticCameraRestart>";
                    }
                }
                else
                {
                    autoRestart = "";
                }

                //Make sure that we have something to save for the license info
                var LI = xmlDoc.GetElementsByTagName("licenseInformation");
                if (LI.Count > 0)
                {
                    licenseInfo = LI[0].OuterXml;
                }
                else
                {
                    licenseInfo = "<licenseInformation><dateIssued>YYYYMMDDHHMMSS</dateIssued><daysLeft>text</daysLeft><dateExpires>YYYYMMDDHHMMSS</dateExpires></licenseInformation>";
                }

                //Make sure that we have something to save for the camerainfo
                var CI = xmlDoc.GetElementsByTagName("cameraConfiguration");
                if (CI.Count > 0)
                {
                    camInfo = CI[0].OuterXml;
                }
                else
                {
                    CameraValues CV = new CameraValues();
                    camInfo = "<cameraConfiguration>";
                    camInfo = CV.toXML();
                    camInfo = "</cameraConfiguration>";
                }

                string newFile = "";
                switch (values)
                {
                case "EMAIL":
                    newFile += email.toXML();     //New value
                    newFile += autoRestart;
                    newFile += aoiSetting;
                    newFile += licenseInfo;
                    newFile += camInfo;
                    break;

                case "AOI":
                    newFile += emailSetting;
                    newFile += autoRestart;
                    newFile += defaultAOI.toXML();     //New value
                    newFile += licenseInfo;
                    newFile += camInfo;
                    break;

                case "LICENSE":
                    newFile += emailSetting;
                    newFile += autoRestart;
                    newFile += aoiSetting;     //New value
                    if (newLicense.Trim() != "")
                    {
                        newFile += newLicense;
                    }
                    else
                    {
                        newFile += licenseInfo;
                    }
                    newFile += camInfo;
                    break;

                case "CAM":
                    newFile += emailSetting;
                    newFile += autoRestart;
                    newFile += aoiSetting;
                    newFile += licenseInfo;
                    newFile += CAMS.toXML(true);     //New value
                    break;

                default:
                    //Save All
                    newFile += email.toXML();      //New value
                    newFile += autoRestart;
                    newFile += defaultAOI.toXML(); //New value
                    newFile += licenseInfo;
                    newFile += CAMS.toXML(true);   //New value
                    break;
                }

                settingsContent = "<?xml version=\"1.0\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + newFile + "</SOAP-ENV:Envelope>";

                newFile = newFile.Replace("&", "&amp;");
                newFile = newFile.Replace("\"", "&quot;").Replace("'", "&apos;");
                newFile = "<?xml version=\"1.0\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + newFile + "</SOAP-ENV:Envelope>";
                //Assign it and save it!
                writeToFile(Settings, newFile);
            }
            catch
            {
                saveAll();
            }
        }