public bool AddWorkableUnitToQueue(Type model, string name, Coordinates parkingPos, Coordinates workingPos) { lock (addLock) { FactoryQueueElement factoryQueueElement = new FactoryQueueElement(model, name, parkingPos, workingPos); if (Queue.Count < QueueCapacity) { Queue.Add(factoryQueueElement); } else { return(false); } if (Storage.Count < StorageCapacity) { //Storage.Add(); } return(true); } }
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); }