/// <summary> /// Get the information about types of all adapters. /// </summary> /// <returns></returns> public AdapterType[] GetAdapterTypes() { var xAdapterTypes = Content.XDocument.XPathSelectElement( "/configuration/adapter-types"); List<AdapterType> result = new List<AdapterType>(); foreach (XElement xAdapterType in xAdapterTypes.Elements()) { string name = xAdapterType.Attribute(XName.Get("name")).Value; string assemblyAndClrType = xAdapterType.Attribute(XName.Get("clr-type")).Value; XAttribute xDescription = xAdapterType.Attribute(XName.Get("description")); string description = string.Empty; if (xDescription != null) { description = xDescription.Value; } XElement xConfigurationMetadata = xAdapterType.Element(XName.Get("class-metadata")); ClassMetadata configurationMetadata = XSerializer.Deserialize<ClassMetadata>(xConfigurationMetadata); AdapterType adapterType = new AdapterType(name, assemblyAndClrType, description, configurationMetadata); result.Add(adapterType); } return result.ToArray(); }
/// <summary> /// Adds a new type of adapter. /// </summary> /// <remarks> /// If there is any existing adapter type with this name it get replaced /// with the given adapter type. /// </remarks> /// <param name="adapterType">information about adapter type</param> public void AddAdapterType(AdapterType adapterType) { XElement xAdapterType = new XElement(XName.Get("adapter-type")); xAdapterType.SetAttributeValue(XName.Get("name"), adapterType.Name); xAdapterType.SetAttributeValue(XName.Get("clr-type"), adapterType.AssemblyAndClrType); xAdapterType.SetAttributeValue(XName.Get("description"), adapterType.Description); XElement xConfigurationMetadata = new XElement(XName.Get("class-metadata")); XSerializer.Serializer(adapterType.ConfigurationMetadata, xConfigurationMetadata); xAdapterType.Add(xConfigurationMetadata); var xAdapterTypes = Content.XDocument.XPathSelectElement( "/configuration/adapter-types"); // if there is already an adapter with the same name replace the CLR type quietly // this maintains the uniqueness of the adapter types RemoveElements(string.Format( "/configuration/adapter-types/adapter-type[@name='{0}']", adapterType.Name)); xAdapterTypes.Add(xAdapterType); }
/// <summary> /// Gets the information about the type of an adapter specified by its /// name. /// </summary> /// <param name="name">name of the adapter</param> /// <exception cref="System.ArgumentException">if there is no adapter /// with such a name</exception> /// <returns></returns> public AdapterType GetAdapterType(string name) { var xAdapterType = Content.XDocument.XPathSelectElement( string.Format("/configuration/adapter-types/adapter-type[@name='{0}']", name)); if (xAdapterType == null) { throw new ArgumentException(string.Format("Cannot find adapter named '{0}'.", name), "name"); } string assemblyAndClrType = xAdapterType.Attribute(XName.Get("clr-type")).Value; XAttribute xDescription = xAdapterType.Attribute(XName.Get("description")); string description = string.Empty; if (xDescription != null) { description = xDescription.Value; } XElement xConfigurationMetadata = xAdapterType.Element(XName.Get("class-metadata")); ClassMetadata configurationMetadata = XSerializer.Deserialize<ClassMetadata>(xConfigurationMetadata); AdapterType adapterType = new AdapterType(name, assemblyAndClrType, description, configurationMetadata); return adapterType; }
public ApplicationConfiguration UpdatePlugins(ApplicationConfiguration config) { string binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string adapterPluginsDirectoryFullPath = Path.Combine(binPath, AdapterPluginsDirectory); string actionPluginsDirectoryFullPath = Path.Combine(binPath, ActionPluginsDirectory); if (!Directory.Exists(adapterPluginsDirectoryFullPath)) { Directory.CreateDirectory(adapterPluginsDirectoryFullPath); } if (!Directory.Exists(actionPluginsDirectoryFullPath)) { Directory.CreateDirectory(actionPluginsDirectoryFullPath); } #region Update adapter plugins AdapterType[] oldAdapterTypes = config.GetAdapterTypes(); foreach (AdapterType adapterType in oldAdapterTypes) { config.RemoveAdapterType(adapterType.Name); } var adapterPlugins = PluginLoader.FindPlugins<AdapterPluginAttribute>(adapterPluginsDirectoryFullPath); foreach (PluginInfo<AdapterPluginAttribute> adapterPlugin in adapterPlugins) { string assemblyAndClrType = GetTypeAndRelativeAssemblyPath( AdapterPluginsDirectory, adapterPlugin.AssemblyFullPath, adapterPlugin.TypeFullName); AdapterType adapterType = new AdapterType( name: adapterPlugin.PluginAttribute.PluginName, assemblyAndClrType: assemblyAndClrType, description: adapterPlugin.PluginAttribute.PluginDescription, clrType: adapterPlugin.PluginType); config.AddAdapterType(adapterType); } #endregion #region Update action plugins ActionType[] oldActionTypes = config.GetActionTypes(); foreach (ActionType actionType in oldActionTypes) { config.RemoveActionType(actionType.Name); } #region Add built-in actions Type sendMessageActionType = typeof(XRouter.Processor.BuiltInActions.SendMessageAction); var sendMessageActionInfo = new PluginInfo<ActionPluginAttribute>(sendMessageActionType.Assembly, sendMessageActionType); config.AddActionType(new ActionType( name: sendMessageActionInfo.PluginAttribute.PluginName, assemblyAndClrType: String.Join(",", sendMessageActionInfo.TypeFullName, Path.GetFileName(sendMessageActionInfo.AssemblyFullPath)), description: sendMessageActionInfo.PluginAttribute.PluginDescription, clrType: sendMessageActionInfo.PluginType)); Type xsltTransformActionType = typeof(XRouter.Processor.BuiltInActions.XsltTransformationAction); var xsltTransformActionInfo = new PluginInfo<ActionPluginAttribute>(xsltTransformActionType.Assembly, xsltTransformActionType); config.AddActionType(new ActionType( name: xsltTransformActionInfo.PluginAttribute.PluginName, assemblyAndClrType: String.Join(",", xsltTransformActionInfo.TypeFullName, Path.GetFileName(xsltTransformActionInfo.AssemblyFullPath)), description: xsltTransformActionInfo.PluginAttribute.PluginDescription, clrType: xsltTransformActionInfo.PluginType)); #endregion var actionPlugins = PluginLoader.FindPlugins<ActionPluginAttribute>(adapterPluginsDirectoryFullPath).ToList(); foreach (PluginInfo<ActionPluginAttribute> actionPlugin in actionPlugins) { string assemblyAndClrType = GetTypeAndRelativeAssemblyPath( ActionPluginsDirectory, actionPlugin.AssemblyFullPath, actionPlugin.TypeFullName); ActionType actionType = new ActionType( name: actionPlugin.PluginAttribute.PluginName, assemblyAndClrType: assemblyAndClrType, description: actionPlugin.PluginAttribute.PluginDescription, clrType: actionPlugin.PluginType); config.AddActionType(actionType); } #endregion return config; }