Ejemplo n.º 1
0
        private void ReportDiff(GeneratedDaoAssemblyInfo info, TypeSchema typeSchema)
        {
            OldInfoString = info.TypeSchemaInfo ?? string.Empty;
            NewInfoString = typeSchema.ToString();
            DiffReport diff = DiffReport.Create(OldInfoString, NewInfoString);
            // TODO: inject this and log
            ConsoleDiffReportFormatter diffFormatter = new ConsoleDiffReportFormatter(diff);

            diffFormatter.Format(); // outputs to console
            FireEvent(SchemaDifferenceDetected, new SchemaDifferenceEventArgs {
                GeneratedDaoAssemblyInfo = info, TypeSchema = typeSchema, DiffReport = diff
            });
        }
Ejemplo n.º 2
0
        private void GenerateOrThrow(SchemaDefinition schema, TypeSchema typeSchema)
        {
            string tempPath = TypeSchemaTempPathProvider(schema, typeSchema);

            if (Directory.Exists(tempPath))
            {
                string newPath = tempPath.GetNextDirectoryName();
                Directory.Move(tempPath, newPath);
            }
            if (!GenerateDaoAssembly(typeSchema, out CompilationException compilationException))
            {
                throw new DaoGenerationException(SchemaName, typeSchema.Hash, Types.ToArray(), compilationException);
            }
        }
Ejemplo n.º 3
0
 public WrapperModel(Type pocoType, TypeSchema schema, string wrapperNamespace = "TypeWrappers", string daoNameSpace = "Daos")
 {
     BaseType         = pocoType;
     WrapperNamespace = wrapperNamespace;
     DaoNamespace     = daoNameSpace;
     TypeNamespace    = pocoType.Namespace;
     TypeName         = pocoType.Name.TrimNonLetters();
     WrapperTypeName  = pocoType.ToTypeString(false).Replace(TypeName, $"{TypeName}Wrapper");
     BaseTypeName     = pocoType.ToTypeString(false);
     ForeignKeys      = schema.ForeignKeys.Where(fk => fk.PrimaryKeyType.Equals(pocoType)).ToArray();
     ChildPrimaryKeys = schema.ForeignKeys.Where(fk => fk.ForeignKeyType.Equals(pocoType)).ToArray();
     LeftXrefs        = schema.Xrefs.Where(xref => xref.Left.Equals(pocoType)).Select(xref => TypeXrefModel.FromTypeXref(xref, daoNameSpace)).ToArray();
     RightXrefs       = schema.Xrefs.Where(xref => xref.Right.Equals(pocoType)).Select(xref => TypeXrefModel.FromTypeXref(xref, daoNameSpace)).ToArray();
 }
Ejemplo n.º 4
0
        protected internal bool GenerateDaoAssembly(TypeSchema typeSchema, out CompilationException compilationEx)
        {
            try
            {
                compilationEx = null;
                SchemaDefinition schema       = SchemaDefinitionCreateResult.SchemaDefinition;
                string           assemblyName = "{0}.dll"._Format(schema.Name);

                string                   writeSourceTo = TypeSchemaTempPathProvider(schema, typeSchema);
                CompilerResults          results       = GenerateAndCompile(assemblyName, writeSourceTo);
                GeneratedDaoAssemblyInfo info          = new GeneratedDaoAssemblyInfo(schema.Name, results)
                {
                    TypeSchema       = typeSchema,
                    SchemaDefinition = schema
                };
                info.Save();

                GeneratedAssemblies.SetAssemblyInfo(schema.Name, info);

                Message = "Type Dao Generation completed successfully";
                FireEvent(GenerateDaoAssemblySucceeded, new GenerateDaoAssemblyEventArgs(info));

                TryDeleteDaoTemp(writeSourceTo);

                return(true);
            }
            catch (CompilationException ex)
            {
                Message = ex.Message;
                if (!string.IsNullOrEmpty(ex.StackTrace))
                {
                    Message = "{0}:\r\nStackTrace: {1}"._Format(Message, ex.StackTrace);
                }
                compilationEx = ex;
                FireEvent(GenerateDaoAssemblyFailed, EventArgs.Empty);
                return(false);
            }
        }
Ejemplo n.º 5
0
        public Assembly GetDaoAssembly(bool useExisting = true)
        {
            GeneratedDaoAssemblyInfo info = GeneratedAssemblies.GetGeneratedAssemblyInfo(SchemaName) as GeneratedDaoAssemblyInfo;

            if (info == null)
            {
                TypeSchema       typeSchema = SchemaDefinitionCreateResult.TypeSchema;
                SchemaDefinition schemaDef  = SchemaDefinitionCreateResult.SchemaDefinition;
                string           schemaName = schemaDef.Name;
                string           schemaHash = typeSchema.Hash;
                info = new GeneratedDaoAssemblyInfo(schemaName, typeSchema, schemaDef);

                // check for the info file
                if (info.InfoFileExists && useExisting) // load it from file if it exists
                {
                    info = info.InfoFilePath.FromJsonFile <GeneratedDaoAssemblyInfo>();
                    if (info.TypeSchemaHash == null || !info.TypeSchemaHash.Equals(schemaHash)) // regenerate if the hashes don't match
                    {
                        ReportDiff(info, typeSchema);
                        GenerateOrThrow(schemaDef, typeSchema);
                    }
                    else
                    {
                        GeneratedAssemblies.SetAssemblyInfo(schemaName, info);
                    }
                }
                else
                {
                    GenerateOrThrow(schemaDef, typeSchema);
                }

                info = GeneratedAssemblies.GetGeneratedAssemblyInfo(SchemaName) as GeneratedDaoAssemblyInfo;
            }

            return(info.GetAssembly());
        }
Ejemplo n.º 6
0
 public void Generate(TypeSchema schema, string writeTo)
 {
     TypeSchema = schema;
     WriteSource(writeTo);
 }
Ejemplo n.º 7
0
 public WrapperGenerator(string wrapperNamespace, string daoNamespace, TypeSchema typeSchema = null)
 {
     WrapperNamespace = wrapperNamespace;
     DaoNamespace     = daoNamespace;
     TypeSchema       = typeSchema;
 }
Ejemplo n.º 8
0
 protected internal void GenerateWrappers(TypeSchema schema, string writeSourceTo)
 {
     _wrapperGenerator.Generate(schema, writeSourceTo);
 }
 public TypeSchemaPropertyManager(TypeSchema typeSchema)
 {
     TypeSchema = typeSchema;
 }
Ejemplo n.º 10
0
 public GeneratedDaoAssemblyInfo(string infoFileName, TypeSchema typeSchema, SchemaDefinition schemaDefintion)
     : base(infoFileName)
 {
     TypeSchema       = typeSchema;
     SchemaDefinition = schemaDefintion;
 }
 public SchemaDefinitionCreateResult(SchemaDefinition schemaDefinition, TypeSchema typeSchema, KeyColumn[] missingKeyColumns = null, ForeignKeyColumn[] missingForeignKeyColumns = null)
 {
     this.SchemaDefinition = schemaDefinition;
     this.TypeSchema       = typeSchema;
     this.Warnings         = new SchemaWarnings(missingKeyColumns, missingForeignKeyColumns);
 }