Author Topic: Read Values returned from ConfigServer  (Read 3981 times)

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Read Values returned from ConfigServer
« on: July 18, 2013, 09:45:49 PM »
Hi guys,
smashing my head for 2 days and can't see my error...so I connected to ConfigServer, send a request and it returns (yay! xml! values needed!)
And got stuck lol

Trying to capture the 853 from:
[code]
<DBID value="853" />
[/code]

My code:
[code]
XDocument resultDocument = objectsRead.ConfObject; //Capture the XML part of the object
var temp = resultDocument.Descendants("DBID").Select(x => "DBID " + x.Attribute("value").Value).ToList();
[/code]

And I need to catch the DBID to send it to another CfgQuery...BUT the read of this value fails...
I think it has to do something with the UTF8...I tried many ways and same issue.
Anybody has a code to read these values and a little slap to me to understand why am I failing so miserably?

XML is:
[code]
<?xml version="1.0" encoding="utf-16"?>
<ConfData xmlns="http://schemas.genesyslab.com/Protocols/Configuration/ConfServer/2005/">
  <CfgPerson>
    <DBID value="853" />
    <tenantDBID value="101" />
    <lastName value="Rodrigues Geske" />
    <firstName value="Eduardo" />
    <employeeID value="T01039" />
    <userName value="T01039" />
    <password value="81DC9BDB52D04DC20036DBD8313ED055" />
    <isAgent value="2" />
    <CfgAgentInfo>
      <placeDBID value="0" />
      <skillLevels>
        <CfgSkillLevel>
          <skillDBID value="104" />
          <level value="0" />
        </CfgSkillLevel>
      </skillLevels>
      <agentLogins>
        <CfgAgentLoginInfo>
          <agentLoginDBID value="277" />
          <wrapupTime value="0" />
        </CfgAgentLoginInfo>
      </agentLogins>
      <capacityRuleDBID value="0" />
      <siteDBID value="0" />
      <contractDBID value="0" />
    </CfgAgentInfo>
    <isAdmin value="1" />
    <state value="1" />
  </CfgPerson>
</ConfData>
[/code]

Thanks!

Offline spin

  • Newbie
  • *
  • Posts: 7
  • Karma: 2
Re: Read Values returned from ConfigServer
« Reply #1 on: July 21, 2013, 04:22:59 AM »
hi,

I had to do something similar but I was looking for the isAgent.  I've modified it slightly for you so please don't take this as 100% working but hopefully this helps?

BTW I'm not strong in XML parsing so please don't laugh if there is a far easier way to do this.  I was happy when I got it to work.

Dim varObjectsRead As EventObjectsRead = varMessage
Dim varNavigator As XPathNavigator = varObjectsRead.ConfObject.CreateNavigator()
                    Dim varNodes As XPathNodeIterator = varNavigator.Select("//*")

                    Dim xdoc As New XmlDocument
                    varNodes.MoveNext()
                    varNavigator = varNodes.Current.Clone
                    Dim varXML As String = varNavigator.InnerXml

                    'load the XML string into an XML document
                    xdoc.LoadXml(varXML)

                    Dim xNode As XmlNode = xdoc.FirstChild
                    'navigate to the attributes
                    xNode = xNode.FirstChild

                    'cycle through attributes until finding the "DBID"
                    Dim varXMLValue As String
                    Do Until xNode Is Nothing ' after going to the end the variable will switch to nothing
                    If XNode.Name = "DBID" Then
                        varDBIDValue = xNode.Attributes(0).Value.ToString
                        xNode = xNode.NextSibling
                    Loop

       

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: Read Values returned from ConfigServer
« Reply #2 on: July 21, 2013, 09:13:37 PM »
Nice! Thanks!
Will try it tomorrow! I promised myself no coding this weekend ;)

Offline Kubig

  • Hero Member
  • *****
  • Posts: 2752
  • Karma: 44
Re: Read Values returned from ConfigServer
« Reply #3 on: August 06, 2013, 11:37:24 AM »
Is there any exact reason for using RequestReadObjects? It is possible to use Cfg queries, that returns objects and not XML. So, it is more easily to "parse" retrieved information

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: Read Values returned from ConfigServer
« Reply #4 on: August 06, 2013, 12:25:29 PM »
Yup, I got it later ;) I'm now using that method.
Thanks