Example #1
0
        // Returns the AID of the first found service provider
        public static AID FindService(string serviceName, Agent myAgent, int timeOut)
        {
            AID providerAID = null;
            bool found = false;

            double t1 = PerformanceCounter.GetValue();
            while (!found)
            {
                if (PerformanceCounter.GetValue() - t1 > timeOut)
                    break;

                Application.DoEvents();

                // search for a provider
                DFAgentDescription template = new DFAgentDescription();
                ServiceDescription sd = new ServiceDescription();
                sd.setType(serviceName);
                template.addServices(sd);

                DFAgentDescription[] result = DFService.search(myAgent, template);
                if (result != null && result.Length > 0)
                {
                    providerAID = result[0].getName();
                    found = true;
                }
            }

            return providerAID;
        }
        //TODO - Refactor to support list of service names
        public static List <AID> Find(string serviceName, Agent myAgent)
        {
            var providers = new List <AID>();
            var found     = false;

            while (!found)
            {
                var template = new DFAgentDescription();
                var sd       = new ServiceDescription();
                sd.setType(serviceName);
                template.addServices(sd);

                DFAgentDescription[] result = DFService.search(myAgent, template);

                if (result == null || result.Length <= 0)
                {
                    continue;
                }

                foreach (var t in result)
                {
                    providers.Add(t.getName());
                    found = true;
                }
            }

            return(providers);
        }
Example #3
0
 // Registers a service on behalf of an agent
 public static void RegisterService(string serviceName, Agent myAgent)
 {
     DFAgentDescription dfd = new DFAgentDescription();
     dfd.setName(myAgent.getAID());
     ServiceDescription sd = new ServiceDescription();
     sd.setType(serviceName);
     sd.setName(serviceName);
     dfd.addServices(sd);
     DFService.register(myAgent, dfd);
 }
        public static void Register(string serviceName, Agent myAgent)
        {
            var dfd = new DFAgentDescription();

            dfd.setName(myAgent.getAID());
            var sd = new ServiceDescription();

            sd.setType(serviceName);
            sd.setName(serviceName);
            dfd.addServices(sd);
            DFService.register(myAgent, dfd);
        }