Start by creating a new QvEventLogConnection.cs class, which is initialized from the previously developed QvEventLogServer class.
You need to implement methods from the QlikView.QVX.Library, so a reference is required the same as in the QvEventLogServer implementation:
using QlikView.Qvx.QvxLibrary;
Implementing the Init() method
First, implement the Init() method, which is used to initialize a new connection. It should contain the following:
• All of the fields in a new QvxField[] array
• An array of table definitions in a new MTables list as a new list of QvxTable
Add fields to a new QvxField[] array by defining a field name and additional parameters using the QvxField method from QvxLibrary. The following example code shows a sample QvxField[] array within the Init() method:
public override void Init()
{
var eventLogFields = new QvxField[]
{
new QvxField("Category", QvxFieldType.QVX_TEXT,
QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
new QvxField("EntryType", QvxFieldType.QVX_TEXT,
QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
new QvxField("Message", QvxFieldType.QVX_TEXT,
QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII)
};
}
The variable name implemented, var eventLogFields, is referenced in the QvxTable array below.
Initialize the MTables[] list as a new list of QvxTable and add your QVX tables to it with the relevant properties.
The following example shows an MTables list that references the eventLogFields variable from the QvxField[] array:
MTables = new List<QvxTable>
{
new QvxTable
{
TableName = "ApplicationsEventLog",
GetRows = GetApplicationEvents,
Fields = eventLogFields
}
};
Implementing the GetRows() method
The next step is to implement the GetRows() method to extract the source data rows. In the code example above, this is called GetApplicationEvents and instantiates a new QvxDataRow for each row from the source data.
The following code example describes this process and adds a new QvxDataRow based on the name of the QVX Table, using the FindTable() method (in this case, searching for the “ApplicationsEventLog” table from the MTables list previously implemented):
private IEnumerable<QvxDataRow> GetApplicationEvents()
{
var ev = new EventLog("Application");
foreach (var evl in ev.Entries)
{
yield return MakeEntry(evl as EventLogEntry, FindTable("ApplicationsEventLog",
MTables));
}
}
private QvxDataRow MakeEntry(EventLogEntry evl, QvxTable table)
{
var row = new QvxDataRow();
row[table.Fields[0]] = evl.Category;
row[table.Fields[1]] = evl.EntryType.ToString();
row[table.Fields[2]] = evl.Message;
return row;
}
Example
The following code example shows the final implementation:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using QlikView.Qvx.QvxLibrary;
namespace QvEventLogConnectorSimple
{
internal class QvEventLogConnection : QvxConnection
{
public override void Init()
{
var eventLogFields = new QvxField[]
{
new QvxField("Category", QvxFieldType.QVX_TEXT,
QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
new QvxField("EntryType", QvxFieldType.QVX_TEXT,
QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
new QvxField("Message", QvxFieldType.QVX_TEXT,
QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
};
MTables = new List<QvxTable>
{
new QvxTable
{
TableName = "ApplicationsEventLog",
GetRows = GetApplicationEvents,
Fields = eventLogFields
}
};
}
private IEnumerable<QvxDataRow> GetApplicationEvents()
{
var ev = new EventLog("Application");
foreach (var evl in ev.Entries)
{
yield return MakeEntry(evl as EventLogEntry, FindTable("ApplicationsEventLog",
MTables));
}
}
private QvxDataRow MakeEntry(EventLogEntry evl, QvxTable table)
{
var row = new QvxDataRow();
row[table.Fields[0]] = evl.Category;
row[table.Fields[1]] = evl.EntryType.ToString();
row[table.Fields[2]] = evl.Message;
return row;
}
}
}
The next step is Building your solution.
Did this page help you?
If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!