public void processLuggage(LuggageBag luggage)
 {
     List<LuggageBag> luggageToForward = this.queue.checkLuggageQueue();
     while (luggageToForward.Count() > 0)
     {
         LuggageBag bag = luggageToForward[0];
         luggageToForward.RemoveAt(0);
         List<IComponent> possibleRoutes = new List<IComponent>();
         // Find components with possible routes.
         foreach (IComponent nextComponent in this.nextComponents)
         {
             List<IComponent> sinks = nextComponent.getSinks().FindAll(x => x.Equals(bag.destination));
             if (sinks.Count > 0)
             {
                 possibleRoutes.Add(nextComponent);
             }
         }
         // Find the route with the least amount of luggage on.
         int min_luggage_in_sink = -1;
         IComponent min_sink = null;
         foreach (IComponent sink in possibleRoutes)
         {
             if (min_sink == null || sink.Count() < min_luggage_in_sink)
             {
                 min_sink = sink;
                 min_luggage_in_sink = sink.Count();
             }
         }
         min_sink.EnqueueLuggage(bag);
         this.LuggageCounter++;
     }
 }
        public void testBufferConstructor()
        {
            int dequeueDeltaMiliSeconds = 0;
            List<IProblem> problems = new List<IProblem>();
            int id = 0;
            G12_Robust_Software_Systems.Model.Components.Buffer buf = new G12_Robust_Software_Systems.Model.Components.Buffer(dequeueDeltaMiliSeconds, problems, id);
            Assert.AreEqual(buf.name, "Buffer number: " + id.ToString());

            Assert.AreEqual(buf.stuck, false);
            IComponent destination = buf;
            LuggageBag lb = new LuggageBag(destination);

            bool fail1 = true;
            try {
                buf.getSinks();
            }
            catch (Exception e)
            {
                if (e.GetType().FullName == "System.Diagnostics.Contracts.__ContractsRuntime+ContractException")
                    fail1 = false;
            }
            Assert.IsTrue(fail1);

            /**
            // Check count() and enqueluggage with problem and without problem
            List<Personnel> plist = new List<Personnel>();
            List<IRole> roles = new List<IRole>();
            roles.Add(new StuckLuggageRole());
            Personnel p1 = new Personnel(1, roles);
            plist.Add(p1);
            PersonnelController pc = new PersonnelController(plist);

            Stuck s = new Stuck(0, pc);
            problems.Add(s);
            buf.EnqueueLuggage(lb);
            Assert.AreEqual(buf.Count(), 1);

            s = new Stuck(100, pc);
            problems.Add(s);
            buf.EnqueueLuggage(lb);
            Assert.AreEqual(buf.Count(), 1);

            //AddNextComponent()
            try
            {
                buf.addNextComponent(buf);
            }
            catch (NotImplementedException)
            {
                Assert.IsTrue(true);
            }

            //InAndOutCounters()
            Assert.AreEqual(buf.InAndOutCounters().Item1, 2);

            //GetSinks()
            Assert.AreEqual(buf.getSinks().Count, 1);
            **/
        }
        public void enqueueLuggage(int dequeueDeltaMiliSeconds, LuggageBag luggage)
        {
            Contract.Requires(dequeueDeltaMiliSeconds >= 0, "dequeueDeltaMiliSeconds cannot be less than zero");
            Contract.Requires(luggage != null, "luggage cannot be null");

            Tuple<long, LuggageBag> luggageTuple = new Tuple<long, LuggageBag>(DateTime.Now.Ticks + dequeueDeltaMiliSeconds * 10000, luggage);
            this.queue.Enqueue(luggageTuple);
        }
        public void testConveyorBeltSplitterConstructor()
        {
            int dequeueDeltaMiliSeconds = 1000;
            int id = 0;
            List<IProblem> problems = new List<IProblem>();
            ConveyorBeltSplitter cbs = new ConveyorBeltSplitter(dequeueDeltaMiliSeconds, problems, id);
            Assert.AreEqual(cbs.name, "Splitter number: " + id.ToString());

            Assert.AreEqual(cbs.stuck, false);
            IComponent destination = cbs;
            LuggageBag lb = new LuggageBag(destination);

            Assert.AreEqual(cbs.getSinks().Count, 0);

            // Check count() and enqueluggage with problem and without problem
            List<Personnel> plist = new List<Personnel>();
            List<IRole> roles = new List<IRole>();
            roles.Add(new StuckLuggageRole());
            Personnel p1 = new Personnel(1, roles);
            plist.Add(p1);
            PersonnelController pc = new PersonnelController(plist);

            Stuck s = new Stuck(0, pc);
            problems.Add(s);
            cbs.EnqueueLuggage(lb);

            bool fail1 = true;
            try
            {
                cbs.getSinks();
            }
            catch (Exception e)
            {
                if (e.GetType().FullName == "System.Diagnostics.Contracts.__ContractsRuntime+ContractException")
                    fail1 = false;
            }
            Assert.IsTrue(fail1);
            /**
            Assert.AreEqual(1,cbs.Count());

            s = new Stuck(100, pc);
            problems.Add(s);
            cbs.EnqueueLuggage(lb);
            Assert.AreEqual(2,cbs.Count());

            try
            {
                cbs.addNextComponent(cbs);
            }
            catch (NotImplementedException)
            {
                Assert.IsTrue(true);
            }

            Assert.AreEqual(cbs.getSinks().Count, 1);**/
        }
        public void testLuggageBagConstructor()
        {
            List<IProblem> problems = new List<IProblem>();
            int id= 0;
            IComponent c_destination = new Airplane(problems, id);
            LuggageBag lb = new LuggageBag(c_destination);
            Assert.AreEqual(lb.destination, c_destination);

            Assert.AreEqual(c_destination.getSinks().Count, 1);
        }
 public void processLuggage(LuggageBag luggage)
 {
     List<LuggageBag> luggageToForward = this.queue.checkLuggageQueue();
     while (luggageToForward.Count() > 0)
     {
         this.nextComponent.EnqueueLuggage(luggageToForward[0]);
         luggageToForward.RemoveAt(0);
         this.LuggageCounter++;
     }
 }
        public void testAirplaneConstructor()
        {
            List<IProblem> problems = new List<IProblem>();
            int id= 0;
            Airplane ap = new Airplane(problems, id);

            // Constructor()
            Assert.AreEqual(ap.name, "Airplane number: "+id.ToString());
            Assert.AreEqual(ap.initialized, true);
            Assert.AreEqual(ap.stuck, false);
            IComponent destination = ap;
            LuggageBag lb = new LuggageBag(destination);

            // Check count() and enqueluggage with problem and without problem
            List<Personnel> plist = new List<Personnel>();
            List<IRole> roles = new List<IRole>();
            roles.Add(new StuckLuggageRole());
            Personnel p1 = new Personnel(1, roles);
            plist.Add(p1);
            PersonnelController pc = new PersonnelController(plist);

            Stuck s = new Stuck(0, pc);
            problems.Add(s);
            ap.EnqueueLuggage(lb);
            Thread.Sleep(1000);
            Assert.AreEqual(0, ap.Count());

            s = new Stuck(100, pc);
            problems.Add(s);
            ap.EnqueueLuggage(lb);
            Assert.AreEqual(1, ap.Count());

            //DequeLuggage()
            //ap.DequeueLuggage();
            //Assert.AreEqual(ap.Count(), 0);

            //AddNextComponent()
            try
            {
                ap.addNextComponent(ap);
            }
            catch (NotImplementedException)
            {
                Assert.IsTrue(true);
            }

            //InAndOutCounters()
            Assert.AreEqual(ap.InAndOutCounters().Item1, 2);

            //GetSinks()
            //Assert.AreEqual(ap.getSinks(), );
            Assert.AreEqual(ap.getSinks().Count, 1);
            //Assert.AreEqual(ap.getSinks().ToString(), "Airplane number: 0");
        }
        public void testSortingMachineTest()
        {
            int dequeueDeltaMiliSeconds = 0;
            int id = 0;
            List<IProblem> problems = new List<IProblem>();
            SortingMachine sm = new SortingMachine(dequeueDeltaMiliSeconds, problems, id);
            Assert.AreEqual(sm.name, "Sorting m. number: " + id.ToString());

            Assert.AreEqual(sm.stuck, false);
            IComponent destination = sm;
            LuggageBag lb = new LuggageBag(destination);

            Assert.AreEqual(sm.getSinks().Count, 0);
            /**
            // Check count() and enqueluggage with problem and without problem
            List<Personnel> plist = new List<Personnel>();
            List<IRole> roles = new List<IRole>();
            roles.Add(new StuckLuggageRole());
            Personnel p1 = new Personnel(1, roles);
            plist.Add(p1);
            PersonnelController pc = new PersonnelController(plist);

            Stuck s = new Stuck(0, pc);
            problems.Add(s);
            sm.EnqueueLuggage(lb);
            Assert.AreEqual(sm.Count(), 1);

            s = new Stuck(100, pc);
            problems.Add(s);
            sm.EnqueueLuggage(lb);
            Assert.AreEqual(sm.Count(), 1);

            //DequeLuggage()

            //AddNextComponent()
            try
            {
                sm.addNextComponent(sm);
            }
            catch (NotImplementedException)
            {
                Assert.IsTrue(true);
            }

            //InAndOutCounters()
            Assert.AreEqual(sm.InAndOutCounters().Item1, 2);

            //GetSinks()
            Assert.AreEqual(sm.getSinks().Count, 1);
            **/
        }
 public void processLuggage(LuggageBag luggage)
 {
     long start = DateTime.Now.Ticks;
     while (true){
         while (this.luggageAndDequeueDelta.Count > 0 && (((long)this.luggageAndDequeueDelta[0].Item1) * 10000000 + start) <= DateTime.Now.Ticks)
         {
             LuggageBag element = this.luggageAndDequeueDelta[0].Item2;
             this.luggageAndDequeueDelta.RemoveAt(0);
             this.queue.enqueueLuggage(0, element);
             this.LuggageCounter++;
         }
         if (this.luggageAndDequeueDelta.Count == 0)
         {
             break;
         }
         System.Threading.Thread.Sleep(10);
     }
 }
 public void EnqueueLuggage(LuggageBag luggage)
 {
     //Contract.Requires(initialized != false, "Initialized must be true");
     Contract.Requires(luggage != null, "Luggage must not be null");
     while (this.stuck) ;
     if (this.initialized_thread == false)
     {
         Thread DequeueThread = new Thread(new ThreadStart(this.DequeueLuggage));
         DequeueThread.Start();
         while (!DequeueThread.IsAlive) ;
         this.initialized_thread = true;
     }
     foreach (IProblem problem in this.problems)
     {
         if (problem.Fail())
         {
             this.stuck = true;
             problem.HandleProblem();
             this.stuck = false;
         }
     }
     enqueueBehaviour.processLuggage(luggage);
 }
Example #11
0
 public void processLuggage(LuggageBag luggage)
 {
     List<LuggageBag> receivedLuggage = this.queue.checkLuggageQueue();
     this.LuggageCounter += receivedLuggage.Count();
 }