This project is read-only.
... it was time to add it to the Business Desktop using the Task Editor. Within it, I set the command line parameter I wanted to use just as I would a VB 6 task. However, when I launched my task, the validation I had in place to check the command line parameter popped an error message stating it was incorrect. Instead of my command line parameter the task now had the following XML string:
<UserID Value ="admin/>
<Password Value=""/>
<TrustedConnection Value="False"/>
<SQLServerName Value="MAS70"/>
<DBName Value="MAS500_app"/>
<CompanyID Value="SOA"/>
<TaskID Value="1000061000"/>

What I learned is that in order for .NET EXEs to run within a MAS 500 session, the Business Desktop needs this information to figure out what this task is. In short it overwrites any command line parameters you set up within the task editor. The question now was how to work around it.

My first thought was to just determine the taskID running and execute the appropriate code based on that. However, the Application.Framework does not include a property for this. So looking at the problem again from a different direction I realized each menu item on the Business Desktop is a unique TaskID. Knowing this I figured I use the TaskID as my command line parameter now with a little re-engineering of my code. Now in order to do this I needed to ensure that my EXE could be used as a stand alone or from the Business Desktop. To accomplish this I came up with the following functions. I've noted some code that you would need to set in order to use it in your project.

Private Function GetCommandLineParams() As Boolean
'Purpose: Procedure to read and validate the command line parameter passed in for a valid taskID
'Written By: Louis Davis, MCAD
'Date: 27 December 2006
Dim arguments As String() = Environment.GetCommandLIneArgs
'The follwing is just an example. You would need to set up an array with the TaskIDs you will be using
Dim ParameterList As String() = 1000061000", "1000061001", "1000061002
Dim iCount As Integer = 0
Dim bValidParameter As Boolean = False
Dim strCommandLine As String = Environment.CommandLine.ToString
Dim bRunning As Boolean = False

'Check to see if task is running as stand alone or from Business Desktop
If strCommandlIne.IndexOf("<") = -1 Then
'Running as Stand Alone
'Get second element of commandline argument and populate a module level variable
mstrCommandLine = arguments(1).ToString

'Check to see if a command line parameter was used
If mstrCommandLine.Length = 0 Then
bRunning = False
MessageBox.Show("Processing stopped. You need to pass a valid command line parameter.", {Your app name}, MessageBoxButtons.Ok, MessageBoxIcon.Error)
Return bRunning
Exit Function
'Read XML Business Desktop generates to get TaskID
mstrCommandLine = GetTaskID(strCommandLine.SubString(strCommandLine.IndexOf("<")).ToString)
End If

'Validate the command line parameter passed in is a valid one
For iCount = ParamaterList.getLowerBound(0) To ParamaterList.getUpperBound(0)
If mstrCommandLine.Equals(ParameterList(iCount).ToString.ToUpper) Then
bValidParameter = True
Exit For
End If

'Check to see if flag is false. If so display error message and return false
If Not bValidParameter Then
bRunning = False
MessageBox.Show("Processing stopped. You need to pass a valid command line parameter.", {Your app name}, MessageBoxButtons.Ok, MessageBoxIcon.Error)
bRunning = True
End If

Return bRunning

End Function

Private Function GetTaskID(ByVal XMLString As String) As String
'Purpose: Function to parse XML string passed in for TaskID it may contains. This function
' is expecting the XML Command Line string that is created when a .NET task is launched
' from the Business Desktop.
'Written By: Louis Davis, MCAD
'Date: 4 January 2007
Dim _doc As New XMLDocument
Dim strTaskID As String

Dim nodelist as XmlNodeList
Dim node As XmlNode

'Load XML into document

'Get List of the name nodes
nodelist = _doc.SelectNodes("Environment/Task/TaskID")

'Loop through the nodes
For each node in nodelist
'get TaskID
strTaskID = node.Attribute.GetNamedItem("Value").Value
Catch ex as XmlException
Catch ex as Exception
End Try

Return strTaskID
End Function

For these functions you will need to import System.XML and System.Configuration. This is first version code so could probably be refactored a bit, so feel free to improve upon it as you need to. I hope you find the information useful.

Louis Davis

Last edited Feb 11, 2007 at 2:30 AM by MAltadonna, version 1


No comments yet.