Exemplo n.º 1
0
        /// <summary>
        /// Loads extensions from the configuration file
        /// </summary>
        /// <param name="id">Extension ID</param>
        /// <param name="logger">Logger</param>
        /// <exception cref="ExtensionException">Loading failure</exception>
        private void LoadExtension(string id, IEventWriter logger)
        {
            if (Extensions.ContainsKey(id))
            {
                throw new ExtensionException(id, "Extension has been already loaded");
            }

            var        extensionsConfig = ServiceDescriptor.ExtensionsConfiguration;
            XmlElement configNode       = (extensionsConfig != null) ? extensionsConfig.SelectSingleNode("extension[@id='" + id + "'][1]") as XmlElement : null;

            if (configNode == null)
            {
                throw new ExtensionException(id, "Cannot get the configuration entry");
            }

            var descriptor = WinSWExtensionDescriptor.FromXml(configNode);

            if (descriptor.Enabled)
            {
                IWinSWExtension extension = CreateExtensionInstance(descriptor.Id, descriptor.ClassName);
                extension.Descriptor = descriptor;
                extension.Configure(ServiceDescriptor, configNode, logger);
                Extensions.Add(id, extension);
                logger.LogEvent("Extension loaded: " + id, EventLogEntryType.Information);
            }
            else
            {
                logger.LogEvent("Extension is disabled: " + id, EventLogEntryType.Warning);
            }
        }
Exemplo n.º 2
0
        private void LoadExtensionFromXml(string id)
        {
            XmlNode?   extensionsConfig = this.ServiceDescriptor.ExtensionsConfiguration;
            XmlElement?configNode       = extensionsConfig is null ? null : extensionsConfig.SelectSingleNode("extension[@id='" + id + "'][1]") as XmlElement;

            if (configNode is null)
            {
                throw new ExtensionException(id, "Cannot get the configuration entry");
            }

            var descriptor = WinSWExtensionDescriptor.FromXml(configNode);

            if (descriptor.Enabled)
            {
                IWinSWExtension extension = this.CreateExtensionInstance(descriptor.Id, descriptor.ClassName);
                extension.Descriptor = descriptor;
                try
                {
                    extension.Configure(this.ServiceDescriptor, configNode);
                }
                catch (Exception ex)
                { // Consider any unexpected exception as fatal
                    Log.Fatal("Failed to configure the extension " + id, ex);
                    throw new ExtensionException(id, "Failed to configure the extension");
                }

                this.Extensions.Add(id, extension);
                Log.Info("Extension loaded: " + id);
            }
            else
            {
                Log.Warn("Extension is disabled: " + id);
            }
        }
Exemplo n.º 3
0
        private void LoadExtensionFromYaml(string id)
        {
            var extensionConfigList = this.ServiceDescriptor.YamlExtensionsConfiguration;

            if (extensionConfigList is null)
            {
                throw new ExtensionException(id, "Cannot get the configuration entry");
            }

            var configNode = GetYamlonfigById(extensionConfigList, id);

            var descriptor = WinSWExtensionDescriptor.FromYaml(configNode);

            if (descriptor.Enabled)
            {
                IWinSWExtension extension = this.CreateExtensionInstance(descriptor.Id, descriptor.ClassName);
                extension.Descriptor = descriptor;

                try
                {
                    extension.Configure(this.ServiceDescriptor, configNode);
                }
                catch (Exception ex)
                { // Consider any unexpected exception as fatal
                    Log.Fatal("Failed to configure the extension " + id, ex);
                    throw new ExtensionException(id, "Failed to configure the extension");
                }

                this.Extensions.Add(id, extension);
                Log.Info("Extension loaded: " + id);
            }
            else
            {
                Log.Warn("Extension is disabled: " + id);
            }

            YamlExtensionConfiguration GetYamlonfigById(List <YamlExtensionConfiguration> configs, string id)
            {
                foreach (var item in configs)
                {
                    if (item.GetId().Equals(id))
                    {
                        return(item);
                    }
                }

                throw new ExtensionException(id, $@"Can't find extension with id: ""{id}"" ");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads extensions from the configuration file
        /// </summary>
        /// <param name="id">Extension ID</param>
        /// <param name="logger">Logger</param>
        /// <exception cref="Exception">Loading failure</exception>
        private void LoadExtension(string id)
        {
            if (Extensions.ContainsKey(id))
            {
                throw new ExtensionException(id, "Extension has been already loaded");
            }

            XmlNode?   extensionsConfig = ServiceDescriptor.ExtensionsConfiguration;
            XmlElement?configNode       = (extensionsConfig != null) ? extensionsConfig.SelectSingleNode("extension[@id='" + id + "'][1]") as XmlElement : null;

            if (configNode == null)
            {
                throw new ExtensionException(id, "Cannot get the configuration entry");
            }

            var descriptor = WinSWExtensionDescriptor.FromXml(configNode);

            if (descriptor.Enabled)
            {
                IWinSWExtension extension = CreateExtensionInstance(descriptor.Id, descriptor.ClassName);
                extension.Descriptor = descriptor;
                try
                {
                    extension.Configure(ServiceDescriptor, configNode);
                }
                catch (Exception ex)
                { // Consider any unexpected exception as fatal
                    Log.Fatal("Failed to configure the extension " + id, ex);
                    throw ex;
                }

                Extensions.Add(id, extension);
                Log.Info("Extension loaded: " + id);
            }
            else
            {
                Log.Warn("Extension is disabled: " + id);
            }
        }