public override void Initialize()
        {
            base.Initialize();

            Name = this.GetNameAttributeValue();

            _identifierValidator.Validate(this, ConfigurationFileAttributeNames.Name, Name);

            if (string.IsNullOrWhiteSpace(_plugins.PluginsDirectory))
            {
                throw new ConfigurationParseException(this,
                                                      string.Format("The value of attribute '{0}' is missing. This attribute is required if there are '{1}' elements under element '{2}'.",
                                                                    ConfigurationFileAttributeNames.PluginsDirPath, ConfigurationFileElementNames.Plugin, ConfigurationFileElementNames.Plugins), _plugins);
            }

            var pluginDirectory = GetPluginDirectory();

            if (!Directory.Exists(pluginDirectory))
            {
                //if (!Helpers.TryEnsureConfigurationDirectoryExists(pluginDirectory))
                throw new ConfigurationParseException(this, $"Plugin directory '{pluginDirectory}' does not exist.",
                                                      this.Parent);
            }

            if (!Enabled)
            {
                LogHelper.Context.Log.WarnFormat("Plugin '{0}' is disabled. Services, service implementations, settings, web API controllers and other configuration defined in this plugin will be ignored.", Name);
            }
        }
        public override void Initialize()
        {
            base.Initialize();

            _identifierValidator.Validate(this, ConfigurationFileAttributeNames.Name, Name);

            if (IsResolvedFromDiContainer)
            {
                throw new ConfigurationParseException(this, $"Settings cannot use '{ConfigurationFileElementNames.ValueInjectedObject}' element.");
            }
        }
Example #3
0
 public override void Initialize()
 {
     base.Initialize();
     Alias = this.GetAttributeValue <string>(ConfigurationFileAttributeNames.Alias);
     _identifierValidator.Validate(this, ConfigurationFileAttributeNames.Alias, Alias);
 }
Example #4
0
        public override void Initialize()
        {
            base.Initialize();

            Name = this.GetNameAttributeValue();

            //if (!Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
            //    throw new ConfigurationParseException(this, $"The value of '{ConfigurationFileAttributeNames.Name}' should be a file name with extension '.dll'.", false);

            if (Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
            {
                throw new ConfigurationParseException(this, $"The value of '{ConfigurationFileAttributeNames.Name}' should be an assembly file name without the file extension'.");
            }

            Alias = this.GetAttributeValue <string>(ConfigurationFileAttributeNames.Alias);

            _identifierValidator.Validate(this, ConfigurationFileAttributeNames.Alias, Alias);

            if (_xmlElement.HasAttribute(ConfigurationFileAttributeNames.Plugin))
            {
                var pluginName = this.GetAttributeValue <string>(ConfigurationFileAttributeNames.Plugin);

                var plugin = _configuration.Plugins?.GetPlugin(pluginName);

                if (plugin == null)
                {
                    throw new ConfigurationParseException(this, $"There is no plugin with name '{pluginName}'.");
                }

                Plugin = plugin;
            }

            string assemblyPath;

            if (_xmlElement.HasAttribute(ConfigurationFileAttributeNames.OverrideDirectory))
            {
                assemblyPath = Path.Combine(this.GetAttributeValue <string>(ConfigurationFileAttributeNames.OverrideDirectory), $"{Name}.dll");

                if (!File.Exists(assemblyPath))
                {
                    throw new ConfigurationParseException(this, $"Could not find assembly '{Name}'.");
                }
            }
            else
            {
                assemblyPath = _assemblyLocator.FindAssemblyPath(Name, Plugin?.Name, out var searchedDirectories);

                if (string.IsNullOrWhiteSpace(assemblyPath))
                {
                    var errorMessage = new StringBuilder();
                    errorMessage.AppendLine($"Could not find assembly '{Name}'. The following directories were searched:");

                    foreach (var searchedDiretory in searchedDirectories)
                    {
                        errorMessage.AppendLine($"  '{searchedDiretory}'");
                    }

                    throw new ConfigurationParseException(this, errorMessage.ToString());
                }
            }

            AbsolutePath = assemblyPath;

            LogHelper.Context.Log.InfoFormat("Resolved assembly '{0}' as '{1}'", Name, assemblyPath);

            if (Plugin != null)
            {
                var assemblyDirectory = Path.GetDirectoryName(assemblyPath);

                if (string.Compare(assemblyDirectory, Plugin.GetPluginDirectory(), StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new ConfigurationParseException(this, $"The assembly '{Name}' is configured as a plugin assembly for plugin '{Plugin.Name}'. Therefore the resolved assembly file should be in plugin directory '{Plugin.GetPluginDirectory()}'. Either remove the '{ConfigurationFileAttributeNames.Plugin}' attribute, or make sure that the assembly is in plugin directory and no other assembly with the same name exists in other probing folders.");
                }
            }

            //if (_xmlElement.HasAttribute(ConfigurationFileAttributeNames.LoadAssemblyAlways) &&
            //    this.GetAttributeValue<bool>(ConfigurationFileAttributeNames.LoadAssemblyAlways))
            //{
            //    try
            //    {
            //        LogHelper.Context.Log.InfoFormat("The value of attribute '{0}' is true. Loading assembly {1}.", ConfigurationFileAttributeNames.LoadAssemblyAlways, assemblyPath);
            //        _assemblyLocator.LoadAssembly(Path.GetFileName(assemblyPath), Path.GetDirectoryName(assemblyPath));
            //    }
            //    catch (Exception e)
            //    {
            //        LogHelper.Context.Log.Warn(e.Message, e);
            //        throw new ConfigurationParseException(this, $"Failed to load the assembly '{assemblyPath}'.");
            //    }
            //}
        }