Пример #1
0
        /// <summary>
        /// Adds amount to content.
        /// Raising NearCapacity, CapacityReached or OverCapacity depending on filled amount.
        /// </summary>
        /// <param name="amount">The amount filled.</param>
        public void Fill(int amount)
        {
            //If raised. Will stop container from being filled.
            if (Content + amount > Capacity && UseNearCapacity)
            {
                CapacityDeviationEventArgs args = new CapacityDeviationEventArgs();
                args.Amount = Capacity - Content;
                OnNearCapacity(args);
                return;
            }
            int PriorContent = Content;

            Content += amount;

            if (PriorContent < Capacity && Content == Capacity)
            {
                OnCapacityReached(EventArgs.Empty);
            }
            else if (Content > Capacity)
            {
                CapacityDeviationEventArgs args = new CapacityDeviationEventArgs();
                args.Amount = Content - Capacity;
                OnOverCapacity(args);

                //Set Content to Capacity, as all excess would be "spilled".
                Content = Capacity;
            }
        }
Пример #2
0
 protected override void OnNearCapacity(CapacityDeviationEventArgs e)
 {
     //Bucket specific code.
     IsNearCapacityRaised = true;
     //Raise baseclass event.
     base.OnNearCapacity(e);
 }
Пример #3
0
        protected virtual void OnOverCapacity(CapacityDeviationEventArgs e)
        {
            EventHandler <CapacityDeviationEventArgs> handler = OverCapacity;

            handler?.Invoke(this, e);
        }
Пример #4
0
 public void TestInitalize()
 {
     _eventIsRaised = false;
     _eventSender   = null;
     _eventArgs     = null;
 }
Пример #5
0
 private void Bucket_NearCapacity(object sender, CapacityDeviationEventArgs e)
 {
     _eventIsRaised = true;
     _eventSender   = sender;
     _eventArgs     = e;
 }