Esempio n. 1
0
        private HashSet <Coord> _positionCache;        // Cached hash-set used for returning all positions in the LayeredSpatialMap

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="comparer">
        /// Equality comparer to use for comparison and hashing of type T. Be especially mindful of the
        /// efficiency of its GetHashCode function, as it will determine the efficiency of
        /// many AdvancedLayeredSpatialMap functions.
        /// </param>
        /// <param name="numberOfLayers">Number of layers to include.</param>
        /// <param name="startingLayer">Index to use for the first layer.</param>
        /// <param name="layersSupportingMultipleItems">
        /// A layer mask indicating which layers should support multiple items residing at the same
        /// location on that layer. Defaults to no layers.
        /// </param>
        public AdvancedLayeredSpatialMap(IEqualityComparer <T> comparer, int numberOfLayers, int startingLayer = 0, uint layersSupportingMultipleItems = 0)
        {
            if (numberOfLayers > 32 - startingLayer)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfLayers), $"More than {32 - startingLayer} layers is not supported by {nameof(AdvancedLayeredSpatialMap<T>)} starting at layer {startingLayer}");
            }

            _layers        = new ISpatialMap <T> [numberOfLayers];
            StartingLayer  = startingLayer;
            _positionCache = new HashSet <Coord>();

            LayerMasker          = new LayerMasker(numberOfLayers + startingLayer);
            _internalLayerMasker = new LayerMasker(numberOfLayers);

            for (int i = 0; i < _layers.Length; i++)
            {
                if (LayerMasker.HasLayer(layersSupportingMultipleItems, i + StartingLayer))
                {
                    _layers[i] = new AdvancedMultiSpatialMap <T>(comparer);
                }
                else
                {
                    _layers[i] = new AdvancedSpatialMap <T>(comparer);
                }
            }

            foreach (var layer in _layers)
            {
                layer.ItemAdded   += (_, e) => ItemAdded?.Invoke(this, e);
                layer.ItemRemoved += (_, e) => ItemRemoved?.Invoke(this, e);
                layer.ItemMoved   += (_, e) => ItemMoved?.Invoke(this, e);
            }
        }
Esempio n. 2
0
        } // RemoveAt

        public new void RemoveRange(int index, int count)
        {
            int c = Count;
            base.RemoveRange(index, count);
            if (ItemRemoved != null && c != Count) 
                ItemRemoved.Invoke(this, new EventArgs());
        } // RemoveRange    
Esempio n. 3
0
     } // Remove
 
     public new void Clear()
     {
         int c = Count;
         base.Clear();
         if (ItemRemoved != null && c != Count)
             ItemRemoved.Invoke(this, new EventArgs());
     } // Clear
Esempio n. 4
0
        public Task PlaylistItemRemoved(long playlistItemId)
        {
            if (Room == null)
            {
                return(Task.CompletedTask);
            }

            Scheduler.Add(() =>
            {
                if (Room == null)
                {
                    return;
                }

                Debug.Assert(APIRoom != null);

                Room.Playlist.Remove(Room.Playlist.Single(existing => existing.ID == playlistItemId));
                APIRoom.Playlist.RemoveAll(existing => existing.ID == playlistItemId);

                ItemRemoved?.Invoke(playlistItemId);
                RoomUpdated?.Invoke();
            });

            return(Task.CompletedTask);
        }
Esempio n. 5
0
        /// <summary>
        /// Removes the item at the specified index from this <see cref="BaseCollection{T}"/>.
        /// </summary>
        /// <param name="index">The index.</param>
        public virtual void RemoveAt(int index)
        {
            T i = InternalList[index];

            InternalList.RemoveAt(index);
            ItemRemoved?.Invoke(this, i);
        }
 public void AfterRemove(TElement element)
 {
     element.graph = null;
     element.AfterRemove();
     ItemRemoved?.Invoke(element);
     CollectionChanged?.Invoke();
 }
        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);
                }
            }
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 private void root_ChildRemoved(object sender, ChildEventArgs e)
 {
     if (m_lastRemoveIndex >= 0)
     {
         ItemRemoved.Raise(this, new ItemRemovedEventArgs <object>(m_lastRemoveIndex, e.Child, e.Parent));
     }
 }
Esempio n. 10
0
        /// <inheritdoc />
        public bool Remove(
            T item
            )
        {
            // Is the item present?
            //
            int itemIndex = InternalList.IndexOf(item);

            if (itemIndex == -1)
            {
                return(false);
            }

            // Remove the item
            //
            bool res = InternalList.Remove(item);

            if (res)
            {
                IsChanged = true;

                ItemRemoved?.Invoke(
                    this,
                    new ItemChangedEventArgs <T>(
                        item,
                        itemIndex
                        )
                    );
            }

            return(res);
        }
Esempio n. 11
0
        /// <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)
                    );
            }
        }
Esempio n. 12
0
        public void RemoveItemNamed(string id)
        {
            var item = items [id];

            items.Remove(id);
            ItemRemoved?.Invoke(this, new InventoryEventArgs(item));
        }
Esempio n. 13
0
        internal void Apply(ItemRemoved @event)
        {
            Id = @event.AggregateRootId;
            var item = GetCartItem(@event.ProductName);

            CartItems.Remove(item);
        }
Esempio n. 14
0
        private void OnDirectoryWatcherDeleted(object sender, FileSystemEventArgs e)
        {
            mutex.WaitOne();
            string path  = e.FullPath;
            string name  = System.IO.Path.GetFileName(path);
            int    index = WatchedDirectories.IndexOf(path);

            if (index >= 0)
            {
                WatchedDirectories.RemoveAt(index);
                ExpectingDirectories.Add(path);
                ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, path, name));
            }
            else
            {
                foreach (DirectoryScanOptions scanOptions in ScanOptions)
                {
                    if (scanOptions.IsIncluded(name, path, ItemType.Directory))
                    {
                        ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, path, name));
                        break;
                    }
                }
            }
            mutex.Set();
        }
Esempio n. 15
0
 public static void OnItemRemoved(Item item)
 {
     if (ItemRemoved != null)
     {
         ItemRemoved.Invoke(item);
     }
 }
Esempio n. 16
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            object item = SelectedItem;

            if (item != null)
            {
                int index = dgvAdditionalFiles.SelectedRows[0].Index;
                AdditionalFilesEventArgs cancelEvent = new AdditionalFilesEventArgs(item);
                ItemRemoving?.Invoke(this, cancelEvent);

                if (!cancelEvent.Cancel)
                {
                    m_files.Remove(item);
                    Rebind();

                    if (dgvAdditionalFiles.Rows.Count > 0)
                    {
                        if (index >= dgvAdditionalFiles.Rows.Count)
                        {
                            index = dgvAdditionalFiles.Rows.Count - 1;
                        }
                        dgvAdditionalFiles.Rows[index].Selected = true;
                    }

                    ItemRemoved?.Invoke(this, new AdditionalFilesEventArgs(item));
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Removes the item specified, if it exists.  Throws ArgumentException if the item is
        /// not in the spatial map.
        /// </summary>
        /// <param name="item">The item to remove.</param>
        public void Remove(T item)
        {
            Point pos;

            try
            {
                pos = _itemMapping[item];
            }
            catch (KeyNotFoundException)
            {
                throw new ArgumentException(
                          $"Tried to remove an item from the {GetType().Name} that has not been added.",
                          nameof(item));
            }

            _itemMapping.Remove(item);

            // Key guaranteed to exist due to state invariant of spatial map (oldPos existed in the other map)
            var posList = _positionMapping[pos];

            posList.Remove(item);
            if (posList.Count == 0)
            {
                _itemListPool.Return(posList, false);
                _positionMapping.Remove(pos);
            }

            ItemRemoved?.Invoke(this, new ItemEventArgs <T>(item, pos));
        }
Esempio n. 18
0
        public void Remove(IDuratedItem <T> durateditem)
        {
            var duration         = durateditem.Duration;
            var durateditem_real =
                durateditem as DuratedItem <T> ??
                items.FirstOrDefault(item => item.Value.Equals(durateditem.Value) && item.Duration == duration);

            elements_start.Remove(durateditem_real, duration.Start);
            elements_end.Remove(durateditem_real, duration.End);

            items.Remove(durateditem_real);

            FieldChanged?.Invoke(duration);

            if (GeneralDuration.Value == duration)
            {
                GeneralDuration_recalc();
            }
            else if (duration.Contains(GeneralDuration.Value.End))
            {
                GeneralDuration_recalc_end();
            }
            else if (duration.Contains(GeneralDuration.Value.Start))
            {
                GeneralDuration_recalc_start();
            }

            ItemRemoved?.Invoke(duration, durateditem.Value);
        }
Esempio n. 19
0
        private async Task ExpireKeysAsync()
        {
            while (_alive)
            {
                try
                {
                    var keys = _expiry.ToList();
                    foreach (var key in keys)
                    {
                        if (key.Value > DateTimeOffset.UtcNow)
                        {
                            continue;
                        }

                        if (_values.TryRemove(key.Key, out var value) && _expiry.TryRemove(key.Key, out _))
                        {
                            ItemRemoved?.Invoke(this, new CacheItemEventArgs <TValue>(value));
                        }
                    }

                    await Task.Delay(TimeSpan.FromSeconds(2));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"ExpiringDictionary: Exception: {e}");
                }
            }
        }
Esempio n. 20
0
        public void RemoveUnique(Duration duration)
        {
            var durateditem = items.Single(item => item.Duration == duration);

            elements_start.Remove(durateditem, duration.Start);
            elements_end.Remove(durateditem, duration.End);

            items.Remove(durateditem);

            FieldChanged?.Invoke(duration);

            if (GeneralDuration.Value == duration)
            {
                GeneralDuration_recalc();
            }
            else if (duration.Contains(GeneralDuration.Value.End))
            {
                GeneralDuration_recalc_end();
            }
            else if (duration.Contains(GeneralDuration.Value.Start))
            {
                GeneralDuration_recalc_start();
            }

            ItemRemoved?.Invoke(duration, durateditem.Value);
        }
Esempio n. 21
0
 void VB._dispReferences_Events.ItemRemoved(VB.Reference reference)
 {
     using (var removing = new Reference(reference))
     {
         ItemRemoved?.Invoke(this, new ReferenceEventArgs(new ReferenceInfo(removing), removing.Type));
     }
 }
Esempio n. 22
0
        public new bool Remove(T obj)
        {
            var b = base.Remove(obj);

            ItemRemoved?.Invoke(this, new EventListArgs <T>(obj));
            return(b);
        }
Esempio n. 23
0
 public void InvokeItemRemoved()
 {
     if (ItemRemoved != null)
     {
         ItemRemoved.Invoke(null, new EventArgs());
     }
 }
Esempio n. 24
0
        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());
            }
        }
        /// <inheritdoc/>
        public async Task DeleteOriginalFile(string resultId)
        {
            var result = _repo.GetResult(resultId);

            _logger.LogInformation("Requested to delete {0}", result.OriginalPath);

            if (!AddToInProgressList(result, false))
            {
                throw new OrganizationException("Path is currently processed otherwise. Please try again later.");
            }

            try
            {
                _fileSystem.DeleteFile(result.OriginalPath);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error deleting {0}", result.OriginalPath);
            }
            finally
            {
                RemoveFromInprogressList(result);
            }

            await _repo.Delete(resultId).ConfigureAwait(false);

            ItemRemoved?.Invoke(this, new GenericEventArgs <FileOrganizationResult>(result));
        }
Esempio n. 26
0
 public async Task <bool> RemoveAsync(TEntity entity)
 {
     ItemRemoved?.Invoke(this, new List <TEntity> {
         entity
     });
     return(await _conn.DeleteAsync(entity) > 0);
 }
Esempio n. 27
0
        } // Add

        public new void Remove(T obj)
        {
            int c = Count;
            base.Remove(obj);
            if (ItemRemoved != null && c != Count) 
                ItemRemoved.Invoke(this, new EventArgs());
        } // Remove
Esempio n. 28
0
 /// <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()!");
 }
Esempio n. 29
0
 private void DomNode_ChildRemoved(object sender, ChildEventArgs e)
 {
     if (IsPrototypeItem(e.Child, e.Parent))
     {
         ItemRemoved.Raise(this, new ItemRemovedEventArgs <object>(e.Index, e.Child, e.Parent));
     }
 }
Esempio n. 30
0
        public void RemoveAt(int index)
        {
            var item = list[index];

            list.RemoveAt(index);
            ItemRemoved?.Invoke(item, index);
        }