ADCS logging data btw. NAV2013 and VT100Plugin in 1 xml file

okioki Member Posts: 46
edited 2015-01-30 in NAV Tips & Tricks
The VT100Plugin-Service has an option to output debug information (see here), but every transferred data package is stored in a single file (some with the extension .txt, some with .xml). So it is difficult to examine the traffic in all.

To review a whole data session, I've written a function which outputs the incoming and outgoing data from C7714 "ADCS WS" with timestamp information in one xml file.
The advantage is that you can view this file nicely formatted in the internet browser.

The layout is as follows:
<ADCS-VT100-Log>
  <datablock direction="to NAVISION" timeStamp="2015-01-30 16:40.16,55">
    <ADCS>
      <Header ID="49676947" Sequence="0" UseCaseCode="hello" />
    </ADCS>
  </datablock>
  <datablock direction="to TERMINAL" timeStamp="2015-01-30 16:40.16,566">
    <ADCS>
      <Header ID="49676947" Sequence="0" UseCaseCode="LOGIN" StackCode="" RunReturn="0" FormTypeOpt="Card" NoOfLines="2" InputIsHidden="0">
        <Comment />
        <Functions>
          <Function>ESC</Function>
        </Functions>
      </Header>
      <Lines>
        <Header>
          <Field Type="Text" MaxLen="19">Herzlich Willkommen</Field>
        </Header>
        <Body>
          <Field FieldID="1" Type="Input" MaxLen="20" Descrip="Benutzer ID" />
          <Field FieldID="2" Type="OutPut" MaxLen="250" Descrip="Kennwort:" />
        </Body>
      </Lines>
    </ADCS>
  </datablock>
  <datablock direction="to NAVISION" timeStamp="2015-01-30 16:41.03,887">
    <ADCS>
      <Header ID="49676947" Sequence="14" UseCaseCode="LOGIN" StackCode="" RunReturn="0" FormTypeOpt="Card" NoOfLines="2" InputIsHidden="0">
        <Functions>
          <Function Key1="27">ESC</Function>
        </Functions>
        <Input FieldID="1">kommiss_Md07</Input>
      </Header>
      <Lines>
        <Header>
          <Field Type="Text" MaxLen="19">Herzlich Willkommen</Field>
        </Header>
        <Body>
          <Field FieldID="1" Type="Input" MaxLen="20" Descrip="Benutzer ID" />
          <Field FieldID="2" Type="OutPut" MaxLen="250" Descrip="Kennwort:" />
        </Body>
      </Lines>
    </ADCS>
  </datablock>
  <datablock direction="to TERMINAL" timeStamp="2015-01-30 16:41.03,902">
    <ADCS>
      <Header ID="49676947" Sequence="14" UseCaseCode="LOGIN" StackCode="" RunReturn="0" FormTypeOpt="Card" NoOfLines="2" InputIsHidden="1" LoginID="KOMMISS_MD07">
        <Comment />
        <Functions>
          <Function>ESC</Function>
        </Functions>
      </Header>
      <Lines>
        <Header>
          <Field Type="Text" MaxLen="19">Herzlich Willkommen</Field>
        </Header>
        <Body>
          <Field FieldID="1" Type="OutPut" MaxLen="20" Descrip="Benutzer ID">KOMMISS_MD07</Field>
          <Field FieldID="2" Type="Input" MaxLen="250" Descrip="Kennwort:" />
        </Body>
      </Lines>
    </ADCS>
  </datablock>
</ADCS-VT100-Log>
Inside the <datablock>-tag you see the original xml data which is exchanged between VT100 and NAV. New datablocks are always appended at the end.

The function (should be placed in the C7714) which does the task follows here:
PROCEDURE LogData@1000000000(pSend@1000000000 : Boolean;VAR vDocument@1000000001 : Text);
VAR
  LXmlDoc@1000000002 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
  LXmlDoc1@1000000003 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
  LRootNode@1000000004 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
  LImportNode@1000000005 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
  LXMLDOMMgt@1000000006 : Codeunit 6224;
  LDocument@1000000007 : Text;
  LDirection@1000000008 : Text;
  LFilename@1000000009 : Text;
  LPath@1000000010 : Text;
BEGIN
  LPath := 'C:\Temp\';
  LFilename := 'Protocol.xml';
  IF NOT EXISTS(LPath+LFilename) THEN BEGIN
    LXmlDoc := LXmlDoc.XmlDocument;
    LXmlDoc.LoadXml('<ADCS-VT100-Log></ADCS-VT100-Log>');
    LXmlDoc.Save(LPath+LFilename);
    CLEAR(LXmlDoc);
  END;
  IF pSend THEN
    LDirection := 'to TERMINAL'
  ELSE
    LDirection := 'to NAVISION';

  LDocument := '<datablock direction="'+LDirection+'" timeStamp="'+FORMAT(CURRENTDATETIME,0,'<Year4>-<Month,2>-<Day,2> <Hours24,2>:<Minutes,2>.<Seconds,2><Second dec.><Comma,,>')+'">' + vDocument + '</datablock>';
  // Load new data part
  LXmlDoc1 := LXmlDoc1.XmlDocument;
  LXmlDoc1.LoadXml(LDocument);
  LXmlDoc := LXmlDoc.XmlDocument;
  // Load existing Protocol
  LXmlDoc.Load(LPath+LFilename);
  LRootNode := LXmlDoc.DocumentElement;
  // Append new data part in existing protocol
  LImportNode := LXmlDoc.ImportNode(LXmlDoc1.DocumentElement,TRUE);
  LRootNode.AppendChild(LImportNode);
  // save and that's all
  LXmlDoc.Save(LPath+LFilename);
END;
You can easily change the location of the file and its name.

LogData() should be called in the NAV standard function ProcessDocument() in C7714 - shown here:
PROCEDURE ProcessDocument(...);
BEGIN
  LogData(FALSE,Document); // <<<<<<<<<<<<<<<< log data from VT100
  InputXmlDocument := InputXmlDocument.XmlDocument;
  InputXmlDocument.LoadXml(Document);
  ADCSManagement.ProcessDocument(InputXmlDocument);
  ADCSManagement.GetOutboundDocument(OutputXmlDocument);
  Document := OutputXmlDocument.OuterXml;
  LogData(TRUE,Document); // <<<<<<<<<<<<<<<< log data from NAV
END;

Oli
Sign In or Register to comment.