Esempio n. 1
0
        public virtual EnsureSchemaStatus TryEnsureSchema(Type type, bool force, out Exception ex, ILogger logger = null)
        {
            EnsureSchemaStatus result = EnsureSchemaStatus.Invalid;

            ex = null;
            try
            {
                string schemaName = Dao.RealConnectionName(type);
                if (!SchemaNames.Contains(schemaName) || force)
                {
                    _schemaNames.Add(schemaName);
                    SchemaWriter schema = ServiceProvider.Get <SchemaWriter>();
                    schema.WriteSchemaScript(type);
                    ExecuteSql(schema, ServiceProvider.Get <IParameterBuilder>());
                    result = EnsureSchemaStatus.Success;
                }
                else
                {
                    result = EnsureSchemaStatus.AlreadyDone;
                }
            }
            catch (Exception e)
            {
                ex     = e;
                result = EnsureSchemaStatus.Error;
                logger = logger ?? Log.Default;
                logger.AddEntry("Non fatal error occurred trying to write schema for type {0}: {1}", LogEventType.Warning, ex, type.Name, ex.Message);
            }
            return(result);
        }
Esempio n. 2
0
		private static void WriteSqlFile(FileInfo daoFile, FileInfo sqlFile, SqlDialect dialect)
		{
			Assembly daoAssembly = Assembly.LoadFrom(daoFile.FullName);
			SchemaWriter schemaWriter = SchemaWriters[dialect]();
			schemaWriter.WriteSchemaScript(daoAssembly);
			schemaWriter.ToString().SafeWriteToFile(sqlFile.FullName);
		}