public async Task <bool> LoadComponent(string name) { var cData = new ComponentData() { Id = Guid.NewGuid(), Status = ComponentStatusEnum.Starting, Info = new ComponentInfo() { Name = name } }; ComponentsData.Add(cData); try { var availableComponent = AvailableComponents.FirstOrDefault(c => c.Name == name); if (availableComponent == null) { throw new Exception($"Component name {name} not found!"); } var componentAttribute = availableComponent.ComponentType.GetCustomAttribute <NeonComponentAttribute>(); cData.Info = new ComponentInfo() { Name = componentAttribute.Name, Version = componentAttribute.Version, Author = componentAttribute.Author, Category = componentAttribute.Category, Description = componentAttribute.Description }; var componentObject = _neonManager.Resolve(availableComponent.ComponentType) as INeonComponent; if (componentObject == null) { throw new Exception($"Component {name} not implement INeonComponent interface"); } var configFileName = Path.Combine(_config.ConfigDirectory.DirectoryName, GetComponentConfigFileName(cData)); var componentConfig = _fileSystemManager.ReadFromFile(configFileName, componentAttribute.ConfigType); if (componentConfig == null) { _logger.LogWarning($"Component config {cData.Info.Name} ({GetComponentConfigFileName(cData)}) don't exists, creating default"); componentConfig = componentObject.GetDefaultConfig(); _fileSystemManager.WriteToFile(configFileName, componentConfig); } await componentObject.Init(componentConfig); await componentObject.Start(); var polls = GetComponentPollAttribute(availableComponent.ComponentType); if (polls.Count == 0) { _schedulerService.AddPolling(async() => { await componentObject.Poll(); }, $"COMPONENT_{name.ToUpper()}", SchedulerServicePollingEnum.NormalPolling); } else { polls.ForEach(p => { if (p.ComponentPollRate.IsEnabled) { _schedulerService.AddPolling(() => { p.Method.Invoke(componentObject, null); }, $"COMPONENT_{name.ToUpper()}_{p.Method.Name}", p.ComponentPollRate.Rate); } }); } componentObject.ComponentId = cData.Id.ToString(); cData.Status = ComponentStatusEnum.Started; _runningComponents.Add(cData.Id, componentObject); SaveComponentConfig(componentObject, componentConfig); return(true); } catch (ComponentNeedConfigException ex) { _logger.LogError($"Error during load component {name} - config values need configuration: {string.Join(',', ex.ConfigKeys)}"); cData.Status = ComponentStatusEnum.NeedConfiguration; cData.Error = ex; return(false); } catch (Exception ex) { _logger.LogError($"Error during load component {name} - {ex.Message}"); cData.Error = ex; cData.Status = ComponentStatusEnum.Error; return(false); } }