private static bool GetResources(ResourceTypes resource) { if ((resource & ResourceTypes.Pb) != 0) { if (Pb_Factory.GetProduct() == 0) { //Console.WriteLine("GetProduct returned 0 !!!!..."); StateLogger.DrawState("GetProduct returned 0 !!!!..."); } } if ((resource & ResourceTypes.S) != 0) { if (S_Factory.GetProduct() == 0) { StateLogger.DrawState("GetProduct returned 0 !!!!..."); } } //Console.WriteLine("GetProduct returned 0 !!!!..."); if ((resource & ResourceTypes.Hg) != 0) { if (Hg_Factory.GetProduct() == 0) { StateLogger.DrawState("GetProduct returned 0 !!!!..."); } } //Console.WriteLine("GetProduct returned 0 !!!!..."); return(true); }
public void Run() { //Console.WriteLine($"{this.ToString()} Started..."); //Console.WriteLine($"{this.ToString()} waitting for resources {needResources}..."); Storehouse.AddTask(new Tasks.GetResourcesTask(this, getResourceSem, needResources)); getResourceSem.Wait(); LogEndWork(); //Console.WriteLine($"{this.ToString()} Back to labolatory..."); StateLogger.DrawState($"{this.ToString()} Back to labolatory..."); }
private void WaitIfOccupied() { charmsSem.Wait(); if (charmsCount == 0 && !wasReleasedOccupied) { charmsSem.Release(); return; } charmsSem.Release(); StateLogger.DrawState($"Factory {Name} is OCCUPIED with {charmsCount} charms"); isOccupiedSem.Wait(); StateLogger.DrawState($"Factory {Name} CONTINUE work"); wasReleasedOccupied = false; }
public void Run() { Running = true; //Console.WriteLine($"{Name} Started"); StateLogger.DrawState($"{Name} Started"); while (Running) { productionSem.Wait(); WaitIfOccupied(); //Console.WriteLine($"Factory {Name} is producing new resource"); StateLogger.DrawState($"Factory {Name} is producing new resource"); Thread.Sleep(MinProdTime + random.Next() % Interval); AddProduct(); StateLogger.DrawState($"Factory {Name} is produced new resource"); Thread.Sleep(0); } //Console.WriteLine($"{Name} End Work"); StateLogger.DrawState($"{Name} End Work"); }