Esempio n. 1
0
 public Person(string name, string pnumber, Bagage bagage, uint gateId)
 {
     Name           = name;
     PassagerNumber = pnumber;
     Bagage         = bagage;
     GateId         = gateId;
 }
Esempio n. 2
0
 /// <summary>
 /// Constructor used for when reading data
 /// </summary>
 /// <param name="bagage"></param>
 public Person(Bagage bagage)
 {
     Name           = "";
     PassagerNumber = "";
     Bagage         = bagage;
     GateId         = 0;
 }
Esempio n. 3
0
        /// <summary>
        /// Gets the next availlable bagage on the ingoing buffers
        /// </summary>
        /// <returns></returns>
        private Bagage GetNextBagage()
        {
            for (int i = 0; i < InGoingBuffers.Length; i++)
            {
                CounterDesk curBuffer = InGoingBuffers[i];

                Monitor.Enter(curBuffer.Buffer.Lock);

                try
                {
                    if (curBuffer.Buffer.IsBufferEmpty)
                    {
                        Monitor.PulseAll(curBuffer.Buffer.Lock);
                        continue;
                    }

                    Bagage curBagage = curBuffer.Buffer.RemoveFromBackBuffer();
                    InGoingBagageHandler?.Invoke(curBagage);

                    return(curBagage);
                }
                finally
                {
                    Monitor.Exit(curBuffer.Buffer.Lock);
                }
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Processes the bagage and sends it to the outgoing buffer
        /// </summary>
        /// <param name="bagage"></param>
        private void ProcessBagage(Bagage bagage)
        {
            for (int i = 0; i < OutGoingBuffers.Length; i++)
            {
                Gate curGate = OutGoingBuffers[i];

                Monitor.Enter(OutGoingBuffers[i].Buffer.Lock);

                try
                {
                    if (bagage.Sticker.GateId != curGate.Id)
                    {
                        continue;
                    }

                    if (curGate.Buffer.IsBufferFull)
                    {
                        Monitor.PulseAll(curGate.Buffer.Lock);
                        Monitor.Wait(curGate.Buffer.Lock);
                    }

                    curGate.Buffer.AddToFrontBuffer(bagage);
                    OutGoingBagageHandler?.Invoke(bagage);
                }
                finally
                {
                    Monitor.Exit(OutGoingBuffers[i].Buffer.Lock);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// The thread work
 /// </summary>
 protected override void ThreadWork()
 {
     while (true)
     {
         Bagage curBagage = ProcessPerson();
         PutBagageOnBelt(curBagage);
     }
 }
Esempio n. 6
0
        protected override void ThreadWork()
        {
            while (true)
            {
                Bagage bagage = GetNextBagage();

                if (bagage != null)
                {
                    ProcessBagage(bagage);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Generates a random person with bagage
        /// and gives them an gateId
        /// </summary>
        /// <param name="gateId"></param>
        /// <returns></returns>
        public Person GeneratePerson(uint gateId)
        {
            string rndBrand  = bagagebrands[rnd.Next(0, bagagebrands.Length)];
            Array  colors    = Enum.GetValues(typeof(Color));
            Color  rndColor  = (Color)colors.GetValue(rnd.Next(colors.Length));
            float  rndWeight = rnd.Next(20, 1000) / 100;
            Bagage curB      = new Bagage(rndBrand, rndColor, rndWeight);

            string rndName   = names[rnd.Next(0, names.Length)];
            string rndNumber = Guid.NewGuid().GetHashCode().ToString();

            Person curP = new Person(rndName, rndNumber, curB, gateId);

            return(curP);
        }
Esempio n. 8
0
        /// <summary>
        /// Puts the bagage on the belt if the buffer is not full
        /// </summary>
        /// <param name="bagage"></param>
        private void PutBagageOnBelt(Bagage bagage)
        {
            Monitor.Enter(Buffer.Lock);

            try
            {
                if (Buffer.IsBufferFull)
                {
                    Monitor.Wait(Buffer.Lock);
                }

                Buffer.AddToFrontBuffer(bagage);

                if (Buffer.BufferCounter == 1)
                {
                    Monitor.PulseAll(Buffer.Lock);
                }
            }
            finally
            {
                Monitor.Exit(Buffer.Lock);
            }
        }