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); }
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); }
/// <summary> /// Method for convenient testing of local connectors. /// </summary> public APIConfiguration CreateTestConfiguration(SafeType <Connector> connectorClass, PropertyBag configData, string prefix) { Debug.Assert(null != connectorClass); Type rawConnectorClass = connectorClass.RawType; Object[] attributes = connectorClass.RawType.GetCustomAttributes( typeof(ConnectorClassAttribute), false); if (attributes.Length > 0) { ConnectorClassAttribute attribute = (ConnectorClassAttribute)attributes[0]; Assembly assembly = IOUtil.GetAssemblyContainingType(rawConnectorClass.FullName); String fileName = assembly.Location; 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); } LocalConnectorInfoImpl rv = new LocalConnectorInfoImpl(); rv.ConnectorClass = connectorClass; rv.ConnectorConfigurationClass = connectorConfigurationClass; rv.ConnectorDisplayNameKey = connectorDisplayNameKey; rv.ConnectorCategoryKey = attribute.ConnectorCategoryKey; rv.ConnectorKey = ( new ConnectorKey(rawConnectorClass.Name + ".bundle", "1.0", rawConnectorClass.Name));; APIConfigurationImpl impl = LocalConnectorInfoManagerImpl.CreateDefaultAPIConfiguration(rv); rv.DefaultAPIConfiguration = impl; // if (false) // { // rv.Messages = CreateDummyMessages(); // } // else { rv.Messages = LocalConnectorInfoManagerImpl.LoadMessages(assembly, rv, attribute.MessageCatalogPaths); } ConfigurationPropertiesImpl configProps = (ConfigurationPropertiesImpl)impl.ConfigurationProperties; string fullPrefix = StringUtil.IsBlank(prefix) ? null : prefix + "."; foreach (ConfigurationPropertyImpl property in configProps.Properties) { object value = configData.GetProperty(null != fullPrefix ? fullPrefix + property.Name : property.Name, property.ValueType, property.Value); if (value != null) { property.Value = value; } } return(impl); } throw new ArgumentException("ConnectorClass does not define ConnectorClassAttribute"); }