"Fossies" - the Fresh Open Source Software Archive

Member "selenium-selenium-4.8.1/third_party/dotnet/devtools/src/generator/CodeGen/DomainGenerator.cs" (17 Feb 2023, 2648 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
    2 {
    3     using Humanizer;
    4     using Microsoft.Extensions.DependencyInjection;
    5     using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition;
    6     using System;
    7     using System.Collections.Generic;
    8     using System.Linq;
    9 
   10     /// <summary>
   11     /// Generates code for Domain Definitions
   12     /// </summary>
   13     public sealed class DomainGenerator : CodeGeneratorBase<DomainDefinition>
   14     {
   15         public DomainGenerator(IServiceProvider serviceProvider)
   16             : base(serviceProvider)
   17         {
   18         }
   19 
   20         public override IDictionary<string, string> GenerateCode(DomainDefinition domainDefinition, CodeGeneratorContext context)
   21         {
   22             var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
   23 
   24             var typeGenerator = ServiceProvider.GetRequiredService<ICodeGenerator<TypeDefinition>>();
   25             foreach (var type in domainDefinition.Types)
   26             {
   27                 typeGenerator.GenerateCode(type, context)
   28                     .ToList()
   29                     .ForEach(x => result.Add(x.Key, x.Value));
   30             }
   31 
   32             var eventGenerator = ServiceProvider.GetRequiredService<ICodeGenerator<EventDefinition>>();
   33             foreach (var @event in domainDefinition.Events)
   34             {
   35                 eventGenerator.GenerateCode(@event, context)
   36                     .ToList()
   37                     .ForEach(x => result.Add(x.Key, x.Value));
   38             }
   39 
   40             var commandGenerator = ServiceProvider.GetRequiredService<ICodeGenerator<CommandDefinition>>();
   41             foreach (var command in domainDefinition.Commands)
   42             {
   43                 commandGenerator.GenerateCode(command, context)
   44                     .ToList()
   45                     .ForEach(x => result.Add(x.Key, x.Value));
   46             }
   47 
   48             if (String.IsNullOrWhiteSpace(Settings.DefinitionTemplates.DomainTemplate.TemplatePath))
   49                 return result;
   50 
   51             var domainGenerator = TemplatesManager.GetGeneratorForTemplate(Settings.DefinitionTemplates.DomainTemplate);
   52 
   53             var className = domainDefinition.Name.Dehumanize();
   54 
   55             string codeResult = domainGenerator(new
   56             {
   57                 domain = domainDefinition,
   58                 className = className,
   59                 rootNamespace = Settings.RootNamespace,
   60                 context = context
   61             });
   62 
   63             var outputPath = Utility.ReplaceTokensInPath(Settings.DefinitionTemplates.DomainTemplate.OutputPath, className, context, Settings);
   64             result.Add(outputPath, codeResult);
   65 
   66             return result;
   67         }
   68     }
   69 }