public void CanExtractCacheSchema() { CacheSchemaExtractor schemaExtractor = _serviceRegistry.Get <CacheSchemaExtractor>(); DaoGenerator generator = new DaoGenerator("Premera.Ehri.EnsLib.Data"); generator.Generate(schemaExtractor.Extract(), "C:\\bam\\daoWorkspace\\src"); }
private static void Compile(DirectoryInfo[] dirs, FileInfo file) { DaoGenerator generator = new DaoGenerator(GetNamespace()); CompilerResults results = generator.Compile(dirs, file.FullName); OutputCompilerErrors(results); }
public static void GenerateDaoFromSchema() { string schemaPath = GetArgument("schema"); string nameSpace = GetArgument("nameSpace"); string outputPath = GetPathArgument("output"); outputPath = string.IsNullOrEmpty(outputPath) ? "./Dao_Generated" : outputPath; Args.ThrowIfNullOrEmpty(nameSpace, "specify /nameSpace:<value>"); DaoGenerator daoGenerator = new DaoGenerator(nameSpace) {GenerateQiClasses = false}; daoGenerator.Generate(SchemaDefinition.Load(schemaPath), new HomePath(outputPath)); Message.PrintLine("Generation complete: {0}", ConsoleColor.Green, outputPath); }
public void GenerateSource(string sourcePath) { DirectoryInfo sourceDir = new DirectoryInfo(sourcePath); if (!sourceDir.Exists) { sourceDir.Create(); } DaoGenerator generator = new DaoGenerator(string.IsNullOrEmpty(Namespace) ? "{0}.Generated."._Format(this.GetType().Namespace).RandomLetters(6): Namespace); Subscribe(generator); generator.Generate(GetSchemaDefinition(), sourcePath); }
private void Subscribe(DaoGenerator generator) { if (OnTableStarted != null) { generator.BeforeClassStreamResolved += OnTableStarted; } if (OnGenerateStarted != null) { generator.GenerateStarted += OnGenerateStarted; } if (OnGenerateComplete != null) { generator.GenerateComplete += OnGenerateComplete; } }
/// <summary> /// Instantiate a new instance of TypeDaoGenerator /// </summary> /// <param name="logger"></param> /// <param name="types"></param> public TypeDaoGenerator(ILogger logger = null, IEnumerable <Type> types = null) { _namespace = "TypeDaos"; _daoGenerator = new DaoGenerator(DaoNamespace); _wrapperGenerator = new WrapperGenerator(WrapperNamespace, DaoNamespace); _typeSchemaGenerator = new TypeSchemaGenerator(); _additonalReferenceAssemblies = new HashSet <Assembly>(); TypeSchemaTempPathProvider = (schemaDef, typeSchema) => System.IO.Path.Combine(RuntimeSettings.AppDataFolder, "DaoTemp_{0}"._Format(schemaDef.Name)); _types = new HashSet <Type>(); if (logger != null) { Subscribe(logger); } if (types != null) { AddTypes(types); } }
public void GenerateCSharpOnClick(object sender, EventArgs e) { DaoGenerator generator = new DaoGenerator(); generator.Namespace = Namespace ?? DefaultNamespace; generator.BeforeClassStreamResolved += (s, t) => FormModelBinder.SetByTag("SchemaStatus", "Writing code for {0}"._Format(t.Name)); DirectoryInfo srcDir = GetSourceDir(true); if (MappedSchemaDefinition.SchemaDefinition.Tables.Length == 0) { MessageBox.Show("No tables were found in the current schema.\r\n\r\nExtract or load a schema first.", "No Tables Found", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MappedSchemaDefinition.MapSchemaClassAndPropertyNames(); generator.Generate(MappedSchemaDefinition.SchemaDefinition, srcDir.FullName); } string text = "Code generated to: {0}"._Format(srcDir.FullName); SetStatus(text); }
public static void GenerateShouldUseSpecifiedTargetResolver() { string filePath = MethodBase.GetCurrentMethod().Name; if (File.Exists(filePath)) { File.Delete(filePath); } DaoGenerator generator = new DaoGenerator("Test"); SchemaDefinition schema = GetTestSchema(); generator.DisposeOnComplete = false; generator.Generate(schema, (s) => { return new FileStream(filePath, FileMode.Create); }); string output = File.ReadAllText(filePath); Expect.IsGreaterThan(output.Length, 0); OutLine(output, ConsoleColor.Cyan); SchemaTests.DeleteSchema(schema); }
private static void Generate(SchemaDefinition schema, Action<string> resultInspector = null, bool silent = false) { DirectoryInfo dir = new DirectoryInfo(Arguments["gen"]); if (!dir.Exists) { dir.Create(); } string ns = GetNamespace(); if (resultInspector == null) { resultInspector = (s) => { }; } DaoGenerator generator = new DaoGenerator(ns, resultInspector); if (!silent) { // TODO: define and wireup generator events //generator.BeforeClassParse += BeforeTableHandler; //generator.AfterClassParse += AfterTableHandler; } generator.Generate(schema, dir.FullName); }
public static void GenerateShouldFireAssociatedEvents() { // TODO: add Query class events (events were added on 08/12/2015) DaoGenerator gen = new DaoGenerator("Test.Ns"); bool? started = false; bool? complete = false; bool? beforeParse = false; bool? afterParse = false; bool? beforeResolved = false; bool? afterResolved = false; bool? beforeWrite = false; bool? afterWrite = false; bool? beforeCollectionParse = false; bool? afterCollectionParse = false; bool? beforeCollectionStreamResolved = false; bool? afterCollectionStreamResolved = false; bool? beforeWriteCollection = false; bool? afterWriteCollection = false; bool? beforeColumnClassParse = false; bool? afterColumnClassParse = false; bool? beforeColumnStreamResolved = false; bool? afterColumnStreamResolved = false; bool? beforeWriteColumns = false; bool? afterWriteColumns = false; gen.GenerateStarted += (g, s) => { started = true; }; gen.GenerateComplete += (g, s) => { complete = true; }; gen.BeforeClassParse += (ns, t) => { beforeParse = true; }; gen.AfterClassParse += (ns, t) => { afterParse = true; }; gen.BeforeClassStreamResolved += (s, t) => { beforeResolved = true; }; gen.AfterClassStreamResolved += (s, t) => { afterResolved = true; }; gen.BeforeWriteClass += (c, s) => { beforeWrite = true; }; gen.AfterWriteClass += (c, s) => { afterWrite = true; }; gen.BeforeCollectionParse += (n, t) => { beforeCollectionParse = true; }; gen.AfterCollectionParse += (n, t) => { afterCollectionParse = true; }; gen.BeforeCollectionStreamResolved += (n, t) => { beforeCollectionStreamResolved = true; }; gen.AfterCollectionStreamResolved += (n, t) => { afterCollectionStreamResolved = true; }; gen.BeforeWriteCollection += (c, s) => { beforeWriteCollection = true; }; gen.AfterWriteCollection += (c, s) => { afterWriteCollection = true; }; gen.BeforeColumnsClassStreamResolved += (s, t) => { beforeColumnStreamResolved = true; }; gen.AfterColumnsClassStreamResolved += (s, t) => { afterColumnStreamResolved = true; }; gen.BeforeWriteColumnsClass += (c, s) => { beforeWriteColumns = true; }; gen.AfterWriteColumnsClass += (c, s) => { afterWriteColumns = true; }; gen.BeforeColumnsClassParse += (c, s) => { beforeColumnClassParse = true; }; gen.AfterColumnsClassParse += (c, s) => { afterColumnClassParse = true; }; gen.Generate(GetTestSchema()); Expect.IsTrue(started.Value, "GenerateStarted didn't fire"); Expect.IsTrue(complete.Value, "GenerateComplete didn't fire"); Expect.IsTrue(beforeParse.Value, "BeforeParse didn't fire"); Expect.IsTrue(afterParse.Value, "AfterParse didn't fire"); Expect.IsTrue(beforeResolved.Value, "BeforeStreamResolved didn't fire"); Expect.IsTrue(afterResolved.Value, "AfterStreamResolved didn't fire"); Expect.IsTrue(beforeWrite.Value, "BeforeWriteResult didn't fire"); Expect.IsTrue(afterWrite.Value, "AfterWriteResult didn't fire"); Expect.IsTrue(beforeCollectionParse.Value, "BeforeCollectionParse didn't fire"); Expect.IsTrue(afterCollectionParse.Value, "AfterCollectionParse didn't fire"); Expect.IsTrue(beforeCollectionStreamResolved.Value, "BeforeCollectionStreamResolved didn't fire"); Expect.IsTrue(afterCollectionStreamResolved.Value, "AfterCollectionStreamResolved didn't fire"); Expect.IsTrue(beforeWriteCollection.Value, "BeforeWriteCollection didn't fire"); Expect.IsTrue(afterWriteCollection.Value, "AfterWriteCollection didn't fire"); Expect.IsTrue(beforeColumnStreamResolved.Value, "BeforeColumnStreamResolved didn't fire"); Expect.IsTrue(afterColumnStreamResolved.Value, "AfterColumnStreamResolved didn't fire"); Expect.IsTrue(beforeWriteColumns.Value, "BeforeWriteColumns didn't fire"); Expect.IsTrue(afterWriteColumns.Value, "AfterWriteColumns didn't fire"); Expect.IsTrue(beforeColumnClassParse.Value, "BeforeColumnClassParse didn't fire"); Expect.IsTrue(afterColumnClassParse.Value, "AfterColumnClassParse didn't fire"); }
private static void Compile(DirectoryInfo[] dirs, FileInfo file) { DaoGenerator generator = new DaoGenerator(GetNamespace()); CompilerResults results = AdHocCSharpCompiler.CompileDirectories(dirs, file.Name, DaoGenerator.DefaultReferenceAssemblies.ToArray(), false); OutputCompilerErrors(results); }