project BLF > class BScanDaemonQueue > method CreateScanDaemonQueue

Description

CreateScanDaemonQueue


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BScanDaemonProcessor.LoadExternalWork


program code (program6/bscandaemonqueue.p)

/* ============================================ */
    /* Set default return-status and clear the data */
    /* ============================================ */
    assign oiReturnStatus = -98.
    <M-1 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BScanDaemonQueue>
    if viFcReturnSuper <> 0 
    then do: 
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then Return.
    end. /* if viFcReturnSuper <> 0 */
    
    /* ============================== */
    /* Find the Scan   Daemon-record  */
    /* ============================== */
    <Q-2 run DaemonPrim (all) (Read) (NoCache)
          (input {&SCANDAEMON}, (DaemonName)
           input ?, (DaemonId)
           output dataset tqDaemonPrim) in BBaseDaemon >
    find tqDaemonPrim where
         tqDaemonPrim.tcDaemonName = {&SCANDAEMON}
         no-lock no-error.
    if not available tqDaemonPrim
    then do:
        assign vcMsgScanQ     = trim(#T-11'Scan daemon record does not exist.':255(379)T-11#)
               oiReturnStatus = -3.
        <M-3 run SetMessage
          (input  vcMsgScanQ (icMessage), 
           input  '':U (icArguments), 
           input  '':U (icFieldName), 
           input  '':U (icFieldValue), 
           input  'E':U (icType), 
           input  1 (iiSeverity), 
           input  '':U (icRowid), 
           input  'BLF-205':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BScanDaemonQueue>
        Return.
    end. /* if not available tqDaemonPrim */
    assign viParentDaemonId   = tqDaemonPrim.tiDaemonId
           vcParentDaemonName = tqDaemonPrim.tcDaemonName
           vcScanActivity     = "Create":U.
    
    /* ============================ */
    /* Get the active companies     */
    /* ============================ */
    <Q-5 run CompanyByCodeActiveID (all) (Read) (NoCache)
          (input ?, (CompanyId)
           input ?, (CompanyCode)
           input true, (CompanyIsActive)
           output dataset tqCompanyByCodeActiveID) in BCompany >

    /* ============================ */
    /* Get the locations            */
    /* ============================ */
    <Q-17 run ScanDaemonLocationInfo (all) (Read) (NoCache)
       (input ?, (CompanyId)
        output dataset tqScanDaemonLocationInfo) in BScanDaemon >                            
    

    MAJORDOCUMENTSCREATIONBLOCK :
    DO :
        for each tqCompanyByCodeActiveID,
            each tqScanDaemonLocationInfo where tqScanDaemonLocationInfo.tiCompany_ID = tqCompanyByCodeActiveID.tiCompany_ID:
        
            /* =================================================================== */
            /* Now we have a component and a directory available, we can go though */
            /* all subdirectories (=CompanyCodes) of it to find the os-files       */
            /* Max number of Queue-records created = 100                           */
            /* =================================================================== */
    
            Assign 
                vcScanDirectory         = tqScanDaemonLocationInfo.tcScanDaemonLocationDir
                vcScanComponent         = tqScanDaemonLocationInfo.tcBusComponentCode
                vcScanCreatorUserName   = "".
    
            assign vcScanDirectory = replace(vcScanDirectory,"~\":U,"/":U).

            /* ========================================================================================= */
            /* Create a DameonQueue for every combination of a file in a scan-dir and a company          */
            /* ========================================================================================= */
            assign file-info:file-name = vcScanDirectory.
            if file-info:file-type begins "D":U
            then do :
                input stream sOSRead from os-dir(file-info:file-name).
                repeat :
                    import stream sOSRead vcFileShortName vcFileFullName vcFileType.

                    if vcFileType = "F":U and 
                       not (vcFileShortName matches "+++*+++*":U)
                    then do:
                        assign vcFileRenamed                                               = replace(vcFileFullName,"~\":U,"/":U).
                               entry(num-entries(vcFileRenamed,"/":U),vcFileRenamed,"/":U) = "+++":U + string(viSessionID) + "+++":U + entry(num-entries(vcFileRenamed,"/":U),vcFileRenamed,"/":U).
                        os-rename value(vcFileFullName) 
                                  value(vcFileRenamed).
                        if os-error <> 0 
                        then do: 
                            assign vcMsgScanQ     = trim(substitute(#T-13'Scan daemon error: unable to rename the file '&1' into '&2'.':255(381)T-13#,trim(vcFileFullName),trim(vcFileRenamed))) + chr(10) + 
                                                    trim(substitute(#T-14'Operating system error: '&1'.':255(382)T-14#,string(os-error)))
                                   viBlockReturn  = -3.
                            <M-6 run SetMessage
          (input  vcMsgScanQ (icMessage), 
           input  '':U (icArguments), 
           input  '':U (icFieldName), 
           input  '':U (icFieldValue), 
           input  'E':U (icType), 
           input  3 (iiSeverity), 
           input  '':U (icRowid), 
           input  'BLF-206':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BScanDaemonQueue>
                            Leave MAJORDOCUMENTSCREATIONBLOCK.
                        end. /* if os-error <> 0 */
                        
                        /* =========================== */
                        /* Create a DaemonQueue record */
                        /* =========================== */   
                        <M-7 run AddDetailLine (input  'fcDaemonQueue':U (icTable), 
                            input  '':U (icParentRowid), 
                            output viBlockReturn (oiReturnStatus)) in BScanDaemonQueue>
                        if viBlockReturn < 0 
                        then Leave MAJORDOCUMENTSCREATIONBLOCK.
                        assign tfcDaemonQueue.DaemonId                  = tqDaemonPrim.tiDaemonId
                               tfcDaemonQueue.DaemonQueueStatus         = {&DAEMONQUEUESTATUS-WAITING}
                               tfcDaemonQueue.DaemonQueuePriority       = 1
                               tfcDaemonQueue.DaemonQueueRef            = substring(vcFileFullName,1,60,"CHARACTER":U)

                               tfcDaemonQueue.DaemonQueueRefDescription = vcScanComponent + "|":U + vcFileShortName + "|":U + vcFileFullName + "|":U + vcFileRenamed + "|":U + vcScanCreatorUserName + "| ((":U + trim(string(tqCompanyByCodeActiveID.tiCompany_ID)) + "))":U.  
                        if viCounter > 99
                        then Leave MAJORDOCUMENTSCREATIONBLOCK.
                        
                    end. /* if vcFileType = "F":U and  */
                end. /* repeat : */
                input stream sOSRead Close.
            end. /*  if file-info:file-type begins "D":U */
         End. /* for each tqScanDaemonLocationInfo*/     
     END. /* MAJORDOCUMENTSCREATIONBLOCK : DO : */
    
    /* =========== */
    /* Clear stuff */
    /* =========== */
    empty temp-table tqCompanyByCodeActiveID.
    Empty Temp-table tScanInfo.
    input stream sOSRead      Close. /* may be closed twice: causes no error */
    
    /* ============================= */
    /* Check for Errors in the block */
    /* ============================= */
    if viBlockReturn <> 0
    then do : 
        assign oiReturnStatus = viBlockReturn.
        if oiReturnStatus < 0 
        then return.
    end. /* if viBlockReturn <> 0 */
    
    /* =================================== */
    /* Validate, AddtionalUpdates and Save */
    /* =================================== */
    if can-find (first tfcDaemonQueue where 
                       tfcDaemonQueue.tc_Status = "N":U)
    then do :
        <M-8 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BScanDaemonQueue>
        if viFcReturnSuper <> 0 
        then do: 
            assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then Return.
        end. /* if viFcReturnSuper <> 0 */
        <M-9 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BScanDaemonQueue>
        if viFcReturnSuper <> 0 
        then do: 
            assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then Return.
        end. /* if viFcReturnSuper <> 0 */
        <M-10 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BScanDaemonQueue>
        if viFcReturnSuper <> 0 
        then do: 
            assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then Return.
        end. /* if viFcReturnSuper <> 0 */
    end. /* if can find */
            
    /* ========================= */
    /* Set return-status = 0     */
    /* ========================= */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.