public static string CreateDefaultIniString(IEnumerable<string> conns)
		{
			var ini = new Ini();
			ini.Header = "Shell高级设置\n以#开头则为注释行";
			ini["HttpHeader"].Comment = "设置全局Http头\n键值可以自己添加,e.g. Accept:*/*";
			ini["HttpHeader"]["Accept"] = "*/*";
			ini["HttpHeader"]["User-Agent"] = "IE9.0";
			ini["HttpHeader"]["Cookie"] = "Test:Test123";

			ini["Post"].Comment = "设置提交的Post包(正在开发中)";
			ini["Post"]["post"] = "A=a&B=b&C=c";

			ini["SqlConnection"].Comment = "设置数据库连接\n" +
											"type为数据库类型\n" +
											"conn为连接字符串";
			//ini["SqlConnection"]["type"] = "mysql";
			//ini["SqlConnection"]["conn"] = "127.0.0.1;root;password;utf-8;";

			foreach (var conn in conns)
			{
				foreach (var i in conn.Split(new [] {"\n", "\r\n"},StringSplitOptions.RemoveEmptyEntries))
				{
					ini["SqlConnection"].InsertComment(i);
				}
			}

			return ini.OutputString();
		}
示例#2
0
        public static string OutputString(Ini file)
        {
            var sb = new StringBuilder();

            foreach (var element in file.Elements)
            {
                if (!IniSettings.PreserveFormatting)
                {
                    element.FormatDefault();
                }
                // do not write if:
                if (!(                 // 1) element is a blank line AND blank lines are not allowed
                        (element is IniBlankLine && !IniSettings.AllowBlankLines)
                        // 2) element is an empty value AND empty values are not allowed
                        || (!IniSettings.AllowEmptyValues && element is IniValue && ((IniValue)element).Value == "")))
                {
                    sb.Append(element.Line + IniSettings.NewLine);
                }
            }
            return(sb.ToString());
        }
示例#3
0
        public static Ini FromElements(IEnumerable <IniElement> elemes)
        {
            var ret = new Ini();

            ret.Elements.AddRange(elemes);
            if (ret.Elements.Count > 0)
            {
                IniSection section = null;

                if (ret.Elements[ret.Elements.Count - 1] is IniBlankLine)
                {
                    ret.Elements.RemoveAt(ret.Elements.Count - 1);
                }
                foreach (var element in ret.Elements)
                {
                    var el = element;
                    if (el is IniSectionStart)
                    {
                        section = new IniSection(ret, (IniSectionStart)el);
                        ret.Sections.Add(section);
                    }
                    else if (section != null)
                    {
                        section.Elements.Add(el);
                    }
                    else if (ret.Sections.Exists(a => a.Name == ""))
                    {
                        ret.Sections[0].Elements.Add(el);
                    }
                    else if (el is IniValue)
                    {
                        section = new IniSection(ret, IniSectionStart.FromName(""));
                        section.Elements.Add(el);
                        ret.Sections.Add(section);
                    }
                }
            }
            return(ret);
        }
示例#4
0
文件: Ini.cs 项目: kevins1022/Altman
		internal IniSection(Ini parent, IniSectionStart sect)
		{
			SectionStart = sect;
			Parent = parent;
		}
示例#5
0
文件: Ini.cs 项目: kevins1022/Altman
		public static Ini FromElements(IEnumerable<IniElement> elemes)
		{
			var ret = new Ini();
			ret.Elements.AddRange(elemes);
			if (ret.Elements.Count > 0)
			{
				IniSection section = null;

				if (ret.Elements[ret.Elements.Count - 1] is IniBlankLine)
					ret.Elements.RemoveAt(ret.Elements.Count - 1);
				foreach (var element in ret.Elements)
				{
					var el = element;
					if (el is IniSectionStart)
					{
						section = new IniSection(ret, (IniSectionStart)el);
						ret.Sections.Add(section);
					}
					else if (section != null)
						section.Elements.Add(el);
					else if (ret.Sections.Exists(a => a.Name == ""))
						ret.Sections[0].Elements.Add(el);
					else if (el is IniValue)
					{
						section = new IniSection(ret, IniSectionStart.FromName(""));
						section.Elements.Add(el);
						ret.Sections.Add(section);
					}
				}
			}
			return ret;
		}
示例#6
0
文件: Ini.cs 项目: kevins1022/Altman
		public void WriteIniFile(Ini file)
		{
			WriteElements(file.Elements);
		}
示例#7
0
文件: Ini.cs 项目: kevins1022/Altman
		public static string OutputString(Ini file)
		{
			var sb = new StringBuilder();
			foreach (var element in file.Elements)
			{
				if (!IniSettings.PreserveFormatting)
					element.FormatDefault();
				// do not write if: 
				if (!( // 1) element is a blank line AND blank lines are not allowed
					(element is IniBlankLine && !IniSettings.AllowBlankLines)
					// 2) element is an empty value AND empty values are not allowed
					|| (!IniSettings.AllowEmptyValues && element is IniValue && ((IniValue)element).Value == "")))
					sb.Append(element.Line + IniSettings.NewLine);
			}
			return sb.ToString();
		}
示例#8
0
 internal IniSection(Ini parent, IniSectionStart sect)
 {
     SectionStart = sect;
     Parent       = parent;
 }
示例#9
0
 public void WriteIniFile(Ini file)
 {
     WriteElements(file.Elements);
 }