Monday, September 28, 2009

Geographic Domain in Client Add-in

When writing add-in to the ClickSchedule client, I was trying to get the full navigation tree from ClickSchedule client. I have made this short code:
' Option 1 - using the client's loaded domain
Public Function DoAddIn( _
ByRef objCallingApp As Object, _
ByRef objCallingDoc As Object, _
ByRef lDocType As Integer, _
ByRef varSelectedEngineers As Object, _
ByRef varSelectedTasks As Object, _
ByRef varSelectedAssignments As Object) _
As Boolean

' Get the client domain navigation tree
Dim navObj As Object = _
CType(CType(objCallingApp, _
W6BFClient.W6BFClient).Domain, _
W6BFClient.Domain).NavigationTree
If Not IsArray(navObj) Then Return False
Dim navArr As System.Array = navObj

' Request full navigation tree
Dim request As XmlDocument = New XmlDocument
request.LoadXml( _
"<SXPServerGetTree Revision=""7.5.0"">" & _
"<NavigationTree/></SXPServerGetTree>")
Dim ids As XmlNode = _
request.DocumentElement.FirstChild

' Set the collection ids
Dim first As System.Array = navArr(0)
For index As Integer = _
first.GetUpperBound(0) To 2 Step -3

ids.AppendChild(request.CreateElement( _
"CollectionID")).InnerText = _
first(index).ToString()
Next

' Create connection object (this is add-in, _
' connection already open by the client)
Dim sxp As W6Logon.Connection = _
New W6Logon.Connection
Dim response As XmlDocument = sxp.Send(request)
End Function

The problem with this option is the requirement for the user to have one or more districts loaded in the client, prior to opening this add-in. So, here is the second option:
' Option 2 - not using the client's loaded domain
Public Function DoAddIn( _
ByRef objCallingApp As Object, _
ByRef objCallingDoc As Object, _
ByRef lDocType As Integer, _
ByRef varSelectedEngineers As Object, _
ByRef varSelectedTasks As Object, _
ByRef varSelectedAssignments As Object) _
As Boolean

' Get the client app manager
Dim clientAppManager As _
W6BFClient.IW6BFClientAppManager = _
CType(objCallingApp, _
W6BFClient.IW6BFClientAppManager)

' Request admin setting
Dim requestAdmin As XmlDocument = New XmlDocument
requestAdmin.LoadXml( _
"<SXPServerGetObjects Revision=""7.5.0"">" & _
"<ObjectType>UserSetting</ObjectType>" & _
"<Indexes><Distinct>0</Distinct>" & _
"<Index><LowBound><Property>" & _
"<Name>Category</Name>" & _
"<Value>Power Scheduler Client</Value>" & _
"</Property><Property>" & _
"<Name>SubCategory</Name>" & _
"<Value>Administrative Settings</Value>" & _
"</Property></LowBound><HighBound>" & _
"<Property><Name>Category</Name>" & _
"<Value>Power Scheduler Client</Value>" & _
"</Property><Property>" & _
"<Name>SubCategory</Name>" & _
"<Value>Administrative Settings</Value>" & _
"</Property></HighBound></Index></Indexes>" & _
"<RequestedProperties>" & _
"<Item>Key</Item><Item>Owner</Item>" & _
"</RequestedProperties>" & _
"</SXPServerGetObjects>")
Dim responseAdmin As XmlDocument = SendSxp( _
"SXPServerGetObjects Administrative" & _
" Settings", requestAdmin)

' Get the template key
Dim template As String = _
clientAppManager.AdminTemplateName.ToLower()
Dim key As Integer = -1
For Each child As XmlNode In _
responseAdmin.DocumentElement.FirstChild.ChildNodes

Dim owner As String = child.SelectSingleNode( _
"Owner").InnerText.ToLower()
If template.Equals(owner) Then
key = CInt(child.SelectSingleNode( _
"Key").InnerText)
Exit For
End If
Next
If (key = -1) Then Return False

' Request template setting
Dim requestTemplate As XmlDocument = _
New XmlDocument
requestTemplate.LoadXml( _
"<SXPServerGetObjects Revision=""7.5.0"">" & _
"<ObjectType>UserSetting</ObjectType>" & _
"<KeySet><Key>" & key.ToString() & _
"</Key></KeySet><RequestedProperties>" & _
"<Item>Key</Item><Item>Body</Item>" & _
"</RequestedProperties></SXPServerGetObjects>")
Dim responseTemplate As XmlDocument = SendSxp( _
"SXPServerGetObjects AdminTemplateName", _
requestTemplate)

' Get the task property ids for the navigation tree
Dim body As XmlDocument = New XmlDocument
body.LoadXml( _
responseTemplate.DocumentElement.FirstChild. _
FirstChild.SelectSingleNode( _
"Body").InnerText)
Dim navigationProperties As XmlNode = _
body.DocumentElement.SelectSingleNode( _
"SOFTWARE/IET/W-6BreakFix/Client/" & _
"Administration/Navigation")

' Request task scheme
Dim requestTaskScheme As XmlDocument = _
New XmlDocument
requestTaskScheme.LoadXml( _
"<SXPServerGetCollectionsScheme " & _
"Revision=""7.5.0"">" & _
"<Collections><Collection><ID>2</ID>" & _
"</Collection></Collections>" & _
"</SXPServerGetCollectionsScheme>")
Dim responseTaskScheme As XmlDocument = SendSxp( _
"SXPServerGetCollectionsScheme", _
requestTaskScheme)

' Request full navigation tree
Dim request As XmlDocument = New XmlDocument
request.LoadXml( _
"<SXPServerGetTree Revision=""7.5.0"">" & _
"<NavigationTree/></SXPServerGetTree>")
Dim ids As XmlNode = _
request.DocumentElement.FirstChild

' Set the collection ids
For index As Integer = _
1 To navigationProperties.ChildNodes.Count

Dim propertyID As String = _
navigationProperties.SelectSingleNode( _
"Level" & index.ToString() & _
"/FieldNumber").InnerText.Replace("""", "")
Dim collectionID As String = _
responseTaskScheme.DocumentElement. _
SelectSingleNode( _
"Collections/Collection/Attributes" & _
"/Attribute[ID='" & _
propertyID & _
"']/KeyTypeInfo/ObjectType").InnerText
ids.AppendChild(request.CreateElement( _
"CollectionID")).InnerText = collectionID
Next

' Create connection object (this is add-in, _
' connection already open by the client)
Dim sxp As W6Logon.Connection = _
New W6Logon.Connection
Dim response As XmlDocument = sxp.Send(request)
End Function

The second option is longer, but works without loaded districts.

No comments:

Post a Comment

Please keep comments clean at the ClickDev blog.

 
HTML Hit Counter