protected void readConfig(string configFile) { services = new List <ServiceInfoType>(); //adapterTypes = new Dictionary<AdapterTypes,ArrayList>(); adapterNames = new Dictionary <string, AdapterSpec>(); XPathNavigator nav = new XPathDocument(configFile).CreateNavigator(); // Add plain services to list XPathNodeIterator startservices = nav.Select("//StartService"); foreach (XPathNavigator node in startservices) { services.Add(new ServiceInfoType(getChild(node, "Contract"), getChild(node, "Service"))); } // Add adapters to list, and to dictionary XPathNodeIterator adapters = nav.Select("//Adapter"); Console.WriteLine(adapters.Count + " adapters in config"); foreach (XPathNavigator node in adapters) { // Get the relevant info for this adapter // Attributes string sType = node.GetAttribute("type", ""); AdapterTypeEnum type = AdapterFactory.GetType(sType); string name = node.GetAttribute("name", ""); // Children string contract = getChild(node, "Contract", true); string service = getChild(node, "Service"); // Add elements to the service array and dictionary if (adapterNames.ContainsKey(name)) { throw new ConfigException("Duplicate adapter name \"" + name + "\""); } else { // Add a null adapter for now. An adapter will be created when the service is actually started ServiceInfoType serviceInfo = new ServiceInfoType(contract, service); AdapterSpec adapterInfo = new AdapterSpec(type, name, serviceInfo); adapterNames.Add(name, adapterInfo); //adapterServices.Add(service, adapterInfo); //services.Add(serviceInfo); } } }
protected void updateAdapters() { var dirPort = DssEnvironment.ServiceForwarder <dirProxy.DirectoryPort>(new Uri("http://localhost:50000/directory")); //Console.WriteLine("Querying directory"); //dirProxy.QueryRequest request = new dirProxy.QueryRequest(); //request.QueryRecord = new ServiceInfoType(); Arbiter.ExecuteToCompletion(DssEnvironment.TaskQueue, Arbiter.Choice <dirProxy.GetResponse, Fault>( dirPort.Get(), delegate(dirProxy.GetResponse success) { // See if each service matches a known one from the config file, if so, make an adapter //Console.WriteLine("Checking " + success.RecordList.Length + " services"); foreach (var rec in success.RecordList) { //Uri foundUri = new Uri(rec.Service); AdapterSpec adapterSpec = null; //Console.WriteLine("Checking " + rec.Service); foreach (var adapter in adapterNames.Values) { //Console.WriteLine("Comparing " + rec.Service + " to " + adapter.ServiceInfo.Service); //Uri testUri = new Uri(adapter.ServiceInfo.Service); //if (Uri.Compare(foundUri, testUri, UriComponents.Path, UriFormat.UriEscaped, StringComparison.InvariantCultureIgnoreCase) == 0) if (rec.Service.EndsWith(adapter.ServiceConfig.Service)) { //Console.WriteLine("* Assigned * " + rec.Service + " to " + adapter.ServiceInfo.Service); if (adapterSpec == null) { adapterSpec = adapter; } else { Console.WriteLine("WARNING: duplicate service: " + rec.Service + " (already had one for " + adapter.ServiceConfig.Service + ")"); } } } if (adapterSpec != null) { AdapterFactory.CreateAdapterIfNeeded(adapterSpec, rec); } } }, delegate(Fault fault) { Console.WriteLine("AdapterBank: Fault querying directory: " + fault.Reason); })); }