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;
 }
示例#2
0
        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;
 }
示例#4
0
 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;
 }
示例#5
0
 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;
 }
示例#6
0
 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();
     }
 }
示例#7
0
 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;
 }
示例#8
0
 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);
         }
     } 
 }
示例#9
0
 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;
     }
 }
示例#10
0
 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;
 }
示例#11
0
 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;
 }
示例#12
0
 public abstract string GenerateTables(Schema schema);
示例#13
0
 public abstract string GenerateStoredProcedures(Schema schema);
示例#14
0
 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;
 }
示例#15
0
 public abstract string Generate(Schema schema);
示例#16
0
 public DalGenOptionsDialog(Schema schema)
 {
     InitializeComponent();
     this.schema = schema;
     lblPlatform.Text = schema.Platform;
 }
示例#17
0
 public abstract string GenerateInterface(Schema schema);
示例#18
0
 public TreeBuilder(Schema schema)
 {
     this.schema = schema;
 }
示例#19
0
 public abstract string GenerateClass(Schema schema);
示例#20
0
 public abstract string GenerateEntities(Schema schema);