Print
Category: Zeus Framework
Hits: 5780

Index of XML Batch Processing

Some of the text and images has been copied from Luca Perrone (StuderAG) and translated into english.

1. Introduction

The XML Batch processing allows to run processes described as X-Objects (in XML). The batch processor loads a project (XML file) and starts a target process. There are different running modes:

The structure of the XML starts with a root object of type TXProcProject. The root object contains different targets. A target describes a processing for a specific goal. A target can also depend on other targets. This allows to create a dependency graph. The target contains various step-objects which implement IXProcess interface. Each step-object class can perform an action.

Following example simply copies a file called TestFile.txt from the temporary directory into a sub directory called test:

<?xml version="1.0"?>
<Projekt Name="MyProcessProject" ClassName="TXProcProject">
 
    <Target Name="Proc_01" ClassName="TXProcTarget">
        <copy ClassName="TXProcCopy"
              SourceDir="C:/Temp/"
              SourceFile="TestFile.txt"
              TargetDir="C:/Temp/test/"
              FailOnError="1"/>
    </Target>
   ...
</Projekt>

2. How to run

In your program code you have to create a XMLBatchProcessor object and to load a xml file with loadProject(). The following code loads a ProcessFile.xml into the batch processor

  TAutoPtr<TXMLBatchProcessor> ptrBatchProcessor 
    = new TXMLBatchProcessor();

  if(ptrBatchProcessor->loadProject(TString(L"ProcessFile.xml")) 
    == RET_NOERROR)
  {
    ptrBatchProcessor->processTarget(TString(L"ProcessMainNode"), m_rMonitor);
  }

The monitor (see m_rMonitor) is an object created outside of the batch processing. You have to implement the the interface IXProcessMonitor.


  class TMyProcessMonitor : public TZObject, 
                            public IXProcessMonitor
  {
    public:
      // Creates the processing monitor
      inline TProcessMonitor() { }

      // callback if a target has been started
      inline virtual void MQUALIFIER onProcessingTargetStarted(IXProcTarget& rTarget,
                                                    IXProcess::EProcessingMode eMode)
      {
        ...
      }

      // callback if a target has been ended
      inline virtual void MQUALIFIER onProcessingTargetEnded(IXProcTarget& rTarget,
                                                             Retval retValue)
      {
        ...
      }

      // callback when processing a step
      inline virtual void MQUALIFIER onProcessing(IXProcess& rProcess,
                                                  const IString& rActionKey,
                                                  const IString& rActionValue,
                                                  bool bFailOnError,
                             IXProcessMonitor::EMonitorErrorLevel eErrorState)
      {
        ...
      }

      ...
       
      // Memory Management
      MEMORY_MANAGER_INLINEIMPL()
      MEMORY_MANAGER_IMPL_END;

    private:
  };

2.1 Dry run

The dry run allows to run all processes without taking any actions (such as copying or deleting files). The dry run can be used to establish to number of files, actions or other items to be processed by a monitor. We often use this to set the maximum of a progress bar or precalculate a processing time.

2.2 Regular run

All processes of a traget and the dependend targets are executed. If a process fails the execution is aborted and an error is returned. This mode can be used to run critical targets or if a result of a target is used as input for a next target.

2.3 Regular run without abort

All processes of a traget and the dependend targets are executed. If a process fails the execution is NOT aborted. The error is only passed to a registered monitor object. We use this mode mostly for checking of states. Here it is not really critical, but we want to find all bugs at once.


3. Class structure

The Zeus-Framework provides various classes and interface to run the XML Batches.

The Zeus-Framework provides following processing steps: