public void Generate()
        {
            StringBuilder descriptionsBuilder = new StringBuilder(@"CLI
***

CLI access is not currently included in the Nethermind launcher but will be added very soon.

");

            List <Type> cliModules = new List <Type>();

            foreach (string assemblyName in _assemblyNames)
            {
                Assembly assembly = Assembly.Load(new AssemblyName(assemblyName));
                foreach (Type type in assembly.GetTypes().Where(t => typeof(CliModuleBase).IsAssignableFrom(t)).Where(t => !t.IsInterface && !t.IsAbstract))
                {
                    if (!type.Name.Contains("Ndm"))
                    {
                        cliModules.Add(type);
                    }
                }
            }

            foreach (Type cliModule in cliModules.OrderBy(t => t.Name))
            {
                CliModuleAttribute moduleAttribute = cliModule.GetCustomAttribute <CliModuleAttribute>();
                descriptionsBuilder.Append($@"{moduleAttribute.ModuleName}
{string.Empty.PadLeft(moduleAttribute.ModuleName.Length, '^')}

");

                var properties = cliModule.GetMethods(BindingFlags.Public | BindingFlags.Instance);
                foreach (MethodInfo methodInfo in properties.OrderBy(p => p.Name))
                {
                    CliPropertyAttribute propertyAttribute = methodInfo.GetCustomAttribute <CliPropertyAttribute>();
                    CliFunctionAttribute functionAttribute = methodInfo.GetCustomAttribute <CliFunctionAttribute>();

                    if (propertyAttribute != null)
                    {
                        descriptionsBuilder.AppendLine($" {propertyAttribute.ObjectName}.{propertyAttribute.PropertyName}")
                        .AppendLine($"  {propertyAttribute.Description ?? "<check JSON RPC docs>"}")
                        .AppendLine();
                    }

                    if (functionAttribute != null)
                    {
                        descriptionsBuilder.AppendLine($" {functionAttribute.ObjectName}.{functionAttribute.FunctionName}({string.Join(", ", methodInfo.GetParameters().Select(p => p.Name))})")
                        .AppendLine($"  {functionAttribute.Description ?? "<check JSON RPC docs>"}")
                        .AppendLine();
                    }
                }
            }

            string result = descriptionsBuilder.ToString();

            Console.WriteLine(result);
            string sourceDir = DocsDirFinder.FindDocsDir();

            File.WriteAllText(Path.Combine(sourceDir, "cli.rst"), result);
        }
Beispiel #2
0
        public void Generate()
        {
            StringBuilder descriptionsBuilder = new StringBuilder(@"Metrics
********

Nethermind metrics can be consumed by Prometheus/Grafana if configured in Metrics configuration categoru (check configuration documentation for details). Metrics then can be used to monitor running nodes.

");

            List <Type> metricsTypes = new List <Type>();

            foreach (string assemblyName in _assemblyNames)
            {
                Assembly assembly = Assembly.Load(new AssemblyName(assemblyName));
                foreach (Type type in assembly.GetTypes().Where(t => t.Name == "Metrics"))
                {
                    metricsTypes.Add(type);
                }
            }

            foreach (Type metricsType in metricsTypes.OrderBy(t => t.FullName))
            {
                if (metricsType.FullName == null)
                {
                    // for some reasons it could be null
                    continue;
                }

                string metricsCategoryName = metricsType.FullName.Replace("Nethermind.", "").Replace(".Metrics", "");
                descriptionsBuilder.Append($@"
{metricsCategoryName}
{string.Empty.PadLeft(metricsCategoryName.Length, '^')}

");

                var properties = metricsType.GetProperties(BindingFlags.Public | BindingFlags.Static);
                foreach (PropertyInfo methodInfo in properties.OrderBy(p => p.Name))
                {
                    DescriptionAttribute attribute = methodInfo.GetCustomAttribute <DescriptionAttribute>();
                    string description             = attribute == null ? "<missing description>" : attribute.Description;
                    descriptionsBuilder.AppendLine(@$ "
 nethermind_{MetricsUpdater.BuildGaugeName(methodInfo.Name)}
  {description}
");
                }
            }

            string result = descriptionsBuilder.ToString();

            Console.WriteLine(result);
            File.WriteAllText("metrics.rst", result);
            string sourceDir = DocsDirFinder.FindDocsDir();

            File.WriteAllText(Path.Combine(sourceDir, "metrics.rst"), result);
        }
        public void Generate()
        {
            StringBuilder descriptionsBuilder = new StringBuilder(@"JSON RPC
********

JSON RPC is available via HTTP and WS (needs to be explicitly switched on in the InitConfig).
Some of the methods listed below are not implemented by Nethermind (they are marked).

");

            List <Type> jsonRpcModules = new List <Type>();

            foreach (string assemblyName in _assemblyNames)
            {
                Assembly assembly = Assembly.Load(new AssemblyName(assemblyName));
                foreach (Type type in assembly.GetTypes().Where(t => typeof(IModule).IsAssignableFrom(t)).Where(t => t.IsInterface && t != typeof(IModule)))
                {
                    jsonRpcModules.Add(type);
                }
            }

            foreach (Type jsonRpcModule in jsonRpcModules.OrderBy(t => t.Name))
            {
                string moduleName = jsonRpcModule.Name.Substring(1).Replace("Module", "").ToLowerInvariant();
                descriptionsBuilder.Append($@"{moduleName}
{string.Empty.PadLeft(moduleName.Length, '^')}

");

                var properties = jsonRpcModule.GetMethods(BindingFlags.Public | BindingFlags.Instance);
                foreach (MethodInfo methodInfo in properties.OrderBy(p => p.Name))
                {
                    JsonRpcMethodAttribute attribute = methodInfo.GetCustomAttribute <JsonRpcMethodAttribute>();
                    string notImplementedString      = attribute == null || attribute.IsImplemented ? string.Empty : "[NOT IMPLEMENTED] ";
                    descriptionsBuilder.AppendLine($" {methodInfo.Name}({string.Join(", ", methodInfo.GetParameters().Select(p => p.Name))})")
                    .AppendLine($"  {notImplementedString}{attribute?.Description ?? "<description missing>"}").AppendLine();
                }
            }

            string result = descriptionsBuilder.ToString();

            Console.WriteLine(result);
            File.WriteAllText("jsonrpc.rst", result);
            string sourceDir = DocsDirFinder.FindDocsDir();

            File.WriteAllText(Path.Combine(sourceDir, "jsonrpc.rst"), result);
        }
        public void Generate()
        {
            StringBuilder descriptionsBuilder = new StringBuilder(@"Configuration
*************

Use '/' as the path separator so the configs can be shared between all platforms supported (Linux, Windows, MacOS).
'--config', '--baseDbPath', and '--log' options are available from the command line to select config file, base DB directory prefix and log level respectively. 

");

            StringBuilder exampleBuilder = new StringBuilder(@"Sample configuration (mainnet)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

::

    {
");

            List <(Type ConfigType, Type ConfigInterface)> configTypes = new List <(Type, Type)>();

            foreach (string assemblyName in _assemblyNames)
            {
                Assembly assembly = Assembly.Load(new AssemblyName(assemblyName));
                foreach (Type type in assembly.GetTypes().Where(t => typeof(IConfig).IsAssignableFrom(t)).Where(t => !t.IsInterface))
                {
                    var configInterface = type.GetInterfaces().Single(i => i != typeof(IConfig));
                    configTypes.Add((type, configInterface));
                }
            }

            foreach ((Type configType, Type configInterface) in configTypes.OrderBy(t => t.ConfigType.Name))
            {
                descriptionsBuilder.Append($@"{configType.Name}
{string.Empty.PadLeft(configType.Name.Length, '^')}

");

                ConfigCategoryAttribute categoryAttribute = configInterface.GetCustomAttribute <ConfigCategoryAttribute>();
                if (categoryAttribute != null)
                {
                    descriptionsBuilder.AppendLine($"{categoryAttribute.Description}").AppendLine();
                }

                exampleBuilder.AppendLine($"        \"{configType.Name.Replace("Config", string.Empty)}\": {{");

                var properties    = configType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                int propertyIndex = 0;
                foreach (PropertyInfo propertyInfo in properties.OrderBy(p => p.Name))
                {
                    propertyIndex++;
                    PropertyInfo interfaceProperty = configInterface.GetProperty(propertyInfo.Name);
                    if (interfaceProperty == null)
                    {
                        Console.WriteLine($"Property {propertyInfo.Name} is missing from interface {configInterface.Name}.");
                    }

                    ConfigItemAttribute attribute = interfaceProperty.GetCustomAttribute <ConfigItemAttribute>();
                    string defaultValue           = attribute == null ? "[MISSING_DOCS]" : attribute.DefaultValue;

                    if (propertyIndex == properties.Length)
                    {
                        exampleBuilder.AppendLine($"              \"{propertyInfo.Name}\" : {defaultValue}");
                    }
                    else
                    {
                        exampleBuilder.AppendLine($"              \"{propertyInfo.Name}\" : {defaultValue},");
                    }

                    if (attribute == null)
                    {
                        descriptionsBuilder.AppendLine($" {propertyInfo.Name}").AppendLine();
                        continue;
                    }

                    descriptionsBuilder
                    .AppendLine($" {propertyInfo.Name}")
                    .AppendLine($"   {attribute.Description}")
                    .AppendLine($"   default value: {defaultValue}")
                    .AppendLine();
                }

                exampleBuilder.AppendLine("        },");
            }

            exampleBuilder.AppendLine("    }");

            string result = string.Concat(descriptionsBuilder.ToString(), exampleBuilder.ToString());

            Console.WriteLine(result);
            File.WriteAllText("configuration.rst", result);
            string sourceDir = DocsDirFinder.FindDocsDir();

            File.WriteAllText(Path.Combine(sourceDir, "configuration.rst"), result);
        }