Esempio n. 1
0
 private static void CreateDefinitionAccessorCode()
 {
     Functions.AspNetMvc.CSharp.DefinitionAccessorCreator.Create();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerDefCompleted"),
         Consoles.Types.Success);
 }
Esempio n. 2
0
        private static void ConfigureTableSet(string generalTableName)
        {
            Consoles.Write(generalTableName, Consoles.Types.Info);
            var deletedTableName           = generalTableName + "_deleted";
            var historyTableName           = generalTableName + "_history";
            var columnDefinitionCollection = Def.ColumnDefinitionCollection
                                             .Where(o => o.TableName == generalTableName)
                                             .Where(o => !o.NotUpdate)
                                             .Where(o => o.JoinTableName.IsNullOrEmpty())
                                             .Where(o => o.Calc.IsNullOrEmpty())
                                             .OrderBy(o => o.No)
                                             .ToList();
            var columnDefinitionHistoryCollection = columnDefinitionCollection
                                                    .Where(o => o.History > 0)
                                                    .OrderBy(o => o.History);

            ConfigureTablePart(
                generalTableName,
                generalTableName,
                Sqls.TableTypes.Normal,
                columnDefinitionCollection);
            ConfigureTablePart(
                generalTableName,
                deletedTableName,
                Sqls.TableTypes.Deleted,
                columnDefinitionCollection);
            ConfigureTablePart(
                generalTableName,
                historyTableName,
                Sqls.TableTypes.History,
                columnDefinitionHistoryCollection);
        }
Esempio n. 3
0
 private static void CreateMvcCode(string target)
 {
     Functions.AspNetMvc.CSharp.MvcCreator.Create(target);
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerMvcCompleted"),
         Consoles.Types.Success);
 }
 private static void MigrateTable(string tableName, string identity)
 {
     using (var pconn = new NpgsqlConnection(Parameters.Rds.OwnerConnectionString))
     {
         pconn.OpenAsync();
         using (var sconn = new SqlConnection(Parameters.Migration.SourceConnectionString))
         {
             sconn.Open();
             try
             {
                 MigrateTable(
                     tableName: tableName,
                     identity: identity,
                     pconn: pconn,
                     sconn: sconn);
                 MigrateTable(
                     tableName: tableName + "_deleted",
                     identity: null,
                     pconn: pconn,
                     sconn: sconn);
                 MigrateTable(
                     tableName: tableName + "_history",
                     identity: null,
                     pconn: pconn,
                     sconn: sconn);
             }
             catch (Exception e)
             {
                 Consoles.Write(tableName + ":" + e.Message, Consoles.Types.Info);
             }
             sconn.Close();
         }
         pconn.Close();
     }
 }
Esempio n. 5
0
        internal static void CreateTable(
            string generalTableName,
            string sourceTableName,
            bool old,
            IEnumerable <ColumnDefinition> columnDefinitionCollection,
            IEnumerable <IndexInfo> tableIndexCollection,
            EnumerableRowCollection <DataRow> dbColumnCollection,
            string tableNameTemp = "")
        {
            Consoles.Write(sourceTableName, Consoles.Levels.Info);
            if (tableNameTemp == string.Empty)
            {
                tableNameTemp = sourceTableName;
            }
            var sqlCmd = new SqlCmd(
                Def.Code.Sql_CreateTable,
                SqlCmd.Types.PlainSql,
                Sqls.GetSqlParamCollection());

            sqlCmd.CreateColumn(sourceTableName, columnDefinitionCollection);
            sqlCmd.CreatePk(sourceTableName, columnDefinitionCollection, tableIndexCollection);
            sqlCmd.CreateIx(generalTableName, sourceTableName, old, columnDefinitionCollection);
            sqlCmd.CreateDefault(tableNameTemp, columnDefinitionCollection, dbColumnCollection);
            sqlCmd.DropConstraints(sourceTableName, tableIndexCollection);
            sqlCmd.CommandText = sqlCmd.CommandText.Replace("#TableName#", tableNameTemp);
            Def.GetSqlIoOfAdmin(transactional: true).ExecuteNonQuery(sqlCmd);
        }
Esempio n. 6
0
 private static void MigrateDatabase()
 {
     Functions.AspNetMvc.CSharp.Migrator.MigrateDatabaseAsync();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerMigrationCompleted"),
         Consoles.Types.Success);
 }
Esempio n. 7
0
 private static void CreateSolutionBackup()
 {
     Functions.CodeDefiner.BackupCreater.BackupSolutionFiles();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerBackupCompleted"),
         Consoles.Types.Success);
 }
        private static void Execute(ISqlObjectFactory factory, string connectionString)
        {
            var cn = new TextData(connectionString, ';', '=');

            Consoles.Write(cn["uid"], Consoles.Types.Info);
            if (cn["uid"].EndsWith("_Owner"))
            {
                Def.SqlIoBySa(factory).ExecuteNonQuery(
                    factory: factory,
                    dbTransaction: null,
                    dbConnection: null,
                    commandText:
                    Def.Sql.GrantPrivilegeAdmin
                    .Replace("#Uid#", cn["uid"])
                    .Replace("#ServiceName#", Environments.ServiceName));
            }
            else
            {
                Def.SqlIoByAdmin(factory).ExecuteNonQuery(
                    factory: factory,
                    dbTransaction: null,
                    dbConnection: null,
                    commandText:
                    Def.Sql.GrantPrivilegeUser
                    .Replace("#Uid#", cn["uid"])
                    .Replace("#ServiceName#", Environments.ServiceName));
            }
        }
        private static void MigrateTable(
            string tableName,
            NpgsqlConnection pconn,
            SqlConnection sconn,
            string suffix = "")
        {
            Consoles.Write(tableName, Consoles.Types.Info);
            var scmd = new SqlCommand(
                cmdText: $"select * from [{tableName}];",
                connection: sconn);

            using (var reader = scmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    var columns = new List <string>();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        columns.Add(reader.GetName(i));
                    }
                    var pcmd = new NpgsqlCommand(
                        cmdText:
                        $"insert into \"{tableName}\"" +
                        $"({columns.Select(columnName => "\"" + columnName + "\"").Join()})" +
                        $"values" +
                        $"({columns.Select(columnName => "@ip" + columnName).Join()});",
                        connection: pconn);
                    columns.ForEach(columnName =>
                                    pcmd.Parameters.AddWithValue(
                                        "@ip" + columnName,
                                        reader[columnName]));
                    pcmd.ExecuteNonQuery();
                }
            }
        }
Esempio n. 10
0
 private static void WriteErrorToConsole(IEnumerable <string> args)
 {
     Consoles.Write(
         "Incorrect argument. {0}".Params(args.Join(" ")),
         Consoles.Types.Error,
         abort: true);
 }
        private static void ConfigureTableSet(string generalTableName)
        {
            Consoles.Write(generalTableName, Consoles.Types.Info);
            var deletedTableName           = generalTableName + "_deleted";
            var historyTableName           = generalTableName + "_history";
            var columnDefinitionCollection = Def.ColumnDefinitionCollection
                                             .Where(o => o.TableName == generalTableName)
                                             .Where(o => !o.NotUpdate)
                                             .Where(o => o.JoinTableName == string.Empty)
                                             .Where(o => o.Calc == string.Empty)
                                             .OrderBy(o => o.No);
            var columnDefinitionHistoryCollection = columnDefinitionCollection
                                                    .Where(o => o.History > 0)
                                                    .OrderBy(o => o.History);

            ConfigureTablePart(
                generalTableName,
                generalTableName,
                false,
                columnDefinitionCollection);
            ConfigureTablePart(
                generalTableName,
                deletedTableName,
                false,
                columnDefinitionCollection);
            ConfigureTablePart(
                generalTableName,
                historyTableName,
                true,
                columnDefinitionHistoryCollection);
        }
Esempio n. 12
0
        internal static void CreateTable(
            string generalTableName,
            string sourceTableName,
            Sqls.TableTypes tableType,
            IEnumerable <ColumnDefinition> columnDefinitionCollection,
            IEnumerable <IndexInfo> tableIndexCollection,
            EnumerableRowCollection <DataRow> rdsColumnCollection,
            string tableNameTemp = "")
        {
            Consoles.Write(sourceTableName, Consoles.Types.Info);
            if (tableNameTemp.IsNullOrEmpty())
            {
                tableNameTemp = sourceTableName;
            }
            var sqlStatement = new SqlStatement(
                Def.Sql.CreateTable,
                Sqls.SqlParamCollection());

            sqlStatement.CreateColumn(sourceTableName, columnDefinitionCollection);
            sqlStatement.CreatePk(sourceTableName, columnDefinitionCollection, tableIndexCollection);
            sqlStatement.CreateIx(generalTableName, sourceTableName, tableType, columnDefinitionCollection);
            sqlStatement.CreateDefault(tableNameTemp, columnDefinitionCollection);
            sqlStatement.DropConstraint(sourceTableName, tableIndexCollection);
            sqlStatement.CommandText = sqlStatement.CommandText.Replace("#TableName#", tableNameTemp);
            Def.SqlIoByAdmin(transactional: true).ExecuteNonQuery(sqlStatement);
        }
 internal static void Configure()
 {
     Def.TableNameCollection().ForEach(generalTableName =>
     {
         try
         {
             ConfigureTableSet(generalTableName);
         }
         catch (System.Data.SqlClient.SqlException e)
         {
             Consoles.Write($"[{e.Number}] {e.Message}", Consoles.Types.Error);
         }
         catch (System.Exception e)
         {
             Consoles.Write($"[{generalTableName}]: {e}", Consoles.Types.Error);
         }
     });
     try
     {
         ConfigureFullTextIndex();
     }
     catch (System.Data.SqlClient.SqlException e)
     {
         Consoles.Write($"[{e.Number}] {e.Message}", Consoles.Types.Error);
     }
     catch (System.Exception e)
     {
         Consoles.Write($"[{nameof(ConfigureFullTextIndex)}]: {e}", Consoles.Types.Error);
     }
 }
Esempio n. 14
0
 private static void CreateCssCode()
 {
     Functions.Web.Styles.CssCreator.Create();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerCssCompleted"),
         Consoles.Types.Success);
 }
Esempio n. 15
0
 private static void ConfigureDatabase()
 {
     TryOpenConnections();
     Functions.SqlServer.Configurator.Configure();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerRdsCompleted"),
         Consoles.Types.Success);
 }
Esempio n. 16
0
 private static void ConfigureDatabase(ISqlObjectFactory factory)
 {
     TryOpenConnections(factory);
     Functions.Rds.Configurator.Configure(factory);
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerRdsCompleted"),
         Consoles.Types.Success);
 }
 private static void CreateDatabase(ISqlObjectFactory factory, string databaseName)
 {
     Consoles.Write(Environments.ServiceName, Consoles.Types.Info);
     Def.SqlIoBySa(factory).ExecuteNonQuery(
         factory: factory,
         dbTransaction: null,
         dbConnection: null,
         commandText: Def.Sql.CreateDatabase.Replace("#InitialCatalog#", databaseName));
 }
Esempio n. 18
0
 private static IEnumerable <string> PropertyNameCollection(CssDefinition cssDefinition)
 {
     Consoles.Write(cssDefinition.Id, Consoles.Types.Info);
     return(typeof(CssDefinition).GetMembers()
            .Where(o => o.Name != "Id")
            .Where(o => !o.Name.IsNullOrEmpty())
            .Where(o => !cssDefinition[o.Name].ToStr().IsNullOrEmpty())
            .Select(o => o.Name));
 }
Esempio n. 19
0
 private static void CreateCssCode()
 {
     Performances.Record(MethodBase.GetCurrentMethod().Name);
     Functions.Web.Styles.CssCreator.Create();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerCssCompleted"),
         Consoles.Types.Success);
     Performances.Record(MethodBase.GetCurrentMethod().Name);
 }
Esempio n. 20
0
 private static void CreateSolutionBackup()
 {
     Performances.Record(MethodBase.GetCurrentMethod().Name);
     Functions.CodeDefiner.BackupCreater.BackupSolutionFiles();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerBackupCompleted"),
         Consoles.Types.Success);
     Performances.Record(MethodBase.GetCurrentMethod().Name);
 }
Esempio n. 21
0
 private static void InsertTestData()
 {
     Performances.Record(MethodBase.GetCurrentMethod().Name);
     Functions.SqlServer.TestData.Insert();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerInsertTestDataCompleted"),
         Consoles.Types.Success);
     Performances.Record(MethodBase.GetCurrentMethod().Name);
 }
Esempio n. 22
0
 private static void CreateMvcCode(string target)
 {
     Performances.Record(MethodBase.GetCurrentMethod().Name);
     Functions.AspNetMvc.CSharp.MvcCreator.Create(target);
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerMvcCompleted"),
         Consoles.Types.Success);
     Performances.Record(MethodBase.GetCurrentMethod().Name);
 }
Esempio n. 23
0
        private static void ImportByXls(string filePath)
        {
            Consoles.Write(Path.GetFileName(filePath), Consoles.Types.Info);
            var tempFile = new FileInfo(Files.CopyToTemp(filePath, Directories.Temp()));

            UpdateOrInsertToTable(
                new FileInfo(filePath).Name.Replace("import_", string.Empty).FileNameOnly(),
                new XlsIo(tempFile.FullName));
            tempFile.Delete();
        }
Esempio n. 24
0
 private static void ConfigureDatabase()
 {
     TryOpenConnections();
     Performances.Record(MethodBase.GetCurrentMethod().Name);
     Functions.SqlServer.Configurator.Configure();
     Consoles.Write(
         DisplayAccessor.Displays.Get("CodeDefinerRdsCompleted"),
         Consoles.Types.Success);
     Performances.Record(MethodBase.GetCurrentMethod().Name);
 }
Esempio n. 25
0
        public void Save(string logsPath)
        {
            var csvLineCollection = new SortedSet <string>();

            this.ForEach(data => csvLineCollection.Add("{0, 16}".Params(
                                                           data.Value.TimeElapsed.ToString("#,0.0000")) + "\t" + data.Key));
            var csv = csvLineCollection.Reverse().JoinReturn();

            Consoles.Write("\r\n" + csv, Consoles.Types.Info);
            csv.Write(Path.Combine(logsPath, "Performance" + Strings.NewGuid() + ".csv"));
        }
Esempio n. 26
0
        private static void TryOpenConnections()
        {
            int    number;
            string message;

            if (!Sqls.TryOpenConnections(
                    out number, out message, Parameters.Rds.SaConnectionString))
            {
                Consoles.Write($"[{number}] {message}", Consoles.Types.Error, true);
            }
        }
Esempio n. 27
0
        private static void ImportByCsv(string filePath)
        {
            Consoles.Write(Path.GetFileName(filePath), Consoles.Types.Info);
            var tableName = new FileInfo(filePath).Name
                            .Replace("import_", string.Empty).FileNameOnly();

            if (Environments.RdsProvider == "Local")
            {
                BulkInsert(filePath, tableName);
            }
        }
        private static void Execute(string connectionString)
        {
            var cn = new TextData(connectionString, ';', '=');

            Consoles.Write(cn["uid"], Consoles.Types.Info);
            Spids.Kill(cn["uid"]);
            Def.SqlIoBySa().ExecuteNonQuery(
                CommandText(cn["uid"])
                .Replace("#Uid#", cn["uid"])
                .Replace("#Pwd#", cn["pwd"])
                .Replace("#ServiceName#", Environments.ServiceName));
        }
Esempio n. 29
0
        private void ReadXls()
        {
            FileInfo xls = null;

            if (new FileInfo(Path).Exists)
            {
                try
                {
                    xls          = new FileInfo(Path);
                    AccessStatus = Files.AccessStatuses.Read;
                }
                catch (Exception e)
                {
                    AccessStatus = Files.AccessStatuses.Failed;
                    Consoles.Write(e.Message, Consoles.Types.Error, abort: true);
                    return;
                }
            }
            else
            {
                AccessStatus = Files.AccessStatuses.NotFound;
                return;
            }
            var document     = SpreadsheetDocument.Open(xls.FullName, isEditable: false);
            var workbookPart = document.WorkbookPart;
            var sheet        = Sheet(workbookPart);

            if (sheet == null)
            {
                return;
            }
            (workbookPart.GetPartById(sheet.Id) as WorksheetPart).Worksheet.Descendants <Row>()
            .ForEach(row =>
            {
                if (row.RowIndex == 1)
                {
                    row.Elements <Cell>().ForEach(xlsCell => XlsSheet.Columns
                                                  .Add(CellValue(workbookPart, xlsCell)
                                                       .Replace("\n", "\r\n")));
                }
                else
                {
                    XlsSheet.Add(new XlsRow(row.Elements <Cell>().Select((o, i) =>
                                                                         new
                    {
                        Index = XlsSheet.Columns[i],
                        Value = CellValue(workbookPart, o).Replace("\n", "\r\n")
                    })
                                            .ToDictionary(o => o.Index, o => o.Value)));
                }
            });
            document.Close();
        }
Esempio n. 30
0
        private static void CreateZipFile(string tempPath)
        {
            Consoles.Write(
                text: DisplayAccessor.Displays.Get("InCompression"), type: Consoles.Types.Info);
            var zipFileName = ZipFileName();

            Archives.Zip(
                zipFilePath: tempPath,
                sourceFilePath: Path.Combine(Parameters.General.SolutionBackupPath, zipFileName),
                distinationFileName: zipFileName,
                tempPath: Directories.Temp());
        }