public override async Task <bool> SendItemAsync(object expression) { if (!Workers.Any()) { throw new Exception("No workers available!"); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } if (!(expression is Expression <Func <T, object> >)) { throw new Exception("Expression was expected!"); } var predicate = (Expression <Func <T, object> >)expression; var worker = SelectWorker(predicate, out var itemToProcess); if (!worker.CanReceiveItems()) { return(false); } await worker.ReceiveAsync(itemToProcess); return(true); }
public virtual async Task <int> SendItemAsync(object itemToProcess) { try { if (!Workers.Any()) { throw new Exception("No workers available!"); } if (itemToProcess == null) { throw new ArgumentNullException(nameof(itemToProcess)); } var worker = SelectWorker(); while (!worker.CanReceiveItems()) { Thread.Sleep(2000); } await worker.ReceiveAsync(itemToProcess); return(worker.WorkerId); } catch (Exception e) { _logger?.Log(e); return(-1); } }
public virtual async Task <bool> SendItemAsync(object itemToProcess) { try { if (!Workers.Any()) { throw new Exception("No workers available!"); } if (itemToProcess == null) { throw new ArgumentNullException(nameof(itemToProcess)); } var worker = SelectWorker(); while (!worker.CanReceiveItems()) { Thread.Sleep(2000); } await worker.ReceiveAsync(itemToProcess); return(true); } catch (Exception e) { ErrorHandler.HandleException(e); return(false); } }
public string Print() { var enumerable = Enumerable .Range(0, Map.SizeY) .Select( y => { var strings = Enumerable .Range(0, Map.SizeX) .Select( x => { var p = new V(x, Map.SizeY - y - 1); if (Map[p] == CellState.Obstacle) { return("#"); } var wCount = Workers.Count(w => w.Position == p); if (wCount != 0) { return(wCount.ToString()); } if (Workers.Any(w => w.Manipulators.Any(m => w.Position + m == p && Map.IsReachable(w.Position, w.Position + m)))) { return("-"); } if (Workers.Any(w => w.Manipulators.Any(m => w.Position + m == p))) { return("!"); } var booster = Boosters.FirstOrDefault(b => b.Position == p); if (booster != null) { return(booster.ToString()[0].ToString()); } if (Map[p] == CellState.Void) { return("."); } return("*"); }) .ToArray(); return(string.Join("", strings)); }); return(string.Join("\n", enumerable)); }
internal void Seek(double percentLocation) { if (State == WorkState.Paused) { StopWorking(); } else if (State == WorkState.Working) { throw new InvalidOperationException("Cannot be working to seek"); } while (Workers.Any(w => w.State != PipelineWorker.WorkerState.Stopped)) { Thread.Sleep(10); } Processor.SeekTo(percentLocation); }
public WorkerContext() { if (Workers.Any()) { return; } Workers.AddOrUpdate( Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya"), Worker.GetWorker("Vasya", "Vasya", "Vasya")); SaveChanges(); }
public bool ContainEmployee(string name, Position position) { if (position == Position.Manager) { var contain = Managers.Any(e => e.Name == name); return(contain); } if (position == Position.Taskmaster) { var contain = Taskmasters.Any(e => e.Name == name); return(contain); } if (position == Position.Worker) { var contain = Workers.Any(e => e.Name == name); return(contain); } return(false); }
private void Update() { if (!Workers.Any()) { return; } foreach (var worker in Workers) { float scale = 1f + worker.WorkerSkill / 4f; craftTime += Time.deltaTime * scale; } if (craftTime < timeToCraft) { return; } foreach (var worker in Workers) { worker.JobComplete(); } Workers.Clear(); GameManager.Units.CreateUnit <Drone>(spawnPoint.position); }