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();
		}
Beispiel #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());
        }
Beispiel #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);
        }
Beispiel #4
0
		internal IniSection(Ini parent, IniSectionStart sect)
		{
			SectionStart = sect;
			Parent = parent;
		}
Beispiel #5
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;
		}
Beispiel #6
0
		public void WriteIniFile(Ini file)
		{
			WriteElements(file.Elements);
		}
Beispiel #7
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();
		}
Beispiel #8
0
 internal IniSection(Ini parent, IniSectionStart sect)
 {
     SectionStart = sect;
     Parent       = parent;
 }
Beispiel #9
0
 public void WriteIniFile(Ini file)
 {
     WriteElements(file.Elements);
 }