예제 #1
0
        public static ConfigDataJsonNode BuildNode(ConfigData data, ISet <string> languages,
                                                   INetworkSourceSettings?schemaSource = null)
        {
            // build commands node
            var commandsJsonBuilder = new CommandsJsonNode.Builder();

            foreach (var commandCategoryPair in data.CommandCategories)
            {
                var categoryBuilder = new CategoryJsonNode.Builder(commandCategoryPair.Key,
                                                                   commandCategoryPair.Value.Name);
                commandsJsonBuilder.Categories.Add(categoryBuilder.Build());
                foreach (var commandPair in commandCategoryPair.Value.Commands)
                {
                    var command        = commandPair.Value;
                    var commandBuilder = new CommandJsonNode.Builder(command.Key,
                                                                     command.Name, commandCategoryPair.Key);
                    commandBuilder.Description = command.Description;
                    if (command.Parameters != null)
                    {
                        foreach (var parameter in command.Parameters)
                        {
                            var paramBuilder = new ParamJsonNode.Builder(parameter.Name,
                                                                         parameter.GetValuesNode());
                            paramBuilder.Description = parameter.Description;
                            commandBuilder.Parameters.Add(paramBuilder.Build());
                        }
                    }
                    commandsJsonBuilder.Items.Add(commandBuilder.Build());
                }
            }
            // build settings node
            var settingsJsonBuilder = new SettingsJsonNode.Builder();

            foreach (var settingCategoryPair in data.SettingCategories)
            {
                var categoryBuilder = new CategoryJsonNode.Builder(settingCategoryPair.Key,
                                                                   settingCategoryPair.Value.Name);
                settingsJsonBuilder.Categories.Add(categoryBuilder.Build());
                foreach (var settingPair in settingCategoryPair.Value.Settings)
                {
                    var setting        = settingPair.Value;
                    var settingBuilder = new SettingJsonNode.Builder(setting.Key,
                                                                     setting.Name, settingCategoryPair.Key, setting.GetValuesNode());
                    settingBuilder.Description = setting.Description;
                    settingsJsonBuilder.Items.Add(settingBuilder.Build());
                }
            }
            // build final root node
            var builder = new ConfigDataJsonNode.Builder(commandsJsonBuilder.Build(),
                                                         settingsJsonBuilder.Build());

            if (schemaSource != null)
            {
                builder.Schema = schemaSource.JsonSchemaUrl;
            }
            builder.Languages.UnionWith(languages);
            return(builder.Build());
        }
예제 #2
0
        public static ConfigDataJsonNode CreateNode(INetworkSourceSettings?schemaSource = null)
        {
            var commandsJsonBuilder = new CommandsJsonNode.Builder();
            var settingsJsonBuilder = new SettingsJsonNode.Builder();
            var builder             = new ConfigDataJsonNode.Builder(commandsJsonBuilder.Build(),
                                                                     settingsJsonBuilder.Build());

            if (schemaSource != null)
            {
                builder.Schema = schemaSource.JsonSchemaUrl;
            }
            return(builder.Build());
        }