All the configuration required for the generator - where to generate output files, the location of input files etc. While this isn't immutable in practice, the contents shouldn't be changed after being passed to the generator.
        internal static void Run(CodeGeneratorRequest request, CodeGeneratorResponse.Builder response)
        {
            var arguments = new List<string>();
            foreach (var arg in request.Parameter.Split(' '))
            {
                var timmedArg = (arg ?? "").Trim();
                if (!string.IsNullOrEmpty(timmedArg))
                {
                    arguments.Add(timmedArg);
                }
            }
            // Adding fake input file to make TryValidate happy.
            arguments.Add(System.Reflection.Assembly.GetExecutingAssembly().Location);

            GeneratorOptions options = new GeneratorOptions
            {
                Arguments = arguments
            };
            IList<string> validationFailures;
            if (!options.TryValidate(out validationFailures))
            {
                response.Error += new InvalidOptionsException(validationFailures).Message;
                return;
            }

            Generator generator = Generator.CreateGenerator(options);
            generator.Generate(request, response);
        }
Exemple #2
0
    internal static int Main(string[] args) {
      try {
        // Hack to make sure everything's initialized
        DescriptorProtoFile.Descriptor.ToString();
        GeneratorOptions options = new GeneratorOptions {Arguments = args};

        IList<string> validationFailures;
        if (!options.TryValidate(out validationFailures)) {
          // We've already got the message-building logic in the exception...
          InvalidOptionsException exception = new InvalidOptionsException(validationFailures);
          Console.WriteLine(exception.Message);
          return 1;
        }

        Generator generator = Generator.CreateGenerator(options);
        generator.Generate();
        return 0;
      }
      catch (Exception e) {
        Console.Error.WriteLine("Error: {0}", e.Message);
        Console.Error.WriteLine();
        Console.Error.WriteLine("Detailed exception information: {0}", e);
        return 1;
      }
    }
Exemple #3
0
 private static GeneratorOptions ParseCommandLineArguments(string[] args)
 {
     GeneratorOptions options = new GeneratorOptions();
       //string baseDir = "c:\\Users\\Jon\\Documents\\Visual Studio 2008\\Projects\\ProtocolBuffers";
       //options.OutputDirectory = baseDir + "\\tmp";
       //options.InputFiles = new[] { baseDir + "\\protos\\nwind-solo.protobin" };
       options.OutputDirectory = ".";
       options.InputFiles = args;
       return options;
 }
        internal static int Main(string[] args)
        {
            try
            {
                // Hack to make sure everything's initialized
                DescriptorProtoFile.Descriptor.ToString();
                GeneratorOptions options = new GeneratorOptions {Arguments = args};

                IList<string> validationFailures;
                if (!options.TryValidate(out validationFailures))
                {
                    // We've already got the message-building logic in the exception...
                    InvalidOptionsException exception = new InvalidOptionsException(validationFailures);
                    Console.WriteLine(exception.Message);
                    return 1;
                }

                var request = new CodeGeneratorRequest.Builder();
                foreach (string inputFile in options.InputFiles)
                {
                    ExtensionRegistry extensionRegistry = ExtensionRegistry.CreateInstance();
                    CSharpOptions.RegisterAllExtensions(extensionRegistry);
                    using (Stream inputStream = File.OpenRead(inputFile))
                    {
                        var fileSet = FileDescriptorSet.ParseFrom(inputStream, extensionRegistry);
                        foreach (var fileProto in fileSet.FileList)
                        {
                            request.AddFileToGenerate(fileProto.Name);
                            request.AddProtoFile(fileProto);
                        }
                    }
                }

                Generator generator = Generator.CreateGenerator(options);
                var response = new CodeGeneratorResponse.Builder();
                generator.Generate(request.Build(), response);
                if (response.HasError)
                {
                    throw new Exception(response.Error);
                }
                foreach (var file in response.FileList)
                {
                    File.WriteAllText(file.Name, file.Content);
                }
                return 0;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine("Detailed exception information: {0}", e);
                return 1;
            }
        }
 /// <summary>
 /// Returns a generator configured with the specified options.
 /// </summary>
 public static Generator CreateGenerator(GeneratorOptions options)
 {
     return new Generator(options);
 }
 private Generator(GeneratorOptions options)
 {
     options.Validate();
       this.options = options;
 }
Exemple #7
0
 /// <summary>
 /// Returns a generator configured with the specified options.
 /// </summary>
 public static Generator CreateGenerator(GeneratorOptions options)
 {
     return(new Generator(options));
 }
Exemple #8
0
 private Generator(GeneratorOptions options)
 {
     options.Validate();
     this.options = options;
 }