Ejemplo n.º 1
0
        public Result Handle(Input input)
        {
            var result = new Result();

            if (string.IsNullOrWhiteSpace(input.SelectedText))
            {
                result.ErrorMessage = "Editörden bir text seçiniz.(Tablo adı)";
                return(result);
            }

            var selectedText = ProcedureTextUtility.ClearProcedureText(input.SelectedText);

            var dbItemNameParser = DbItemNameInfoParser.Parse(selectedText);

            var connectionInfo = FindDbItemContainerDatabaseConnectionInfo(input, result);

            if (connectionInfo == null)
            {
                return(result);
            }

            var table = GetTableInfo(new SqlDatabase(connectionInfo.ConnectionStringDev), dbItemNameParser);

            var generator = new ContractBodyGenerator
            {
                Columns    = table.Columns,
                Padding    = 4,
                RegionText = dbItemNameParser.ToString()
            };

            generator.GenerateDatabaseColumns();
            result.ContractClassBody = generator.GeneratedString;

            return(result);
        }
Ejemplo n.º 2
0
 static string ClearProcedure(string procedureName)
 {
     return(ProcedureTextUtility.ClearProcedureText(procedureName));
 }
Ejemplo n.º 3
0
        public void Handle()
        {
            var selectedText = _input.ProcedureName;

            if (string.IsNullOrWhiteSpace(selectedText))
            {
                CreateNewSqlFile(Environment.NewLine, "Temp Sql File");
                return;
            }

            selectedText = ProcedureTextUtility.ClearProcedureText(selectedText);

            string query = null;

            var dbItemNameParser = DbItemNameInfoParser.Parse(selectedText);

            var procedureName = dbItemNameParser.Name;
            var schemaName    = dbItemNameParser.SchemaName;
            var databaseName  = dbItemNameParser.DatabaseName;

            var foundCount = 0;

            foreach (var info in DatabaseConnectionStrings.Connections)
            {
                if (databaseName != null && info.DatabaseName != databaseName)
                {
                    continue;
                }

                Result.ProcedureContainerDatabaseConnectionInfo = info;

                var dev  = new SqlDatabase(info.ConnectionStringDev);
                var prep = new SqlDatabase(info.ConnectionStringPrep);

                using (dev)
                {
                    using (prep)
                    {
                        string devVersion  = null;
                        string prepVersion = null;
                        var    found       = false;

                        var fileName = info.DatabaseName + "." + selectedText;

                        query = "SELECT sm.definition,SCHEMA_NAME(O.schema_id) AS SchemaName " +
                                "  from sys.sql_modules sm WITH(NOLOCK) INNER JOIN " +
                                "       sys.objects o WITH(NOLOCK) ON sm.object_id = o.object_id " +
                                " where o.name = " + " '" + procedureName + "' AND SCHEMA_NAME(O.schema_id)= '" + schemaName + "'";

                        dev.CommandText = query;
                        var dr = dev.ExecuteReader();
                        while (dr.Read())
                        {
                            devVersion = dr.GetString(0);
                            found      = true;
                            foundCount++;
                            break;
                        }
                        dr.Close();

                        prep.CommandText = query;
                        dr = prep.ExecuteReader();
                        while (dr.Read())
                        {
                            prepVersion = dr.GetString(0);
                            found       = true;
                            foundCount++;
                            break;
                        }

                        dr.Close();

                        // maybe table information was requested.
                        if (!found)
                        {
                            if (prep.IsTable(procedureName, schemaName))
                            {
                                prepVersion = sp_Help(prep, procedureName, schemaName);
                                found       = true;
                                foundCount++;
                            }

                            if (dev.IsTable(procedureName, schemaName))
                            {
                                devVersion = sp_Help(dev, procedureName, schemaName);
                                found      = true;
                                foundCount++;
                            }
                        }

                        if (found)
                        {
                            var isEqual = Comparer.Compare(devVersion, prepVersion);
                            if (isEqual)
                            {
                                CreateNewSqlFile(devVersion, fileName);
                            }
                            else
                            {
                                if (devVersion != null)
                                {
                                    CreateNewSqlFile(devVersion, "DEV - " + fileName);
                                }
                                if (prepVersion != null)
                                {
                                    CreateNewSqlFile(prepVersion, "PREP - " + fileName);
                                }
                            }

                            // do not search in other databases.
                            return;
                        }
                    }
                }
            }

            if (foundCount == 0)
            {
                Result.ErrorMessage = "Sp bulunamadı.";
            }
        }