StartProcessUsingManifest

    The Datawatch Monarch Server Automator API provides two methods to launch a process:

    1) StartProcess(ProcessName)

    2) StartProcessUsingManifest(XML)

     

    When you create a process in the Automator, and run it, the process is launched with the first method (StartProcess).

    In what situation do you need to use the StartProcessUsingManifest?

    You can use the StartProcessUsingManifest method in situation when you don't know the location of the file or the file name at the time when the process is executed.  You need to run an existing process from an external program.

    The StartProcessUsingManifest method accepts an XML file as an argument.  The XML file contains a reference to an existing process name, input file location, and optionally runtime fields.  The following is an example of XML file:

    <manifest process="StartProcessWithManifest_client1"> <!-- Process Name-->

      <inputs>

        <item name="jan">

          <uri>file:C:\Datawatch\xml\client1\ClassJan.pdf</uri> <!-- Input file1-->

        </item> 

        <item name="feb">

          <uri>file:C:\Datawatch\xml\client1\ClassFeb.pdf</uri> <!-- Input file2-->

        </item> 

      </inputs>

      <runtime_fields>

        <runtime_field name="Id1">1</runtime_field>

        <runtime_field name="jan">ClassJan.pdf</runtime_field>

      </runtime_fields>

    </manifest>

     

    The runtime fields are useful in a case, which you want to pass certain parameters and read them in the post-export script so can use them for other tasks.  The runtime parameters can be retrieved with the GetRuntimeFieldValue method (e.g. log.GetRuntimeFieldValue("Id1"), or log.GetRuntimeFieldValue("jan")).  This method is a member of the JobLog object.

     

    The following example demonstrate how you can run a process using the StartProcessUsingManifest method.

    First you need to download the Automator API and place it in the folder on the Monarch Server.  The API package can be located in the "Installer Advanced 64-bit\Tools\" folder.  The package name is "Datawatch.DataPump.PumpAPI.7z".  You can use 7z.exe program to unzip files

    (7z X Datawatch.DataPump.PumpAPI.7z).

     

    After uncompressing the Automator API, you need to make references to the API DLLs. select the global script, click on the References, Imports tab, and add references to the DLL (per below screenshot).  In the Assembly box make sure the path is pointing to where you extracted the API files.  Also add the system.io (.Net library) to the Namspace.

    Add the following script in the global script, declaration tab.

     

    Function RunaProcess(byVal ProcessName As String, byRef msg As String, ByRef TrackId As String, Optional byVal InstanceName As String = "DefaultInstance", Optional ByVal ConfigServer As String = "net.tcp://WIN201264G:808", Optional ByVal sXml As String ="") As Boolean

      Dim oPump As PumpAPI = Nothing

      Dim ok As Boolean = True

      Try

        oPump = New PumpAPI(InstanceName, ConfigServer)

        If sXml = "" Then

          TrackId = oPump.StartProcess(ProcessName)

        Else

          TrackId = oPump.StartProcessUsingManifest(sXml)   

        End If

      catch ex as exception

         ok = False

         msg = ex.message

      End Try

      If Not IsNothing(oPump) Then oPump = Nothing

      Return ok

    End Function

     

    Create a project and name it StartProcessWithManifest_Process.

    You can use a dummy model which does not do anything, but has to be a valid Monarch desktop model.

    The input file extension must be an .xml.  In this example the input files are client1.xml, client2.xnml, and client3.xml.

    .

    You can either delete or move the input files.  In this example the xml files are moved a backup folder.

    You can create an export and create a dummy.txt file.  The output file (dummy.txt) will not be used, therefore, the export distribution will delete it.

    In the process post-script add the following scripts:

     

    Dim itemList As JobLogItemList
    Dim item As JobLogItem
    Dim n As Integer
    Dim FileName As String

    If ExportCompleted Then
      itemList = Log.GetInputItems(ProjectID) 'creates an itemlist.  The ProjectID is automatically passed.
      If itemList.Count = 0 Then ' No input items exist
      Else
        n = 0 'initialize the counter
        For Each item In itemList
            n = n + 1 'update the counter
            FileName = item.location
            log.addevent("Input File: " & FileName) 
            Call RunPumpApi(Log, FileName)  
        Next  
      End If
    End If

    Add the following scripts to the Global declarations tab:

     

    Sub RunPumpAPI(ByRef Log As JobLog, ByVal FileName As String)
    dim msg as string
    dim trackid as string
    Dim sXML as String

    Using reader As StreamReader = New StreamReader(FileName)
    sXML = reader.ReadToEnd
    reader.Close()
    End Using

    dim ok as boolean

      log.addevent("inp file: " & filename)
      ok = RunaProcess("", msg, trackId,"DefaultInstance","net.tcp://WIN201264G:808",sXML)
      if ok= false then log.addevent("error..." & msg) 
    End Sub

     

    Make sure to modify the above parameter (net.tcp://WIN201264G:808) to match the config server name in your environment.  Also if the DefaultInstance instance name is different, then change it in above call.

    Save the StartProcessWithManifest_process project.

    Create a new process and add the StartProcessWithManifest_process project to the new process.

    Enable the monitoring option in the process.

    Create a few xml files and drop it in the folder.  The above process is monitoring process and should start when xml files are dropped in the monitoring path. For each xml file that you create you have to have a process.

    When the following xml file is processed by the StartProcessUsingManifest method, it expects a process with the name StartProcessWithManifest_client1 exist in the Automator.

    manifest process="StartProcessWithManifest_client1"> <!-- Process Name-->

      <inputs>

        <item name="jan">

          <uri>file:C:\Datawatch\xml\client1\ClassJan.pdf</uri> <!-- Input file-->

        </item> 

      </inputs>

    </manifest>

     

    The following screenshot shows the input tab of the project in which is referenced in the StartProcessWithManifest_client1 process.

    Please note that syntax for the input file must starts with the word manifest followed by the item name in the xml file (e.g. manifest.jan).

    If the xml file contains multiple input files, then you should add multiple input in the project input tab:

    manifest.jan

    manifest.feb

     

    Rather than using the above example you can use the Automator web-service from an external program.  Write a web service program which consumes the Automator web service URL (http://<ServerName>/<Virtual Directory Name>/Services/DataPump/DataPumpWebService.asmx.), and pass the xml to the StartProcessusingManifest method.

     

    eof