public virtual async Task SetPropertyValueAsync <TProperty>(TKey key, string propertyName, TProperty propertyValue) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (!Table.Columns.ContainsKey(propertyName)) { throw new ArgumentException(@"Invalid property", nameof(propertyName)); } if (Table.KeyColumnsNames.Contains(propertyName)) { throw new ArgumentException(@"A key property cannot be changed", nameof(propertyName)); } using (var cancellationTokenSource = CreateCancellationTokenSource()) { using (var connection = await GetConnectionAsync(cancellationTokenSource.Token).ConfigureAwait(false)) { var keyColumnValues = KeyMapper.GetColumnValues(key); var columnValues = new Dictionary <string, object> { { propertyName, Mapper.DbTypeMapper.ToDbType(propertyValue, Table.Columns[propertyName].Type) } }; using (var command = connection.CreateMergeCommand(DatabaseDriver, Table.Schema, Table.Name, keyColumnValues, columnValues)) { if (await command.ExecuteNonQueryAsync(cancellationTokenSource.Token).ConfigureAwait(false) == 0) { throw new Exception("The database operation failed"); } } } } }
public virtual async Task <TProperty> GetPropertyValueOrDefaultAsync <TProperty>(TKey key, string propertyName) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (!Table.Columns.ContainsKey(propertyName)) { throw new ArgumentException(@"Invalid property", nameof(propertyName)); } using (var cancellationTokenSource = CreateCancellationTokenSource()) { using (var connection = await GetConnectionAsync(cancellationTokenSource.Token).ConfigureAwait(false)) { var keyColumnValues = KeyMapper.GetColumnValues(key); using (var command = connection.CreateSelectTop1Command(DatabaseDriver, Table.Schema, Table.Name, new[] { propertyName }, keyColumnValues)) { var dbValue = await command.ExecuteScalarAsync(cancellationTokenSource.Token).ConfigureAwait(false); if (dbValue != null && !(dbValue is DBNull)) { return((TProperty)Mapper.DbTypeMapper.FromDbType( dbValue, Table.Columns[propertyName].Type, typeof(TValue).GetTypeInfo().GetProperty(propertyName).PropertyType)); } } } } return(default(TProperty)); }
public virtual async Task MergeAsync(TKey key, TValue value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } using (var cancellationTokenSource = CreateCancellationTokenSource()) { using (var connection = await GetConnectionAsync(cancellationTokenSource.Token).ConfigureAwait(false)) { var keyColumnValues = KeyMapper.GetColumnValues(key); var columnValues = GetColumnValues(value); if (columnValues.Any()) { using (var command = connection.CreateMergeCommand(DatabaseDriver, Table.Schema, Table.Name, keyColumnValues, columnValues)) { if (await command.ExecuteNonQueryAsync(cancellationTokenSource.Token).ConfigureAwait(false) == 0) { throw new Exception("The database operation failed"); } } } } } }
public void WhenAssignReferenceOutSideTheOwnerEntityThenThrow() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); ActionAssert.Throws <ArgumentOutOfRangeException>(() => km.PropertyRef(ForClass <B> .Property(x => x.Name))); }
public override void Process() { if (active) { bool up = KeyMapper.GetAxis("Vertical") > 0; bool down = KeyMapper.GetAxis("Vertical") < 0; bool select = KeyMapper.GetButtonDown("Jump") || Input.GetKeyDown(KeyCode.Return); if (canMove >= 20) { if (up) { selectedButton = (selectedButton + buttons.Length - 1) % buttons.Length; canMove = 0; } if (down) { selectedButton = (selectedButton + buttons.Length + 1) % buttons.Length; canMove = 0; } } else { canMove++; } eventSystem.SetSelectedGameObject(buttons[selectedButton]); if (select) { buttons[selectedButton].GetComponent <Button>().onClick.Invoke(); } } }
internal override async Task SendAsync(IOperation op, CancellationToken token = default, TimeSpan?timeout = null) { if (KeyMapper == null) { throw new InvalidOperationException($"Bucket {Name} is not bootstrapped."); } var vBucket = (VBucket)KeyMapper.MapKey(op.Key); var endPoint = op.VBucketId.HasValue ? vBucket.LocateReplica(op.VBucketId.Value) : vBucket.LocatePrimary(); op.VBucketId = vBucket.Index; if (Nodes.TryGet(endPoint !, out var clusterNode)) { try { await clusterNode.SendAsync(op, token, timeout).ConfigureAwait(false); } catch (Exception e) { if (e is CollectionOutdatedException) { Logger.LogInformation("Updating stale manifest for collection and retrying.", e); await RefreshCollectionId(op, clusterNode).ConfigureAwait(false); await clusterNode.SendAsync(op, token, timeout).ConfigureAwait(false); } else { throw;//propagate up } } }
public async Task delete_record_with_secondary_index_using_sequential_key_mapper() { var pKeyMapper = new KeyMapper <Employee, int>(e => e.Id.ToString(), int.Parse, e => e.Id, id => id.ToString()); var rKeyMapper = new SequentialKeyMapper <Employee, int>(true); var keysConverter = new CalculatedKeysConverter <Employee, int, int>(pKeyMapper, rKeyMapper); var logStore = new PocoTableStore <Employee, int, int>("IXLogIndex", "UseDevelopmentStorage=true", keysConverter); TableStore.AddIndex("Log", logStore); var employee = new Employee { Name = "Test", CompanyId = 99, Id = 99, Department = new Department { Id = 5, Name = "Test" } }; await TableStore.InsertAsync(employee); await TableStore.DeleteAsync(employee); var records = await TableStore.GetByIndexPartitionKeyAsync("Log", 99); Assert.AreEqual(1, records.Count()); }
public async Task delete_from_index_using_fixed_key_row() { var pkMapper = new KeyMapper <Employee, string>(e => e.Name, n => n, e => e.Name, n => n); var rkMapper = new FixedKeyMapper <Employee, string>("emp"); var keyConverter = new CalculatedKeysConverter <Employee, string, string>(pkMapper, rkMapper); PocoTableStore <Employee, int, string> table = null; try { table = new PocoTableStore <Employee, int, string>("IXTestEmployeeUT1", "UseDevelopmentStorage=true", e => e.CompanyId, e => e.Id); var index = new PocoTableStore <Employee, string, string>("IXTestEmployeeNameIndexUT1", "UseDevelopmentStorage=true", keyConverter); table.AddIndex("Name2", index); var employee = new Employee { Name = "Test", CompanyId = 99, Id = 99, Department = new Department { Id = 5, Name = "Test" } }; await table.InsertOrReplaceAsync(employee); await table.DeleteAsync(employee); } finally { await table.DeleteTableAsync(); } }
public void WhenAssignReferenceOutSideTheOwnerEntityThenThrow() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); Executing.This(() => km.PropertyRef(ConfOrm.ForClass <B> .Property(x => x.Name))).Should().Throw <ArgumentOutOfRangeException>(); }
void Start() { canvas.gameObject.SetActive(true); keyMapper = new KeyMapper(); foreach (var text in gameOverTexts) { text.enabled = false; } gameOver = false; Time.timeScale = 1f; enemiesKilled = new List <Image>(); flash.gameObject.SetActive(true); ItemHolder = GameObject.FindWithTag("ItemHolder").GetComponent <ItemHolder>(); player = GameObject.FindWithTag("Player"); // Level //Debug.Log("Start ending"); NextLevel(); }
public void SetShortcut(ModifierKey modifier, Key key) { string shortcut = KeyMapper.GetShortcut(modifier, key); using GLibString gshortcut = shortcut; Gtk.Menu.SetAccelerator(Handle, gshortcut); }
public virtual async Task <bool> RemoveExpirationAsync(TKey key) { using var cancellationTokenSource = CreateCancellationTokenSource(); await using var connection = await GetConnectionAsync(cancellationTokenSource.Token).ConfigureAwait(false); var keyColumnValues = KeyMapper.GetColumnValues(key); var columnValues = new Dictionary <string, object> { { _expirationColumnName, DBNull.Value } }; await using var command = connection.CreateTextCommand( DatabaseDriver.GetSqlStatementTemplate(SqlStatement.Update), new { schemaName = DatabaseDriver.ParseIdentifier(Table.Schema ?? DatabaseDriver.DefaultSchema), tableName = DatabaseDriver.ParseIdentifier(Table.Name), columnValues = SqlHelper.GetCommaEqualsStatement(DatabaseDriver, columnValues.Keys.ToArray()), filter = SqlHelper.GetCombinedAndStatement(DatabaseDriver, SqlHelper.GetAndEqualsStatement(DatabaseDriver, keyColumnValues.Keys.ToArray()), SqlHelper.GetIsNotNullStatement(DatabaseDriver, columnValues.Keys.ToArray())) }, keyColumnValues.Concat(columnValues).Select(c => c.ToDbParameter(DatabaseDriver))); var teste = SqlHelper.GetCombinedAndStatement(DatabaseDriver, SqlHelper.GetAndEqualsStatement(DatabaseDriver, keyColumnValues.Keys.ToArray()), SqlHelper.GetIsNotNullStatement(DatabaseDriver, columnValues.Keys.ToArray())); if (await command.ExecuteNonQueryAsync(cancellationTokenSource.Token).ConfigureAwait(false) == 0) { return(false); } return(true); }
public virtual async Task SetAbsoluteKeyExpirationAsync(TKey key, DateTimeOffset expiration) { using (var cancellationTokenSource = CreateCancellationTokenSource()) { using (var connection = await GetConnectionAsync(cancellationTokenSource.Token).ConfigureAwait(false)) { var keyColumnValues = KeyMapper.GetColumnValues(key); var columnValues = new Dictionary <string, object> { { _expirationColumnName, expiration } }; using (var command = connection.CreateTextCommand( DatabaseDriver.GetSqlStatementTemplate(SqlStatement.Update), new { schemaName = DatabaseDriver.ParseIdentifier(Table.Schema ?? DatabaseDriver.DefaultSchema), tableName = DatabaseDriver.ParseIdentifier(Table.Name), columnValues = SqlHelper.GetCommaEqualsStatement(DatabaseDriver, columnValues.Keys.ToArray()), filter = SqlHelper.GetAndEqualsStatement(DatabaseDriver, keyColumnValues.Keys.ToArray()) }, keyColumnValues.Concat(columnValues).Select(c => c.ToDbParameter(DatabaseDriver)))) { if (await command.ExecuteNonQueryAsync(cancellationTokenSource.Token).ConfigureAwait(false) == 0) { throw new ArgumentException("Invalid key", nameof(key)); } } } } }
void FetchControls() { horizontal = KeyMapper.GetAxis("Horizontal"); PlayerInstanciationScript.player.direction = horizontal > 0 ? DIRECTION.RIGHT : DIRECTION.LEFT; }
public void SetOndelete() { var hbm = new HbmKey(); var mapper = new KeyMapper <string>(hbm); mapper.OnDeleteCascade(); hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Cascade); }
public void WhenAssignFKToWhiteSpacesThenAssignNone() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.ForeignKey(" "); hbm.foreignkey.Should().Be("none"); }
public void WhenAssignFKToValidNameThenAssignName() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.ForeignKey("FKDeLaPizza"); hbm.foreignkey.Should().Be("FKDeLaPizza"); }
public void WhenExplicitAssignementThenOverrideDefaultColumnName() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.Column("blha"); hbm.Columns.First().name.Should().Be.EqualTo("blha"); }
public void WhenAssignReferenceToNullThenNullifyReference() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.PropertyRef(null); hbm.propertyref.Should().Be.Null(); }
public void SetShortcut(ModifierKey modifier, Key key) { NSEventModifierFlags nsModifier = KeyMapper.GetModifier(modifier); string mappedKey = KeyMapper.GetKey(key); ObjC.Call(Handle, "setKeyEquivalentModifierMask:", new UIntPtr((ulong)nsModifier)); ObjC.Call(Handle, "setKeyEquivalent:", NSString.Create(mappedKey)); }
public void AssignPropertyReference() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.PropertyRef(ConfOrm.ForClass <Animal> .Property(x => x.Name)); hbm.propertyref.Should().Be("Name"); }
public void AutoAssignColumnNameByDefault() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); hbm.Columns.Should().Have.Count.EqualTo(1); hbm.Columns.First().name.Should().Not.Be.Empty().And.Not.Be.Null(); }
public void SetUpdate() { var hbm = new HbmKey(); var mapper = new KeyMapper <string>(hbm); mapper.Update = false; hbm.update.Should().Be.False(); hbm.updateSpecified.Should().Be.True(); }
public void SetNotNull() { var hbm = new HbmKey(); var mapper = new KeyMapper <string>(hbm); mapper.NotNull = true; hbm.IsNullable.Should().Have.Value(); hbm.IsNullable.Value.Should().Be.False(); }
public void SetColumn() { var hbm = new HbmKey(); var mapper = new KeyMapper <string>(hbm); mapper.Column = "peppe"; hbm.Columns.Should().Have.Count.EqualTo(1); hbm.Columns.First().name.Should().Be.EqualTo("peppe"); }
public void SetUnique() { var hbm = new HbmKey(); var mapper = new KeyMapper <string>(hbm); mapper.Unique = true; hbm.unique.Should().Be.True(); hbm.uniqueSpecified.Should().Be.True(); }
public virtual Task <ISet <TItem> > GetValueOrEmptyAsync(TKey key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var keyColumnValues = KeyMapper.GetColumnValues(key); return(new InternalSet(ConnectionString, Table, Mapper, DatabaseDriver, keyColumnValues).AsCompletedTask <ISet <TItem> >()); }
internal override async Task Send(IOperation op, TaskCompletionSource <IMemoryOwner <byte> > tcs) { var bucket = KeyMapper.MapKey(op.Key); var endPoint = bucket.LocatePrimary(); var clusterNode = BucketNodes[endPoint]; await CheckConnection(clusterNode).ConfigureAwait(false); await op.SendAsync(clusterNode.Connection).ConfigureAwait(false); }
public void AssignOnDeleteAction() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.OnDelete(OnDeleteAction.Cascade); hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Cascade); km.OnDelete(OnDeleteAction.NoAction); hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Noaction); }
public void WhenAssignFKToNullThenSetToNull() { var hbm = new HbmKey(); hbm.foreignkey = "aPreviousValue"; var km = new KeyMapper(typeof(Animal), hbm); km.ForeignKey(null); hbm.foreignkey.Should().Be.Null(); }
public void EmptyCacheShouldLookupFirstValue() { bool lookupCalled = false; using (var mapper = new KeyMapper<int>(this.emptyDictionary, x => { lookupCalled = true; return 1234; })) { var key = mapper.Map("1234"); Assert.Equal(1234, key); Assert.Equal(true, lookupCalled); } }
public void PrimedCacheShouldNotAttemptLookup() { int lookupCount = 0; using (var mapper = new KeyMapper<int>(this.primedDictionary, x => { lookupCount++; return 0; })) { var key = mapper.Map("1234"); Assert.Equal(1234, key); Assert.Equal(0, lookupCount); } }
/// <summary> /// Loads the set of product subcategories from the database /// for surrogate key mapping. /// </summary> private void PrimeProductSubcategoryKeyMapper() { var initialCache = this.LoadKeyCache( SqlQueries.ProductSubcategoryKeyMap, "ProductSubcategoryKey", "BusinessKey"); this.productSubcategoryMapper = new KeyMapper<int>( initialCache, x => { var message = string.Format( CultureInfo.CurrentCulture, "Error, product subcategory key '{0}' not found in cache", x); throw new InvalidOperationException(message); }); }