diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-02-24 19:04:47 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-02-24 19:04:47 +0200 |
| commit | 40746c60fed9e70f3cb7f6f12f55595a77a1adfa (patch) | |
| tree | 815a77a25888aceed48d15a9ce2f977e0d9ee845 /Software/Visual_Studio/Tango.Core | |
| parent | 64b768178dc9e64293a52c1b6d2631709af9502a (diff) | |
| download | Tango-40746c60fed9e70f3cb7f6f12f55595a77a1adfa.tar.gz Tango-40746c60fed9e70f3cb7f6f12f55595a77a1adfa.zip | |
Fixed PPC and Machine Studio issues before next release.
Started working on Advanced Installer libraries.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Components/CmdCommand.cs | 94 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Tango.Core.csproj | 3 |
2 files changed, 96 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Components/CmdCommand.cs b/Software/Visual_Studio/Tango.Core/Components/CmdCommand.cs new file mode 100644 index 000000000..ef8c913eb --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Components/CmdCommand.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.Core.Components +{ + public class CmdCommand : ExtendedObject + { + public enum OutEncoding + { + Default, + Unicode, + } + + private Process _process; + + public String Arguments { get; set; } + + public TimeSpan Timeout { get; set; } + + public String WorkingDir { get; set; } + + public int ExitCode { get; set; } + + public OutEncoding OutputEncoding { get; set; } + + public CmdCommand(String processName, String arguments) + { + Timeout = TimeSpan.FromSeconds(5); + + _process = new Process(); + _process.StartInfo.CreateNoWindow = true; + _process.StartInfo.FileName = processName; + _process.StartInfo.UseShellExecute = false; + _process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + _process.StartInfo.RedirectStandardError = true; + _process.StartInfo.RedirectStandardOutput = true; + _process.StartInfo.Arguments = arguments; + _process.StartInfo.Verb = "runas"; + + if (WorkingDir != null) + { + _process.StartInfo.WorkingDirectory = WorkingDir; + } + + Arguments = arguments; + } + + public Task Run() + { + return Task.Factory.StartNew(() => + { + LogManager.Log($"Starting process {_process.StartInfo.FileName} with arguments {Arguments}..."); + _process.Start(); + _process.WaitForExit((int)Timeout.TotalMilliseconds); + + if (_process.HasExited) + { + String output = _process.StandardOutput.ReadToEnd(); + String error = _process.StandardError.ReadToEnd(); + + if (OutputEncoding == OutEncoding.Unicode) + { + byte[] data = Encoding.Default.GetBytes(output); + output = Encoding.Unicode.GetString(data); + + data = Encoding.Default.GetBytes(error); + error = Encoding.Unicode.GetString(data); + } + + LogManager.Log($"Process exited with exit code {_process.ExitCode}."); + LogManager.Log($"Process Standard Output:\n{output}"); + LogManager.Log($"Process Standard Error:\n{error}"); + + ExitCode = _process.ExitCode; + + if (_process.ExitCode != 0) + { + throw new IOException($"The process {_process.StartInfo.FileName} has exited with the code {_process.ExitCode}."); + } + } + else + { + throw new TimeoutException($"The process {_process.StartInfo.FileName} has not exited within the given timeout of {Timeout.TotalSeconds} seconds."); + } + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index eb80279ef..5d83c5137 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -85,6 +85,7 @@ <Compile Include="..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="Components\CmdCommand.cs" /> <Compile Include="IO\KnownFolders.cs" /> <Compile Include="Json\ProtobufContractResolver.cs" /> <Compile Include="Threading\ActionTimer.cs" /> @@ -194,7 +195,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> |
