Esempio n. 1
0
 public void Modify(ModifyContext context, string key, string value)
 {
     if (File.Exists(context.CfgPath))
     {
         context.RemoveReadonly(context.CfgPath);
         try
         {
             var text = File.ReadAllText(context.CfgPath, Encoding.UTF8);
             if (string.IsNullOrEmpty(context.ReplaceIf))
             {
                 if (text.IndexOf(value) == -1)
                 {
                     File.WriteAllText(context.CfgPath, text.Replace(key, value), Encoding.UTF8);
                 }
             }
             else if (text.IndexOf(context.ReplaceIf) == -1)
             {
                 File.WriteAllText(context.CfgPath, text.Replace(key, context.ReplaceIf + value), Encoding.UTF8);
             }
         }
         catch (Exception ex)
         {
             Console.Write(ex.ToString());
         }
     }
 }
Esempio n. 2
0
        public void Modify(ModifyContext context, string key, string value)
        {
            context.BeginModify();

            context.RemoveAppSetting(key);

            context.EndModify();
        }
Esempio n. 3
0
        public void Modify(ModifyContext context, string key, string value)
        {
            context.BeginModify();

            context.GetAppSetting(key).Attributes["value"].Value = value;

            context.EndModify();
        }
Esempio n. 4
0
 public void Modify(ModifyContext context, string key, string value)
 {
     if (File.Exists(context.CfgPath))
     {
         context.RemoveReadonly(context.CfgPath);
         try
         {
             var text = File.ReadAllText(context.CfgPath, Encoding.UTF8);
             if (string.IsNullOrEmpty(key) || text.IndexOf(key) == -1)
             {
                 File.AppendAllText(context.CfgPath, value, Encoding.UTF8);
             }
         }
         catch (Exception ex)
         {
             Console.Write(ex.ToString());
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 应用程序的主入口点。
 /// </summary>
 static void Main(string[] args)
 {
     if (args.Length > 3)
     {
         string cfgpath   = args[0];
         string xpath     = args[1];
         string replaceif = "";
         var    type      = ConvertToType(args[2]);
         var    key       = args[3];
         string val       = string.Empty;
         if (type != ModifyType.Delete && args.Length > 4)
         {
             val = args[4];
         }
         if (type == ModifyType.Replace && args.Length > 5)
         {
             replaceif = args[5];
         }
         ModifyContext context = new ModifyContext(@cfgpath, xpath, replaceif);
         var           mdf     = ModifyFactory.GetModify(type);
         mdf.Modify(context, key, val);
     }
 }