Example #1
0
        protected ComponentAccessor(
            string componentName,
            IComponentService component,
            ApplicationConfiguration configuration)
        {
            ComponentName = componentName;
            ComponentType = configuration.GetComponentType(componentName);
            this.component = component;

            ConfigurationReduction = new XmlReduction();
        }
        public void ClearConfiguration()
        {
            ApplicationConfiguration originalConfiguration = Configuration;

            try {
                XDocument xConfig = XDocument.Parse(ApplicationConfiguration.InitialContent);
                Configuration = new ApplicationConfiguration(xConfig);
                Configuration = ConsoleServer.UpdatePlugins(Configuration);
            } catch (Exception ex) {
                Configuration = originalConfiguration;
                string message = string.Format("Cannot create new configuration: " + ex.Message);
                MessageBox.Show(ex.Message, "Operation failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #3
0
 public void UpdateConfig(ApplicationConfiguration config)
 {
     component.UpdateConfig(config);
 }
 /// <summary>
 /// Gets a configuration reduced with given reduction.
 /// </summary>
 /// <param name="reduction">a filter to select only parts of the
 /// configuration</param>
 /// <returns>reduced configuration</returns>
 public ApplicationConfiguration GetReducedConfiguration(XmlReduction reduction)
 {
     XDocument reducedContent = reduction.GetReducedXml(Content);
     var result = new ApplicationConfiguration(reducedContent);
     return result;
 }
 public bool ReadConfiguration(XDocument xConfig, bool throwOnError)
 {
     try {
         Configuration = new ApplicationConfiguration(xConfig);
         return true;
     } catch (Exception ex) {
         if (throwOnError) {
             throw;
         } else {
             string message = string.Format("Cannot read configuration: " + ex.Message);
             MessageBox.Show(ex.Message, "Operation failed", MessageBoxButton.OK, MessageBoxImage.Error);
             return false;
         }
     }
 }
Example #6
0
        public void UpdatePluginsInApplicationConfiguration()
        {
            XDocument xConfig = storage.GetApplicationConfiguration();
            // clone the config so that is can be later compared
            XDocument xOldConfig = XDocument.Parse(xConfig.ToString());

            var config = new ApplicationConfiguration(xConfig);
            config = UpdatePlugins(config);

            if (!CanBeEqual(xOldConfig, config.Content)) {
                ChangeConfiguration(config);
            }
        }
Example #7
0
 public ProcessorAccessor(string componentName, IProcessorService processor, ApplicationConfiguration configuration)
     : base(componentName, processor, configuration)
 {
     this.processor = processor;
 }
Example #8
0
        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;
        }
Example #9
0
 public ApplicationConfiguration GetConfiguration()
 {
     XDocument configXml = storage.GetApplicationConfiguration();
     var result = new ApplicationConfiguration(configXml);
     return result;
 }
Example #10
0
 public void ChangeConfiguration(ApplicationConfiguration config)
 {
     this.storage.SaveApplicationConfiguration(config.Content);
 }
Example #11
0
 public void UpdateConfig(ApplicationConfiguration config)
 {
     Configuration = config;
 }
Example #12
0
 public GatewayAccessor(string componentName, IGatewayService gateway, ApplicationConfiguration configuration)
     : base(componentName, gateway, configuration)
 {
     this.gateway = gateway;
 }