Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
        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);
            }));
        }
Exemple #3
0
 /// <summary>
 /// Return the AdapterSpec associated with the name, as specified in
 /// the config file.  Throws UnknownAdapterNameException.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public AdapterSpec GetAdapterSpec(string name)
 {
     lock (this)
     {
         try
         {
             return(adapterNames[name]);
         }
         catch (KeyNotFoundException)
         {
             AdapterSpec adapterSpec = new AdapterSpec(name, AdapterFactories);
             adapterNames.Add(name, adapterSpec);
             return(adapterSpec);
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// Return the AdapterSpec associated with the name, as specified in
 /// the config file.  Throws UnknownAdapterNameException.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public AdapterSpec <T> GetAdapterSpec <T>(string name) where T : IAdapter
 {
     lock (this)
     {
         try
         {
             return((AdapterSpec <T>)adapterNames[name]);
         }
         catch (KeyNotFoundException)
         {
             AdapterSpec <T> adapterSpec = new AdapterSpec <T>(name, AdapterFactories);
             adapterNames.Add(name, (AdapterSpecN)adapterSpec);
             return(adapterSpec);
         }
     }
 }
Exemple #5
0
        public static void CreateAdapterIfNeeded(AdapterSpec adapterSpec, ServiceInfoType serviceRecord)
        {
            Monitor.Enter(adapterSpec);
            try
            {
                if (adapterSpec.Adapter == null)
                {
                    switch (adapterSpec.Type)
                    {
                    case AdapterTypeEnum.Vector:
                        adapterSpec.Adapter = (IAdapter <Object>)(new Adapters.VectorAdapter(serviceRecord));
                        break;

                    case AdapterTypeEnum.Drive:
                        adapterSpec.Adapter = (IAdapter <Object>)(new Adapters.DriveAdapter(serviceRecord));
                        break;

                    default:
                        throw new Exception("Adapter type " + GetTypeName(adapterSpec.Type) + " not yet supported");
                    }
                }
                else
                {
                    //Console.WriteLine("*** ERROR *** Adapter for this AdapterSpec already has been created");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("*** ERROR *** " + e);
            }
            finally
            {
                //Console.WriteLine("Unlocking");
                Monitor.Exit(adapterSpec);
            }
        }
Exemple #6
0
 public MyroSound(Myro.Adapters.AdapterBank bank)
 {
     soundAdapter = bank.GetAdapterSpec("tonegen");
 }