private void LoadExtensionFromXml(string id) { var extensionsConfig = this.ServiceDescriptor.XmlExtensions; var 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) { var 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); } }
private void LoadExtensionFromYaml(string id) { var extensionConfigList = this.ServiceDescriptor.YamlExtensions; 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) { var 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); } YamlExtensionConfig GetYamlonfigById(List <YamlExtensionConfig> 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}"" "); } }