-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ef24406
Showing
95 changed files
with
8,738 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.sln.docstates | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
x64/ | ||
bld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
||
# Roslyn cache directories | ||
*.ide/ | ||
|
||
# MSTest test Results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
#NUNIT | ||
*.VisualState.xml | ||
TestResult.xml | ||
|
||
# Build Results of an ATL Project | ||
[Dd]ebugPS/ | ||
[Rr]eleasePS/ | ||
dlldata.c | ||
|
||
*_i.c | ||
*_p.c | ||
*_i.h | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.svclog | ||
*.scc | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
|
||
# Installshield output folder | ||
[Ee]xpress/ | ||
|
||
# NuGet Packages Directory | ||
#packages/* | ||
## TODO: If the tool you use requires repositories.config | ||
## uncomment the next line | ||
!packages/repositories.config | ||
|
||
# Enable "build/" folder in the NuGet Packages folder since | ||
# NuGet packages use it for MSBuild targets. | ||
# This line needs to be after the ignore of the build folder | ||
# (and the packages folder if the line above has been uncommented) | ||
!packages/build/ | ||
|
||
# Windows Store app package directory | ||
AppPackages/ | ||
|
||
# Others | ||
sql/ | ||
*.Cache | ||
ClientBin/ | ||
[Ss]tyle[Cc]op.* | ||
~$* | ||
*~ | ||
*.dbmdl | ||
*.dbproj.schemaview | ||
*.pfx | ||
*.publishsettings | ||
node_modules/ | ||
|
||
|
||
# Microsoft Fakes | ||
FakesAssemblies/ | ||
|
||
# LightSwitch generated files | ||
GeneratedArtifacts/ | ||
_Pvt_Extensions/ | ||
ModelManifest.xml | ||
/.vs/VSWorkspaceState.json | ||
/.vs/slnx.sqlite | ||
|
||
*/packages/ | ||
*/.vs/ | ||
.vs/ | ||
|
||
|
||
|
||
## Ignore eclipse and maven build artifacts | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
.loadpath | ||
.recommenders | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
|
||
# validation artifacts | ||
*.json | ||
|
||
# Java annotation processor (APT) | ||
.factorypath | ||
|
||
# sbteclipse plugin | ||
.target | ||
|
||
# Annotation Processing | ||
.apt_generated/ | ||
.apt_generated_test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.1.32328.378 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EABridge_Example_AddIn", "EABridge_Example_AddIn\EABridge_Example_AddIn.csproj", "{9865ECCC-F07B-447A-BD11-C75B081EEBA4}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EABridge_Example_AddIn_Tests", "EABridge_Example_AddIn_Tests\EABridge_Example_AddIn_Tests.csproj", "{7B90E5BE-58B0-4326-BD48-815220DC0D3B}" | ||
EndProject | ||
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "EABridge_Example_AddIn_Setup", "EABridge_Example_AddIn_Setup\EABridge_Example_AddIn_Setup.wixproj", "{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Debug|x86.Build.0 = Debug|Any CPU | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Release|x86.ActiveCfg = Release|Any CPU | ||
{9865ECCC-F07B-447A-BD11-C75B081EEBA4}.Release|x86.Build.0 = Release|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Debug|x86.Build.0 = Debug|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Release|x86.ActiveCfg = Release|Any CPU | ||
{7B90E5BE-58B0-4326-BD48-815220DC0D3B}.Release|x86.Build.0 = Release|Any CPU | ||
{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}.Debug|Any CPU.ActiveCfg = Debug|x86 | ||
{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}.Debug|x86.ActiveCfg = Debug|x86 | ||
{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}.Debug|x86.Build.0 = Debug|x86 | ||
{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}.Release|Any CPU.ActiveCfg = Release|x86 | ||
{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}.Release|Any CPU.Build.0 = Release|x86 | ||
{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}.Release|x86.ActiveCfg = Release|x86 | ||
{788CC963-0BEA-4CC6-826C-589AEA2AD2DB}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C3020ED3-76DD-48D8-8380-FEBD30D0B75C} | ||
EndGlobalSection | ||
EndGlobal |
195 changes: 195 additions & 0 deletions
195
AddIn/EABridge_Example_AddIn/ApplicationHandlers/ExampleHeadlessApplicationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
using EABridge_Example_AddIn.Utils; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
namespace EABridge_Example_AddIn.ApplicationHandlers | ||
{ | ||
public class ExampleHeadlessApplicationHandler | ||
{ | ||
|
||
public event OperationCompleteHandler OperationComplete; | ||
|
||
public delegate void OperationCompleteHandler(ExampleHeadlessApplicationHandler sender, ExternApplicationEventArgs e); | ||
|
||
private Process p; | ||
|
||
private Thread thread = null; | ||
|
||
|
||
public bool IsThreadRunning() | ||
{ | ||
return thread != null; | ||
} | ||
|
||
public void StartExternValidationOperationAsync(string guid, string path) | ||
{ | ||
string reportFile = ExampleHeadlessApplicationHandler.GetReportFilePath(); | ||
string[] arguments = ComputeArguments(guid, path, reportFile, false); | ||
StartExternApplicationAsync(arguments, reportFile); | ||
} | ||
|
||
private string[] ComputeArguments(string guid, string path, string targePath, bool isVerbose) | ||
{ | ||
string[] arguments = new string[5]; | ||
|
||
arguments[0] = "validate"; | ||
|
||
arguments[1] = @"""" + path + @""""; | ||
arguments[2] = @"""" + targePath + @""""; | ||
|
||
|
||
if (guid.Length > 0) | ||
{ | ||
arguments[3] = @"""" + guid + @""""; | ||
} | ||
else | ||
{ | ||
arguments[3] = ""; | ||
} | ||
arguments[4] = "-v"; | ||
|
||
string executablePath = HeadlessApplicationUtils.FindExecutable(); | ||
|
||
if (!File.Exists(executablePath)) | ||
{ | ||
Debug.WriteLine("Error: " + executablePath + " not found."); | ||
throw new FileNotFoundException("Error: " + executablePath + " not found."); | ||
} | ||
return arguments; | ||
} | ||
|
||
private void StartExternApplicationAsync(string[] arguments, | ||
string reportFile, | ||
DataReceivedEventHandler outputActionHandler = null) | ||
{ | ||
string args = string.Join(" ", arguments); | ||
args += HeadlessApplicationUtils.GetExecuableInIArguments(); | ||
thread = new Thread(() => StartExternApplication(args, reportFile, outputActionHandler)); | ||
thread.Start(); | ||
} | ||
|
||
private void StartExternApplication(string arguments, | ||
string reportFile, | ||
DataReceivedEventHandler outputActionHandler = null) | ||
{ | ||
p = new Process(); | ||
|
||
try | ||
{ | ||
Debug.WriteLine("Starting headless application: " + arguments); | ||
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | ||
p.EnableRaisingEvents = true; | ||
if (outputActionHandler != null) | ||
{ | ||
p.OutputDataReceived -= outputActionHandler; | ||
p.ErrorDataReceived -= outputActionHandler; | ||
p.OutputDataReceived += outputActionHandler; | ||
p.ErrorDataReceived += outputActionHandler; | ||
} | ||
p.StartInfo.UseShellExecute = false; | ||
p.StartInfo.CreateNoWindow = true; | ||
p.StartInfo.RedirectStandardOutput = true; | ||
p.StartInfo.RedirectStandardError = false; | ||
p.StartInfo.FileName = HeadlessApplicationUtils.FindExecutable(); | ||
p.StartInfo.Arguments = arguments; | ||
DateTime startTime = DateTime.Now; | ||
p.Start(); | ||
string standardOutput = ""; | ||
if (outputActionHandler == null) | ||
{ | ||
// read cli output and save it in a temporary log | ||
standardOutput = p.StandardOutput.ReadToEnd(); | ||
} else | ||
{ | ||
p.BeginOutputReadLine(); | ||
} | ||
|
||
p.WaitForExit(); | ||
|
||
DateTime endTime = DateTime.Now; | ||
|
||
|
||
|
||
|
||
ExternApplicationEventArgs eventArgs = new ExternApplicationEventArgs(); | ||
eventArgs.ReportFile = reportFile; | ||
eventArgs.ReturnCode = p.ExitCode; | ||
eventArgs.Duration = DateTimeUtils.GetTimeDifferenceInMilisec(startTime, endTime); | ||
|
||
if (!string.IsNullOrEmpty(standardOutput)) | ||
{ | ||
try | ||
{ | ||
string logFilePath = GetReportFilePath(); | ||
var sw = File.AppendText(logFilePath); | ||
sw.Write(standardOutput); | ||
sw.Close(); | ||
eventArgs.LogFile = logFilePath; | ||
} | ||
catch (Exception) | ||
{ | ||
// do nothing | ||
} | ||
} | ||
|
||
if (this != null) | ||
{ | ||
OperationComplete(this, eventArgs); | ||
thread = null; | ||
} | ||
} | ||
catch (ThreadAbortException) | ||
{ | ||
Debug.WriteLine("Validation aborted."); | ||
} | ||
finally | ||
{ | ||
p = null; | ||
} | ||
} | ||
|
||
public void KillProcess() | ||
{ | ||
try | ||
{ | ||
if (thread != null) | ||
{ | ||
if (p != null) | ||
{ | ||
|
||
p.Kill(); | ||
} | ||
if (thread.IsAlive) | ||
{ | ||
thread.Abort(); | ||
} | ||
} | ||
thread = null; | ||
} | ||
catch (Exception) | ||
{ | ||
// ignored | ||
} | ||
} | ||
|
||
public static string GetReportFilePath() | ||
{ | ||
return Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
} | ||
} | ||
|
||
|
||
public class ExternApplicationEventArgs : EventArgs | ||
{ | ||
public string ReportFile { get; set; } | ||
|
||
public int ReturnCode { get; set; } | ||
|
||
public long Duration { get; set; } | ||
|
||
public string LogFile { get; set; } | ||
} | ||
|
||
} |
Oops, something went wrong.