Esempio n. 1
0
        /// <summary>
        /// 设置参数文件
        /// </summary>
        public void SetParameterFile()
        {
            //存储到文件
            string sFileDir = AppConfigOperation.GetConfigurationValue("ApplicationFullPath") + @"\PathPlanning\Method\Parameter\" +
                              ((int)EPathPlanningMethod.RRTStar).ToString() + ".ini"; //参数文件地址

            IniOperation.WriteProfileString("PlanningStep", "StepType", ((int)(MStepType)).ToString(), sFileDir);
            IniOperation.WriteProfileString("PlanningStep", "Step", MStep.ToString(), sFileDir);
            IniOperation.WriteProfileString("PlanningStep", "FixedNearDistanceRatio", FixedNearDistanceRatio.ToString(), sFileDir);
            IniOperation.WriteProfileString("PlanningStep", "RandomStepMax", MRandomStepMax.ToString(), sFileDir);
            IniOperation.WriteProfileString("PlanningStep", "RandomStepMin", MRandomStepMin.ToString(), sFileDir);
            IniOperation.WriteProfileString("Extension", "SelectionType", ((int)MSelectionType).ToString(), sFileDir);
            IniOperation.WriteProfileString("Extension", "ChooseTargetThreshold", MChooseTargetThreshold.ToString(), sFileDir);
            IniOperation.WriteProfileString("Extension", "MaxNodeNumber", MMaxNodeNumber.ToString(), sFileDir);
            IniOperation.WriteProfileString("Extension", "ReachMode", ((int)MReachMode).ToString(), sFileDir);
            IniOperation.WriteProfileString("Others", "AutoOptimizeParameter", (Convert.ToInt32(MAutoOptimizeParameter)).ToString(), sFileDir);
            IniOperation.WriteProfileString("Others", "IsDrawingTree", (Convert.ToInt32(MIsDrawingTree)).ToString(), sFileDir);

            IniOperation.WriteProfileString("Others", "IsDubinsMode", (Convert.ToInt32(MIsDubinsMode)).ToString(), sFileDir);
            IniOperation.WriteProfileString("Others", "TurningRadius", TurningRadius.ToString(), sFileDir);

            #region NearNodesFilter
            IniOperation.WriteProfileString("NearNodesFilter", "NearNodesFilter", (Convert.ToInt32(NearNodesFilter)).ToString(), sFileDir);
            IniOperation.WriteProfileString("NearNodesFilter", "TriggerNum", TriggerNum.ToString(), sFileDir);
            #endregion
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="keyName"></param>
        /// <param name="keyValue"></param>
        private void AppConfigItem(AppConfigOperation type, string keyName, string keyValue = "")
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                //获取App.config文件绝对路径
                string basePath = FileUtils.GetProjectRootPath();
                //basePath = basePath.Substring(, basePath.Length - );
                string path = basePath + @"\App.config";
                xDoc.Load(path);

                XmlNode    xNode;
                XmlElement xElem1;
                XmlElement xElem2;
                //修改完文件内容,还需要修改缓存里面的配置内容,使得刚修改完即可用
                //如果不修改缓存,需要等到关闭程序,在启动,才可使用修改后的配置信息
                Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                xNode  = xDoc.SelectSingleNode("//appSettings");
                xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + keyName + "']");
                switch (type)
                {
                case AppConfigOperation.AddItemType:
                    if (xElem1 == null)
                    {
                        xElem2 = xDoc.CreateElement("add");
                        xElem2.SetAttribute("key", keyName);
                        xElem2.SetAttribute("value", keyValue);
                        xNode.AppendChild(xElem2);
                        cfa.AppSettings.Settings.Add(keyName, keyValue);
                    }
                    break;

                case AppConfigOperation.ModifyItemType:
                    if (xElem1 != null)
                    {
                        xElem1.SetAttribute("value", keyValue);
                        cfa.AppSettings.Settings[keyName].Value = keyValue;
                    }
                    break;

                case AppConfigOperation.RemoveItemType:
                    if (xElem1 != null)
                    {
                        xNode.RemoveChild(xElem1);
                    }
                    break;
                }
                //改变缓存中的配置文件信息(读取出来才会是最新的配置)
                cfa.Save();
                ConfigurationManager.RefreshSection("appSettings");

                xDoc.Save(path);
            }
            catch (Exception e)
            {
                string error = e.Message;
                Console.WriteLine(type.ToString() + " AppConfigItem Error : " + error);
            }
        }
        private void SavePassword()
        {
            string password   = pboxPassword1.Password;
            string secretCode = new AppConfigOperation().Read("AppSecret");
            var    aesUtil    = new AESUtil();
            var    byteDatas  = aesUtil.AesEncrypt(password, secretCode);
            var    strData    = Encoding.UTF8.GetString(byteDatas);
            var    xml        = new XMLOperation();

            if (xml.SetNodeValue("/root/user/unlockpassword", strData))
            {
                new AlertWindow("设置密码成功!").Show();
                Close();
            }
            else
            {
                new AlertWindow("设置密码失败!").Show();
            }
        }