Пример #1
0
 public override void OnProtoReport(ProtoReport report)
 {
     Console.WriteLine("Proto report: {0}", report);
 }
Пример #2
0
 static void WorkSingleFile(string file)
 {
     if (settings.BuildProtoc)
     {
         var startInfo = new ProcessStartInfo
         {
             FileName  = "protoc",
             Arguments = new ArgsBuilder()
                         .Multi(settings.ProtoImports,
                                (x, b) => b.Key('I', x))
                         .Key('o', $"{file}.bin")
                         .Key("csharp_out", settings.OutputDir)
                         .DictValue("csharp_opt", new Dictionary <string, string>
             {
                 { "base_namespace", settings.NamespaceBase },
                 { "file_extension", settings.ProtoExtension }
             })
                         .Key("error_format", settings.ErrorFormat,
                              condition: settings.ErrorFormat != "default")
                         .Flag("include_imports")
                         .Flag("include_source_info")
                         .Key("dependency_out", $"{file}.dep",
                              condition: report != null)
                         .File(file)
                         .ToString(),
             CreateNoWindow         = true,
             RedirectStandardError  = true,
             RedirectStandardOutput = true,
             WorkingDirectory       = Environment.CurrentDirectory,
         };
         using var process           = Process.Start(startInfo);
         process.OutputDataReceived += (_, e) =>
         {
             if (e.Data != null)
             {
                 Console.WriteLine(e.Data);
             }
         };
         process.ErrorDataReceived += (_, e) =>
         {
             if (e.Data != null)
             {
                 Console.Error.WriteLine(e.Data);
             }
         };
         process.BeginOutputReadLine();
         process.BeginErrorReadLine();
         process.WaitForExit();
         if (process.ExitCode != 0)
         {
             log.WriteError(text: $"protoc exit with code {process.ExitCode} with {file}");
             return;
         }
         var bin = $"{file}.bin";
         WorkSingleBinFile(bin);
         if (File.Exists(bin))
         {
             File.Delete(bin);
         }
         if (report != null)
         {
             var dep = $"{file}.dep";
             var(rep, gen) = ProtoReport.ReadReport(dep, file);
             if (rep != null)
             {
                 report.Protos.Add(rep);
             }
             if (gen != null)
             {
                 report.Generateds.Add(gen);
             }
             if (File.Exists(dep))
             {
                 File.Delete(dep);
             }
         }
     }
     else
     {
         WorkSingleBinFile(file);
     }
 }