private static void Remove(SmsContainerElement o)
 {
     if (o.State != SmsElementStateCode.Free)
     {
         o.CurrentCapacity--;
     }
     if (o.CurrentCapacity == 0)
     {
         o.State = SmsElementStateCode.Free;
     }
     else
     {
         o.State = CapacityToStateConverter(o.CurrentCapacity, o.MaxCapacity);
     }
 }
 private static void Add(SmsContainerElement o)
 {
     if (o.State != SmsElementStateCode.Full)
     {
         o.CurrentCapacity++;
     }
     if (o.CurrentCapacity == o.MaxCapacity)
     {
         o.State = SmsElementStateCode.Full;
     }
     else
     {
         o.State = CapacityToStateConverter(o.CurrentCapacity, o.MaxCapacity);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts emulating process.
        /// </summary>
        /// <returns>Statistics for current run.</returns>
        public StatisticResults Emulate()
        {
            StatisticResults result = new StatisticResults();
            SmsChannelElement channelOne = new SmsChannelElement(this.P1);
            SmsChannelElement channelTwo = new SmsChannelElement(this.P2);
            SmsEmitterElement emitter = new SmsEmitterElement(this.R);
            SmsContainerElement container = new SmsContainerElement(ContainerCapacity);
            
            UInt32 tiks = 0;
            while (tiks++ != TotalCount)
            {

                result.Add(container, emitter, channelOne, channelTwo);
                if (channelTwo.IsDone)
                {
                    channelTwo.SetFree();
                }

                if (container.NonEmpty && channelTwo.IsFree)
                {
                    --container;
                    channelTwo.TakeRequest();
                }

                if (channelOne.IsBlocked || channelOne.IsDone)
                {
                    if (channelTwo.IsFree)
                    {
                        channelOne.SetFree();
                        channelTwo.TakeRequest();
                    }
                    else
                    {
                        if (container.NotFull)
                        {
                            channelOne.SetFree();
                            ++container;
                        }
                        else
                        {
                            channelOne.SetBlocked();
                        }
                    }
                }
                
                if (emitter.IsBlocked || emitter.IsDone) 
                {
                    if (channelOne.IsFree)
                    {
                        channelOne.TakeRequest();
                        emitter.SetFree();
                    }
                    else
                    {
                        emitter.SetBlocked();
                    }
                }
                
            }
            Sms.TotalTaktsCount = tiks;
            return result;
        }