예제 #1
0
        private bool Connect(ProductDbType dbType, DatabaseProperties databaseProperties)
        {
            IDatabaseFunctions databaseFunctions;

            if (dbType == ProductDbType.Oracle)
            {
                databaseFunctions = new OracleOperationFunctions(databaseProperties);
            }
            else
            {
                databaseFunctions = new SqlServerOperationFunctions(databaseProperties);
            }

            try
            {
                _isConnectionDefined = databaseFunctions.TestConnection();
                DatabaseFunctions    = databaseFunctions;
                return(_isConnectionDefined);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                throw ex;
            }
        }
예제 #2
0
 public bool SetConnection(ProductDbType dbType)
 {
     if (dbType == ProductDbType.None)
     {
         throw new InvalidOperationException(Messages.ErrorMessage007);
     }
     else
     {
         return(Connect(dbType));
     }
 }
예제 #3
0
        private static void SetConnectionStartDatabaseOperation(ProductDbType dbType, DatabaseProperties databaseProperties, string operation)
        {
            var productDatabase = new ProductDatabase();

            if (productDatabase.SetConnection(dbType, databaseProperties))
            {
                OperationType operationType = productDatabase.GetOperationType(operation);
                productDatabase.StartDatabaseOperation(operationType);
            }
            else
            {
                throw new Exception(Messages.ErrorMessage001);
            }
        }
예제 #4
0
 private static string GetDbFolder(ProductDbType dbType)
 {
     if (dbType == ProductDbType.Oracle)
     {
         return(OracleFolder);
     }
     else if (dbType == ProductDbType.SqlServer)
     {
         return(SqlServerFolder);
     }
     else
     {
         throw new Exception(Messages.ErrorMessage006);
     }
 }
예제 #5
0
        private static void SelectDatabase(ProductDatabase productDatabase)
        {
            Console.WriteLine("Type to select database type:");
            Console.WriteLine("(O) - Oracle");
            Console.WriteLine("(S) - SQL Server");

            ProductDbType dbType = productDatabase.GetDatabaseType(Console.ReadLine());

            if (productDatabase.SetConnection(dbType))
            {
                SelectOperation(productDatabase);
            }
            else
            {
                throw new Exception(Messages.ErrorMessage001);
            }
        }
예제 #6
0
        public static List <string> ListFolders(ProductDbType dbType, OperationType operationType, int?currentVersion = null, int?updateVersion = null)
        {
            Dictionary <int, string> folderList = new Dictionary <int, string>();

            if (dbType == ProductDbType.Oracle)
            {
                folderList = OracleListFolder;
            }
            else if (dbType == ProductDbType.SqlServer)
            {
                folderList = SqlServerListFolder;
            }

            if (operationType == OperationType.Install)
            {
                return(folderList
                       .OrderBy(o => o.Key)
                       .Select(s => GetScriptsPath(dbType, operationType) + s.Value)
                       .ToList());
            }
            else if (operationType == OperationType.Update)
            {
                if (currentVersion != null)
                {
                    List <string> updateFolders = new List <string>();

                    for (int i = currentVersion.Value + 1; i <= updateVersion.Value; i++)
                    {
                        updateFolders.AddRange(
                            folderList
                            .OrderBy(o => o.Key)
                            .Select(s => GetScriptsPath(dbType, operationType, i) + s.Value)
                            .ToList()
                            );
                    }
                    return(updateFolders);
                }
                else
                {
                    throw new ArgumentException(Messages.ErrorMessage014);
                }
            }

            throw new ArgumentException(Messages.ErrorMessage007);
        }
예제 #7
0
        private DatabaseProperties RequestDbInputsProperties(ProductDbType dbType)
        {
            string dbUser     = null;
            string dbPassword = null;

            if (dbType == ProductDbType.SqlServer)
            {
                bool isTrustedConnection = RequestSqlServerTrustedConnection();
                Console.WriteLine("Enter Sql Server Database Name:");
                string databaseName = Console.ReadLine();

                if (!isTrustedConnection)
                {
                    dbUser     = RequestDatabaseUser();
                    dbPassword = RequestDatabasePassword();
                }

                Console.WriteLine("Enter the Server name:");
                string serverName = Console.ReadLine();

                return(new DatabaseProperties(dbUser, dbPassword, serverName, databaseName, isTrustedConnection));
            }
            else if (dbType == ProductDbType.Oracle)
            {
                dbUser     = RequestDatabaseUser();
                dbPassword = RequestDatabasePassword();

                Console.WriteLine("Enter the TNS connection string:");
                string tnsOrServerConnection = Console.ReadLine();
                Console.WriteLine("Enter data TABLESPACE:");
                string tablespaceData = Console.ReadLine().ToUpper();
                Console.WriteLine("Enter index TABLESPACE:");
                string tablespaceIndex = Console.ReadLine().ToUpper();

                return(new DatabaseProperties(dbUser, dbPassword, tnsOrServerConnection, tablespaceData, tablespaceIndex));
            }
            else
            {
                throw new Exception(Messages.ErrorMessage006);
            }
        }
예제 #8
0
        public static bool CreateSqlScriptFile(ProductDbType dbType, string fileName, string fileContent)
        {
            string filePath = $@"{GetBaseFolder(dbType)}\{fileName}.sql";

            if (File.Exists(filePath))
            {
                othersLogger.Error(Messages.ErrorMessage025(filePath));
            }

            using var file = File.CreateText(filePath);
            file.Write(fileContent);
            file.Close();

            if (File.Exists(filePath))
            {
                othersLogger.Info(Messages.Message017(filePath));
                return(true);
            }
            else
            {
                othersLogger.Error(Messages.ErrorMessage025(filePath));
                return(false);
            }
        }
예제 #9
0
 public static string GetConnectionString(DatabaseProperties databaseProperties, ProductDbType dbType)
 {
     if (dbType == ProductDbType.Oracle)
     {
         return(string.Format(_oracleConnectionString, databaseProperties.DatabaseUser, databaseProperties.DatabasePassword, databaseProperties.ServerOrTns));
     }
     else if (dbType == ProductDbType.SqlServer)
     {
         if (databaseProperties.IsTrustedConnection)
         {
             return(string.Format(_sqlServerTrustedConnectionString, databaseProperties.ServerOrTns, databaseProperties.DatabaseName));
         }
         else
         {
             return(string.Format(_sqlServerConnectionString, databaseProperties.ServerOrTns, databaseProperties.DatabaseName, databaseProperties.DatabaseUser, databaseProperties.DatabasePassword));
         }
     }
     return(null);
 }
예제 #10
0
 private static string GetScriptsPath(ProductDbType dbType, OperationType operationType, int?version = null) =>
 GetBaseFolder(dbType) + GetOperationFolder(operationType, version);
예제 #11
0
 private static string GetBaseFolder(ProductDbType dbType) =>
 Path.GetDirectoryName(new Uri(Assembly.GetAssembly(typeof(ProductDatabase)).CodeBase).LocalPath) + SqlScriptsFolder + GetDbFolder(dbType);
예제 #12
0
 public bool SetConnection(ProductDbType dbType, DatabaseProperties databaseProperties) =>
 Connect(dbType, databaseProperties);
예제 #13
0
        private bool Connect(ProductDbType dbType)
        {
            DatabaseProperties databaseProperties = RequestDbInputsProperties(dbType);

            return(Connect(dbType, databaseProperties));
        }