<![CDATA[
/*
    $Id$

    File:       gen_tasker.wsf
    Calling:    cscript ..\..\..\utils\gen_scheduler\gen_tasker.wsf
    Parameters:

    Context:    Scheduled task
    Note:       De code veronderstelt (nog) dat de current folder een cust/xxxx/tasks folder is
                Concreter: ../Oracle.udl wordt gebruikt
*/
]]>

<job id="IncludeGenExport">
  <script language="JScript" src="../wsf_shared.js"/>
  <script language="JScript" src="../utils_settings.js"/>
  <script language="JScript" src="../putorders/puo_shared.js"/>
  <script language="JScript" src="../json2.js"/>
  <script language="JScript" src="./gen_tasker.js"/>

  <script language="JScript">

    __LOGFILEPREFIX = 'tasker';
    var applicatieRun = new Date();

    try
    {
        var oAbout = new ActiveXObject("SLNKDWF.About");
        WScript.Echo("SLNKDWF Version: " + oAbout.VersionString);
    }
    catch(e)
    {
        __Log("SLNKDWFx64.DLL is not properly installed.\n{0}".format(e.description));
        WScript.Quit(1);
    }

    var Oracle = Connect2Oracle('gen_tasker.wsf');

    var sql = "SELECT fac_version_cust FROM fac_version";
    var oRs = Oracle.Execute(sql);
    var customerId = oRs(0).Value;
    oRs.Close();
    __Log("CustomerId: " + customerId);

    var fso  = new ActiveXObject("Scripting.FileSystemObject");
    // We zijn altijd gescheduled vanuit cust/XXXX/Tasks
/* global */ var custabspath = fso.GetAbsolutePathName("../");
    var WshNetwork = new ActiveXObject("WScript.Network");

    Log2File(0, "===========================================================");
    Log2File(0, "GEN_TASKER STARTED (" + toDateTimeString(applicatieRun) + ") " + WshNetwork.UserDomain + "\\" + WshNetwork.UserName);
    Log2File(2, "puo_loglevel: " + S("puo_loglevel"));

    var retval = 0;
    try
    {
        var retval = tasker_loop();
        var sql = "UPDATE fac_version"
                + "   SET fac_version_tasker_date = SYSDATE";
        Oracle.Execute(sql);
    }
    catch(e)
    {
        Log2File(0, "Uncaught error in gen_tasker.wsf:\n" + e.description);
    }

    var endDate = new Date();
    var duration = Math.round((endDate - applicatieRun) / 1000 / 360) / 10;
    Log2File(0, "GEN_TASKER FINISHED ({0}, duration {1} hours)".format(toDateTimeString(endDate), duration));
    if (retval == 10)
        Log2File(0, "GEN_TASKER RELOAD REQUESTED, RESTARTING");

    Oracle.Close();

    WScript.Quit(retval);
  </script>
</job>