Ejemplo n.º 1
0
        public static void ReplaceSingleFile(string file,
                                             ReplaceTemplate template,
                                             Action <string> afterAction)
        {
            if (!File.Exists(file))
            {
                return;
            }
            string content = File.ReadAllText(file, FileHelper.Encoding);

            int h1 = content.GetHashCode();

            foreach (ReplaceTemplateItem doitem in template.Items)
            {
                content = ReplaceGroup(content, template);
            }
            int h2 = content.GetHashCode();

            if (h1 != h2)
            {
                if (afterAction != null)
                {
                    afterAction(file);
                }

                FileInfo fi = new FileInfo(file);
                FileHelper.Rename(file, file + ".bak");
                File.WriteAllText(file, content, FileHelper.Encoding);
            }
        }
Ejemplo n.º 2
0
 public static void ReplaceFiles(string[] files,
                                 ReplaceTemplate template,
                                 Action <string> afterAction)
 {
     foreach (string file in files)
     {
         ReplaceSingleFile(file, template, afterAction);
     }
 }
Ejemplo n.º 3
0
        private ReplaceTemplate GetTemplate(DataRow drTemplate, string templateName)
        {
            ReplaceTemplate template = new ReplaceTemplate(templateName);

            foreach (DataRow row in drTemplate.GetChildRows("template_item"))
            {
                template.Items.Add(ReplaceUtils.GetTemplateItem(row));
            }
            return(template);
        }
Ejemplo n.º 4
0
        public static string ReplaceGroup(string input, ReplaceTemplate template)
        {
            foreach (ReplaceTemplateItem replacement in template.Items)
            {
                //ReplaceReference.Reference(replacement);
                input = ReplaceGroup(input, replacement);
            }

            return(input);
        }
Ejemplo n.º 5
0
        public static ReplaceTemplate GetInstance(string xmlsnippet)
        {
            Random          rd   = new Random(10000);
            string          name = DateTime.Now.ToString("yyyyMMddhhmmss--") + rd.Next().ToString();
            ReplaceTemplate inst = new ReplaceTemplate(name);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlsnippet);
            inst.LoadXml(doc);

            return(inst);
        }