Describes WinSW extensions in IWinSWExtension
Any extension has its own descriptor instance.
示例#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);
            }
        }
示例#2
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 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 = 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);
            }
        }