public void AddKey(IKeyInfo key, bool isUnique) { if (isUnique) { this.uniqueKeys.Add(key); } else { this.otherKeys.Add(key); } }
private static IKeyInfoHelper GetKeyInfoHelper(IKeyInfo keyInfo) { var provider = keyInfo as IKeyInfoHelperProvider; if (provider == null) { return(null); } return(provider.KeyInfoHelper); }
internal Index( ITable <TEntity> table, IKeyInfo <TEntity, TKey> keyInfo, IDataStructure <TKey, TEntity> dataStructure) : base(table, keyInfo) { this.dataStructure = dataStructure; this.Rebuild(); }
/// <summary> /// Creates a new unique index. /// </summary> /// <typeparam name="TUniqueKey"> /// The type of the unqiue index key. /// </typeparam> /// <param name="indexFactory"> /// The index factory. /// </param> /// <param name="keyInfo"> /// The definition of the index key /// </param> /// <returns> The unique index. </returns> public IUniqueIndex <TEntity, TUniqueKey> CreateUniqueIndex <TUniqueKey>( IIndexFactory indexFactory, IKeyInfo <TEntity, TUniqueKey> keyInfo) { var index = indexFactory.CreateUniqueIndex(this, keyInfo); this.indexes.Add(index); this.OnIndexChanged(); return(index); }
public Table <TEntity, TPrimaryKey> CreateTable <TEntity, TPrimaryKey>( IKeyInfo <TEntity, TPrimaryKey> primaryKey, IdentitySpecification <TEntity> identitySpecification, IDatabase database, object tableInfo) where TEntity : class { return(new ExtendedTable <TEntity, TPrimaryKey>( database, primaryKey, identitySpecification, tableInfo)); }
public void Execute(IGameEngine gameEngine, IKeyInfo commandKey) { foreach (var command in _commands) { if (!command.HandlesInput(commandKey)) { continue; } command.Execute(gameEngine, commandKey); } }
public void PrimitiveKeyInfoService_CreateKey() { PrimitiveKeyInfoService service = new PrimitiveKeyInfoService(); IKeyInfo <BinaryEntity, Binary> key = null; bool res = service.TryCreateKeyInfo <BinaryEntity, Binary>(x => x.Binary, out key); Assert.IsTrue(res); Assert.IsNotNull(key); Assert.AreEqual(1, key.EntityKeyMembers.Length); Assert.AreEqual(typeof(Binary), key.KeyType); }
public bool TryCreateKeyInfo <TEntity, TKey>( Expression <Func <TEntity, TKey> > keySelector, out IKeyInfo <TEntity, TKey> result) where TEntity : class { if (!ValidateType(typeof(TKey))) { result = null; return(false); } IKeyInfoHelper helper = PrimitiveKeyInfo <TEntity, TKey> .KeyInfoHelper; if (!helper.TryParseKeySelectorExpression(keySelector.Body, true, out MemberInfo[] members))
public Table <TEntity, TPrimaryKey> CreateTable <TEntity, TPrimaryKey>( IKeyInfo <TEntity, TPrimaryKey> primaryKey, IdentitySpecification <TEntity> identitySpecification, IDatabase database) where TEntity : class { Table <TEntity, TPrimaryKey> table = new DefaultTable <TEntity, TPrimaryKey>( database, primaryKey, identitySpecification); return(table); }
public EncryptionService(IKeyInfo keyInfo, IOutputPrinter consolePrinter) { _consolePrinter = consolePrinter; _keyinfo = keyInfo; //Create a key if necessary if (!File.Exists(_keyinfo.KeyPath)) { PublishKey(); } //Load the key LoadKey(); }
public static IIndex CreateIndex(ITable table, IKeyInfo key, bool unique) { return(typeof(DatabaseReflectionHelper.WrapperMethods) .GetMethod("CreateIndex") .MakeGenericMethod( table.EntityType, table.PrimaryKeyIndex.KeyInfo.KeyType, key.KeyType) .Invoke(null, new object[] { table, key, unique }) as IIndex); }
public static IKeyInfo EnsureKey( MemberInfo[] members, bool unique, DbTableInfoBuilder tableBuilder) { IKeyInfo keyInfo = tableBuilder.FindKey(members, false, unique); if (keyInfo == null) { keyInfo = KeyInfoHelper.CreateKeyInfo(tableBuilder.EntityType, members); tableBuilder.AddKey(keyInfo, unique); } return(keyInfo); }
private static IKeyInfoHelper GetKeyInfoHelper(IKeyInfo keyInfo) { if (!(keyInfo is IKeyInfoHelperProvider helperProvider)) { throw new ArgumentException("", "keyInfo"); } var helper = helperProvider.KeyInfoHelper; if (helper == null) { throw new ArgumentException("", "keyInfo"); } return(helper); }
public static IKeyInfo CreateKeyInfo(LambdaExpression selector) { Type entityType = selector.Parameters[0].Type; Type resultType = selector.Body.Type; MethodInfo factory = ReflectionHelper .GetMethodInfo <IKeyInfoFactory>(f => f.Create <object, object>(null)) .GetGenericMethodDefinition() .MakeGenericMethod(entityType, resultType); IKeyInfo result = factory.Invoke( ExtendedKeyInfoFactory.Instance, new object[] { selector }) as IKeyInfo; return(result); }
public DbRelationInfo( string primaryTable, string foreignTable, IKeyInfo primaryKeyInfo, IKeyInfo foreignKeyInfo, Delegate primaryToForeignConverter, Delegate foreignToPrimaryConverter, bool cascadedDelete) { this.PrimaryTable = primaryTable; this.ForeignTable = foreignTable; this.PrimaryKeyInfo = primaryKeyInfo; this.ForeignKeyInfo = foreignKeyInfo; this.PrimaryToForeignConverter = primaryToForeignConverter; this.ForeignToPrimaryConverter = foreignToPrimaryConverter; this.CascadedDelete = cascadedDelete; }
public static IIndex <TEntity, TKey> CreateIndex <TEntity, TPrimaryKey, TKey>( Table <TEntity, TPrimaryKey> table, IKeyInfo <TEntity, TKey> key, bool unique) where TEntity : class { IIndexFactory factory = new RedBlackTreeIndexFactory(); if (unique) { return(table.CreateUniqueIndex(factory, key)); } else { return(table.CreateIndex(factory, key)); } }
public bool TryCreateKeyInfo <TEntity, TKey>( Expression <Func <TEntity, TKey> > keySelector, out IKeyInfo <TEntity, TKey> result) where TEntity : class { result = null; bool success = false; foreach (IKeyInfoService factory in this.factories) { if (factory.TryCreateKeyInfo(keySelector, out result)) { success = true; break; } } return(success); }
public override void Execute(IKeyInfo directionKey) { this.Engine.Player.Move(directionKey); ICharacter currentEnemy = this.FindEnemy(); if (currentEnemy != null) { this.EnterBattle(currentEnemy); return; } IGameItem currentItem = this.FindItem(); if (currentItem != null) { this.CollectItem(currentItem); } }
private void MovePlayer(IGameEngine gameEngine, IKeyInfo keyInfo) { gameEngine.Player.Move(gameEngine, keyInfo); var currentEnemy = FindEnemy(gameEngine); if (currentEnemy != null) { EnterBattle(gameEngine, currentEnemy); return; } var currentItem = FindItem(gameEngine); if (currentItem != null) { CollectItem(gameEngine, currentItem); } }
private static IIndex FindIndex(ITable table, IKeyInfo key, bool unique) { IEnumerable <IIndex> indexes = table.Indexes; if (unique) { indexes = indexes.OfType <IUniqueIndex>(); } foreach (IIndex index in indexes) { if (index.KeyInfo == key) { return(index); } } throw new InvalidOperationException("Index was not found"); }
private static Func <TFrom, TTo> CreateConversion <TFrom, TTo>( IKeyInfo <TFrom> fromKeyInfo, IKeyInfo <TTo> toKeyInfo, int[] mapping) { IKeyInfoHelper from = GetKeyInfoHelper(fromKeyInfo); IKeyInfoHelper to = GetKeyInfoHelper(toKeyInfo); ParameterExpression keyParam = Expression.Parameter(fromKeyInfo.KeyType); Expression body = KeyExpressionHelper.CreateKeyConversionExpression( keyParam, toKeyInfo.EntityKeyMembers, mapping, from, to); return(Expression.Lambda <Func <TFrom, TTo> >(body, keyParam).Compile()); }
public static Table <TEntity, TPrimaryKey> CreateTable <TEntity, TPrimaryKey>( Database database, IKeyInfo <TEntity, TPrimaryKey> primaryKeyInfo, Expression <Func <TEntity, long> > identity, object[] constraintFactories) where TEntity : class { Table <TEntity, TPrimaryKey> table = database.Tables.Create <TEntity, TPrimaryKey>( primaryKeyInfo, identity != null ? new IdentitySpecification <TEntity>(identity) : null); foreach (var constraintFactory in constraintFactories.Cast <IConstraintFactory <TEntity> >()) { table.Contraints.Add(constraintFactory); } return(table); }
private static Delegate CreateConverter( MethodInfo converterMethod, IKeyInfo primaryKeyInfo, IKeyInfo foreignKeyInfo, IRelationContraint[] relationConstraints) { MethodInfo factory = converterMethod .GetGenericMethodDefinition() .MakeGenericMethod(primaryKeyInfo.KeyType, foreignKeyInfo.KeyType); Delegate result = factory.Invoke( null, new object[] { primaryKeyInfo, foreignKeyInfo, relationConstraints.ToArray() }) as Delegate; return(result); }
public DbTableInfo( string tableName, Type entityType, MemberInfo identityField, PropertyInfo[] properties, IKeyInfo primaryKeyInfo, IKeyInfo[] uniqueKeys, IKeyInfo[] foreignKeys, object[] constraintFactories) { this.TableName = tableName; this.EntityType = entityType; this.IdentityField = identityField; this.Properties = properties; this.ConstraintFactories = constraintFactories; this.PrimaryKeyInfo = primaryKeyInfo; this.UniqueKeys = uniqueKeys; this.ForeignKeys = foreignKeys; this.initializer = new FastLazy <Func <object[], object> >(CreateEntityInitializer); }
public DbTableInfo( string tableName, Type entityType, MemberInfo identityField, PropertyInfo[] properties, IKeyInfo primaryKeyInfo, IKeyInfo[] uniqueKeys, IKeyInfo[] foreignKeys, object[] constraintFactories) { this.TableName = tableName; this.EntityType = entityType; this.IdentityField = identityField; this.Properties = properties; this.ConstraintFactories = constraintFactories; this.PrimaryKeyInfo = primaryKeyInfo; this.UniqueKeys = uniqueKeys; this.ForeignKeys = foreignKeys; this.initializer = new FastLazy<Func<object[], object>>(CreateEntityInitializer); }
/// <summary> /// Initializes a database table. /// </summary> /// <typeparam name="TEntity"> /// Specifies the type of the entities of the table. /// </typeparam> /// <typeparam name="TPrimaryKey"> /// Specifies the type of the primary key of the entities. /// </typeparam> /// <param name="primaryKey"> /// An IKeyInfo object that represents the primary key of the entities. /// </param> /// <param name="identitySpecification"> /// An IdentitySpecification to set an identity field. /// </param> /// <returns> /// The table. /// </returns> public Table <TEntity, TPrimaryKey> Create <TEntity, TPrimaryKey>( IKeyInfo <TEntity, TPrimaryKey> primaryKey, IdentitySpecification <TEntity> identitySpecification, object tableInfo = null) where TEntity : class { if (primaryKey == null) { throw new ArgumentNullException("primaryKey"); } ITableService service = this.database .DatabaseEngine .ServiceProvider .GetService <ITableService>(); if (service == null) { throw new NMemoryException(ExceptionMessages.ServiceNotFound, "TableService"); } Table <TEntity, TPrimaryKey> table = service.CreateTable <TEntity, TPrimaryKey>( primaryKey, identitySpecification, this.database, tableInfo); if (table == null) { throw new NMemoryException(ExceptionMessages.TableNotCreated); } this.RegisterTable(table); return(table); }
public bool TryCreateKeyInfo <TEntity, TKey>( Expression <Func <TEntity, TKey> > keySelector, out IKeyInfo <TEntity, TKey> result) where TEntity : class { if (!ReflectionHelper.IsAnonymousType(typeof(TKey))) { result = null; return(false); } IKeyInfoHelper helper = AnonymousTypeKeyInfo <TEntity, TKey> .KeyInfoHelper; MemberInfo[] members; if (!helper.TryParseKeySelectorExpression(keySelector.Body, true, out members)) { result = null; return(false); } result = new AnonymousTypeKeyInfo <TEntity, TKey>(members); return(true); }
/// <summary> /// Initializes a new instance of the <see cref="Table{TEntity, TPrimaryKey}"/> /// class. /// </summary> /// <param name="database"> The database. </param> /// <param name="primaryKey"> The primary key. </param> /// <param name="identitySpecification"> The identity specification. </param> public Table( IDatabase database, IKeyInfo <TEntity, TPrimaryKey> primaryKey, IdentitySpecification <TEntity> identitySpecification) : base(database, false) { this.VerifyType(); this.id = Interlocked.Increment(ref counter); this.indexes = new List <IIndex <TEntity> >(); this.constraints = new ConstraintCollection <TEntity>(); this.primaryKeyIndex = this.CreateUniqueIndex(new DictionaryIndexFactory(), primaryKey); this.RegisterTimestampConstraints(); if (identitySpecification != null) { this.identityField = new IdentityField <TEntity>(identitySpecification); } }
public void Execute(IGameEngine gameEngine, IKeyInfo keyInfo) { MovePlayer(gameEngine, keyInfo); }
private static Delegate CreateConverter( MethodInfo converterMethod, IKeyInfo primaryKeyInfo, IKeyInfo foreignKeyInfo, IRelationContraint[] relationConstraints) { MethodInfo factory = converterMethod .GetGenericMethodDefinition() .MakeGenericMethod(primaryKeyInfo.KeyType, foreignKeyInfo.KeyType); Delegate result = factory.Invoke( null, new object[] { primaryKeyInfo, foreignKeyInfo, relationConstraints.ToArray() }) as Delegate; return result; }
private static IKeyInfoHelper GetKeyInfoHelper(IKeyInfo keyInfo) { var provider = keyInfo as IKeyInfoHelperProvider; if (provider == null) { return null; } return provider.KeyInfoHelper; }
public bool HandlesInput(IKeyInfo keyInfo) { return(keyInfo.Key == ConsoleKey.D); }
public MultipleUniqueKeyFoundException(IKeyInfo keyInfo, Exception inner) : base(GetMessage(keyInfo), inner) { }
internal IndexBase(ITable <TEntity> table, IKeyInfo <TEntity, TKey> keyInfo) { this.table = table; this.keyInfo = keyInfo; }
private static string GetMessage(IKeyInfo info) { var fields = string.Join(", ", info.EntityKeyMembers.Select(x => x.Name)); return string.Format("Unique key violation ({0})", fields); }