static void Main(string[] args) { Console.WriteLine("Worm xml schema generator. v0.3 2007"); if (args.Length == 0) { ShowUsage(); return; } CommandLine.Utility.Arguments param = new CommandLine.Utility.Arguments(args); string server = null; if (!param.TryGetParam("S", out server)) { server = "(local)"; } string dbName = null; if (!param.TryGetParam("D", out dbName)) { if (!File.Exists(server)) { Console.WriteLine("Database is not specified or file {0} not found", server); ShowUsage(); return; } } string e; string user = null; string psw = null; if (!param.TryGetParam("E", out e)) { e = "false"; bool showUser = true; if (!param.TryGetParam("U", out user)) { Console.Write("User: "******"P", out psw)) { if (showUser) { Console.WriteLine("User: "******"Password: "******"schemas", out schemas); string namelike = null; param.TryGetParam("name", out namelike); string file = null; if (!param.TryGetParam("O", out file)) { file = dbName + ".xml"; } string merge = null; if (!param.TryGetParam("F", out merge)) { merge = "merge"; } switch (merge) { case "merge": case "error": //do nothing break; default: Console.WriteLine("Invalid \"Existing file behavior\" parameter."); ShowUsage(); return; } string drop = null; if (!param.TryGetParam("R", out drop)) { drop = "false"; } bool dr = bool.Parse(drop); string namesp = dbName; param.TryGetParam("N", out namesp); string u = "true"; if (!param.TryGetParam("Y", out u)) { u = "false"; } bool unify = bool.Parse(u); string hi = "true"; if (!param.TryGetParam("H", out hi)) { hi = "false"; } bool hie = bool.Parse(hi); string tr = "true"; if (!param.TryGetParam("T", out tr)) { tr = "false"; } bool transform = bool.Parse(tr); string es = "true"; if (!param.TryGetParam("ES", out es)) { es = "false"; } bool escapeTables = bool.Parse(es); string ec = "true"; if (!param.TryGetParam("EC", out ec)) { ec = "false"; } bool escapeColumns = bool.Parse(ec); string cn = "true"; if (!param.TryGetParam("CN", out cn)) { cn = "false"; } bool capitalize = bool.Parse(cn); string ss = "false"; if (!param.TryGetParam("SS", out ss)) { ss = "false"; } bool showStatement = bool.Parse(ss); string v = "1"; if (!param.TryGetParam("V", out v)) { v = "1"; } DatabaseProvider dp = null; string m = null; if (!param.TryGetParam("M", out m)) { m = "msft"; } switch (m) { case "msft": case "mssql": if (i) { dp = new MSSQLProvider(server, dbName); } else { dp = new MSSQLProvider(server, dbName, user, psw); } break; case "sqlce": dp = new SQLCEProvider(server, psw); break; case "mysql": if (i) { dp = new MySQLProvider(server, dbName); } else { dp = new MySQLProvider(server, dbName, user, psw); } break; default: Console.WriteLine("Invalid manufacturer parameter."); ShowUsage(); return; } dp.OnDatabaseConnecting += (sender, conn) => Console.WriteLine("Connecting to \"{0}\"...", FilterPsw(conn)); dp.OnStartLoadDatabase += (sender, cmd) => Console.WriteLine("Retriving tables via {0}...", showStatement ? cmd : string.Empty); SourceView db = dp.GetSourceView(schemas, namelike, escapeTables, escapeColumns); WXMLModel model = null; if (File.Exists(file)) { if (merge == "error") { Console.WriteLine("The file " + file + " is already exists."); ShowUsage(); return; } Console.WriteLine("Loading file " + file); model = WXMLModel.LoadFromXml(new System.Xml.XmlTextReader(file)); } else { model = new WXMLModel(); model.Namespace = namesp; model.SchemaVersion = v; if (!Path.IsPathRooted(file)) { file = Path.Combine(Directory.GetCurrentDirectory(), file); } //File.Create(file); } SourceToModelConnector g = new SourceToModelConnector(db, model); Console.WriteLine("Generating xml..."); HashSet <EntityDefinition> ents = new HashSet <EntityDefinition>(); g.OnEntityCreated += (sender, entity) => { Console.WriteLine("Create class {0} ({1})", entity.Name, entity.Identifier); ents.Add(entity); }; g.OnPropertyCreated += (sender, prop, created) => { EntityDefinition entity = prop.Entity; if (!ents.Contains(entity)) { ents.Add(entity); Console.WriteLine("Alter class {0} ({1})", entity.Name, entity.Identifier); } Console.WriteLine("\t{1} property {2}.{0}", prop.Name, created ? "Add" : "Alter", entity.Name); }; g.OnPropertyRemoved += (sender, prop) => Console.WriteLine("Remove: {0}.{1}", prop.Entity.Name, prop.Name); g.ApplySourceViewToModel(dr, hie ? relation1to1.Hierarchy : unify ? relation1to1.Unify : relation1to1.Default, transform, capitalize, dp.CaseSensitive); using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(file, Encoding.UTF8)) { writer.Formatting = System.Xml.Formatting.Indented; model.GetXmlDocument().Save(writer); } Console.WriteLine("Done!"); //Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Orm xml schema generator. v0.1 2007"); if (args.Length == 0) { ShowUsage(); return; } CommandLine.Utility.Arguments param = new CommandLine.Utility.Arguments(args); string server = null; if (!param.TryGetParam("S", out server)) { server = "(local)"; } string m = null; if (!param.TryGetParam("M", out m)) { m = "msft"; } switch (m) { case "msft": //do nothing break; default: Console.WriteLine("Invalid manufacturer parameter."); ShowUsage(); return; } string db = null; if (!param.TryGetParam("D", out db)) { Console.WriteLine("Database is not specified"); ShowUsage(); return; } string e; string user = null; string psw = null; if (!param.TryGetParam("E", out e)) { e = "false"; if (!param.TryGetParam("U", out user)) { Console.WriteLine("User is not specified"); ShowUsage(); return; } if (!param.TryGetParam("P", out psw)) { Console.Write("Password: "******"schemas", out schemas); string namelike = null; param.TryGetParam("name", out namelike); string file = null; if (!param.TryGetParam("O", out file)) { file = server + ".xml"; } string merge = null; if (!param.TryGetParam("F", out merge)) { merge = "merge"; } switch (merge) { case "merge": case "error": //do nothing break; default: Console.WriteLine("Invalid \"Existing file behavior\" parameter."); ShowUsage(); return; } string drop = null; if (!param.TryGetParam("R", out drop)) { drop = "false"; } bool dr = bool.Parse(drop); string namesp = string.Empty; param.TryGetParam("N", out namesp); string u = null; if (!param.TryGetParam("Y", out u)) { u = "false"; } bool unify = bool.Parse(u); string tr = null; if (!param.TryGetParam("T", out tr)) { tr = "false"; } bool transform = bool.Parse(tr); Generator g = new Generator(server, m, db, i, user, psw, transform); g.MakeWork(schemas, namelike, file, merge, dr, namesp, unify); Console.WriteLine("Done!"); //Console.ReadKey(); }