public void LoadCommand(String connectionString, String outputDirectoryPath, String namespaceName, String databaseKey)
        {
            this.Commands.Clear();

            var sv = this;
            var sc = _SchemaData;

            sc.NamespaceName = namespaceName;
            sc.DatabaseKey   = databaseKey;

            DatabaseSchemaReader db = DatabaseSchemaReader.Create(sc.DatabaseServer, connectionString);

            var tt = db.GetTables();
            var ss = db.GetStoredProcedures();
            var uu = db.GetUserDefinedTableTypes();

            {
                var cm = new ImportTableCommand(sc, connectionString);
                cm.Names.AddRange(tt.Where(el => this.ImportAllObject == true || el.LastAlteredTime > sc.LastExecuteTimeOfImportTable).Select(el => el.Name));
                cm.Names.RemoveAll(name => sc.IgnoreObjects.Exists(el => el.Name == name));
                sv.Commands.Add(cm);
            }
            {
                var cm = new ImportStoredProcedureCommand(sc, connectionString);
                cm.Names.AddRange(ss.Where(el => this.ImportAllObject == true || el.LastAlteredTime > sc.LastExecuteTimeOfImportStoredProcedure).Select(el => el.Name));
                cm.Names.RemoveAll(name => sc.IgnoreObjects.Exists(el => el.Name == name));
                sv.Commands.Add(cm);
            }
            {
                var cm = new ImportUserDefinedTableTypeCommand(sc, connectionString);
                cm.Names.AddRange(uu.Where(el => this.ImportAllObject == true || el.LastAlteredTime > sc.LastExecuteTimeOfImportUserDefinedTableType).Select(el => el.Name));
                cm.Names.RemoveAll(name => sc.IgnoreObjects.Exists(el => el.Name == name));
                sv.Commands.Add(cm);
            }

            {
                var cm = new DeleteObjectCommand(outputDirectoryPath, sc, connectionString);
                cm.Started += (o, ea) =>
                {
                    var tNames = db.GetTables().Select(el => el.Name).ToList();
                    var sNames = db.GetStoredProcedures().Select(el => el.Name).ToList();
                    var uNames = db.GetUserDefinedTableTypes().Select(el => el.Name).ToList();
                    cm.TableNames.AddRange(sc.Tables.Where(el => tNames.Contains(el.Name) == false).Select(el => el.Name));
                    cm.StoredProcedures.AddRange(sc.StoredProcedures.Where(el => sNames.Contains(el.Name) == false).Select(el => el.Name));
                    cm.UserDefinedTableTypes.AddRange(sc.UserDefinedTableTypes.Where(el => uNames.Contains(el.Name) == false).Select(el => el.Name));
                };
                sv.Commands.Add(cm);
            }

            {
                var cm = new GenerateSourceCodeCommand(outputDirectoryPath, sc);
                cm.Started += (o, ea) =>
                {
                    cm.Tables.AddRange(sc.Tables);
                    cm.StoredProcedures.AddRange(sc.StoredProcedures);
                    cm.UserDefinedTableTypes.AddRange(sc.UserDefinedTableTypes);
                };
                sv.Commands.Add(cm);
            }
        }
        private void ImportTable(String connectionString, Int32 offsetHour)
        {
            var l = new List <DatabaseObject>();
            DatabaseSchemaReader db = DatabaseSchemaReader.Create(AValue.SchemaData.DatabaseServer, connectionString);

            foreach (var item in db.GetTables())
            {
                if (this.ImportAllCheckBox.IsChecked == false &&
                    item.LastAlteredTime + TimeSpan.FromHours(offsetHour) < AValue.SchemaData.LastExecuteTimeOfImportTable)
                {
                    continue;
                }
                if (AValue.SchemaData.IgnoreObjects.Exists(el => el.Name == item.Name) == true)
                {
                    continue;
                }

                l.Add(item);
            }

            _Tables.Clear();
            foreach (var item in l.Select(el => CheckedItem.Create(el)))
            {
                item.IsChecked = true;
                _Tables.Add(item);
            }
            this.TableSelectAllCheckBox.IsChecked = true;
        }
        private void ImportStoredProcedure()
        {
            DatabaseSchemaReader db = DatabaseSchemaReader.Create(AValue.SchemaData.DatabaseServer, this.GetSelectedConnectionString());
            var l = db.GetStoredProcedures().ToList();

            _StoredProcedures.Clear();
            foreach (var item in AValue.SchemaData.StoredProcedures.Where(el => l.Exists(sp => sp.Name == el.Name) == false).Select(el => CheckedItem.Create(el)))
            {
                _StoredProcedures.Add(item);
            }
            this.StoredProcedureSelectAllCheckBox.IsChecked = true;
        }
        private void ImportTable()
        {
            DatabaseSchemaReader db = ImportSchemaCommand.CreateDatabaseSchemaReader(AValue.SchemaData.DatabaseServer, this.GetSelectedConnectionString());
            var l = db.GetTables().ToList();

            _Tables.Clear();
            foreach (var item in AValue.SchemaData.Tables.Where(el => l.Exists(t => t.Name == el.Name) == false).Select(el => CheckedItem.Create(el)))
            {
                _Tables.Add(item);
            }
            this.TableSelectAllCheckBox.IsChecked = true;
        }
        public static TableStoredProcedureFactory Create(DatabaseSchemaReader reader)
        {
            var r = reader;

            switch (reader.DatabaseServer)
            {
            case DatabaseServer.SqlServer: return(new SqlServerTableStoredProcedureFactory(r));

            case DatabaseServer.MySql: return(new MySqlTableStoredProcedureFactory(r));

            case DatabaseServer.Oracle:
            case DatabaseServer.PostgreSql: throw new NotSupportedException();

            default: throw new InvalidOperationException();
            }
        }
Beispiel #6
0
        protected override void Execute()
        {
            DatabaseSchemaReader r = this.DatabaseSchemaReader;
            var names      = this.Names;
            var totalCount = names.Count;
            var tt         = new List <Table>();
            var ss         = new List <MetaData.StoredProcedure>();

            for (int i = 0; i < totalCount; i++)
            {
                var name = names[i];
                var t    = r.GetTable(name);

                var tExisted = this.SchemaData.Tables.FirstOrDefault(el => el.Name == t.Name);
                if (tExisted == null)
                {
                    tt.Add(t);
                }
                else
                {
                    foreach (var parameter in t.Columns)
                    {
                        var p = tExisted.Columns.Find(el => el.Name == parameter.Name);
                        if (p == null)
                        {
                            continue;
                        }
                        parameter.EnumName   = p.EnumName;
                        parameter.EnumValues = p.EnumValues;
                    }
                    tt.Add(t);
                }
                //CRUD用のストアドをDBに追加
                ss.AddRange(this.AddStoredProcedure(t));
                this.OnProcessProgress(new ProcessProgressEventArgs(t.Name, i / totalCount));
            }
            //スキーマファイルに追加
            this.AddOrReplace(this.SchemaData.Tables, tt, (item, element) => item.Name == element.Name);
            this.AddOrReplace(this.SchemaData.StoredProcedures, ss, (item, element) => item.Name == element.Name);
            this.SchemaData.LastExecuteTimeOfImportTable = DateTime.Now;
        }
 public TableStoredProcedureFactory(DatabaseSchemaReader reader)
 {
     this.DatabaseSchemaReader = reader;
 }
 public MySqlTableStoredProcedureFactory(DatabaseSchemaReader reader)
     : base(reader)
 {
 }
 public MySqlTableStoredProcedureFactory(DatabaseSchemaReader reader)
     : base(reader)
 {
 }
Beispiel #10
0
 public ImportSchemaCommand(SchemaData schemaData, String connectionString)
 {
     this.SchemaData           = schemaData;
     this.DatabaseSchemaReader = DatabaseSchemaReader.Create(schemaData.DatabaseServer, connectionString);
 }
        private static void BuildSelect(ODataQueryOptions queryOptions, DatabaseSchemaReader.DataSchema.DatabaseTable schema, ref string replaceOver, ref string query)
        {
            if (queryOptions.Select != null)
            {

                foreach (var item in schema.Columns)
                {
                    var linqVerifica = (from queryOption in queryOptions.Select.Properties
                                        where queryOption.ToUpper().Equals(item.Name.ToUpper())
                                        select queryOption).SingleOrDefault();

                    if (string.IsNullOrEmpty(linqVerifica))
                    {

                        query = query.Replace("[" + item.Name + "],", "");
                        query = query.Replace("[" + item.Name + "]", "");

                    }
                    else
                    {
                        replaceOver = "OVER(ORDER BY " + item.Name + ")";
                    }

                }

                char[] delimiters = new char[] { '\r', '\n' };
                string[] parts = query.Split(delimiters,
                 StringSplitOptions.RemoveEmptyEntries);
                parts = query.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                int PartBeforeFrom = 0;
                for (int i = 0; i < parts.Length; i++)
                {
                    if (!string.IsNullOrEmpty(parts[i]) && parts[i].Contains("FROM"))
                    {
                        query = query.Replace(parts[PartBeforeFrom], parts[PartBeforeFrom].Replace(",", ""));
                    }
                    if (!string.IsNullOrEmpty(parts[i].Trim()))
                        PartBeforeFrom = i;

                }
            }
            query = query.Replace("OVER(ORDER BY )", replaceOver);
        }
        private static void BuildOrderBy(ODataQueryOptions queryOptions, DatabaseSchemaReader.DataSchema.DatabaseTable schema, ref string replaceOver, ref string query)
        {
            if (queryOptions.OrderBy != null)
            {
                int countOrder = 0;

                foreach (OrderByProperty itemOrder in queryOptions.OrderBy.Properties)
                {
                    if (countOrder == 0)
                        query = query + " Order By " + itemOrder.RawValue.ToString();
                    else
                        query = query + " , " + itemOrder.RawValue.ToString();

                    countOrder = countOrder + 1;
                }
            }
        }
        private static void BuildFilter(ODataQueryOptions queryOptions, DatabaseSchemaReader.DataSchema.DatabaseTable schema, ref string replaceOver, ref string query)
        {
            if (queryOptions.Filter != null )
            {
                //int countParam
                var binaryOperator = queryOptions.Filter.Expression as BinaryOperatorNode;
                if (binaryOperator != null)
                {
                    var property = binaryOperator.Left as SingleValuePropertyAccessNode ?? binaryOperator.Right as SingleValuePropertyAccessNode;
                    var constant = binaryOperator.Left as ConstantNode ?? binaryOperator.Right as ConstantNode;

                    if (property != null && property.PropertyName != null && constant != null && constant.Value != null)
                    {
                        if(binaryOperator.OperatorKind == BinaryOperatorKind.Equal)
                            query = query.Replace("WHERE", " where " + property.PropertyName + " = '" + constant.LiteralText + "' and ");
                        //Debug.WriteLine("Property: " + property.PropertyName);
                        //Debug.WriteLine("Operator: " + binaryOperator.OperatorKind);
                        //Debug.WriteLine("Value: " + constant.LiteralText);
                    }
                }
            }

            if (queryOptions.Filter != null)
            {
                int countOrder = 0;

                //foreach (var itemQuery in queryOptions.Filter.)
                //{
                //    //if (countOrder == 0)
                //    //    query = query + " Order By " + itemOrder.RawValue.ToString();
                //    //else
                //    //    query = query + " , " + itemOrder.RawValue.ToString();

                //    //countOrder = countOrder + 1;
                //}
            }
        }
 public SqlServerTableStoredProcedureFactory(DatabaseSchemaReader reader)
     : base(reader)
 {
 }
 public SqlServerTableStoredProcedureFactory(DatabaseSchemaReader reader)
     : base(reader)
 {
 }
Beispiel #16
0
 private void RunCodeWriter(DirectoryInfo directory, string ns, bool readStoredProcedures, DatabaseSchemaReader.CodeGen.CodeTarget codeTarget)
 {
     var runner = new CodeWriterRunner(_databaseSchema, directory, ns, readStoredProcedures);
     runner.CodeTarget = codeTarget;
     if (readStoredProcedures)
     {
         toolStripStatusLabel1.Text = @"Reading stored procedures";
     }
     if (!backgroundWorker1.IsBusy)
     {
         backgroundWorker1.RunWorkerAsync(runner);
     }
 }