示例#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;
        }
示例#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;
        }
示例#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;
        }
示例#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];
        }
示例#5
0
 public void StartAnt(Ant ant)
 {
     _workEvent.Set();
 }