void VB._dispReferences_Events.ItemAdded(VB.Reference reference) { using (var adding = new Reference(reference)) { ItemAdded?.Invoke(this, new ReferenceEventArgs(new ReferenceInfo(adding), adding.Type)); } }
public bool TryAddItemInstance(IItemInstance itemInstance) { ItemBatch queriedBatch = itemBatches. FirstOrDefault( b => b.item == itemInstance.data && b.fillLevel <= maxBatchSize - b.item.stackWeight); if (queriedBatch != default(ItemBatch)) { if (queriedBatch.TryAdd(itemInstance)) { ItemAdded?.Invoke(itemInstance); return(true); } return(false); } else { if (!slotToItemBatch.Any(s => s.Value == null)) { return(false); } CreateNewItemBatch(itemInstance.data, itemInstance); ItemAdded?.Invoke(itemInstance); return(true); } }
public bool TryAddItem(Item item) { ItemBatch queriedBatch = itemBatches.FirstOrDefault( b => b.item == item && b.fillLevel <= maxBatchSize - item.stackWeight); IItemInstance itemInstance = default; if (queriedBatch != default(ItemBatch)) { itemInstance = queriedBatch.AddNew(1)[0]; ItemAdded?.Invoke(itemInstance); return(true); } else { if (!slotToItemBatch.Any(s => s.Value == null)) { return(false); } itemInstance = ItemManager.CreateItemInstance(item, null); CreateNewItemBatch(item, itemInstance); UpdateEmptyBatches(); ItemAdded?.Invoke(itemInstance); return(true); } }
public void AddOrUpdate(TKey key, TValue value, int ttl) { var added = false; _values.AddOrUpdate(key, k => { added = true; return(value); }, (k, v) => { added = false; return(value); } ); var expiry = DateTimeOffset.UtcNow + TimeSpan.FromSeconds(ttl); _expiry.AddOrUpdate(key, expiry, (k, d) => expiry); if (added) { ItemAdded?.Invoke(this, new CacheItemEventArgs <TValue>(value)); } else // updated { ItemUpdated?.Invoke(this, new CacheItemEventArgs <TValue>(value)); } }
private void Sync_Collection(object sender, NotifyCollectionChangedEventArgs e) { if (DisableSync) { return; } if (e.NewItems != null) { foreach (var item in e.NewItems.Cast <TViewModel>()) { ItemAdded?.Invoke(item); ModelCollection?.Add(item.Model); } } if (e.OldItems != null) { foreach (var item in e.OldItems.Cast <TViewModel>()) { ItemRemoved?.Invoke(item); ModelCollection?.Remove(item.Model); } } }
void OnItemAdded(object sender, MultiButtonEntryItemEventArgs e) { e.Item.Parent = this; _children.Add(e.Item); e.Item.Deleted += Item_Deleted; ItemAdded?.Invoke(this, e); }
public Task PlaylistItemAdded(MultiplayerPlaylistItem item) { if (Room == null) { return(Task.CompletedTask); } Scheduler.Add(() => { if (Room == null) { return; } Debug.Assert(APIRoom != null); Room.Playlist.Add(item); APIRoom.Playlist.Add(createPlaylistItem(item)); ItemAdded?.Invoke(item); RoomUpdated?.Invoke(); }); return(Task.CompletedTask); }
public virtual void AddOrUpdate(IEnumerable <TEntity> collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } foreach (var entity in collection) { // Check to see if this is a new entity (by checking the key) if (IsNew(entity)) { InternalSet.Add(entity); ItemAdded?.Invoke(entity); } else { // Is this entity already attached? var entry = DataContext.ChangeTracker.Entries <TEntity>().SingleOrDefault(n => KeysEqual(n.Entity, entity)); if (entry == null) { // BUG: Entity exists but is not the one they saved here... InternalSet.Add(entity); entry = DataContext.ChangeTracker.Entries <TEntity>().SingleOrDefault(n => KeysEqual(n.Entity, entity)); } entry.State = EntityState.Modified; ItemModified?.Invoke(entity); } } }
/// <summary> /// Treated as a cleanup method of sorts, this cleans up certain members of this inventory. /// </summary> public virtual void OnDisable() { ItemAdded.RemoveAllListeners(); ItemRemoved.RemoveAllListeners(); ContentChanged.RemoveAllListeners(); Debug.Log(this.name + " OnDisable()!"); }
/// <summary> /// Queue a new operation /// </summary> /// <param name="batch">TableBatchOperation to queue</param> /// <param name="tableName">Name of the table to run it against</param> public void Add(TableBatchOperation batch, string tableName) { if (_isDraining) { // no items can be added during a drain throw new Exception("Cannot queue items during a drain."); } if ((batch == null) || (batch.Count == 0)) { throw new ArgumentNullException("Empty batch"); } if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentNullException("tableName"); } // examine the batch, split into unique operations of a max of 100 elements each foreach (IGrouping <string, TableOperation> operationByPartitionKeys in batch.GroupBy(b => b.Entity.PartitionKey)) { string partitionKey = operationByPartitionKeys.Key; Dictionary <TableOperationType, TableBatchOperationWrapper> operationsByType = new Dictionary <TableOperationType, TableBatchOperationWrapper>() { { TableOperationType.Delete, new TableBatchOperationWrapper(new TableBatchOperation(), tableName) }, { TableOperationType.Insert, new TableBatchOperationWrapper(new TableBatchOperation(), tableName) }, { TableOperationType.InsertOrMerge, new TableBatchOperationWrapper(new TableBatchOperation(), tableName) }, { TableOperationType.InsertOrReplace, new TableBatchOperationWrapper(new TableBatchOperation(), tableName) }, { TableOperationType.Merge, new TableBatchOperationWrapper(new TableBatchOperation(), tableName) }, { TableOperationType.Replace, new TableBatchOperationWrapper(new TableBatchOperation(), tableName) } }; foreach (TableOperation operation in operationByPartitionKeys.OrderBy(o => o.Entity.RowKey).ThenBy(o => o.OperationType)) { if ((operation.OperationType == TableOperationType.Invalid) || (operation.OperationType == TableOperationType.Retrieve)) { throw new ArgumentOutOfRangeException("Unsupported operation for queue!"); } operationsByType[operation.OperationType].Batch.Add(operation); ItemAdded?.Invoke(tableName, Enum.GetName(typeof(TableOperationType), operation.OperationType) ?? "Unknown", partitionKey, operation.Entity.RowKey); if (operationsByType[operation.OperationType].Batch.Count == 100) { _queue.Enqueue(operationsByType[operation.OperationType]); operationsByType[operation.OperationType] = new TableBatchOperationWrapper(new TableBatchOperation(), tableName); } } // flush each op/group to the queue, because next iteration of the loop changes the partition key foreach (TableOperationType type in operationsByType.Keys) { if (operationsByType[type].Batch.Count > 0) { _queue.Enqueue(operationsByType[type]); } } } }
public void OverwriteAt(int index, Control c, bool fitted = false) { if (!ValidIndex(index)) { return; } if (cells[index] != null) { Remove(cells[index]); if (ItemRemoved != null) { ItemRemoved.Invoke(this, new EventArgs()); } } cells[index] = c; fitToCell[index] = fitted; Add(c); if (ItemAdded != null) { ItemAdded.Invoke(this, new EventArgs()); } }
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs args) { switch (args.Action) { case NotifyCollectionChangedAction.Add: ItemAdded?.Invoke(this, args.NewStartingIndex, (T)args.NewItems[0]); OnCountChanged(); break; case NotifyCollectionChangedAction.Remove: ItemRemoved?.Invoke(this, args.OldStartingIndex, (T)args.OldItems[0]); OnCountChanged(); break; case NotifyCollectionChangedAction.Move: ItemMoved?.Invoke(this, args.OldStartingIndex, args.NewStartingIndex, (T)args.NewItems[0]); break; case NotifyCollectionChangedAction.Replace: ItemReplaced?.Invoke(this, args.OldStartingIndex, (T)args.OldItems[0], (T)args.NewItems[0]); break; case NotifyCollectionChangedAction.Reset: ItemsReset?.Invoke(this); OnCountChanged(); break; } CollectionChanged?.Invoke(this, args); }
/// <inheritdoc /> public T this[int index] { get { return(InternalList[index]); } set { if (InternalList[index].Equals(value)) { return; } AssertValid(value); var oldItem = InternalList[index]; InternalList[index] = value; IsChanged = true; ItemRemoved?.Invoke( this, new ItemChangedEventArgs <T>(oldItem, index) ); ItemAdded?.Invoke( this, new ItemChangedEventArgs <T>(value, index) ); } }
public void Add(T item) { m_list.Add(item); syncToPrevList(); ItemAdded?.Invoke(item); OnChanged?.Invoke(); }
public void Insert(int index, T value) { m_list.Insert(index, value); syncToPrevList(); ItemAdded?.Invoke(value); OnChanged?.Invoke(); }
public void AddItem(IItem item) { lock (stacks) { if (item is IDecayItem decayItem) { decayItem.Decayed += Item_Decayed; } if (!item.Stackable) { stacks.Add(new InventoryStack(item)); return; } var existingStack = GetItemStack(item); if (existingStack != null) { existingStack.Add(item); } else { stacks.Add(new InventoryStack(item)); } ItemAdded?.Invoke(this, new ItemEventArgs(item)); } }
public void WHEN_receiving_message_once_THEN_proyects_in_proc() { var commandId = SequentialGuid.GenerateNewGuid(); var e = new ItemAdded { SourceType = "DomainAggregate", CorrelationId = commandId, SourceId = Guid.Empty, Id = 1, Name = "Silla", Version = 1 }; this.sut.Project(e, (context) => { context.Items.Add(new Item { UnidentifiableId = e.Id, Name = e.Name }); }, (context) => { }); using (var context = this.contextFactory.Invoke()) { var item = context.Items.Where(i => i.UnidentifiableId == 1).FirstOrDefault(); var log = context.ReadModelingEvents.Where(l => l.SourceId == Guid.Empty && l.Version == 1).FirstOrDefault(); Assert.Equal("Silla", item.Name); Assert.True(log != null); Assert.Equal(commandId, log.CorrelationId); } }
/// <summary> /// Sets an item count (for deserializing) /// </summary> /// <param name="itemName">The item's name</param> /// <param name="count">The count</param> public static void SetItemCount(string itemName, int count) { ItemDef itemDef = _itemDefs.FirstOrDefault(x => x.Name.Equals(itemName, StringComparison.InvariantCultureIgnoreCase)); if (itemDef == null) { return; } if (count <= 0) { RemoveItem(itemDef); return; } var item = GetItem(itemDef); if (item != null) { item.Count = count; } else { Items.Add(new InventoryItem(itemDef) { Count = count }); } ItemAdded?.Invoke(itemDef); }
// TODO: remove temp code after cleanup public TreeViewItem AddItem(ITreeViewItem item, TreeViewItem Parent = null) { TreeViewItem TVI = new TreeViewItem(); TVI.Tag = item; TVI.Header = item.Header(); if (Parent == null) { Tree.Items.Add(TVI); } else { Parent.Items.Add(TVI); } if (item.IsExpandable()) { TVI.Expanded += TVI_Expanded; TVI.Collapsed += TVI_Collapsed; TreeViewItem TVDummy = new TreeViewItem() { Header = "DUMMY" }; TVI.Items.Add(TVDummy); } ItemAdded?.Invoke(item, null); return(TVI); }
public void WHEN_receiving_message_twice_THEN_consumes_only_once() { var commandId = SequentialGuid.GenerateNewGuid(); var e = new ItemAdded { SourceType = "DomainAggregate", CorrelationId = commandId, SourceId = Guid.Empty, Id = 1, Name = "Silla", Version = 1 }; var mailSent = 0; this.sut.Consume <MailingSubscription>(e, () => { ++mailSent; Console.WriteLine("Mail sent once!"); }); this.sut.Consume <MailingSubscription>(e, () => { ++mailSent; Console.WriteLine("Mail sent twice! this not good...."); }); Assert.Equal(1, mailSent); }
private void Handle(ItemAdded evt) { var existingBasket = _indexer.Get <Basket>(evt.Id); var orderLines = existingBasket.OrderLines; if (orderLines == null || orderLines.Length == 0) { existingBasket.OrderLines = new[] { evt.OrderLine }; } else { var orderLineList = orderLines.ToList(); orderLineList.Add(evt.OrderLine); existingBasket.OrderLines = orderLineList.ToArray(); } _indexer.Index(existingBasket); _graphClient.Cypher .Match("(basket:Basket)", "(product:Product)") .Where((Basket basket) => basket.Id == evt.Id) .AndWhere((Product product) => product.Id == evt.OrderLine.ProductId) .Create("basket-[:HAS_ORDERLINE {orderLine}]->product") .WithParam("orderLine", evt.OrderLine) .ExecuteWithoutResults(); }
protected void OnItemAdded(object sender) { if (ItemAdded != null) { ItemAdded.Invoke(sender, new System.EventArgs()); } }
// Inserts an element into this list at a given index. The size of the list // is increased by one. If required, the capacity of the list is doubled // before inserting the new element. // public void Insert(int index, T item) { // Note that insertions at the end are legal. if ((uint)index > (uint)_size) { throw new InvalidOperationException("Argument out of range"); } Contract.EndContractBlock(); if (_size == _items.Length) { EnsureCapacity(_size + 1); } if (index < _size) { Array.Copy(_items, index, _items, index + 1, _size - index); } _items[index] = item; _size++; _version++; if (ItemAdded != null) { ItemAdded.Invoke((T)_items[index]); } }
private void ExtendedListbox_DragDropCompleted(object sender, DragEventArgs e) { try { //prevent to do drag drop in the same window - will create an item copy if (((extendedListbox <T>)sender).Name != _Source.Name) { //change target - step 1 update the items in the box if (!(((extendedListbox <T>)sender).Items.Contains(_Source.SelectedItem))) { ((extendedListbox <T>)sender).Items.Add(_Source.SelectedItem); if (((extendedListbox <T>)sender).ItemAdded != null) { ItemAdded.Invoke((extendedListbox <T>)sender, (T)_Source.SelectedItem); } if (_Source.ItemRemoved != null) { _Source.ItemRemoved.Invoke(_Source, (T)_Source.SelectedItem); } _Source.Items.Remove(_Source.SelectedItem); } } } catch (Exception ee) { } DragDropBusy = false; }
} // AddRange public new void Insert(int index, T item) { int c = Count; base.Insert(index, item); if (ItemAdded != null && c != Count) ItemAdded.Invoke(this, new EventArgs()); } // Insert
} // Insert public new void InsertRange(int index, IEnumerable<T> collection) { int c = Count; base.InsertRange(index, collection); if (ItemAdded != null && c != Count) ItemAdded.Invoke(this, new EventArgs()); } // InsertRange
} // Clear public new void AddRange(IEnumerable<T> collection) { int c = Count; base.AddRange(collection); if (ItemAdded != null && c != Count) ItemAdded.Invoke(this, new EventArgs()); } // AddRange
public new void Add(T item) { int c = Count; base.Add(item); if (ItemAdded != null && c != Count) ItemAdded.Invoke(this, new EventArgs()); } // Add
private void LoadAssets(ContentTreeNode parent, string[] files) { for (int i = 0; i < files.Length; i++) { var path = StringUtils.NormalizePath(files[i]); // Check if node already has that element (skip during init when we want to walk project dir very fast) if (_isDuringFastSetup || !parent.Folder.ContainsChild(path)) { // Create file item ContentItem item = null; if (FlaxEngine.Content.GetAssetInfo(path, out var assetInfo)) { var proxy = GetAssetProxy(assetInfo.TypeName, path); item = proxy?.ConstructItem(path, assetInfo.TypeName, ref assetInfo.ID); } if (item == null) { item = new FileItem(path); } // Link item.ParentFolder = parent.Folder; // Fire event if (_enableEvents) { ItemAdded?.Invoke(item); WorkspaceModified?.Invoke(); } _itemsCreated++; } } }
/// <inheritdoc/> public bool AddToInProgressList(FileOrganizationResult result, bool isNewItem) { if (string.IsNullOrWhiteSpace(result.Id)) { result.Id = result.OriginalPath.GetMD5().ToString("N", CultureInfo.InvariantCulture); } if (!_inProgressItemIds.TryAdd(result.Id, false)) { return(false); } result.IsInProgress = true; if (isNewItem) { ItemAdded?.Invoke(this, new GenericEventArgs <FileOrganizationResult>(result)); } else { ItemUpdated?.Invoke(this, new GenericEventArgs <FileOrganizationResult>(result)); } return(true); }
private void Handle(ItemAdded evt) { var existingBasket = _indexer.Get<Basket>(evt.Id); var orderLines = existingBasket.OrderLines; if (orderLines == null || orderLines.Length == 0) { existingBasket.OrderLines = new[] {evt.OrderLine}; } else { var orderLineList = orderLines.ToList(); orderLineList.Add(evt.OrderLine); existingBasket.OrderLines = orderLineList.ToArray(); } _indexer.Index(existingBasket); _graphClient.Cypher .Match("(basket:Basket)", "(product:Product)") .Where((Basket basket) => basket.Id == evt.Id) .AndWhere((Product product) => product.Id == evt.OrderLine.ProductId) .Create("basket-[:HAS_ORDERLINE {orderLine}]->product") .WithParam("orderLine", evt.OrderLine) .ExecuteWithoutResults(); }
private void Apply(ItemAdded obj) { _orderLines = FSharpList<OrderLine>.Cons(obj.OrderLine, _orderLines); }