Exemplo n.º 1
0
        public IEnumerable<JObject> GetNetwork(Ant ant)
        {
            var array = new List<JObject>();
            foreach (var network in GetNetwork())
            {
                if (!network.Check(ant))
                    continue;
                foreach (var targetAnts in _ants)
                {
                    if (network.Service1 != targetAnts.GetName() && network.Service2 != targetAnts.GetName())
                        continue;

                    foreach (var targetAnt in targetAnts.GetAnt())
                    {
                        if (targetAnt == ant)
                            continue;
                        var obj = new JObject();
                        obj.Add("ant", targetAnts.GetId());
                        obj.Add("id", targetAnt.GetId());
                        obj.Add("host", new JArray(network.GetAddress(targetAnt)));
                        obj.Add("port", targetAnt.GetPort());
                        array.Add(obj);
                    }
                }
            }
            return array;
        }
Exemplo n.º 2
0
        public bool Check(Ant ant)
        {
            if (Service1 != ant.GetAnts().GetName() && Service2 != ant.GetAnts().GetName())
                return false;

            foreach (var ip in ant.GetAddress())
            {
                if (Check(ip))
                    return true;
            }
            return false;
        }
Exemplo n.º 3
0
        public IEnumerable<byte[]> GetAddress(Ant ant)
        {
            if (Service1 != ant.GetAnts().GetName() && Service2 != ant.GetAnts().GetName())
                return null;

            var _list = new List<byte[]>();
            foreach (var address in ant.GetAddress())
            {
                if (Check(address))
                {
                    _list.Add(address);
                }
            }
            return _list;
        }
Exemplo n.º 4
0
        public Ant JoinAnt(IChannel channel, JObject args)
        {
            int id = -1;
            if (_removeAnt.Count != 0)
            {
                id = _removeAnt.Dequeue();
            }
            else
            {
                id = _maxAnt++;
            }

            _ant[id] = new Ant(this, id, args.Value<int>("port"));
            _ant[id].AddAddress(args.Value<JArray>("host").Values<byte[]>());
            _ant[id].AddChannel(channel);

            return _ant[id];
        }
Exemplo n.º 5
0
 public void StartAnt(Ant ant)
 {
     _workEvent.Set();
 }