public void TestDropProperty() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "aspnet_Applications"); Assert.AreEqual(4, sv.SourceFields.Count); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(4, model.GetActiveEntities().First().GetActiveProperties().Count()); SourceFieldDefinition fld = sv.SourceFields.Find(item => item.SourceFieldExpression == "[Description]"); sv.SourceFields.Remove(fld); Assert.AreEqual(3, sv.SourceFields.Count); c.ApplySourceViewToModel(true, relation1to1.Default, true, true, false); Assert.AreEqual(3, model.GetActiveEntities().First().GetActiveProperties().Count()); sv.SourceFields.Add(fld); Assert.AreEqual(4, sv.SourceFields.Count); c.ApplySourceViewToModel(true, relation1to1.Default, true, true, false); Assert.AreEqual(4, model.GetActiveEntities().First().GetActiveProperties().Count()); }
public void TestFillModelRelations() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "aspnet_Applications,aspnet_Paths"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(2, model.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetEntities().Count()); var aspnet_Applications = model.GetEntity("e_dbo_aspnet_Applications"); Assert.IsNotNull(aspnet_Applications); var aspnet_Paths = model.GetEntity("e_dbo_aspnet_Paths"); Assert.IsNotNull(aspnet_Paths); Assert.IsNotNull(aspnet_Paths.GetProperty("Application")); Assert.IsNotNull(aspnet_Paths.GetProperty("PathId")); Assert.IsNotNull(aspnet_Paths.GetProperty("Path")); Assert.IsNotNull(aspnet_Paths.GetProperty("LoweredPath")); Assert.AreEqual(1, aspnet_Applications.One2ManyRelations.Count()); Assert.AreEqual(aspnet_Paths, aspnet_Applications.One2ManyRelations.First().Entity); }
public void TestAlterEntities() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "ent1,ent2,1to2"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(3, model.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetEntities().Count()); sv = p.GetSourceView(null, "ent1,ent2,1to2"); c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(3, model.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetEntities().Count()); }
public void TestFillModel() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "ent1,ent2,1to2"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(3, model.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetEntities().Count()); Assert.IsNotNull(model.GetEntity("e_dbo_ent1")); Assert.IsNotNull(model.GetEntity("e_dbo_ent2")); Assert.AreEqual(1, model.GetEntity("e_dbo_ent1").GetProperties().Count()); Assert.AreEqual(1, model.GetEntity("e_dbo_ent1").GetPkProperties().Count()); Assert.IsTrue(model.GetEntity("e_dbo_ent1").GetPkProperties().First().HasAttribute(Field2DbRelations.PrimaryKey)); Assert.AreEqual(2, model.GetEntity("e_dbo_ent2").GetProperties().Count()); Assert.AreEqual(1, model.GetRelations().Count()); }
public void TestGenerateScriptDropConstraint() { var p = new MSSQLProvider(GetTestDB(), null); var sv = p.GetSourceView(); var model = new WXMLModel(); var smc = new SourceToModelConnector(sv, model); smc.ApplySourceViewToModel(false, relation1to1.Hierarchy, true, true, false); Assert.AreEqual(28, model.GetActiveEntities().Count()); Assert.AreEqual(32, model.GetSourceFragments().Count()); EntityPropertyDefinition prop = model.GetActiveEntities().SelectMany(item => item.GetProperties().OfType <EntityPropertyDefinition>()).First(); SourceConstraint c = new SourceConstraint(SourceConstraint.UniqueConstraintTypeName, "xxx"); c.SourceFields.AddRange(prop.SourceFields.Cast <SourceFieldDefinition>()); prop.SourceFragment.Constraints.Add(c); var msc = new ModelToSourceConnector(p.GetSourceView(), model); var tbl = msc.SourceView.GetSourceFragments().Single(item => item.Selector == prop.SourceFragment.Selector && item.Name == prop.SourceFragment.Name); tbl.Constraints.Add(new SourceConstraint(SourceConstraint.UniqueConstraintTypeName, "xxx")); string script = msc.GenerateSourceScript(p, false); Assert.IsFalse(string.IsNullOrEmpty(script), script); Assert.AreEqual(1, new Regex("DROP CONSTRAINT").Matches(script).Count); }
public void TestGenerateComplex() { SourceView sv = TestsSourceModel.TestsSourceModel.CreateComplexSourceView(); var model = new WXMLModel(); var smc = new SourceToModelConnector(sv, model); smc.ApplySourceViewToModel(); Assert.AreEqual(2, model.GetActiveEntities().Count()); Assert.AreEqual(4, model.GetActiveRelations().Count()); model.GetActiveRelations().First().Constraint = RelationConstraint.Unique; var msc = new ModelToSourceConnector(new SourceView(), model); var p = new MSSQLProvider(null, null); string script = msc.GenerateSourceScript(p, false); Assert.IsFalse(string.IsNullOrEmpty(script)); Console.WriteLine(script); Assert.AreEqual(6, new Regex("CREATE TABLE ").Matches(script).Count); Assert.AreEqual(2, new Regex("PRIMARY KEY CLUSTERED").Matches(script).Count); Assert.AreEqual(8, new Regex("FOREIGN KEY").Matches(script).Count); Assert.AreEqual(1, new Regex("UNIQUE CLUSTERED").Matches(script).Count); }
public void TestGenerateScript() { var p = new MSSQLProvider(GetTestDB(), null); var sv = p.GetSourceView(); var model = new WXMLModel(); var smc = new SourceToModelConnector(sv, model); smc.ApplySourceViewToModel(); Assert.AreEqual(28, model.GetActiveEntities().Count()); Assert.AreEqual(32, model.GetSourceFragments().Count()); var msc = new ModelToSourceConnector(new SourceView(), model); string script = msc.GenerateSourceScript(p, false); Assert.IsFalse(string.IsNullOrEmpty(script)); Assert.AreEqual(32, new Regex("CREATE TABLE ").Matches(script).Count); Console.WriteLine(script); }
public void TestM2MSimilarRelations() { SourceView sv = CreateComplexSourceView(); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); }
public void TestO2MSimilarRelations() { SourceView sv = new SourceView(); SourceFragmentDefinition sf1 = new SourceFragmentDefinition("tbl1", "tbl1", "dbo"); SourceFragmentDefinition sf2 = new SourceFragmentDefinition("tbl2", "tbl2", "dbo"); SourceFieldDefinition pkField = new SourceFieldDefinition(sf1, "id", "int") { IsNullable = false }; sv.SourceFields.Add(pkField); sv.SourceFields.Add(new SourceFieldDefinition(sf2, "id", "int") { IsNullable = false }); sv.SourceFields.Add(new SourceFieldDefinition(sf2, "prop1_id", "int")); sv.SourceFields.Add(new SourceFieldDefinition(sf2, "prop2_id", "int")); SourceConstraint pk = new SourceConstraint(SourceConstraint.PrimaryKeyConstraintTypeName, "pk1"); pk.SourceFields.Add(pkField); SourceConstraint pk2 = new SourceConstraint(SourceConstraint.PrimaryKeyConstraintTypeName, "pk2"); pk2.SourceFields.Add(sv.GetSourceFields(sf2).Single(item => item.SourceFieldExpression == "id")); SourceConstraint fk1 = new SourceConstraint(SourceConstraint.ForeignKeyConstraintTypeName, "fk1"); fk1.SourceFields.Add(sv.GetSourceFields(sf2).Single(item => item.SourceFieldExpression == "prop1_id")); SourceConstraint fk2 = new SourceConstraint(SourceConstraint.ForeignKeyConstraintTypeName, "fk2"); fk2.SourceFields.Add(sv.GetSourceFields(sf2).Single(item => item.SourceFieldExpression == "prop2_id")); sf1.Constraints.Add(pk); sf2.Constraints.Add(pk2); sf2.Constraints.Add(fk1); sf2.Constraints.Add(fk2); sv.References.Add(new SourceReferences(pk, fk1, pkField, sv.GetSourceFields(sf2).Single(item => item.SourceFieldExpression == "prop1_id") )); sv.References.Add(new SourceReferences(pk, fk2, pkField, sv.GetSourceFields(sf2).Single(item => item.SourceFieldExpression == "prop2_id") )); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); }
public void TestAdventureWorks() { SourceView view; BinaryFormatter f = new BinaryFormatter { AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple }; ResolveEventHandler d = null; d = (sender, args) => { AppDomain.CurrentDomain.AssemblyResolve -= d; return(typeof(WXMLModel).Assembly); }; AppDomain.CurrentDomain.AssemblyResolve += d; Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream fs = assembly.GetManifestResourceStream( string.Format("{0}.TestFiles.{1}", assembly.GetName().Name, "AdventureWorks.sourceview"))) { Assert.IsNotNull(fs); view = (SourceView)f.Deserialize(fs); } Assert.IsNotNull(view); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(view, model); c.ApplySourceViewToModel(false, relation1to1.Default, true, true, false); Assert.AreEqual(70, model.GetActiveEntities().Count()); Assert.AreEqual(70, model.GetSourceFragments().Count()); model = new WXMLModel(); c = new SourceToModelConnector(view, model); c.ApplySourceViewToModel(false, relation1to1.Unify, true, true, false); Assert.AreEqual(67, model.GetActiveEntities().Count()); Assert.AreEqual(70, model.GetSourceFragments().Count()); model = new WXMLModel(); c = new SourceToModelConnector(view, model); c.ApplySourceViewToModel(false, relation1to1.Hierarchy, true, true, false); Assert.AreEqual(70, model.GetActiveEntities().Count()); Assert.AreEqual(70, model.GetSourceFragments().Count()); }
public void TestFillModel4() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "aspnet_Membership, 3to3"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(2, model.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetEntities().Count()); }
public void TestFillModel3() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "complex_fk"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(1, model.GetSourceFragments().Count()); Assert.AreEqual(1, model.GetEntities().Count()); }
public void TestGenerateScriptHierachy() { var p = new MSSQLProvider(GetTestDB(), null); var sv = p.GetSourceView(); var model = new WXMLModel(); var smc = new SourceToModelConnector(sv, model); smc.ApplySourceViewToModel(false, relation1to1.Hierarchy, true, true, false); Assert.AreEqual(28, model.GetActiveEntities().Count()); Assert.AreEqual(32, model.GetSourceFragments().Count()); var msc = new ModelToSourceConnector(new SourceView(), model); string script = msc.GenerateSourceScript(p, false); Assert.IsFalse(string.IsNullOrEmpty(script)); Console.WriteLine(script); Assert.AreEqual(sv.GetSourceFragments().Count(), new Regex("CREATE TABLE ").Matches(script).Count); IEnumerable <SourceConstraint> pks = sv.GetSourceFragments().SelectMany(item => item.Constraints.Where(cns => cns.ConstraintType == SourceConstraint.PrimaryKeyConstraintTypeName)); Assert.AreEqual(pks.Count(), new Regex("PRIMARY KEY CLUSTERED").Matches(script).Count); Assert.AreEqual(2, new Regex("UNIQUE NONCLUSTERED").Matches(script).Count); Assert.AreEqual(1, new Regex("UNIQUE CLUSTERED").Matches(script).Count); Assert.AreEqual(sv.GetSourceFragments().SelectMany(item => item.Constraints.Where(cns => cns.ConstraintType == SourceConstraint.ForeignKeyConstraintTypeName)).Count(), new Regex("FOREIGN KEY").Matches(script).Count); msc = new ModelToSourceConnector(sv, model); script = msc.GenerateSourceScript(p, false); Assert.IsTrue(string.IsNullOrEmpty(script), script); RelationDefinitionBase r = model.GetActiveRelations().First(item => item.Constraint == RelationConstraint.PrimaryKey); r.Constraint = RelationConstraint.Unique; r.SourceFragment.Constraints.Single(item => item.ConstraintType == SourceConstraint.PrimaryKeyConstraintTypeName).ConstraintType = SourceConstraint.UniqueConstraintTypeName; msc = new ModelToSourceConnector(sv, model); script = msc.GenerateSourceScript(p, false); Assert.IsTrue(string.IsNullOrEmpty(script), script); }
public void TestFillUnify() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "aspnet_Membership, aspnet_Users"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(false, relation1to1.Unify, true, true, false); Assert.AreEqual(2, model.GetSourceFragments().Count()); Assert.AreEqual(1, model.GetEntities().Count()); Assert.AreEqual(2, model.GetEntities().Single().GetSourceFragments().Count()); }
public void TestAdventureWorksLinq() { SourceView view; BinaryFormatter f = new BinaryFormatter(); ResolveEventHandler d = null; d = (sender, args) => { AppDomain.CurrentDomain.AssemblyResolve -= d; return(typeof(WXMLModel).Assembly); }; AppDomain.CurrentDomain.AssemblyResolve += d; Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream fs = assembly.GetManifestResourceStream( string.Format("{0}.Files.{1}", assembly.GetName().Name, "AdventureWorks.sourceview"))) { Assert.IsNotNull(fs); view = (SourceView)f.Deserialize(fs); } Assert.IsNotNull(view); WXMLModel model = new WXMLModel { LinqSettings = new LinqSettingsDescriptor { ContextName = "TestCtxDataContext" }, Namespace = "LinqCodeGenTests" }; SourceToModelConnector c = new SourceToModelConnector(view, model); c.ApplySourceViewToModel(false, relation1to1.Default, false, false, false); LinqContextGenerator gen = new LinqContextGenerator(model); Console.WriteLine(gen.GenerateCode(LinqToCodedom.CodeDomGenerator.Language.CSharp)); }
public void TestAlter() { var p = new MSSQLProvider(GetTestDB(), null); var sv = p.GetSourceView(); var model = new WXMLModel(); var smc = new SourceToModelConnector(sv, model); smc.ApplySourceViewToModel(false, relation1to1.Hierarchy, true, true, false); Assert.AreEqual(28, model.GetActiveEntities().Count()); Assert.AreEqual(32, model.GetSourceFragments().Count()); var msc = new ModelToSourceConnector(new SourceView(), model); foreach (SourceFragmentDefinition sf in sv.GetSourceFragments().ToArray()) { foreach (SourceFieldDefinition field in sv.GetSourceFields(sf).Where(item => !item.IsFK)) { msc.SourceView.SourceFields.Add(new SourceFieldDefinition(new SourceFragmentDefinition(field.SourceFragment.Identifier, field.SourceFragment.Name, field.SourceFragment.Selector), field.SourceFieldExpression, field.SourceType, field.SourceTypeSize, field.IsNullable, field.IsAutoIncrement, field.DefaultValue)); break; } } string script = msc.GenerateSourceScript(p, false); Assert.IsFalse(string.IsNullOrEmpty(script)); Console.WriteLine(script); Assert.AreEqual(4, new Regex("CREATE TABLE ").Matches(script).Count); Assert.AreEqual(26, new Regex("ALTER TABLE ").Matches(script.Remove(script.IndexOf("--Creating primary keys"))).Count); IEnumerable <SourceConstraint> pks = sv.GetSourceFragments().SelectMany(item => item.Constraints.Where(cns => cns.ConstraintType == SourceConstraint.PrimaryKeyConstraintTypeName)); Assert.AreEqual(pks.Count(), new Regex("PRIMARY KEY CLUSTERED").Matches(script).Count); Assert.AreEqual(2, new Regex("UNIQUE NONCLUSTERED").Matches(script).Count); Assert.AreEqual(1, new Regex("UNIQUE CLUSTERED").Matches(script).Count); Assert.AreEqual(sv.GetSourceFragments().SelectMany(item => item.Constraints.Where(cns => cns.ConstraintType == SourceConstraint.ForeignKeyConstraintTypeName)).Count(), new Regex("FOREIGN KEY").Matches(script).Count); }
public void TestFillHierarchy() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "aspnet_Membership, aspnet_Users"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(2, model.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetEntities().Count()); EntityDefinition membership = model.GetEntity("e_dbo_aspnet_Membership"); Assert.IsNotNull(membership); EntityDefinition users = model.GetEntity("e_dbo_aspnet_Users"); Assert.IsNotNull(users); Assert.AreEqual(membership.BaseEntity, users); Assert.AreEqual(2, membership.GetSourceFragments().Count()); Assert.AreEqual(1, membership.OwnSourceFragments.Count()); Assert.AreEqual(1, users.GetSourceFragments().Count()); Assert.AreEqual(1, users.OwnSourceFragments.Count()); Assert.IsNull(users.BaseEntity); }
public void TestDropEntityProperty() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "aspnet_Paths, aspnet_Applications"); Assert.AreEqual(8, sv.SourceFields.Count); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(4, model.GetEntity("e_dbo_aspnet_Paths").GetActiveProperties().Count()); Assert.IsTrue(sv.SourceFields.Remove(sv.SourceFields.Find(item => item.SourceFieldExpression == "[ApplicationId]" && item.SourceFragment.Name == "[aspnet_Paths]"))); Assert.AreEqual(7, sv.SourceFields.Count); c.ApplySourceViewToModel(true, relation1to1.Default, true, true, false); Assert.AreEqual(3, model.GetEntity("e_dbo_aspnet_Paths").GetActiveProperties().Count()); }
public void TestCompareLinqCtxMoreTables() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "ent1,ent2,1to2,ent3,3to3,complex_pk,complex_fk,aspnet_Applications,aspnet_Membership,aspnet_Users"); Assert.AreEqual(10, sv.GetSourceFragments().Count()); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(false, relation1to1.Default, false, false, false); Assert.AreEqual(10, model.GetSourceFragments().Count()); Assert.AreEqual(8, model.GetEntities().Count()); model.LinqSettings = new LinqSettingsDescriptor { ContextName = "TestCtxDataContext" }; model.Namespace = "LinqCodeGenTests"; LinqContextGenerator gen = new LinqContextGenerator(model, new WXML.CodeDom.WXMLCodeDomGeneratorSettings()); Console.WriteLine(gen.GenerateCode(LinqToCodedom.CodeDomGenerator.Language.CSharp)); Assembly assembly = gen.Compile(LinqToCodedom.CodeDomGenerator.Language.CSharp); Assert.IsNotNull(assembly); Type ctxType = assembly.GetType( string.IsNullOrEmpty(model.Namespace) ? model.LinqSettings.ContextName : model.Namespace + "." + model.LinqSettings.ContextName ); Assert.IsNotNull(ctxType); DataContext ctx = (DataContext)Activator.CreateInstance(ctxType, GetTestDBConnectionString()); Assert.IsNotNull(ctx); ctx.Log = Console.Out; TestCtxDataContext realCtx = new TestCtxDataContext(GetTestDBConnectionString()); Type rctxType = typeof(TestCtxDataContext); foreach (PropertyInfo pi in ctxType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { PropertyInfo rpi = rctxType.GetProperties().SingleOrDefault(item => item.Name == pi.Name); Assert.IsNotNull(rpi, "Cannot find property {0}", pi.Name); Assert.AreEqual(rpi.Attributes, pi.Attributes); Assert.AreEqual(rpi.CanRead, pi.CanRead); Assert.AreEqual(rpi.CanWrite, pi.CanWrite); Assert.AreEqual(rpi.GetGetMethod().Attributes, pi.GetGetMethod().Attributes); IListSource ent1s = (IListSource)pi.GetValue(ctx, null); Assert.IsNotNull(ent1s.GetList()); Assert.AreEqual(((IListSource)rpi.GetValue(realCtx, null)).GetList().Count, ent1s.GetList().Count); } }
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(); }