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; } }
public bool SetConnection(ProductDbType dbType) { if (dbType == ProductDbType.None) { throw new InvalidOperationException(Messages.ErrorMessage007); } else { return(Connect(dbType)); } }
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); } }
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); } }
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); } }
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); }
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); } }
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); } }
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); }
private static string GetScriptsPath(ProductDbType dbType, OperationType operationType, int?version = null) => GetBaseFolder(dbType) + GetOperationFolder(operationType, version);
private static string GetBaseFolder(ProductDbType dbType) => Path.GetDirectoryName(new Uri(Assembly.GetAssembly(typeof(ProductDatabase)).CodeBase).LocalPath) + SqlScriptsFolder + GetDbFolder(dbType);
public bool SetConnection(ProductDbType dbType, DatabaseProperties databaseProperties) => Connect(dbType, databaseProperties);
private bool Connect(ProductDbType dbType) { DatabaseProperties databaseProperties = RequestDbInputsProperties(dbType); return(Connect(dbType, databaseProperties)); }