예제 #1
0
        /// <summary>
        /// Construit les robots qui sont dans la liste de commande
        /// </summary>
        private async void BuildWorkableUnit()
        {
            // Pseudo mutex
            m_IsBuilding = true;
            ITestingUnit lUnit = null;

            // On teste que l'on a pas atteint la capacité max et qu'il reste des éléments dans la Queue

            while (m_Storage.Count <= StorageCapacity && m_Queue.Count > 0)
            {
                lUnit            = Activator.CreateInstance(m_Queue[0].Model, new string[] { m_Queue[0].Name }) as ITestingUnit;
                lUnit.WorkingPos = m_Queue[0].WorkingPos;
                lUnit.ParkingPos = m_Queue[0].ParkingPos;
                await Task.Delay((int)(500d * lUnit.BuildTime));

                m_Queue.RemoveAt(0);
                m_Storage.Add(lUnit);

                //On met à jour l'event
                FactoryProgressEventArgs lNewUnit = new FactoryProgressEventArgs();
                lNewUnit.TestingUnit = lUnit;
                OnStatusChanged(lNewUnit);
            }

            // previent que les constructions sont finies
            m_IsBuilding = false;
        }
예제 #2
0
 private void CreateUnit()
 {
     lock (_mutex)
     {
         if (Storage.Count < StorageCapacity)
         {
             IFactoryQueueElement elementToCreate = Queue.Peek();
             var          modelInstance           = Activator.CreateInstance(elementToCreate.Model);
             ITestingUnit testingUnit             = (ITestingUnit)modelInstance;
             testingUnit.Name       = elementToCreate.Name;
             testingUnit.ParkingPos = elementToCreate.ParkingPos;
             testingUnit.WorkingPos = elementToCreate.WorkingPos;
             FactoryProgressEventArgs arg = new FactoryProgressEventArgs();
             arg.NewStatus    = "Creation start";
             arg.QueueElement = elementToCreate;
             OnStatusChanged(arg);
             var buildTime = testingUnit.BuildTime;
             Thread.Sleep(TimeSpan.FromSeconds(buildTime));
             QueueTime = TimeSpan.FromSeconds(buildTime);
             Queue.Dequeue();
             Storage.Add(testingUnit);
             arg             = new FactoryProgressEventArgs();
             arg.NewStatus   = "Creation end";
             arg.TestingUnit = testingUnit;
             OnStatusChanged(arg);
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Ajoute un nouvel élément à la liste de commande et relance la production si besoin
        /// </summary>
        /// <param name="inModel">Type de robot à construire</param>
        /// <param name="inUnitName">Nom du robot</param>
        /// <param name="inWorkingPos">Position de travail</param>
        /// <param name="inParkPos">Position de recharge</param>
        /// <returns></returns>
        public bool AddWorkableUnitToQueue(Type inModel, string inUnitName, Coordinates inWorkingPos, Coordinates inParkPos)
        {
            if (m_Queue.Count >= m_QueueCapacity)
            {
                return(false);
            }

            // l'ajoute à la liste
            FactoryQueueElement lOrder = new FactoryQueueElement(inUnitName, inModel, inParkPos, inWorkingPos);

            m_Queue.Add(lOrder);

            //On met à jour l'event
            FactoryProgressEventArgs lNewOrder = new FactoryProgressEventArgs();

            lNewOrder.QueueElement = lOrder;
            OnStatusChanged(lNewOrder);

            // lance la construction si ce n'est pas déjà en cours
            if (!m_IsBuilding)
            {
                BuildWorkableUnit();
            }
            return(true);
        }