SideCarCLI – Line interceptors
Summary links SideCarCLI
( 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ā¦.
Leave a Reply