Example #1
0
        private IList <ConnectorInfo> ProcessAssembly(Assembly assembly)
        {
            IList <ConnectorInfo> rv = new List <ConnectorInfo>();

            Type[] types = null;
            try
            {
                types = assembly.GetTypes();
            }
            catch (Exception e)
            {
                TraceUtil.TraceException("Unable to load assembly: " + assembly.FullName + ". Assembly will be ignored.", e);
            }

            foreach (Type type in types)
            {
                Object[] attributes = type.GetCustomAttributes(
                    typeof(ConnectorClassAttribute),
                    false);
                if (attributes.Length > 0)
                {
                    ConnectorClassAttribute attribute =
                        (ConnectorClassAttribute)attributes[0];
                    LocalConnectorInfoImpl info =
                        CreateConnectorInfo(assembly, type, attribute);
                    rv.Add(info);
                }
            }
            return(rv);
        }
Example #2
0
        /// <summary>
        /// Get a object pool for this connector if it supports connector pooling.
        /// </summary>
        public static ObjectPool <PoolableConnector> GetPool(APIConfigurationImpl impl,
                                                             LocalConnectorInfoImpl localInfo)
        {
            ObjectPool <PoolableConnector> pool = null;

            // determine if this connector wants generic connector pooling..
            if (impl.IsConnectorPoolingSupported)
            {
                ConnectorPoolKey key =
                    new ConnectorPoolKey(
                        impl.ConnectorInfo.ConnectorKey,
                        (ConfigurationPropertiesImpl)impl.ConfigurationProperties,
                        impl.ConnectorPoolConfiguration);

                lock (_pools)
                {
                    // get the pool associated..
                    pool = CollectionUtil.GetValue(_pools, key, null);
                    // create a new pool if it doesn't exist..
                    if (pool == null)
                    {
                        Trace.TraceInformation("Creating new pool: " +
                                               impl.ConnectorInfo.ConnectorKey);
                        // this instance is strictly used for the pool..
                        pool = new ObjectPool <PoolableConnector>(
                            new ConnectorPoolHandler(impl, localInfo),
                            impl.ConnectorPoolConfiguration);
                        // add back to the map of _pools..
                        _pools[key] = pool;
                    }
                }
            }
            return(pool);
        }
Example #3
0
        private LocalConnectorInfoImpl CreateConnectorInfo(Assembly assembly,
                                                           Type rawConnectorClass,
                                                           ConnectorClassAttribute attribute)
        {
            String fileName = assembly.Location;

            if (!typeof(Connector).IsAssignableFrom(rawConnectorClass))
            {
                String MSG = ("File " + fileName +
                              " declares a connector " + rawConnectorClass +
                              " that does not implement Connector.");
                throw new ConfigurationException(MSG);
            }
            SafeType <Connector> connectorClass =
                SafeType <Connector> .ForRawType(rawConnectorClass);

            SafeType <Configuration> connectorConfigurationClass = attribute.ConnectorConfigurationType;

            if (connectorConfigurationClass == null)
            {
                String MSG = ("File " + fileName +
                              " contains a ConnectorInfo attribute " +
                              "with no connector configuration class.");
                throw new ConfigurationException(MSG);
            }
            String connectorDisplayNameKey =
                attribute.ConnectorDisplayNameKey;

            if (connectorDisplayNameKey == null)
            {
                String MSG = ("File " + fileName +
                              " contains a ConnectorInfo attribute " +
                              "with no connector display name.");
                throw new ConfigurationException(MSG);
            }
            ConnectorKey key =
                new ConnectorKey(assembly.GetName().Name,
                                 assembly.GetName().Version.ToString(),
                                 connectorClass.RawType.Namespace + "." + connectorClass.RawType.Name);
            LocalConnectorInfoImpl rv = new LocalConnectorInfoImpl();

            rv.ConnectorClass = connectorClass;
            rv.ConnectorConfigurationClass = connectorConfigurationClass;
            rv.ConnectorDisplayNameKey     = connectorDisplayNameKey;
            rv.ConnectorKey            = key;
            rv.DefaultAPIConfiguration = CreateDefaultAPIConfiguration(rv);
            rv.Messages = LoadMessages(assembly, rv, attribute.MessageCatalogPaths);
            return(rv);
        }
Example #4
0
        CreateDefaultAPIConfiguration(LocalConnectorInfoImpl localInfo)
        {
            SafeType <Connector> connectorClass =
                localInfo.ConnectorClass;
            APIConfigurationImpl rv     = new APIConfigurationImpl();
            Configuration        config =
                localInfo.ConnectorConfigurationClass.CreateInstance();
            bool pooling = IsPoolingSupported(connectorClass);

            rv.IsConnectorPoolingSupported = pooling;
            rv.ConfigurationProperties     = (CSharpClassProperties.CreateConfigurationProperties(config));
            rv.ConnectorInfo       = (localInfo);
            rv.SupportedOperations = (FrameworkUtil.GetDefaultSupportedOperations(connectorClass));
            return(rv);
        }
Example #5
0
        private ConnectorMessagesImpl LoadMessages(Assembly assembly,
                                                   LocalConnectorInfoImpl info,
                                                   String[] nameBases)
        {
            if (nameBases == null || nameBases.Length == 0)
            {
                String pkage =
                    info.ConnectorClass.RawType.Namespace;
                nameBases = new String[] { pkage + ".Messages" };
            }
            ConnectorMessagesImpl rv = new ConnectorMessagesImpl();

            CultureInfo[] cultures = GetLocalizedCultures(assembly);
            for (int i = nameBases.Length - 1; i >= 0; i--)
            {
                String          nameBase = nameBases[i];
                ResourceManager manager  = new ResourceManager(nameBase, assembly);
                foreach (CultureInfo culture in cultures)
                {
                    ResourceSet resourceSet = manager.GetResourceSet(culture, true, false);
                    if (resourceSet != null)
                    {
                        IDictionary <string, string> temp =
                            CollectionUtil.GetValue(rv.Catalogs, culture, null);
                        if (temp == null)
                        {
                            temp = new Dictionary <string, string>();
                            rv.Catalogs[culture] = temp;
                        }
                        foreach (System.Collections.DictionaryEntry entry in resourceSet)
                        {
                            String key = "" + entry.Key;
                            String val = "" + entry.Value;
                            temp[key] = val;
                        }
                    }
                }
            }

            return(rv);
        }
Example #6
0
 public ConnectorPoolHandler(APIConfigurationImpl apiConfiguration,
                             LocalConnectorInfoImpl localInfo)
 {
     _apiConfiguration = apiConfiguration;
     _localInfo        = localInfo;
 }
Example #7
0
 /// <summary>
 /// Builds up the maps of supported operations and calls.
 /// </summary>
 public LocalConnectorFacadeImpl(LocalConnectorInfoImpl connectorInfo,
                                 APIConfigurationImpl apiConfiguration)
     : base(apiConfiguration)
 {
     this.connectorInfo = connectorInfo;
 }