#DEFINE XML_PATH "C:\RAR\comenzi.xml"
#DEFINE LOG_PATH "C:\RAR\auto_log.txt"

PROCEDURE AutomateProcesare
    LOCAL lcDate, llSuccess, llTestMode
    llSuccess = .F.
	llTestMode = .F. && Productie
	
    lcDate = DTOC(DATE())
    
    Try
        * Export comenzi in XML
        DO export_comenzi WITH XML_PATH, DATE()
        
        * Procesare prin RAR AutoPass
        loRar = CREATEOBJECT("RarAutoPass")
        IF !loRar.SetCredentials(m.llTestMode)  && .F. pentru productie
            THIS.WriteLog("EROARE: " + loRar.ErrorMsg)
            llSuccess = .F.
            RETURN llSuccess
        ENDIF
        
        IF loRar.ProcessXMLComenzi(XML_PATH)
            THIS.WriteLog("Procesare reu?ita pentru " + lcDate)
            llSuccess = .T.
        ELSE
            THIS.WriteLog("EROARE: " + loRar.ErrorMsg)
            llSuccess = .F.
        ENDIF
        
    Catch To loError
        THIS.WriteLog("EROARE: " + loError.Message)
        llSuccess = .F.
    Endtry
    
    Return llSuccess

PROCEDURE WriteLog
    PARAMETERS tcMessage
    LOCAL llSuccess
    llSuccess = .F.
    
    Try
        STRTOFILE(;
            TTOC(DATETIME()) + ": " + tcMessage + CHR(13) + CHR(10),;
            LOG_PATH,;
            1)
        llSuccess = .T.
        
    Catch To loError
        ? "Eroare scriere log: " + loError.Message
        llSuccess = .F.
    Endtry
    
    Return llSuccess