Exemplo n.º 1
0
        public ServiceInvokerBase(IRegistery registery, string groupPath, ILoadBalance loadBalance, IWeightCalculator <ServiceMetadata> weightCalculator)
        {
            _serviceIdentity  = typeof(TService).Name;
            _loadBalance      = loadBalance;
            _weightCalculator = weightCalculator;
            _groupPath        = groupPath;

            _listener = new NotifyListener();
            _listener.OnMetadataChanged += (metas) => _metadatas = metas;

            _registery = registery;
            _registery.Subscribe(_groupPath, _listener, true);
        }
Exemplo n.º 2
0
        protected virtual T DoSelect <T>(IWeightCalculator <T> calculator, List <T> items, string key)
        {
            var weights = calculator.Calculate(items);

            if (weights.AllEqual())
            {
                return(this.DoSelectEqual(items, key));
            }
            else
            {
                return(this.DoSelectWeight(items, key, weights));
            }
        }
Exemplo n.º 3
0
        public GoalsController(IRepository repository, IWeightCalculator calculator)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (calculator == null)
            {
                throw new ArgumentNullException(nameof(calculator));
            }

            _repository = repository;
            _calculator = calculator;
        }
Exemplo n.º 4
0
        public T Select <T>(IWeightCalculator <T> calculator, List <T> items, string key = "")
        {
            if (calculator == null)
            {
                throw new ArgumentNullException("calculator", "calculator can not be null.");
            }
            if (items == null || !items.Any())
            {
                throw new ArgumentNullException("items", "items can not be null or empty.");
            }
            if (items.Count == 1)
            {
                return(items.ElementAt(0));
            }

            return(this.DoSelect(calculator, items, key));
        }
Exemplo n.º 5
0
 protected override T DoSelect <T>(IWeightCalculator <T> calculator, List <T> items, string key)
 {
     Ensure.NotNullOrEmpty(key, "key");
     return(base.DoSelect(calculator, items, key));
 }
Exemplo n.º 6
0
 public WeightCalculatorWrapper(IWeightCalculator baseWeightCalculator)
 {
     _underlyingWeightCalculator = baseWeightCalculator;
 }
Exemplo n.º 7
0
 public WeighedRandomItemSelector(List <TObject> items, Random randomizer, IWeightCalculator <TObject> weightCalculator)
 {
     _randomizer       = randomizer;
     _items            = items;
     _weightCalculator = weightCalculator;
 }
Exemplo n.º 8
0
Arquivo: IUnary.cs Projeto: lcksy/Dot
 public UnaryServiceInvoker(IRegistery registery, string groupPath, ILoadBalance loadBalance, IWeightCalculator <ServiceMetadata> weightCalculator)
     : base(registery, groupPath, loadBalance, weightCalculator)
 {
 }
Exemplo n.º 9
0
 public PenalisingWeightCalculator(IWeightCalculator _baseWeightCalculator) : base(_baseWeightCalculator)
 {
 }
Exemplo n.º 10
0
 public AStarPathFinder(IGraph <AStarNode> graph, IWeightCalculator weightCalculator, IWeightCalculator heuristicCalculator)
 {
     _graph               = graph;
     _weightCalculator    = weightCalculator;
     _heuristicCalculator = heuristicCalculator;
 }