using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Replace
{
class Program
{
static void Main(string[] args)
{
try
{
var dir = new FileInfo(args[0]); //new DirectoryInfo(System.Environment.CurrentDirectory);
int id = 0;
string name;
string newDir = "replaced";
string[] replaceTags = {"EAID", "EAPK"};
var f= dir;
//foreach (FileInfo f in dir.GetFiles())
{
if (f.Extension == ".xml" || f.Extension == ".uml")
{
id = 0;
// dir.CreateSubdirectory(newDir);
name = Path.Combine(f.Directory.FullName,"replaced"+f.Name);//, Path.Combine(Path.Combine(f.DirectoryName, newDir), f.Name);
StreamReader r = f.OpenText();
string s = r.ReadToEnd();
foreach (string str in replaceTags)
{
while (s.Contains(str))
{
id++;
int start = s.IndexOf(str);
int end = s.IndexOf('"', start);
int end2 = s.IndexOf(' ', start);
if (end < end2)
{
string sub = s.Substring(start, end - start);
s = s.Replace(sub, "VDM." + id);
}
else
{
string sub = s.Substring(start, end2 - start);
s = s.Replace(sub, "VDM." + id);
}
}
}
FileStream file = new FileStream(name, FileMode.Create);
StreamWriter sw = new StreamWriter(file);
sw.Write(s);
sw.Close();
}
}
}
catch
(Exception
e)
{
Console.WriteLine(e.Message);
}
}
}
}