private void SetErrorDetails(SchemaResult r, Exception ex) { this.LastException = ex; r.Message = ex.Message; r.Success = false; r.StackTrace = ex.StackTrace; }
public SchemaResult AddForeignKey(ForeignKeyColumn fk) { SchemaResult r = new SchemaResult(string.Format("ForeignKey {0} was added.", fk.ReferenceName)); try { if (!this._foreignKeys.Contains(fk)) { this._foreignKeys.Add(fk); } else { ForeignKeyColumn existing = (from efk in this._foreignKeys where efk.Equals(fk) select efk).FirstOrDefault(); existing.AllowNull = fk.AllowNull; existing.DbDataType = fk.DbDataType; existing.Key = fk.Key; existing.MaxLength = fk.MaxLength; existing.Name = fk.Name; existing.ReferencedKey = fk.ReferencedKey; existing.ReferencedTable = fk.ReferencedTable; existing.ReferenceName = fk.ReferenceName; existing.TableName = fk.TableName; } } catch (Exception ex) { SetErrorDetails(r, ex); } return(r); }
/// <summary> /// Generate /// </summary> /// <param name="simpleSchemaJson"></param> /// <returns></returns> public SchemaResult GenerateDao(string simpleSchemaJson, DirectoryInfo compileTo = null, bool keepSource = false, string tempDir = ".\\tmp", string partialsDir = null) { try { bool compile = compileTo != null; SchemaResult result = new SchemaResult("Generation completed"); dynamic rehydrated = JsonConvert.DeserializeObject <dynamic>(simpleSchemaJson); if (rehydrated["nameSpace"] == null)// || rehydrated["schemaName"] == null) { result.ExceptionMessage = "Please specify nameSpace"; result.Message = string.Empty; result.Success = false; } else if (rehydrated["schemaName"] == null) { result.ExceptionMessage = "Please specify schemaName"; result.Message = string.Empty; result.Success = false; } else { string nameSpace = (string)rehydrated["nameSpace"]; string schemaName = (string)rehydrated["schemaName"]; result.Namespace = nameSpace; result.SchemaName = schemaName; List <dynamic> foreignKeys = new List <dynamic>(); SetSchema(schemaName, false); ProcessTables(rehydrated, foreignKeys); ProcessXrefs(rehydrated, foreignKeys); foreach (dynamic fk in foreignKeys) { AddColumn(fk.ForeignKeyTable, new Column(fk.ReferencingColumn, DataTypes.Long)); SetForeignKey(fk.PrimaryTable, fk.ForeignKeyTable, fk.ReferencingColumn); } DirectoryInfo daoDir = new DirectoryInfo(tempDir); if (!daoDir.Exists) { daoDir.Create(); } DaoGenerator generator = GetDaoGenerator(compileTo, keepSource, partialsDir, compile, result, nameSpace, daoDir); generator.Generate(CurrentSchema, daoDir.FullName, partialsDir); result.DaoAssembly = generator.DaoAssemblyFile; } return(result); } catch (Exception ex) { SchemaResult r = new SchemaResult(ex.Message); r.StackTrace = ex.StackTrace ?? ""; r.Success = false; return(r); } }
private static SchemaResult GetErrorResult(Exception ex) { SchemaResult result = new SchemaResult(ex.Message); result.ExceptionMessage = ex.Message; result.Success = false; #if DEBUG result.StackTrace = ex.StackTrace; #endif return(result); }
public SchemaResult AddXref(string left, string right) { try { SchemaDefinition schema = CurrentSchema; XrefTable x = new XrefTable(left, right); SchemaResult result = schema.AddXref(x); if (AutoSave) { schema.Save(); } return(result); } catch (Exception ex) { return(GetErrorResult(ex)); } }
public SchemaResult AddTable(string tableName, string className = null) { try { SchemaDefinition schema = CurrentSchema; Table t = new Table(); t.ClassName = className ?? tableName; t.Name = tableName; SchemaResult result = schema.AddTable(t); if (AutoSave) { schema.Save(); } return(result); } catch (Exception ex) { return(GetErrorResult(ex)); } }
public SchemaResult AddTable(Table table) { SchemaResult r = new SchemaResult(string.Format("Table {0} was added.", table.Name)); try { table.ConnectionName = this.Name; if (this._tables.ContainsKey(table.Name)) { this._tables[table.Name] = table; r.Message = string.Format("Table {0} was updated.", table.Name); } else { this._tables.Add(table.Name, table); } } catch (Exception ex) { SetErrorDetails(r, ex); } return(r); }
public SchemaResult AddXref(XrefTable xref) { SchemaResult r = new SchemaResult(string.Format("XrefTable {0} was added.", xref.Name)); try { xref.ConnectionName = this.Name; if (_xrefs.ContainsKey(xref.Name)) { _xrefs[xref.Name] = xref; r.Message = string.Format("XrefTable {0} was updated.", xref.Name); } else { _xrefs.Add(xref.Name, xref); } } catch (Exception ex) { SetErrorDetails(r, ex); } return(r); }
private DaoGenerator GetDaoGenerator(DirectoryInfo compileTo, bool keepSource, string partialsDir, bool compile, SchemaResult result, string nameSpace, DirectoryInfo daoDir) { RazorBaseTemplate.DefaultInspector = (s) => { }; // turn off output to console DaoGenerator generator = new DaoGenerator(nameSpace); if (compile) { if (!compileTo.Exists) { compileTo.Create(); } generator.GenerateComplete += (gen, s) => { List <DirectoryInfo> daoDirs = new List <DirectoryInfo>(); daoDirs.Add(daoDir); if (!string.IsNullOrEmpty(partialsDir)) { daoDirs.Add(new DirectoryInfo(partialsDir)); } gen.DaoAssemblyFile = Compile(daoDirs.ToArray(), gen, nameSpace, compileTo); if (CompilerErrors != null) { result.Success = false; result.Message = string.Empty; foreach (CompilerError err in GetErrors()) { result.Message = string.Format("{0}\r\nFile=>{1}\r\n{2}:::Line {3}, Column {4}::{5}", result.Message, err.FileName, err.ErrorNumber, err.Line, err.Column, err.ErrorText); } } else { result.Message = string.Format("{0}\r\n{1}", result.Message, "Dao compiled"); result.Success = true; } if (!keepSource) { daoDir.Delete(true); daoDir.Refresh(); if (daoDir.Exists) { daoDir.Delete(); } } }; } return(generator); }