/// <summary> /// Get the information about types of all action types. /// </summary> /// <returns></returns> public ActionType[] GetActionTypes() { var xActionTypes = Content.XDocument.XPathSelectElement( "/configuration/action-types"); List<ActionType> result = new List<ActionType>(); foreach (XElement xActionType in xActionTypes.Elements()) { string name = xActionType.Attribute(XName.Get("name")).Value; string assemblyAndClrType = xActionType.Attribute(XName.Get("clr-type")).Value; XAttribute xDescription = xActionType.Attribute(XName.Get("description")); string description = string.Empty; if (xDescription != null) { description = xDescription.Value; } XElement xConfigurationMetadata = xActionType.Element(XName.Get("class-metadata")); ClassMetadata configurationMetadata = XSerializer.Deserialize<ClassMetadata>(xConfigurationMetadata); ActionType actionType = new ActionType(name, assemblyAndClrType, description, configurationMetadata); result.Add(actionType); } return result.ToArray(); }
/// <summary> /// Adds a new type of action. /// </summary> /// <remarks> /// If there is any existing action type with this name it get replaced /// with the given action type. /// </remarks> /// <param name="actionType">information about action type</param> public void AddActionType(ActionType actionType) { XElement xActionType = new XElement(XName.Get("action-type")); xActionType.SetAttributeValue(XName.Get("name"), actionType.Name); xActionType.SetAttributeValue(XName.Get("clr-type"), actionType.ClrTypeAndAssembly); xActionType.SetAttributeValue(XName.Get("description"), actionType.Description); XElement xConfigurationMetadata = new XElement(XName.Get("class-metadata")); XSerializer.Serializer(actionType.ConfigurationMetadata, xConfigurationMetadata); xActionType.Add(xConfigurationMetadata); var xActionTypes = Content.XDocument.XPathSelectElement( "/configuration/action-types"); // if there is already an action with the same name replace the CLR type quietly // this maintains the uniqueness of the action types RemoveElements(string.Format( "/configuration/action-types/action-type[@name='{0}']", actionType.Name)); xActionTypes.Add(xActionType); }
/// <summary> /// Gets the information about the type of an action specified by its /// name. /// </summary> /// <param name="name">name of the action</param> /// <exception cref="System.ArgumentException">if there is no action /// with such a name</exception> /// <returns></returns> public ActionType GetActionType(string name) { var xActionType = Content.XDocument.XPathSelectElement( string.Format("/configuration/action-types/action-type[@name='{0}']", name)); if (xActionType == null) { throw new ArgumentException(string.Format("Cannot find action type named '{0}'.", name), "name"); } string assemblyAndClrType = xActionType.Attribute(XName.Get("clr-type")).Value; XAttribute xDescription = xActionType.Attribute(XName.Get("description")); string description = string.Empty; if (xDescription != null) { description = xDescription.Value; } XElement xConfigurationMetadata = xActionType.Element(XName.Get("class-metadata")); ClassMetadata configurationMetadata = XSerializer.Deserialize<ClassMetadata>(xConfigurationMetadata); ActionType actionType = new ActionType(name, assemblyAndClrType, description, configurationMetadata); return actionType; }
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; }