예제 #1
0
        private void GenerateTypes(StringBuilder builder, ProtocolDomain domain)
        {
            if (domain.Types == null)
            {
                return;
            }

            // Generate objects
            foreach (var type in domain.Types.Where(t => t.Enum == null && t.Type == "object"))
            {
                builder.AppendLine("/// <summary>");
                builder.Append("/// ").AppendLine(FormatDocs(type.Description));
                builder.AppendLine("/// </summary>");
                GenerateTypeDefinition(builder, type.Id);
                builder.AppendLine("{");
                builder.AppendJoin("\n", NormalizeProperties(domain, type.Properties, false));
                builder.AppendLine("}");
            }
        }
예제 #2
0
        private void GenerateEnums(StringBuilder builder, ProtocolDomain domain)
        {
            if (domain.Types == null)
            {
                return;
            }

            // Generate enums
            foreach (var type in domain.Types.Where(t => t.Enum != null))
            {
                _enums.Add($"{domain.Domain}.{type.Id}");

                builder.AppendLine("/// <summary>");
                builder.Append("/// ").AppendLine(FormatDocs(type.Description));
                builder.AppendLine("/// </summary>");
                builder.AppendLine("[JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumMemberConverter))]");
                builder.Append("internal enum ").AppendLine(type.Id);
                builder.AppendLine("{");
                builder.AppendJoin(",\n", NormalizeEnum(type.Enum));
                builder.AppendLine("}");
            }
        }
예제 #3
0
        private void GenerateCommands(StringBuilder builder, ProtocolDomain domain)
        {
            if (domain.Commands == null)
            {
                return;
            }

            foreach (var command in domain.Commands)
            {
                // request
                string baseName = $"{domain.Domain}{command.Name.ToPascalCase()}";
                builder.AppendLine("/// <summary>");
                builder.Append("/// ").AppendLine(FormatDocs(command.Description));
                builder.AppendLine("/// </summary>");
                builder.AppendLine("/// <remarks>");
                builder.Append("/// Will send the command <c>").Append(domain.Domain).Append('.').Append(command.Name).AppendLine("</c>");
                builder.AppendLine("/// </remarks>");
                if (command.Description?.StartsWith("Deprecated", StringComparison.OrdinalIgnoreCase) == true)
                {
                    builder.Append("[System.Obsolete(\"").Append(command.Description.Replace("\n", "\\n", StringComparison.OrdinalIgnoreCase)).AppendLine("\")]");
                }

                GenerateRequestDefinition(builder, baseName);
                builder.AppendLine("{");
                builder.AppendLine("[System.Text.Json.Serialization.JsonIgnore]");
                builder.Append("public string Command { get; } = \"").Append(domain.Domain).Append('.').Append(command.Name).AppendLine("\";");
                builder.AppendJoin("\n", NormalizeProperties(domain, command.Parameters, false));
                builder.AppendLine("}");

                // response
                builder.AppendLine("/// <summary>");
                builder.Append("/// Response from <see cref=\"").Append(baseName).AppendLine("Request\"/>");
                builder.AppendLine("/// </summary>");
                GenerateResponseDefinition(builder, baseName);
                builder.AppendLine("{");
                builder.AppendJoin("\n", NormalizeProperties(domain, command.Returns, true));
                builder.AppendLine("}");
            }
        }
예제 #4
0
        private void GenerateEvents(StringBuilder builder, ProtocolDomain domain)
        {
            if (domain.Events == null)
            {
                return;
            }

            foreach (var e in domain.Events)
            {
                string eventName = e.Name.ToPascalCase();
                builder.AppendLine("/// <summary>");
                builder.Append("/// ").AppendLine(FormatDocs(e.Description));
                builder.AppendLine("/// </summary>");
                builder.AppendLine("/// <remarks>");
                builder.Append("/// Matches on the event <c>").Append(domain.Domain).Append('.').Append(e.Name).AppendLine("</c>");
                builder.AppendLine("/// </remarks>");
                GenerateEventDefinition(builder, domain.Domain + eventName);
                builder.AppendLine("{");
                builder.Append("public string InternalName { get; } = \"").Append(domain.Domain).Append('.').Append(e.Name).AppendLine("\";");
                builder.AppendJoin("\n", NormalizeProperties(domain, e.Parameters, false));
                builder.AppendLine("}");
            }
        }