private bool IsScaffoldColumn(IMetaColumn column, DataBoundControlMode mode, ContainerType containerType) { if (!column.Scaffold) { return(false); } // 1:Many children columns don't make sense for new rows, so ignore them in Insert mode if (mode == DataBoundControlMode.Insert) { var childrenColumn = column as IMetaChildrenColumn; if (childrenColumn != null && !childrenColumn.IsManyToMany) { return(false); } } var fkColumn = column as IMetaForeignKeyColumn; if (fkColumn != null) { // Ignore the FK column if the user doesn't have access to the parent table if (!fkColumn.ParentTable.CanRead(Context.User)) { return(false); } } return(true); }
internal static bool IsFilterableColumn(IMetaColumn column, IPrincipal user) { DisplayAttribute attribute = column.Attributes.FirstOrDefault <DisplayAttribute>(); if ((attribute != null) && attribute.GetAutoGenerateFilter().HasValue) { return(attribute.GetAutoGenerateFilter().Value); } if (!string.IsNullOrEmpty(column.FilterUIHint)) { return(true); } if (!column.Scaffold) { return(false); } if (column.IsCustomProperty) { return(false); } IMetaForeignKeyColumn column2 = column as IMetaForeignKeyColumn; if (column2 != null) { return(column2.ParentTable.CanRead(user)); } return((column.ColumnType == typeof(bool)) || (column.GetEnumType() != null)); }
bool IMetaTable.TryGetColumn(string columnName, out IMetaColumn column) { MetaColumn metaColumn; column = null; if (TryGetColumn(columnName, out metaColumn)) { column = metaColumn; return(true); } return(false); }
bool IMetaTable.TryGetColumn(string columnName, out IMetaColumn column) { MetaColumn column2; column = null; if (this.TryGetColumn(columnName, out column2)) { column = column2; return(true); } return(false); }
internal static bool IsFilterableColumn(IMetaColumn column, IPrincipal user) { Debug.Assert(column != null); var displayAttribute = column.Attributes.FirstOrDefault <DisplayAttribute>(); if (displayAttribute != null && displayAttribute.GetAutoGenerateFilter().HasValue) { return(displayAttribute.GetAutoGenerateFilter().Value); } if (!String.IsNullOrEmpty(column.FilterUIHint)) { return(true); } // non-scaffolded columns should not be displayed by default if (!column.Scaffold) { return(false); } // custom properties won't be queryable by the server if (column.IsCustomProperty) { return(false); } var fkColumn = column as IMetaForeignKeyColumn; if (fkColumn != null) { // Only allow if the user has access to the parent table return(fkColumn.ParentTable.CanRead(user)); } if (column.ColumnType == typeof(bool)) { return(true); } if (column.GetEnumType() != null) { return(true); } return(false); }
internal static bool IsColumnInDictionary(IMetaColumn column, IDictionary <string, object> values) { if (column == null) { throw new ArgumentNullException("column"); } if (values == null) { throw new ArgumentNullException("values"); } IMetaForeignKeyColumn foreignKeyColumn = column as IMetaForeignKeyColumn; if (foreignKeyColumn != null) { return(foreignKeyColumn.ForeignKeyNames.All(fkName => values.ContainsKey(fkName))); } return(values.ContainsKey(column.Name)); }
public object GetObfuscatedValue(IMetaColumn metaColumn, object columnValue) { object value; if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnValue == DBNull.Value) { columnValue = null; } value = this._GetObfuscatedValue(metaColumn, columnValue); return(value); }
public static IQueryable BuildSortQueryable(IQueryable query, IMetaTable table) { IMetaColumn sortColumn = table.SortColumn; if (sortColumn.IsCustomProperty) { // An extra property can't be optimized on server // var data = query.OfType <object>().AsEnumerable(); Func <object, object> lambda = row => DataBinder.GetPropertyValue(row, sortColumn.Name); if (table.SortDescending) { query = data.OrderByDescending <object, object>(lambda).AsQueryable(); } else { query = data.OrderBy <object, object>(lambda).AsQueryable(); } } else { // Build custom expression to optimize sorting on server // var parameter = Expression.Parameter(query.ElementType, "row"); LambdaExpression lambda = null; IMetaForeignKeyColumn foreignKeyColumn = sortColumn as IMetaForeignKeyColumn; if (foreignKeyColumn != null) { // e.g. product => product.Category.CategoryName var foreignKeySortColumn = foreignKeyColumn.ParentTable.SortColumn; lambda = Expression.Lambda(Expression.Property(Expression.Property(parameter, sortColumn.Name), foreignKeySortColumn.Name), parameter); } else { // e.g. product => product.ProductName lambda = Expression.Lambda(Expression.Property(parameter, sortColumn.Name), parameter); } string ordering = table.SortDescending ? "OrderByDescending" : "OrderBy"; var expression = Expression.Call(typeof(Queryable), ordering, new Type[] { query.ElementType, lambda.Body.Type }, query.Expression, lambda); query = query.Provider.CreateQuery(expression); } return(query); }
private object _GetObfuscatedValue(IMetaColumn metaColumn, object columnValue) { IObfuscationStrategy obfuscationStrategy; ColumnConfiguration columnConfiguration; object obfuscatedValue; if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } // KILLS performance - not sure why //EnsureValidConfigurationOnce(this.TableConfiguration); //columnConfiguration = this.TableConfiguration.ColumnConfigurations.SingleOrDefault(c => c.ColumnName.SafeToString().Trim().ToLower() == columnName.SafeToString().Trim().ToLower()); if (!this.ColumnCache.TryGetValue(metaColumn.ColumnIndex, out columnConfiguration)) { columnConfiguration = this.ObfuscationConfiguration.TableConfiguration.ColumnConfigurations.SingleOrDefault(c => c.ColumnName.SafeToString().Trim().ToLower() == metaColumn.ColumnName.SafeToString().Trim().ToLower()); //columnConfiguration = this.TableConfiguration.ColumnConfigurations.SingleOrDefault(c => c.ColumnName == columnName); this.ColumnCache.Add(metaColumn.ColumnIndex, columnConfiguration); } if ((object)columnConfiguration == null) { return(columnValue); // do nothing when no matching column configuration } if (!this.ObfuscationStrategyCache.TryGetValue(columnConfiguration.ObfuscationStrategyAqtn, out obfuscationStrategy)) { obfuscationStrategy = columnConfiguration.GetObfuscationStrategyInstance(); if ((object)obfuscationStrategy == null) { throw new InvalidOperationException(string.Format("Unknown obfuscation strategy '{0}' specified for column '{1}'.", columnConfiguration.ObfuscationStrategyAqtn, metaColumn.ColumnName)); } this.ObfuscationStrategyCache.Add(columnConfiguration.ObfuscationStrategyAqtn, obfuscationStrategy); } obfuscatedValue = obfuscationStrategy.GetObfuscatedValue(this, columnConfiguration, metaColumn, columnValue); return(obfuscatedValue); }
private bool IsScaffoldColumn(IMetaColumn column, DataBoundControlMode mode, ContainerType containerType) { if (!column.Scaffold) { return(false); } if (mode == DataBoundControlMode.Insert) { IMetaChildrenColumn column3 = column as IMetaChildrenColumn; if ((column3 != null) && !column3.IsManyToMany) { return(false); } } IMetaForeignKeyColumn column2 = column as IMetaForeignKeyColumn; if ((column2 != null) && !column2.ParentTable.CanRead(this.Context.User)) { return(false); } return(true); }
bool IMetaTable.TryGetColumn(string columnName, out IMetaColumn column) { MetaColumn metaColumn; column = null; if (TryGetColumn(columnName, out metaColumn)) { column = metaColumn; return true; } return false; }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <MaskingObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { object value; double maskingFactor; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } maskingFactor = (columnConfiguration.ObfuscationStrategySpecificConfiguration.MaskingPercentValue.GetValueOrDefault() / 100.0); value = GetMask(maskingFactor, columnValue); return(value); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <ScriptObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } return(CompileCSharpCode(columnValue, columnConfiguration.ObfuscationStrategySpecificConfiguration.SourceCode)); }
private static object GetSubstitution(IOxymoronEngine oxymoronEngine, DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, long surrogateId, object value) { Type valueType; string _value; const bool SUBSTITUTION_CACHE_ENABLED = true; IDictionary <long, object> dictionaryCache; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } if ((object)dictionaryConfiguration == null) { throw new ArgumentNullException("dictionaryConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)value == null) { return(null); } valueType = value.GetType(); if (valueType != typeof(String)) { return(null); } _value = (String)value; if (DataTypeFascade.Instance.IsWhiteSpace(_value)) { return(_value); } _value = _value.Trim(); if ((dictionaryConfiguration.RecordCount ?? 0L) <= 0L) { return(null); } if (!SUBSTITUTION_CACHE_ENABLED || !oxymoronEngine.SubstitutionCacheRoot.TryGetValue(dictionaryConfiguration.DictionaryId, out dictionaryCache)) { dictionaryCache = new Dictionary <long, object>(); if (SUBSTITUTION_CACHE_ENABLED) { oxymoronEngine.SubstitutionCacheRoot.Add(dictionaryConfiguration.DictionaryId, dictionaryCache); } } if (!SUBSTITUTION_CACHE_ENABLED || !dictionaryCache.TryGetValue(surrogateId, out value)) { if (dictionaryConfiguration.PreloadEnabled) { throw new InvalidOperationException(string.Format("Cache miss when is preload enabled for dictionary '{0}'; current cache slot item count: {1}.", dictionaryConfiguration.DictionaryId, dictionaryCache.Count)); } value = oxymoronEngine.OxymoronHost.GetValueForIdViaDictionaryResolution(dictionaryConfiguration, metaColumn, surrogateId); if (SUBSTITUTION_CACHE_ENABLED) { dictionaryCache.Add(surrogateId, value); } } return(value); }
internal DynamicControl(IMetaColumn column) { _iMetaColumn = column; }
public object GetValueForIdViaDictionaryResolution(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { return(this.DictionaryConfigurationToAdapterMappings[dictionaryConfiguration].GetAlternativeValueFromId(dictionaryConfiguration, metaColumn, surrogateId)); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <DefaultingObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { object value; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } value = GetDefault(metaColumn.ColumnIsNullable ?? columnConfiguration.ObfuscationStrategySpecificConfiguration.DefaultingCanBeNull ?? false, metaColumn.ColumnType); return(value); }
protected abstract object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <TObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue);
internal static bool IsFilterableColumn(IMetaColumn column, IPrincipal user) { Debug.Assert(column != null); var displayAttribute = column.Attributes.FirstOrDefault<DisplayAttribute>(); if (displayAttribute != null && displayAttribute.GetAutoGenerateFilter().HasValue) { return displayAttribute.GetAutoGenerateFilter().Value; } if (!String.IsNullOrEmpty(column.FilterUIHint)) { return true; } // non-scaffolded columns should not be displayed by default if (!column.Scaffold) { return false; } // custom properties won't be queryable by the server if (column.IsCustomProperty) { return false; } var fkColumn = column as IMetaForeignKeyColumn; if (fkColumn != null) { // Only allow if the user has access to the parent table return fkColumn.ParentTable.CanRead(user); } if (column.ColumnType == typeof(bool)) { return true; } if (column.GetEnumType() != null) { return true; } return false; }
protected abstract object CoreGetValueForIdViaDictionaryResolution(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId);
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration<ObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long signHash, valueHash; object value; string sharedSecret; if ((object)columnConfiguration == null) throw new ArgumentNullException("columnConfiguration"); if ((object)metaColumn == null) throw new ArgumentNullException("metaColumn"); if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); signHash = this.GetSignHash(oxymoronEngine, columnValue); valueHash = this.GetValueHash(oxymoronEngine, null, columnValue); sharedSecret = ((valueHash <= 0 ? 1 : valueHash) * (signHash % 2 == 0 ? -1 : 1)).ToString("X"); value = GetCipher(sharedSecret, columnValue); return value; }
protected override object CoreGetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { object value; IDbDataParameter dbDataParameterKey; if ((object)dictionaryConfiguration == null) { throw new ArgumentNullException("dictionaryConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)surrogateId == null) { throw new ArgumentNullException("surrogateId"); } if (DataTypeFascade.Instance.IsNullOrWhiteSpace(this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandText)) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ExecuteCommandText")); } dbDataParameterKey = this.DictionaryUnitOfWork.CreateParameter(ParameterDirection.Input, DbType.Object, 0, 0, 0, false, "@ID", surrogateId); value = this.DictionaryUnitOfWork.ExecuteScalar <string>(this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandType ?? CommandType.Text, this.AdapterConfiguration.AdapterSpecificConfiguration.ExecuteCommandText, new IDbDataParameter[] { dbDataParameterKey }); return(value); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <ObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long valueHash; object value; long randomSeed; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } valueHash = this.GetValueHash(oxymoronEngine, null, metaColumn.ColumnName); randomSeed = valueHash; // create a new repeatable yet random-ish math funcion using the random seed, then executes for column value value = GetSurrogateKey(randomSeed, columnValue); return(value); }
protected override object CoreGetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { if ((object)dictionaryConfiguration == null) { throw new ArgumentNullException("dictionaryConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)surrogateId == null) { throw new ArgumentNullException("surrogateId"); } return(null); }
public object GetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { return(this.CoreGetAlternativeValueFromId(dictionaryConfiguration, metaColumn, surrogateId)); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <ObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long valueHash; object value; long randomSeed; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } valueHash = this.GetValueHash(oxymoronEngine, null, columnValue); randomSeed = valueHash; value = GetShuffle(randomSeed, columnValue); return(value); }
public object GetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration columnConfiguration, IMetaColumn metaColumn, object columnValue) { ColumnConfiguration <TObfuscationStrategyConfiguration> _columnConfiguration; object value; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnValue == DBNull.Value) { columnValue = null; } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } _columnConfiguration = new ColumnConfiguration <TObfuscationStrategyConfiguration>(columnConfiguration); if ((object)_columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } value = this.CoreGetObfuscatedValue(oxymoronEngine, _columnConfiguration, metaColumn, columnValue); return(value); }
internal static Type GetEnumType(this IMetaColumn column) { return(column.Attributes.GetAttributePropertyValue <EnumDataTypeAttribute, Type>(a => a.EnumType, null) ?? (column.ColumnType.IsEnum ? column.ColumnType : null)); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <SubstitutionObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long signHash, valueHash; DictionaryConfiguration dictionaryConfiguration; object value; long surrogateId; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } dictionaryConfiguration = this.GetDictionaryConfiguration(oxymoronEngine, columnConfiguration); valueHash = this.GetValueHash(oxymoronEngine, dictionaryConfiguration.RecordCount, columnValue); surrogateId = valueHash; value = GetSubstitution(oxymoronEngine, dictionaryConfiguration, metaColumn, surrogateId, columnValue); return(value); }
public object GetValueForIdViaDictionaryResolution(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { return this.DictionaryConfigurationToAdapterMappings[dictionaryConfiguration].GetAlternativeValueFromId(dictionaryConfiguration, metaColumn, surrogateId); }
private bool IsScaffoldColumn(IMetaColumn column, DataBoundControlMode mode, ContainerType containerType) { if (!column.Scaffold) { return false; } // 1:Many children columns don't make sense for new rows, so ignore them in Insert mode if (mode == DataBoundControlMode.Insert) { var childrenColumn = column as IMetaChildrenColumn; if (childrenColumn != null && !childrenColumn.IsManyToMany) { return false; } } var fkColumn = column as IMetaForeignKeyColumn; if (fkColumn != null) { // Ignore the FK column if the user doesn't have access to the parent table if (!fkColumn.ParentTable.CanRead(Context.User)) { return false; } } return true; }
public object GetValueForIdViaDictionaryResolution(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { return(this.CoreGetValueForIdViaDictionaryResolution(dictionaryConfiguration, metaColumn, surrogateId)); }
public object GetValueForIdViaDictionaryResolution(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { return this.CoreGetValueForIdViaDictionaryResolution(dictionaryConfiguration, metaColumn, surrogateId); }
protected override object CoreGetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId) { object value; int index; HeaderSpec[] headerSpecs; IEnumerable <IDictionary <string, object> > records; if ((object)dictionaryConfiguration == null) { throw new ArgumentNullException("dictionaryConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)surrogateId == null) { throw new ArgumentNullException("surrogateId"); } if ((object)this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextSpec == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "DelimitedTextSpec")); } if (DataTypeFascade.Instance.IsNullOrWhiteSpace(this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextFilePath)) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "DelimitedTextFilePath")); } using (RecordTextReader delimitedTextReader = new DelimitedTextReader(new StreamReader(File.Open(this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextFilePath, FileMode.Open, FileAccess.Read, FileShare.None)), this.AdapterConfiguration.AdapterSpecificConfiguration.DelimitedTextSpec)) { index = surrogateId.ChangeType <int>() - 1; headerSpecs = delimitedTextReader.ReadHeaderSpecs().ToArray(); records = delimitedTextReader.ReadRecords(); var record = records.ElementAtOrDefault(index); if ((object)record == null) { value = null; } else { value = record[headerSpecs[index].HeaderName]; } } return(value); }
protected abstract object CoreGetAlternativeValueFromId(DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, object surrogateId);