aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Tango.NET/Tango.Protobuf/ProtoCompiler.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-10-31 12:54:44 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-10-31 12:54:44 +0200
commitebdae96290085483d2b5aeaf56c0bdeaaffd95ea (patch)
tree010fdf909fdad9152ad2befe9f1a42fa721f9f0d /Software/Tango.NET/Tango.Protobuf/ProtoCompiler.cs
parent4fbe47ccac2bdcae52aafa07d6a80176e9606bd9 (diff)
downloadTango-ebdae96290085483d2b5aeaf56c0bdeaaffd95ea.tar.gz
Tango-ebdae96290085483d2b5aeaf56c0bdeaaffd95ea.zip
Change Tango.NET to Visual Studio
Diffstat (limited to 'Software/Tango.NET/Tango.Protobuf/ProtoCompiler.cs')
-rw-r--r--Software/Tango.NET/Tango.Protobuf/ProtoCompiler.cs124
1 files changed, 0 insertions, 124 deletions
diff --git a/Software/Tango.NET/Tango.Protobuf/ProtoCompiler.cs b/Software/Tango.NET/Tango.Protobuf/ProtoCompiler.cs
deleted file mode 100644
index eedebf63b..000000000
--- a/Software/Tango.NET/Tango.Protobuf/ProtoCompiler.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Core;
-
-namespace Tango.Protobuf
-{
- /// <summary>
- /// Represents a protobuf compiler base class.
- /// </summary>
- /// <seealso cref="Tango.Protobuf.IProtoCompiler" />
- public abstract class ProtoCompiler : IProtoCompiler
- {
- private const String COMPILERS_FOLDER_NAME = "ProtoCompilers"; //Compilers folder name.
- protected String _compilersPath; //Compilers folder path.
-
- /// <summary>
- /// Gets the compiler language.
- /// </summary>
- public abstract ProtoLanguage Language { get; }
-
- /// <summary>
- /// Gets the proto imports folders.
- /// </summary>
- public List<String> ImportsFolders { get; private set; }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ProtoCompiler"/> class.
- /// </summary>
- public ProtoCompiler()
- {
- _compilersPath = Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), COMPILERS_FOLDER_NAME);
- }
-
- /// <summary>
- /// Compiles the specified .proto message file and saves the result at the specified output folder.
- /// </summary>
- /// <param name="inputFile">.proto file to compile</param>
- /// <returns>
- /// A list of compiled results.
- /// </returns>
- public virtual IEnumerable<ProtoResult> Compile(string inputFile)
- {
- String tmpPath = PathHelper.GetTempFolderPath();
-
- String importsString = String.Empty;
-
- foreach (var path in ImportsFolders)
- {
- importsString = "--proto_path \"" + path + "\" ";
- }
-
- Process p = new Process();
- p.StartInfo.FileName = Path.Combine(_compilersPath, GetProtoCompilerName());
- p.StartInfo.Arguments = String.Format(
- "{0} {1}=\"{2}\" \"{3}\"",
- importsString,
- GetProtoArguments(),
- tmpPath,
- inputFile);
-
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
-
- p.Start();
- p.WaitForExit(5000);
-
- List<ProtoResult> results = new List<ProtoResult>();
-
- foreach (var file in Directory.GetFiles(tmpPath))
- {
- ProtoResult result = new ProtoResult(Path.GetFileName(file), File.ReadAllText(file), Language);
- }
-
- PathHelper.TryDeleteFolder(tmpPath);
-
- return results;
- }
-
- /// <summary>
- /// Compiles the specified .proto message file asynchronously and saves the result at the specified output folder.
- /// </summary>
- /// <param name="inputFile">.proto file to compile</param>
- /// <returns>
- /// A list of compiled results.
- /// </returns>
- public async Task<IEnumerable<ProtoResult>> CompileAsync(string inputFile)
- {
- return await new Task<IEnumerable<ProtoResult>>(() => { return Compile(inputFile); });
- }
-
- /// <summary>
- /// Gets the protobuf compiler CLI arguments (without input/output files!).
- /// </summary>
- /// <returns></returns>
- protected abstract String GetProtoArguments();
-
- /// <summary>
- /// Gets the protobuf compiler CLI file name (override when using a compiler other than the default 'protoc.exe').
- /// </summary>
- /// <remarks>
- /// The compiler program must be located in the compilers folder.
- /// </remarks>
- /// <returns></returns>
- protected virtual String GetProtoCompilerName()
- {
- return "protoc.exe";
- }
-
- /// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- /// </summary>
- public void Dispose()
- {
- //TODO: Dispose...
- }
- }
-}