private bool AddToPasswordHistory(string userName, string newPassword, int historyCount) { using (DbCommand command = DatabaseProvider.DbProviderFactory.CreateCommand()) { object result; InitializeGetHistoryCount(command, userName); result = DatabaseProvider.ExecuteScalar(command); if (result != null && Convert.ToInt32(result) >= historyCount) { int count = Convert.ToInt32(result) - historyCount; int itemCount = 0; InitializeGetUserPasswordHistory(command, userName); using (var reader = DatabaseProvider.ExecuteReader(command)) { while (reader.Read()) { if (itemCount <= count) { using (DbCommand delCommand = DatabaseProvider.DbProviderFactory.CreateCommand()) { InitializeDeletePasswordHistory(delCommand, reader.GetColumnValue <long>("Id")); DatabaseProvider.ExecuteNonQuery(delCommand); } } itemCount++; } } } InitializeAddToPasswordHistory(command, userName, newPassword); return(DatabaseProvider.ExecuteNonQuery(command) > 0); } }
public virtual User[] GetUsers(Dictionary<string, string> query) { List<User> users; using (var selectCommand = DatabaseProvider.DbProviderFactory.CreateCommand()) { users = new List<User>(); InitializeGetUsersCommand(selectCommand, query); using (var reader = DatabaseProvider.ExecuteReader(selectCommand)) { User user; while (reader.Read()) { user = new User(reader.GetString(0)); user.IsAdmin = (bool)reader["IsAdmin"]; user.Expires = reader.GetColumnValue<DateTime>("Expires"); user.UseCardReader = reader.GetColumnValue<bool>("UseCardReader"); user.FriendlyName = reader.GetColumnValue<string>("FriendlyName"); user.UserType = reader.GetColumnValueOrDefault<string>("UserType"); var extendedName = reader.GetColumnValueOrDefault<string>("ExtendedName"); //resolve to proper format var resolvedName = UserNameResolver.FromDb(user.UserName, extendedName, user.UserType); user.UserName = resolvedName.Item1; user.UserType = resolvedName.Item2; users.Add(user); } } } return users.ToArray(); }
public virtual User [] GetUsers( ) { List <User> users; using (var selectCommand = DatabaseProvider.DbProviderFactory.CreateCommand()) { users = new List <User>(); InitializeGetUsersCommand(selectCommand); using (var reader = DatabaseProvider.ExecuteReader(selectCommand)) { User user; while (reader.Read()) { user = new User(reader.GetColumnValue <string>("UserName")); user.IsAdmin = reader.GetColumnValue <bool>("IsAdmin"); var UserType = reader.GetColumnValueOrDefault <string>("UserType"); var extendedName = reader.GetColumnValueOrDefault <string>("ExtendedName"); var resolvedName = UserNameResolver.FromDb(user.UserName, extendedName, user.UserType); user.UserName = resolvedName.Item1; users.Add(user); } } return(users.ToArray()); } }
public void Calculate_Table_Metrics() { if (_telemetry == null) { return; } string scope = "Database"; Dictionary <string, string> parameters = new Dictionary <string, string>(); using (DatabaseProvider provider = DatabaseProvider.Create("CountStats.sql", Program.Context.ConnectionString)) { var reader = provider.ExecuteReader(); parameters.Add("Database", provider.Database); while (reader.Read()) { for (int col = 1; col < reader.FieldCount; col++) //the first field is table name { parameters["Table"] = reader.GetString(0); parameters["Metric"] = reader.GetName(col); TrackMetric(scope, reader.GetString(0), reader.GetName(col), reader.GetInt64(col), parameters); } } } }
private void GetStatsInDatabase(string connectionString) { if (_telemetry == null) { return; } Dictionary <string, string> parameters = new Dictionary <string, string>(); string scope = "Database"; using (DatabaseProvider provider = DatabaseProvider.Create("CountFileStats.sql", connectionString)) { var reader = provider.ExecuteReader(); parameters.Add("Database", provider.Database); while (reader.Read()) { for (int col = 1; col < reader.FieldCount; col++) //the first field is table name { parameters["Database"] = reader.GetString(0); parameters["Metric"] = reader.GetName(col); TrackMetric(scope, reader.GetString(0), reader.GetName(col), reader.GetInt32(col), parameters); } } } }
public static CategoryCollection GetAllCategories() { CategoryCollection newCollection = new CategoryCollection(); DatabaseProvider myDatabase = new DatabaseProvider(); IDataReader myReader = myDatabase.ExecuteReader("GetAllCategories", CommandType.StoredProcedure); while (myReader.Read()) { Category mycategory = new Category(); mycategory.CategoryId = myReader["CategoryID"] is DBNull ? 0 : Convert.ToInt32(myReader["CategoryID"]); mycategory.CategoryName = myReader["CategoryName"] is DBNull ? string.Empty : myReader["CategoryName"].ToString(); mycategory.Description = myReader["Description"] is DBNull ? string.Empty : myReader["Description"].ToString(); newCollection.Add(mycategory); } return(newCollection); }
public static Category GetCategoryByCategoryId(int categoryId) { Category newCategory = new Category(); DatabaseProvider myDatabase = new DatabaseProvider(); myDatabase.AddinParameters("@CategoryID", DbType.Int32, categoryId); IDataReader myReader = myDatabase.ExecuteReader("SELECT * FROM Categories WHERE CategoryID = @CategoryID", CommandType.Text); while (myReader.Read()) { newCategory.CategoryId = myReader["CategoryID"] is DBNull ? 0 : Convert.ToInt32(myReader["CategoryID"]); newCategory.CategoryName = myReader["CategoryName"] is DBNull ? string.Empty : myReader["CategoryName"].ToString(); newCategory.Description = myReader["Description"] is DBNull ? string.Empty : myReader["Description"].ToString(); } return(newCategory); }
public virtual bool IsUserValid(string userName, SecureString password) { var typ = IntGetuserType(userName); if (IsTypeValidateOnDomain(typ)) { return(IsDomainUserValid(userName, password)); } else if (IsTypeValidateOnExternalIdP(typ)) { return(true); } else { userName = FromInputUserName(userName); using (var command = DatabaseProvider.DbProviderFactory.CreateCommand()) { InitializeIsUserValidCommand(command, userName, GetHashedPassword(password)); using (var reader = DatabaseProvider.ExecuteReader(command)) { if (!reader.Read()) { return(false); } var userType = reader.GetColumnValueOrDefault <string>("UserType"); if (userType == UserType.Temp) { var expires = reader.GetColumnValue <DateTime>("Expires"); if (expires < DateTime.UtcNow) { return(false); } } return(true); } } } }
public ForwardInstance[] GetCleanList() { List <ForwardInstance> list = new List <ForwardInstance>(); using (DbCommand command = DatabaseProvider.DbProviderFactory.CreateCommand()) { InitializeGetCleanListCommand(command); using (IDataReader reader = DatabaseProvider.ExecuteReader(command)) { while (reader.Read()) { ForwardInstance instance = new ForwardInstance(); instance.SOPInstanceUID = reader.GetColumnValue <string>(ColumnNameSOPInstanceUID); instance.ReferencedFile = reader.GetColumnValue <string>(ColumnNameReferencedFile); list.Add(instance); } } } return(list.ToArray()); }