The ElsClient object contains the following methods:
The AddEventRecord method adds an event to the ELS.
AddEventRecord(RecordXml as String) As String
| Parameter | Required | Description |
|---|---|---|
|
RecordXml |
Yes |
An XML representation of the record to add to the ELS. |
The RecordXml parameter of this method can be built using the methods GetEmptyRecordXml and SetRecordXMLAttribute.
Example
The following example builds a record XML and adds it to the ELS.
|
Sub Dim strXml
strXml = ElsClient.GetEmptyRecordXml
strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "description", "My Description") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "details", "My Details") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "comments", "My Comments") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "eventtimelocal", "3/10/2011 16:03:39.431") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "userflag01", "true")
MsgBox strXml
Dim strDbKey strDbKey = ElsClient.AddEventRecord(strXml)
MsgBox strDbKey End Sub |
The Connect method connects the object to a service.
Connect(DomainSiteService As String)
| Parameter | Required | Description |
|---|---|---|
|
DomainSiteService |
Yes |
The [Domain]Site.Service to which to connect. A domain is optional. The service must be a valid ELS. |
Returns 0 if successful and a non-zero value if the connection failed.
Example
The following example connects the ElsClient object to the CYGDEMO.ELS on domain 5410:
|
Sub ElsConnect() 'Connect to an ELS Dim ElsClient Set ElsClient = CreateObject("CxEls.ElsClient") ElsClient.Connect("[5410]CYGDEMO.ELS") End Sub |
The DeleteEventRecord method deletes an event from the ELS.
DeleteEventRecord(DbKey as String) As Boolean
| Parameter | Required | Description |
|---|---|---|
|
DbKey |
Yes |
The database key of the record to delete. |
This method returns false if the record was successfully deleted.
Example
The following example deletes record 0000022430 from the ELS.
|
Sub Dim bRet bRet = ElsClient.DeleteEventRecord("0000022430")
If Not(bRet) Then MsgBox "Event record deleted" Else MsgBox "Event record not deleted" End If End Sub |
The Disconnect method disconnects from the service.
Disconnect()
Example
The following example disconnects the client from the connected service.
|
Sub ElsDisconnect() ElsClient.Disconnect() MsgBox "ElsClient has disconnected" End Sub |
The GetConsoleData method returns the console text and display attributes as two 25x80 arrays of unsigned characters.
GetConsoleData(ByRef pText, ByRef pAttr) As Integer
| Parameter | Required | Description |
|---|---|---|
|
pText |
Yes |
A two-dimensional 25x80 array of console text attributes returned by this method. |
|
pAttr |
Yes |
A two-dimensional 25x80 array of console display attributes returned by this method. |
This method returns 0 if successful.
Example
The following example writes the console text and display attributes to a CSV file.
|
Sub Dim aryText, aryAttr, nRet nRet = ElsClient.GetConsoleData(aryText, aryAttr)
' Write text attributes to CSV file Dim i, j, strMsg For i = 0 To UBound(aryText, 1) For j = 0 To UBound(aryText, 2) strMsg = strMsg + CStr(aryText(i, j)) + "," Next strMsg = strMsg + vbCr Next
dim fso, file Set fso = CreateObject("Scripting.FileSystemObject") Set file = fso.OpenTextFile("c:\console_text_attrs.csv", 2, True) file.WriteLine(strMsg) file.Close
strMsg = ""
' Write display attributes to CSV file For i = 0 To UBound(aryAttr, 1) For j = 0 To UBound(aryAttr, 2) strMsg = strMsg + CStr(aryAttr(i, j)) + "," Next strMsg = strMsg + vbCr Next
Set file = fso.OpenTextFile("c:\console_disp_attrs.csv", 2, True) file.WriteLine(strMsg) file.Close
MsgBox nRet End Sub |
The GetEmptyRecordXml method returns an empty ELS header record.
GetEmptyRecordXml() As String
Example
The following example builds a record XML and adds it to the ELS.
|
Sub Dim strXml
strXml = ElsClient.GetEmptyRecordXml
strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "description", "My Description") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "details", "My Details") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "comments", "My Comments") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "eventtimelocal", "3/10/2011 16:03:39.431") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "userflag01", "true")
MsgBox strXml
Dim strDbKey strDbKey = ElsClient.AddEventRecord(strXml)
MsgBox strDbKey End Sub |
The GetRecordXMLAttribute method returns the value of a specified attribute in the specified record XML.
GetRecordXMLAttribute(RecordXml as String, RecordAttribute as String) As String
| Parameter | Required | Description |
|---|---|---|
|
RecordXml |
Yes |
An XML representation of the record from which to retrieve an attribute. |
|
RecordAttribute |
Yes |
The attribute to retrieve from the record. This parameter can be one of the following values:
|
Example
The following example displays the value of the "eventtimelocal" attribute for record 0000022430.
|
Sub Dim aryDbKeys, aryXml, strAttr ReDim aryDbKeys(0)
aryDbKeys(0) = "0000022430"
aryXml = ElsClient.ReadEventRecordsXmlArray(aryDbKeys)
strAttr = ElsClient.GetRecordXMLAttribute(aryXml(0), "eventtimelocal")
MsgBox strAttr End Sub |
The GetReferences method refreshes the list of services referenced by the connected service.
GetReferences()
Example
The following example refreshes the connected services.
|
Sub getElsReferences() ElsClient.GetReferences() MsgBox "Services referenced retrieved" End Sub |
The ReadEventComment method returns the comment for a record as an XML formatted string.
ReadEventComment(Key As String) As String
| Parameter | Required | Description |
|---|---|---|
|
Key |
Yes |
A valid Level 2 DbKey. |
Example
The following example gets the comment from a DbKey.
|
Sub readComments() Dim key Dim comment key = "0000000034"
comment = ElsClient.ReadEventComment(key) MsgBox comment End Sub |
The ReadEventRecords method returns the header record fields as an XML string.
ReadEventRecords(DbKeys As Array) As String
| Parameter | Required | Description |
|---|---|---|
|
DbKeys |
Yes |
An array of valid Level 2 DbKeys. |
Example
The following example gets header records from two DbKeys and stores them in an XML document.
|
Sub readRecords() Dim Keys(1) Dim headersXml
Keys(0) = "0000000034" Keys(1) = "0000000036"
headersXml = ElsClient.ReadEventRecords(Keys)
'Save header records as XML Set xmlDoc = CreateObject("Msxml2.DOMDocument.5.0") xmlDoc.loadXML(headersXml) xmlDoc.save("C:\HeaderRecords.xml") End Sub |
The ReadEventRecords method returns the header record fields as an array of XML strings.
ReadEventRecordsXmlArray(DbKeys As Array) As Variant
| Parameter | Required | Description |
|---|---|---|
|
DbKeys |
Yes |
An array of valid Level 2 DbKeys. |
Example
The following example gets header records from two DbKeys. It then displays the first record in a list box and saves the second record to the hard drive.
|
Sub readRecordArray() Dim Keys(1) Dim arrHeaders
Keys(0) = "0000000034" Keys(1) = "0000000036"
arrHeaders = ElsClient.ReadEventRecordsXmlArray(Keys)
'Display the first record lboList.AddString(arrHeaders(0))
'Save the second record to the hard drive Set xmlDoc = CreateObject("Msxml2.DOMDocument.5.0") xmlDoc.loadXML(arrHeaders(1)) xmlDoc.save("C:\HeaderRecordXml.xml") End Sub |
The ReadUserFlags method takes a valid Event Logging Service database key and returns an array of the user flag values.
ReadUserFlags(DbKey As String)
| Parameter | Required | Description |
|---|---|---|
|
DbKey |
Yes |
A valid Level 1 DBKey for the record to update in a string form. |
Return Value: An array of the current user flag values. Each Entry in the array represents a single flag. The value of each entry is True if the flag is set, False if the flag is not set. The array index is zero based, so index 0 is UserFlag01 and index 9 is UserFlag10, or one less than the name.
Example
The following example gets the user flag values for DbKey 0000000282 and displays a message box with UserFlag07’s state.
|
Dim ElsClient Dim arrFlags
'Create the Els Client Object ElsClient = CreateObject("CxEls.ElsClient" )
'Connect to the appropriate ELS ElsClient.Connect "MYSITE.ELS"
'Read the current user flags on DbKey 0000000282 arrFlags = m_ElsClient.ReadUserFlags( "0000000282")
'Now show the current flag value for UserFlag07 If arrFlags(6) Then MsgBox "UserFlag07 is Set" Else MsgBox "UserFlag07 is not Set" End If |
The SetRecordXMLAttribute method sets the value of a specified attribute in the specified record XML.
SetRecordXMLAttribute(RecordXml as String, RecordAttribute as String, AttributeValue as String) As String
| Parameter | Required | Description |
|---|---|---|
|
RecordXml |
Yes |
An XML representation of the record for which to set an attribute. |
|
RecordAttribute |
Yes |
The attribute to set in the record. This parameter can be one of the following values:
|
|
AttributeValue |
Yes |
The value of the attribute to set. |
Return Value: A string containing the new record XML with the updated attribute.
Example
The following example builds a record XML and adds it to the ELS.
|
Sub Dim strXml
strXml = ElsClient.GetEmptyRecordXml
strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "description", "My Description") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "details", "My Details") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "comments", "My Comments") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "eventtimelocal", "3/10/2011 16:03:39.431") strXml = ElsClient.SetRecordXMLAttribute(_ strXml, "userflag01", "true")
MsgBox strXml
Dim strDbKey strDbKey = ElsClient.AddEventRecord(strXml)
MsgBox strDbKey End Sub |
The UpdateEventComment method adds a comment to a record.
UpdateEventComment(DbKey As String, Comment As String)
| Parameter | Required | Description |
|---|---|---|
|
DbKey |
Yes |
A valid Level 2 DbKey. |
|
Comment |
Yes |
A string comment to add to the record. |
Example
The following example adds a comment to a ELS record.
|
Sub updateElsComment() Dim key Dim myComment
key = "0000000034" myComment = "Hello, World!"
ElsClient.UpdateEventComment key, myComment End Sub |
The UpdateUserFlag method takes a valid Event Logging Service database key and will set the specific User Flag on the corresponding record. If setting more than one flag on a given DbKey, using the UpdateUserFlags is more efficient. Set to True to enable, False to disable. Valid Flag values are 1-10
UpdateUserFlag(DbKey As String, Flag As Integer, Setting As Boolean)
| Parameter | Required | Description |
|---|---|---|
|
DbKey |
Yes |
A valid Level 1 DBKey for the record to update in a string form. |
|
Flag |
Yes |
The flag to change. This is a numeric value of 1 to 10 corresponding to UserFlag01 though UserFlag10. |
|
Setting |
Yes |
A Boolean value of True to set the user flag or False to clear the user flag. |
Return Value: None. An error is generated if the Update to the user flag does not succeed.
Example
The following example clears the first user flag on DbKey 0000000282 and sets the fifth user flag on DbKey 0000000283.
|
Dim ElsClient
'Create the Els Client Object
ElsClient = CreateObject("CxEls.ElsClient" )
'Connect to the appropriate ELS ElsClient.Connect "MYSITE.ELS"
'Clear UserFlag01 on DbKey 0000000282 m_ElsClient.UpdateUserFlag( "0000000282", 1, False) ... ... 'Set UserFlag05 0000000283 m_ElsClient.UpdateUserFlag( "0000000283", 1, True) |
The UpdateUserFlags method takes a valid Event Logging Service database key and will set the specific User Flag on the corresponding record. If setting more than one flag on a given DbKey, using the UpdateUserFlags is more efficient. True means set the flag, False means clear the flag, Empty or Null means leave existing value.
UpdateUserFlags(DbKey As String, ArrFlags)
| Parameter | Required | Description |
|---|---|---|
|
DbKey |
Yes |
A valid Level 1 DBKey for the record to update in a string form. |
|
arrFlags |
Yes |
An array of the flags to change. Each Entry in the array maybe represents a single flag. The value of each entry is True to set the flag, False to clear the Flag or Empty or Null to retain the current value of the flag. The array index is zero based, so index 0 is UserFlag01 and index 9 is UserFlag10. |
Return Value: None. An error is generated if the Update to the user flags does not succeed.
Example
The following example clears UserFlag01 and sets UserFlag05 on DbKey 0000000282. Then, it clears all the flags on DbKey 0000000283 except for UserFlag07.
|
Dim ElsClient Dim arrFlags Dim iIndex
'Create the Els Client Object
ElsClient = CreateObject("CxEls.ElsClient" )
'Connect to the appropriate ELS ElsClient.Connect "MYSITE.ELS"
'allocate the array, Redim is the upperbound based so subtract 1 'from the number of flags.
Redim arrFlags(ElsClient.UserFlagCount - 1)
'Clear UserFlag01, set UserFlag05, and leave all the rest alone arrFlags(0) = False arrFlags(4) = True
'Update the flags on dbkey 0000000282 m_ElsClient.UpdateUserFlags( "0000000282, arrFlags) ... ... 'Now Clear all the flags on 0000000283 except UserFlag07 'Clear all the flags For iIndex = LBound(arrFlags) to UBound(arrFlags ) arrFlags(iIndex) = False Next
'Retain the value for UserFlag07 arrFlags(6) = Empty
'Now update the flags m_ElsClient.UpdateUserFlag( "0000000283", arrFlags) |