Integrated Configuration Class

This commit is contained in:
Eric Fontana
2014-07-17 11:16:00 -04:00
parent f1d186c280
commit 992cc96da6
6 changed files with 72 additions and 39 deletions

View File

@@ -61,21 +61,17 @@ namespace TimberWinR.ServiceHost
readonly CancellationTokenSource _cancellationTokenSource;
readonly CancellationToken _cancellationToken;
readonly Task _serviceTask;
private readonly TcpInputListener _nlogListener;
private readonly Arguments _args;
private TcpInputListener _nlogListener;
public TimberWinRService(Arguments args)
{
_args = args;
_cancellationTokenSource = new CancellationTokenSource();
_cancellationToken = _cancellationTokenSource.Token;
_serviceTask = new Task(RunService, _cancellationToken);
var elistner = new WindowsEvtInputListener(_cancellationToken);
_nlogListener = new TcpInputListener(_cancellationToken, 5140);
var outputRedis = new RedisOutput(new string[] { "tstlexiceapp006.vistaprint.svc", "tstlexiceapp007.vistaprint.svc" }, _cancellationToken);
outputRedis.Connect(_nlogListener);
outputRedis.Connect(elistner);
}
public void Start()
@@ -94,7 +90,18 @@ namespace TimberWinR.ServiceHost
/// </summary>
private void RunService()
{
TimberWinR.Manager manager = new TimberWinR.Manager();
var config = new Configuration(_args.ConfigFile);
var outputRedis = new RedisOutput(new string[] { "tstlexiceapp006.vistaprint.svc", "tstlexiceapp007.vistaprint.svc" }, _cancellationToken);
_nlogListener = new TcpInputListener(_cancellationToken, 5140);
outputRedis.Connect(_nlogListener);
foreach (Configuration.WindowsEvents eventConfig in config.Events)
{
var elistner = new WindowsEvtInputListener(eventConfig, _cancellationToken);
outputRedis.Connect(elistner);
}
TimberWinR.Manager manager = new TimberWinR.Manager(_args.ConfigFile);
//while (!_cancellationTokenSource.IsCancellationRequested)
//{

View File

@@ -57,6 +57,11 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Content Include="testconf.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<TimberWinR>
<Inputs>
<WindowsEvents>
<Events source="System,Application" binaryFormat="PRINT" />
</WindowsEvents>
<Logs>
<Log name="First Set" location="C:\Logs1\*.log" />
<Log name="Second Set" location="C:\Logs2\*.log" recurse="0" splitLongLines="OFF" />
<Log name="Third Set" location="C:\Logs2\1.log,C:\Logs2\2.log" />
</Logs>
<IISLogs>
</IISLogs>
</Inputs>
</TimberWinR>

View File

@@ -151,7 +151,7 @@ namespace TimberWinR
foreach (XAttribute a in attributes)
{
string val = a.Value.ToLower();
string val = a.Value;
switch (a.Name.ToString())
{
@@ -242,7 +242,7 @@ namespace TimberWinR
case "binaryFormat":
if (val == "ASC" || val == "PRINT" || val == "HEX")
{
p.WithMsgErrorMode(val);
p.WithBinaryFormat(val);
}
else
{
@@ -386,7 +386,7 @@ namespace TimberWinR
static void parseXMLConf(string xmlConfFile)
{
XDocument config = XDocument.Load(@"c:\users\jpreddy\desktop\testConf.xml");
XDocument config = XDocument.Load(xmlConfFile);
IEnumerable<XElement> inputs =
from el in config.Root.Descendants("Inputs")
@@ -394,7 +394,6 @@ namespace TimberWinR
// WINDOWS EVENTS
IEnumerable<XElement> xml_events =
from el in inputs.Descendants("WindowsEvents").Descendants("Events")
@@ -631,14 +630,14 @@ namespace TimberWinR
{
// Default values for parameters.
private bool fullText = true;
private bool resolveSIDS = false;
private bool resolveSIDS = true;
private bool formatMsg = true;
private string msgErrorMode = "MSG";
private bool fullEventCode = false;
private string direction = "FW";
private string stringsSep = "|";
private string iCheckpoint;
private string binaryFormat = "HEX";
private string binaryFormat = "PRINT";
public Builder WithFullText(bool value)
{

View File

@@ -22,11 +22,13 @@ namespace TimberWinR.Inputs
/// </summary>
public class WindowsEvtInputListener : InputListener
{
private int _pollingIntervalInSeconds = 1;
private int _pollingIntervalInSeconds = 1;
private TimberWinR.Configuration.WindowsEvents _arguments;
public WindowsEvtInputListener(CancellationToken cancelToken, int pollingIntervalInSeconds = 1)
public WindowsEvtInputListener(TimberWinR.Configuration.WindowsEvents arguments, CancellationToken cancelToken, int pollingIntervalInSeconds = 1)
: base(cancelToken, FieldDefinitions, ParameterDefinitions)
{
_arguments = arguments;
_pollingIntervalInSeconds = pollingIntervalInSeconds;
var task = new Task(EventWatcher, cancelToken);
task.Start();
@@ -39,17 +41,18 @@ namespace TimberWinR.Inputs
var fileName = Path.Combine(System.IO.Path.GetTempPath(),
string.Format("{0}.lpc", Guid.NewGuid().ToString()));
// Instantiate the Event Log Input Format object
var iFmt = new EventLogInputFormat()
{
direction = "FW",
binaryFormat = "PRINT",
direction = _arguments.Direction,
binaryFormat = _arguments.BinaryFormat,
iCheckpoint = fileName,
resolveSIDs = true
resolveSIDs = _arguments.ResolveSIDS,
};
// Create the query
var query = @"SELECT * FROM Application, System";
var query = string.Format("SELECT * FROM {0}", _arguments.Source);
var firstQuery = true;
// Execute the query
@@ -115,23 +118,23 @@ namespace TimberWinR.Inputs
get
{
return new FieldDefinitions()
{
{"EventLog", typeof (string)},
{"RecordNumber", typeof (string)},
{"TimeGenerated", typeof (DateTime)},
{"TimeWritten", typeof (DateTime)},
{"EventID", typeof (int)},
{"EventType", typeof (int)},
{"EventTypeName", typeof (string)},
{"EventCategory", typeof (int)},
{"EventCategoryName", typeof (string)},
{"SourceName", typeof (string)},
{"Strings", typeof (string)},
{"ComputerName", typeof (string)},
{"SID", typeof (string)},
{"Message", typeof (string)},
{"Data", typeof (string)}
};
{
{"EventLog", typeof (string)},
{"RecordNumber", typeof (string)},
{"TimeGenerated", typeof (DateTime)},
{"TimeWritten", typeof (DateTime)},
{"EventID", typeof (int)},
{"EventType", typeof (int)},
{"EventTypeName", typeof (string)},
{"EventCategory", typeof (int)},
{"EventCategoryName", typeof (string)},
{"SourceName", typeof (string)},
{"Strings", typeof (string)},
{"ComputerName", typeof (string)},
{"SID", typeof (string)},
{"Message", typeof (string)},
{"Data", typeof (string)}
};
}
}

View File

@@ -19,7 +19,7 @@ namespace TimberWinR
public Manager(string configurationFile=null)
{
// Read the Configuration file
// Config = new Configuration();
Config = new Configuration(configurationFile);
var loggingConfiguration = new LoggingConfiguration();