public void SaveChangesUnitTest() { //arrange IDBSettings dBSettings = new DBSettings(); IEmployeeActivityDBContext employeeActivityDBContext = new EmployeeActivityDBContext(dBSettings); var tics = DateTime.Now.Ticks; EmployeeActivity employeeActivity = new EmployeeActivity() { FirstName = string.Concat("FName_", tics), LastName = string.Concat("LName_", tics), EmailAddress = string.Concat(tics, "@email.com"), ActivityName = string.Concat("Activity_Name_", tics), Comments = string.Concat("Comments_", tics) }; //act var employeeActivityDbSet = employeeActivityDBContext.EmployeeActivity; employeeActivityDbSet.Add(employeeActivity); employeeActivityDBContext.SaveChanges(); var result = employeeActivityDbSet.Where(x => x.FirstName.Equals(employeeActivity.FirstName)).FirstOrDefault(); //assert Assert.NotEmpty(dBSettings.ConnectionString); Assert.NotNull(employeeActivity); Assert.Equal(result, employeeActivity); }
public SqlConnectionHolder(string databaseFilename, DBSettings?dBSettings = null) { settings = dBSettings ?? new DBSettings(); Source = databaseFilename; Connection = new SqliteConnection($"Data source={Source}"); Connection.Open(); string command = string.Format(CultureInfo.InvariantCulture, PRAGMAS, settings.Synchronous, settings.JournalMode, settings.PageSize, settings.LockingMode); using var cmd = new SqliteCommand(command, Connection); cmd.ExecuteNonQuery(); if (settings.BatchSize < 1) { settings.BatchSize = 1; } // Max number of variables determined by sqlite library at compile time if (settings.BatchSize > 199) { Log.Warning("Maximum batch size is 199. Setting Batch size to 199"); settings.BatchSize = 199; } innerQueue = new WriteObject[settings.BatchSize]; _ = Task.Factory.StartNew(() => KeepFlushQueue()); }
public List <int> ExecuteAll(string spName, ConnectionType connectionType, List <DynamicParameters> paramList) { IRepository <DapperEntity> repository = new Repository <DapperEntity>( new DapperEntity(DBSettings.GetDBConnectionString(connectionType)), connectionType); return(repository.ExecuteAll(spName, paramList)); }
public async void AddEmployeeActivityByFormTest() { //arrange DBSettings dBSettings = new DBSettings(); IMemoryCache memoryCache = MemoryCacheHelper.GetMemoryCache(); CacheSettings cacheSettings = new CacheSettings(); EmployeeActivityByDapperRepository employeeActivityRepository = new EmployeeActivityByDapperRepository(dBSettings, memoryCache, cacheSettings); EmployeeActivityApiByDapperController employeeActivityController = new EmployeeActivityApiByDapperController(employeeActivityRepository); var tics = DateTime.Now.Ticks; EmployeeActivity employeeActivity = new EmployeeActivity() { FirstName = string.Concat("FName_", tics), LastName = string.Concat("LName_", tics), EmailAddress = string.Concat(tics, "@email.com"), ActivityName = string.Concat("Activity_Name_", tics), Comments = string.Concat("Comments_", tics) }; //act var result = await employeeActivityController.AddEmployeeActivityByBody(employeeActivity); //assert Assert.NotEqual <int>(0, result); }
public string ExecuteScalarQuery(string spName, ConnectionType connectionType, DynamicParameters param = null) { IRepository <DapperEntity> repository = new Repository <DapperEntity>( new DapperEntity(DBSettings.GetDBConnectionString(connectionType)), connectionType); return(repository.ExecuteScalarQuery(spName, param, null, null)); }
public IEnumerable <object> Execute(string spName, ConnectionType connectionType, DynamicParameters param = null) { IRepository <DapperEntity> repository = new Repository <DapperEntity>( new DapperEntity(DBSettings.GetDBConnectionString(connectionType)), connectionType); return(repository.Execute(spName, param).ToList()); }
public void AddEmployeeTest() { //arrange IDBSettings dBSettings = new DBSettings(); IMemoryCache memoryCache = MemoryCacheHelper.GetMemoryCache(); CacheSettings cacheSettings = new CacheSettings(); EmployeeActivityByDapperRepository employeeActivityProvider = new EmployeeActivityByDapperRepository(dBSettings, memoryCache, cacheSettings); var tics = DateTime.Now.Ticks; EmployeeActivity employeeActivity = new EmployeeActivity() { FirstName = string.Concat("dapper_", tics), LastName = string.Concat("LName_", tics), EmailAddress = string.Concat(tics, "@email.com"), ActivityName = string.Concat("Activity_Name_", tics), Comments = string.Concat("Comments_", tics) }; //act var result = employeeActivityProvider.AddEmployee(employeeActivity); //assert Assert.NotEmpty(dBSettings.ConnectionString); Assert.NotNull(employeeActivity); Assert.NotEqual <int>(0, result); }
public SqlConnectionHolder(string databaseFilename, DBSettings?dBSettings = null) { settings = dBSettings ?? new DBSettings(); Source = databaseFilename; Connection = new SqliteConnection($"Data source={Source}"); Connection.Open(); string command = string.Format(CultureInfo.InvariantCulture, PRAGMAS, settings.Synchronous, settings.JournalMode, settings.PageSize, settings.LockingMode); using var cmd = new SqliteCommand(command, Connection); cmd.ExecuteNonQuery(); if (settings.BatchSize < 1) { settings.BatchSize = 1; } StartWriter(); }
private void LoadServers() { try { //Retrieve the available servers. List <string> ListResult = DBSettings.GetServers(); for (int j = 0; j < ListResult.Count; j++) { cmbServer.Items.Add(ListResult[j]); } if (this.cmbServer.Items.Count > 0) { this.cmbServer.SelectedIndex = 0; } else { this.cmbServer.Text = "<No available SQL Servers>"; } } catch (Exception ex) { MessageBox.ShowBox("MessageID74", BMC_Icon.Error); ExceptionManager.Publish(ex); } }
void LoadLanguages() { //Retrieve the available Languages. try { List <string> ListResult = DBSettings.GetLanguages(ExchangeConfigRegistryEntities.ODBCServer, ExchangeConfigRegistryEntities.ODBCUsername, ExchangeConfigRegistryEntities.ODBCPwd); for (int j = 0; j < ListResult.Count; j++) { cmbDefaultLang.Items.Add(ListResult[j]); } if (this.cmbDefaultLang.Items.Count > 0) { this.cmbDefaultLang.SelectedIndex = 0; } else { this.cmbDefaultLang.Text = "<No available SQL languages>"; } } catch (Exception ex) { ExceptionManager.Publish(ex); } }
public void AddEmployeeActivityTest() { //arrange DBSettings dBSettings = new DBSettings(); IMemoryCache memoryCache = MemoryCacheHelper.GetMemoryCache(); CacheSettings cacheSettings = new CacheSettings(); EmployeeActivityDBContext employeeActivityDBContext = new EmployeeActivityDBContext(dBSettings); EmployeeActivityRepository employeeActivityRepository = new EmployeeActivityRepository(employeeActivityDBContext, memoryCache, cacheSettings); EmployeeActivityController employeeActivityController = new EmployeeActivityController(employeeActivityRepository); var tics = DateTime.Now.Ticks; EmployeeActivityViewModel employeeActivity = new EmployeeActivityViewModel() { FirstName = string.Concat("FName_", tics), LastName = string.Concat("LName_", tics), EmailAddress = string.Concat(tics, "@email.com"), ActivityName = string.Concat("Activity_Name_", tics), Comments = string.Concat("Comments_", tics) }; //act var result = employeeActivityController.AddEmployeeActivity(employeeActivity); //assert var viewResult = Assert.IsType <RedirectToActionResult>(result); }
private void bnDbSettings_Click(object sender, RoutedEventArgs e) { if (DBSettings.ConfigureDB().Value) { LoadData(); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddMvc().AddXmlDataContractSerializerFormatters(); services.Configure <Settings>(option => { var mainBD = new DBSettings(); Configuration.GetSection("MainDBSetting").Bind(mainBD); option.MainDBConnection = mainBD; option.ChachedEmployee = Configuration.GetSection("Chached").GetValue <bool>("Employee"); option.ChachedPosts = Configuration.GetSection("Chached").GetValue <bool>("Post"); }); services.AddSingleton <ICacheStore>(new CacheStore(Configuration.GetSection("Chached").GetValue <bool>("Employee"), Configuration.GetSection("Chached").GetValue <bool>("Post"))); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "Logrocon API", Description = "ASP.NET Core Web API" }); try { c.IncludeXmlComments(GetXmlCommentsPath()); } catch { } }); }
public static MySqlConnection GetDBConnection(DBSettings dbSettings) { String connectionString = dbSettings.ConnectionString.Value; MySqlConnection conn = new MySqlConnection(connectionString); return(conn); }
public IEnumerable <object> QuerymultipleRecords(List <ModelBase> modelObject, string spName, ConnectionType connectionType, DynamicParameters param = null) { IRepository <DapperEntity> repository = new Repository <DapperEntity>( new DapperEntity(DBSettings.GetDBConnectionString(connectionType)), connectionType); return(repository.QuerymultipleRecords(modelObject, spName, param)); }
private static void SetupDatabase(CommandOptions opts) { var dbSettings = new DBSettings() { ShardingFactor = opts.Shards, LowMemoryUsage = opts.LowMemoryUsage }; SetupOrDie(opts.DatabaseFilename, dbSettings); }
public void ConnectionStringIsNotEmptyTest() { //arrange IDBSettings dBSettings = new DBSettings(); //act //assert Assert.NotEmpty(dBSettings.ConnectionString); }
//private void GetDatabases() //{ // //Retrieve the available Databases. // List<string> objDBNames = DBSettings.GetDatabases(cmbServers.SelectedItem.ToString(), txtUser.Text, txtPassword.Text); // if (objDBNames != null) // { // for (int i = 0; i < objDBNames.Count; i++) // { // cmbDatabases.Items.Add(objDBNames[i]); // } // } // if (this.cmbDatabases.Items.Count > 0) // this.cmbDatabases.SelectedIndex = 0; // else // this.cmbDatabases.Text = "NorthWind"; //} private void btnRestore_Click(object sender, EventArgs e) { try { bool bResult = false; btnRestore.Enabled = false; string strDataBase = string.Empty; Dictionary <string, string> objServer = new Dictionary <string, string>(); objServer.Add("SERVER", cmbServers.SelectedItem.ToString()); objServer.Add("UID", txtUser.Text); objServer.Add("PASSWORD", txtPassword.Text); strDataBase = txtDataBases.Text; objServer.Add("DATABASE", strDataBase); if (ConfigManager.Read("Startuppath") != null) { txtDBFile.Text = ConfigManager.Read("Startuppath"); } objServer.Add("LOCATION", txtDBFile.Text); LogManager.WriteLog("LOCATION:" + txtDBFile.Text.ToString(), LogManager.enumLogLevel.Debug); bool bDBExists = false; string sSQLServerDetails = GetConnectionString(); bDBExists = DBSettings.CheckDBExists(sSQLServerDetails, strDataBase, 60); if (bDBExists == true) { MessageBox.Show(strDataBase + " has not been restored. The DB already exists!", "Restore DB", MessageBoxButtons.OK, MessageBoxIcon.Information); LogManager.WriteLog(strDataBase + " has not been restored. The DB already exists!", LogManager.enumLogLevel.Info); } else { MessageBox.Show("The Restore Process Running for " + strDataBase + "." + " Wait for the success dialog before doing anything else!", "Restore DB", MessageBoxButtons.OK, MessageBoxIcon.Information); bResult = DBSettings.RestoreDB(strType, objServer); if (bResult) { //MessageBox.Show("The database " + strDataBase + " has been restored.", "Restore DB", MessageBoxButtons.OK, MessageBoxIcon.Information); LogManager.WriteLog("The database " + strDataBase + " has been restored.", LogManager.enumLogLevel.Info); } else { MessageBox.Show("The Restore Process failed for " + strDataBase + ".", "Restore DB", MessageBoxButtons.OK, MessageBoxIcon.Error); LogManager.WriteLog("The Restore Process failed for " + strDataBase + ".", LogManager.enumLogLevel.Info); } } } catch (Exception ex) { ExceptionManager.Publish(ex); LogManager.WriteLog("btnRestore_Click:" + ex.Message + ex.Source.ToString(), LogManager.enumLogLevel.Error); } finally { btnRestore.Enabled = true; } }
public EventoScopedService(IProconRepository repositorioProcon, ICrmRepository repositorioCrm, IMapper servicoMapper, IOptions <DBSettings> dbsettingsOptions, IOptions <CrmApiSettings> crmApisettingsOptions, ILogger <EventoScopedService> logger) { _repositorioProcon = repositorioProcon; _repositorioCrm = repositorioCrm; _servicoMapper = servicoMapper; _logger = logger; _crmApiSettingsOptions = crmApisettingsOptions.Value; _dbSettingsOptions = dbsettingsOptions.Value; }
public APIService(ILogger <APIService> logger, IConfiguration config) { _logger = logger; _config = config; DBSettings settings = _config.GetSection("DBSettings").Get <DBSettings>(); var client = new MongoClient(settings.ConnectionString); var database = client.GetDatabase(settings.DatabaseName); _data = database.GetCollection <DataFields>(settings.DBCollectionName); }
// // Returns the database connection string based on the database // connection setting json file. // // Function throws an exception if the connection string for // "MySql" is not specified and the configuration file for // database connection string is not specified or inaccessible. // public static string GetConnectionString() { ConfigurationBuilder builder = null; IConfiguration config = null; string dbSettingsFile = Configuration["DBSettings"]; _logger.Trace($"Config file for DB settings = {dbSettingsFile}."); if (null == dbSettingsFile) { throw new ArgumentNullException( "DBSettings", "Missing config file for database connection " + "string settings."); } builder = new ConfigurationBuilder(); builder.SetBasePath(Directory.GetCurrentDirectory()); builder.AddJsonFile(dbSettingsFile, optional: false, reloadOnChange: true); config = builder.Build(); IConfigurationSection dbConfig = config.GetSection("MySql"); DBSettings mySqlSettings = new DBSettings(); mySqlSettings.Server = dbConfig["Server"]; _logger.Debug($"Server = {mySqlSettings.Server}."); mySqlSettings.Database = dbConfig["Database"]; _logger.Debug($"Database = {mySqlSettings.Database}."); mySqlSettings.UserID = dbConfig["UserID"]; mySqlSettings.UserPasswd = dbConfig["UserPasswd"]; mySqlSettings.Pooling = dbConfig["Pooling"]; _logger.Debug($"Pooling = {mySqlSettings.Pooling}."); string cs = mySqlSettings.ConnectionString; return(cs); }
/// <summary> /// .ctor /// </summary> /// <param name="dataAccessFactory"></param> /// <param name="tableName"></param> /// <param name="configName"></param> public BaseDataRepository(IDataAccessFactory dataAccessFactory, string tableName, string configName) { _dataAccessFactory = dataAccessFactory; _tableName = tableName; _configName = configName; var dataProperty = DBSettings.GetDatabaseProperty(ConfigName); if (dataProperty != null) { _readDateType = dataProperty.Reader.DatabaseType; _writerDataType = dataProperty.Writer.DatabaseType; } }
public Startup(IHostingEnvironment env, IConfiguration configuration) { Configuration = configuration; DBSettings = new DBSettings(); if (env.IsDevelopment()) { Configuration.GetSection("DBSettingsDev").Bind(DBSettings); } else { Configuration.GetSection("DBSettings").Bind(DBSettings); } }
private void Application_Startup(object sender, StartupEventArgs e) { try { LogManager.WriteLog("Entering Cash Desk Operator Client Configuration EXE", LogManager.enumLogLevel.Debug); BMCRegistryHelper.ActiveInstallationType = BMCCategorizedInstallationTypes.Exchange; LogManager.WriteLog("BMCRegistryHelper.InstallationType is :" + BMCRegistryHelper.InstallationType, LogManager.enumLogLevel.Debug); CreateLogsFolder(); LogManager.WriteLog("Inside Application_Startup", LogManager.enumLogLevel.Info); DataSet dsInitialSettings = DBSettings.GetInitialSettings(oCommonUtilities.CreateInstance().GetConnectionString()); if (dsInitialSettings == null) { Settings.OnScreenKeyboard = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("OnScreenKeyboard")); } else { Settings.OnScreenKeyboard = dsInitialSettings.Tables[0].Rows[0]["USE_ON_SCREEN_KEYBOARD"].ToString() != string.Empty ? Convert.ToBoolean(dsInitialSettings.Tables[0].Rows[0]["USE_ON_SCREEN_KEYBOARD"].ToString()) : Convert.ToBoolean(ConfigurationManager.AppSettings.Get("OnScreenKeyboard")); } try { Settings.IsLoginRequired = true; if (ConfigurationManager.AppSettings.Get("IsLoginRequired") != null) { Settings.IsLoginRequired = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsLoginRequired")); } } catch (Exception ex) { ExceptionManager.Publish(ex); } if (Settings.IsLoginRequired) { StartupUri = new Uri("Login.xaml", UriKind.Relative); } else { StartupUri = new Uri("MainScreen.xaml", UriKind.Relative); } } catch (Exception ex) { ExceptionManager.Publish(ex); MessageBox.ShowBox("MessageID33", BMC_Icon.Error); } }
public bool Validate() { DBSettings settings = DBSettings.Default; Dictionary <String, object> userDbRow = new Dictionary <string, object>() { { settings.UserRoot.UserName, Username }, { settings.UserRoot.Password, Password } }; //DataBaseAccess db = new DataBaseAccess(DBSettings.Default.DBConnectStr); //IsUserValidated = db.MatchRow(settings.UserRoot.TableName, userDbRow); IsUserValidated = true; return(true); }
public void EmployeeActivityDataSetIsNotNull() { //arrange IDBSettings dBSettings = new DBSettings(); IEmployeeActivityDBContext employeeActivityDBContext = new EmployeeActivityDBContext(dBSettings); //act var employeeActivity = employeeActivityDBContext.EmployeeActivity; //assert Assert.NotEmpty(dBSettings.ConnectionString); Assert.NotNull(employeeActivity); }
public DBService(DBSettings DBSettings) { try { _DBSettings = DBSettings; this.Client = new MongoClient(_DBSettings.Connection); this.PoduleDB = Client.GetDatabase(_DBSettings.DBName); this.Users = PoduleDB.GetCollection <User>(_DBSettings.Collection); } catch (Exception e) { Console.WriteLine("Error creating DBService in AuthService: " + e); } }
/// <summary> /// Gets the first active DB found in the applications settings. /// </summary> /// <param name="dbConfigurations">The db configurations.</param> /// <returns></returns> private void _GetActiveDb(XmlNodeList dbConfigurations) { DBSettings temp; foreach (XmlNode dbConfig in dbConfigurations) { temp = new DBSettings(dbConfig); if (temp.IsActive) { Db = temp; return; } } }
public void GetEmployeeActivitiesTest() { //arrange IDBSettings dBSettings = new DBSettings(); IMemoryCache memoryCache = MemoryCacheHelper.GetMemoryCache(); CacheSettings cacheSettings = new CacheSettings(); EmployeeActivityByDapperRepository employeeActivityProvider = new EmployeeActivityByDapperRepository(dBSettings, memoryCache, cacheSettings); //act var result = employeeActivityProvider.GetEmployeeActivities().ToList(); //assert Assert.NotNull(result); Assert.NotEmpty(result); }
public static bool TestConnection(DBSettings settings) { bool result = false; if (DBContext.TestConnection(settings.Connection)) { result = true; } else { result = false; } return(result); }