Ejemplo n.º 1
0
        protected IWorker SelectWorker(Expression <Func <TEntity, object> > predicate, out TEntity itemToProcess)
        {
            var chooseWorker = new Func <TKey, IWorker>(key =>
            {
                lock (new object())
                {
                    if (_groupingKeyDictionary.ContainsKey(key))
                    {
                        return(Workers.ElementAt(_groupingKeyDictionary[key]));
                    }
                    var worker = base.SelectWorker();
                    _groupingKeyDictionary.Add(key, worker.WorkerId);
                    return(worker);
                }
            });

            if (!(predicate.Body is NewExpression memberSelector))
            {
                throw new Exception($"Predicate is not valid");
            }
            itemToProcess = GetUnderlyingParameterValue(memberSelector);
            var groupingKey = GetKey(predicate, itemToProcess);

            return(chooseWorker(groupingKey));
        }
Ejemplo n.º 2
0
 internal Worker GetWorker(int index)
 {
     return(Workers.ElementAt(index));
 }