Exemple #1
0
        private void BuildRobot(FactoryQueueElement queueElement)
        {
            if (queueElement == null)
            {
                return;
            }

            this.Queue.Remove(queueElement);
            this.QueueFreeSlots += 1;

            IWorkingUnit workingUnit = (IWorkingUnit)Activator.CreateInstance(queueElement.Model.UnderlyingSystemType, queueElement.Name, 0);

            workingUnit.Model      = queueElement.Model;
            workingUnit.ParkingPos = queueElement.ParkingPos;
            workingUnit.WorkingPos = queueElement.WorkingPos;
            workingUnit.WorkBegins();
            workingUnit.WorkEnds();

            //this.Storage.Add(workingUnit);

            //// Usine signale que la construction d'un robot s'achève
            //if (this.FactoryProgress != null)
            //{ this.FactoryProgress(this, new EventArgs()); }

            TimeSpan ts = TimeSpan.FromMilliseconds(workingUnit.BuildTime);

            this.QueueTime = this.QueueTime.Add(ts);
        }
        public bool AddWorkableUnitToQueue(Type model, string name, Coordinates coordinatesStatio, Coordinates coordinatesWork)
        {
            bool         result      = false;
            IWorkingUnit workingUnit = Activator.CreateInstance(model) as IWorkingUnit;

            workingUnit.ParkingPos = coordinatesStatio;
            workingUnit.WorkingPos = coordinatesWork;
            Thread th = new Thread(() =>
            {
                lock (lockObj)
                {
                    if (QueueFreeSlots == 0 && StorageFreeSlots == 0)
                    {
                        result = false;
                    }
                    else
                    {
                        FactoryQueueElement element = new FactoryQueueElement(model, name, coordinatesStatio, coordinatesWork);
                        Queue.Enqueue(element);
                        Thread.Sleep(TimeSpan.FromSeconds(workingUnit.BuildTime));
                        QueueTime += TimeSpan.FromSeconds(workingUnit.BuildTime);
                        if (StorageFreeSlots > 0)
                        {
                            Queue.Dequeue();
                            IBaseUnit baseUnit = (IBaseUnit)workingUnit;
                            baseUnit.Move(coordinatesStatio, coordinatesWork);

                            Storage.Add(Activator.CreateInstance(model) as ITestingUnit);
                        }
                        result = true;
                    }
                }
            });

            th.Start();
            return(result);
        }