public override string GenerateClass(Schema schema) { CodeWriter writer = new CodeWriter(); string className = "DataStore"; writer.WriteLine(USING_STRING); writer.WriteLine(); writer.WriteLine("namespace DataAccess"); writer.WriteLine("{"); writer.PushIdent(); writer.WriteLineFormat("public class {0}: DatabaseContext, IDataStore", className); writer.WriteLine("{"); writer.PushIdent(); writer.WriteLineFormat("public {0}(IDbConnection connection, IDbTransaction transaction) : base(connection, transaction) {{ }}", className); writer.WriteLineFormat("public {0}(IDbConnection connection) : base(connection, null) {{ }}", className); writer.WriteLine(); foreach (StoredProcedure sp in schema.StoredProcedures) { string methodHeader = "public " + generateMethodHeader(sp); string methodBody = GenerateMethodBody(sp); writer.WriteLine(methodHeader); writer.WriteLine(methodBody); writer.WriteLine(); } writer.PopIdent(); writer.WriteLine("}"); writer.PopIdent(); writer.WriteLine("}"); return writer.Code; }
public static Schema CreateFromConnection(ConnectionInfo conInfo) { Schema schema = new Schema(); schema.CatalogName = conInfo.Catalog; schema.Name = conInfo.Schema; IConnectionFactory fac = null; ISqlConf sqlConf = null; if (conInfo.Type == ConnectionType.SqlServer) { fac = new SqlServerConnectionFactory(); sqlConf = new SQLServerDefaultConf(); schema.Platform = "SQLSERVER"; } else if (conInfo.Type == ConnectionType.MySql) { fac = new MySqlConnectionFactory(); sqlConf = new MySqlDefaultConf(); schema.Platform = "MYSQL"; } using (IDbConnection conn = fac.CreateConnection(conInfo)) { conn.Open(); IDatabaseExplorer dbExplorer = new DatabaseExplorer(conn, sqlConf); schema.Tables = dbExplorer.GetTables(schema).ToList<Table>(); schema.StoredProcedures = dbExplorer.GetStoredProcedures(schema).ToList<StoredProcedure>(); } return schema; }
public override string Generate(Schema schema) { CodeWriter writer = new CodeWriter(); writer.WriteLine("----- TABLES -----"); writer.Write(GenerateTables(schema)); writer.WriteLine("----- STORED PROCEDURES -----"); writer.Write(GenerateStoredProcedures(schema)); return writer.Code; }
public override string GenerateTables(Schema schema) { CodeWriter writer = new CodeWriter(); foreach(Table table in schema.Tables) { writer.WriteLineFormat("-- {0} --", table.Name); writer.WriteLine(GenerateSqlCreate(table)); writer.WriteLine(); } return writer.Code; }
public override string GenerateStoredProcedures(Schema schema) { CodeWriter writer = new CodeWriter(); foreach (StoredProcedure sp in schema.StoredProcedures) { writer.WriteLineFormat("-- {0} --", sp.Name); sp.Definition = DUMMY_BODY; writer.WriteLine(GenerateStoredProcedureCreate(sp)); writer.WriteLine(); } return writer.Code; }
private void open() { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "JSON files (*.json)|*.json"; DialogResult result = dlg.ShowDialog(); if (result == DialogResult.OK) { string fn = dlg.FileName; StreamReader rdr = new StreamReader(fn); string json = rdr.ReadToEnd(); this.schema = Schema.CreateFromJson(json); textBox1.Text = this.schema.ToJson(); buildView(); } }
public override string Generate(Schema schema) { CodeWriter writer = new CodeWriter(); foreach (Table table in schema.Tables) { writer.WriteLineFormat("-- {0} --", table.Name); writer.WriteLine(GenerateInsert(table)); writer.WriteLineFormat("GO"); writer.WriteLine(GenerateUpdate(table)); writer.WriteLine(GenerateDelete(table)); writer.WriteLine(GenerateGetAll(table)); writer.WriteLine("GO"); writer.WriteLine(GenerateGet(table)); writer.WriteLine(); } return writer.Code; }
private void connect() { ConnectionForm cf = new ConnectionForm(); DialogResult result = cf.ShowDialog(); if (result == DialogResult.OK) { try { this.schema = SchemaBuilder.CreateFromConnection(cf.ConnectionInfo); textBox1.Text = this.schema.ToJson(); buildView(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public override void Execute(IDictionary<string, object> scope) { try { this.Status = OperationStatus.RUNNING; SqlConnection conn = scope["CONNECTION"] as SqlConnection; DatabaseExplorer exp = new DatabaseExplorer(conn, new SQLServerDefaultConf()); Schema schema = new Schema(); schema.Name = this.schemaName; schema.Tables = exp.GetTables(schema).ToList<Table>(); schema.StoredProcedures = exp.GetStoredProcedures(schema).ToList<StoredProcedure>(); scope["SCHEMA"] = schema; this.Status = OperationStatus.COMPLETED; } catch (Exception ex) { this.Exception = ex; this.Status = OperationStatus.FAILED; throw ex; } }
public override string GenerateInterface(Schema schema) { CodeWriter writer = new CodeWriter(); writer.WriteLine(USING_STRING); writer.WriteLine(); writer.WriteLine("namespace DataAccess"); writer.WriteLine("{"); writer.PushIdent(); writer.WriteLine("public interface IDataStore"); writer.WriteLine("{"); writer.PushIdent(); foreach (StoredProcedure sp in schema.StoredProcedures) { string methodHeader = generateMethodHeader(sp) + ";"; writer.WriteLine(methodHeader); } writer.PopIdent(); writer.WriteLine("}"); writer.PopIdent(); writer.WriteLine("}"); return writer.Code; }
public override string GenerateEntities(Schema schema) { CodeWriter writer = new CodeWriter(); writer.WriteLine(USING_STRING); writer.WriteLine(); writer.WriteLine("namespace DataAccess"); writer.WriteLine("{"); writer.PushIdent(); foreach (Table table in schema.Tables) { writer.WriteLine(GenerateEntity(table)); writer.WriteLine(); } writer.PopIdent(); writer.WriteLine("}"); return writer.Code; }
public abstract string GenerateTables(Schema schema);
public abstract string GenerateStoredProcedures(Schema schema);
private IDataAccessGenerator selectDalGenerator(Schema schema) { IDataAccessGenerator gen = null; DalGenOptionsDialog dlg = new DalGenOptionsDialog(schema); DialogResult r = dlg.ShowDialog(); if (r == DialogResult.OK) { gen = dlg.SelectedGenerator; } return gen; }
public abstract string Generate(Schema schema);
public DalGenOptionsDialog(Schema schema) { InitializeComponent(); this.schema = schema; lblPlatform.Text = schema.Platform; }
public abstract string GenerateInterface(Schema schema);
public TreeBuilder(Schema schema) { this.schema = schema; }
public abstract string GenerateClass(Schema schema);
public abstract string GenerateEntities(Schema schema);