SideCarCLI – Line interceptors

Summary links SideCarCLI

NoName + Link 
1Description
2Specifications
3Refactor specifications and code
4Create Release
5Finish interceptors
6Send part of command to interceptors
7Line Interceptors
8Finish process after some time
9Documetation Diagram
10Technical Summary
11Create dotnet tool
( Description : SideCar for CLI applications. Interceptors for Line, Finish, Timer . See Code )

For the SideCarCLI I have the concept of Line Interceptors. That means for each line from the original program another program will be start .

The json looks like this

“LineInterceptors”: [
{
“Name”: “WindowsStandardWindowsOutputInterceptor”,
“Arguments”: “/c echo \”{site} {line}\””,
“FullPath”: “cmd.exe”,
“FolderToExecute”: null,
“InterceptOutput”: true
},
{
“Name”: “NextInterceptor”,
“Arguments”: “/c echo {line}”,
“FullPath”: “cmd.exe”,
“FolderToExecute”: null,
“InterceptOutput”: true
}
]

and you can activate by command line

-aLi WindowsStandardWindowsOutputInterceptor

Pretty simple , right ? For the code , means intercepting each line

p.OutputDataReceived += P_OutputDataReceived;
p.ErrorDataReceived += P_ErrorDataReceived;

and then run the process

foreach(var item in runningInterceptors.LineInterceptors)
{
try
{

var local = item;
var dataToBeParsed=new Dictionary<string, string>();

if(this.argsRegex.Count>0)
{
foreach (var reg in argsRegex)
{
dataToBeParsed.Add(“{“+reg.Key+”}”, reg.Value);
}
}
dataToBeParsed[“{line}”]= e.Data;
allProcesses.TryAdd(local.Name, local.RunLineInterceptor(local.Name,dataToBeParsed));

}
catch (Exception ex)
{
Console.WriteLine($”LineInterceptor:{item?.Name} error:!!!” + ex.Message);
}
}

Every time it is interesting how a simple specification means multiple lines of codeā€¦.