-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
124 lines (100 loc) · 4.22 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
namespace QvxEventLogConnector
{
#region Usings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QvxLib;
using System.IO;
using System.Threading;
#endregion
class Program
{
static void Main(string[] args)
{
#region EventLogEntry -> QVX Serializer
// it is not possible to add attributes to this already compiled and existing class
// you have to give an collection of attributes to the serializer to override
// the default behavior
var overideAttributes = new Dictionary<string, List<QvxBaseAttribute>>() {
{"Data", new List<QvxBaseAttribute>() { new QvxIgnoreAttribute(true) }},
{"ReplacementStrings", new List<QvxBaseAttribute>() { new QvxSubfieldAttribute("|") }},
};
var qvxSer = new QvxSerializer<System.Diagnostics.EventLogEntry>(overideAttributes);
#endregion
#region Request Handler
var handler = new QvxDefaultHandleRequestHandler();
handler.QvxEditConnectHandler = (c, d) =>
{
// we don't need a edit Dialog
return new QvxReply() { OutputValues = { "" }, Result = QvxResult.QVX_OK };
};
handler.QvxConnectHandler = (c) =>
{
return new QvxReply() { Result = QvxResult.QVX_OK };
};
handler.QvxDisconnectHandler = () =>
{
return new QvxReply() { Result = QvxResult.QVX_OK };
};
#endregion
#region Execute Handler
var excHand = new QvxQvxExecuteCommandHandler();
excHand.QvxExecuteRequestTablesHandler = () =>
{
return
from c in System.Diagnostics.EventLog.GetEventLogs()
select new QvxTablesRow(c.Log);
};
excHand.QvxExecuteRequestColumnsHandler = (table) =>
{
return
from c in qvxSer.QvxTableHeader.Fields
select new QvxColumsRow(table, c.FieldName);
};
excHand.QvxExecuteRequestSelectHandler = (sql, c) =>
{
var qvxresult = QvxResult.QVX_SYNTAX_ERROR;
Action<QvxDataClient> tmpAction = null;
string eventlogName="";
try
{
// extract the eventlog name from the SQL
eventlogName = sql.Substring(sql.ToUpper().IndexOf("FROM") + 4).Trim();
}
catch
{
}
var enventlog = (from evlog in System.Diagnostics.EventLog.GetEventLogs() where evlog.Log == eventlogName select evlog).FirstOrDefault();
if (enventlog != null)
{
tmpAction = (dataclient) =>
{
qvxSer.Serialize(enventlog.Entries.Cast<System.Diagnostics.EventLogEntry>(), new BinaryWriter(dataclient));
dataclient.Close();
};
qvxresult = QvxResult.QVX_OK;
}
return new Tuple<QvxResult, Action<QvxDataClient>>(qvxresult, tmpAction);
};
#endregion
#region Generic Command Handler
var generic = new QvxDefaultQvxGenericCommandHandler();
generic.HaveStarField = true;
#endregion
#region Wireup
// Connect the execute handler to the default handler
handler.QvxExecuteHandler = excHand.HandleRequest;
handler.QvxGenericCommandHandler = generic.HandleRequest;
var client = new QvxCommandClient(args);
// Connect the default handler to the qvx pipe client
client.HandleQvxRequest = handler.HandleRequest;
#endregion
// Start the Client
client.StartThread();
// Wait or do other stuff :-)
while (client.Running) Thread.Sleep(500);
}
}
}