Apache.NMS.NMSConnectionFactory.LookupConnectionFactoryInfo C# (CSharp) Méthode

LookupConnectionFactoryInfo() private static méthode

Lookup the connection factory assembly filename and class name. Read an external configuration file that maps scheme to provider implementation. Load XML config files named: nmsprovider-{scheme}.config Following is a sample configuration file named nmsprovider-jms.config. Replace the parenthesis with angle brackets for proper XML formatting. (?xml version="1.0" encoding="utf-8" ?) (configuration) (provider assembly="MyCompany.NMS.JMSProvider.dll" classFactory="MyCompany.NMS.JMSProvider.ConnectionFactory"/) (/configuration) This configuration file would be loaded and parsed when a connection uri with a scheme of 'jms' is used for the provider. In this example the connection string might look like: jms://localhost:7222
private static LookupConnectionFactoryInfo ( string paths, string scheme, string &assemblyFileName, string &factoryClassName ) : bool
paths string Folder paths to look in.
scheme string The scheme.
assemblyFileName string Name of the assembly file.
factoryClassName string Name of the factory class.
Résultat bool
        private static bool LookupConnectionFactoryInfo(string[] paths, string scheme, out string assemblyFileName, out string factoryClassName)
        {
            bool foundFactory = false;
            string schemeLower = scheme.ToLower();
            ProviderFactoryInfo pfi;

            // Look for a custom configuration to handle this scheme.
            string configFileName = String.Format("nmsprovider-{0}.config", schemeLower);

            assemblyFileName = String.Empty;
            factoryClassName = String.Empty;

            Tracer.DebugFormat("Attempting to locate provider configuration: {0}", configFileName);
            foreach(string path in paths)
            {
                string fullpath = Path.Combine(path, configFileName);
                Tracer.DebugFormat("Looking for: {0}", fullpath);

                try
                {
                    if(File.Exists(fullpath))
                    {
                        Tracer.DebugFormat("\tConfiguration file found in {0}", fullpath);
                        XmlDocument configDoc = new XmlDocument();

                        configDoc.Load(fullpath);
                        XmlElement providerNode = (XmlElement) configDoc.SelectSingleNode("/configuration/provider");

                        if(null != providerNode)
                        {
                            assemblyFileName = providerNode.GetAttribute("assembly");
                            factoryClassName = providerNode.GetAttribute("classFactory");
                            if(!String.IsNullOrEmpty(assemblyFileName) && !String.IsNullOrEmpty(factoryClassName))
                            {
                                foundFactory = true;
                                Tracer.DebugFormat("Selected custom provider for {0}: {1}, {2}", schemeLower, assemblyFileName, factoryClassName);
                                break;
                            }
                        }
                    }
                }
                catch(Exception ex)
                {
                    Tracer.DebugFormat("Exception while scanning {0}: {1}", fullpath, ex.Message);
                }
            }

            if(!foundFactory)
            {
                // Check for standard provider implementations.
                if(schemaProviderFactoryMap.TryGetValue(schemeLower, out pfi))
                {
                    assemblyFileName = pfi.assemblyFileName;
                    factoryClassName = pfi.factoryClassName;
                    foundFactory = true;
                    Tracer.DebugFormat("Selected standard provider for {0}: {1}, {2}", schemeLower, assemblyFileName, factoryClassName);
                }
            }

            return foundFactory;
        }