Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Your filename goes here!
- string filename = "FULLPATHTOYOURCODEFILENAME"
- StreamReader r = new StreamReader(filename);
- string strCmdText = string.Format(@"/server:YOURSERVERNAME /database:YOURDATABASENAME /user:YOURUSERNAME /password:YOURPASSWORD /views /code:{0} /namespace:D /context:WebData2 /pluralize",filename);
- List<string> lines = new List<string>();
- List<string> orglines = new List<string>();
- List<TableComment> Tablecomments = new List<TableComment>();
- List<Comment> comments = new List<Comment>();
- //skip the first 9 lines.
- for(int i = 0;i<9;i++)r.ReadLine();
- string currenttable = null;
- while(!r.EndOfStream)
- {
- string orgline = r.ReadLine();
- string line = orgline.Replace("\t","").TrimStart(' ');
- // Console.WriteLine(line);
- lines.Add(line);
- orglines.Add(orgline);
- if(line.StartsWith("public System.Data.Linq.Table<"))
- {
- var tc = new TableComment(){
- table = line
- };
- int curr = lines.Count-2;
- while(lines[curr].StartsWith("//"))
- tc.comments.Add(orglines[curr--]);
- if(tc.comments.Count>0)
- Tablecomments.Add(tc);
- }
- if(line.StartsWith("[Table(Name="))
- {
- currenttable = line;
- }
- if(line.StartsWith("[Column("))
- {
- int curr = lines.Count-2;
- Comment c = new Comment(){table = currenttable,fieldname = line};
- while(lines[curr].StartsWith("//"))
- c.comments.Add(orglines[curr--]);
- if(c.comments.Count>0)
- comments.Add(c);
- }
- }
- r.Close();
- //Tablecomments.Dump();
- //run sqlmetal thing
- var prc = System.Diagnostics.Process.Start(@"c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sqlmetal.exe",strCmdText);
- prc.WaitForExit();
- //rebuild comments.
- r = new StreamReader(filename);
- //Save all the comments and the next line (the function line
- lines = new List<string>();
- //List<TableComment> Tablecomments = new List<TableComment>();
- //skip the first 9 lines.
- for(int i = 0;i<10;i++)r.ReadLine();
- while(!r.EndOfStream)
- {
- string orgline = r.ReadLine();
- string line = orgline.Replace("\t","").TrimStart(' ');
- TableComment tc = (from b in Tablecomments.Where (p => p.table == line)
- select b).FirstOrDefault();
- if(tc!=null)
- {
- for(int i = tc.comments.Count-1;i>-1;i--)
- {
- lines.Add(tc.comments[i]);
- //Console.WriteLine(tc.comments[i]);
- }
- //Console.WriteLine(line);
- }
- if(line.StartsWith("[Table(Name="))
- {
- currenttable = line;
- }
- if(line.StartsWith("[Column("))
- {
- var c = (from b in comments where b.table == currenttable && b.fieldname == line select b).FirstOrDefault();
- if(c!=null)
- {
- for(int i = c.comments.Count-1;i>-1;i--)
- {
- lines.Add(c.comments[i]);
- }
- }
- }
- //lines.Add(tc.comments[i]);
- //Console.WriteLine(line);
- lines.Add(orgline);
- }
- r.Close();
- Tablecomments = null;
- File.Delete(filename);
- StreamWriter wr = new StreamWriter(filename);
- foreach(string s in lines)
- {
- wr.WriteLine(s);
- }
- wr.Flush();
- wr.Close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement