Page 1 of 1

Task Object Properties

Posted: Thu Mar 17, 2005 9:24 am
by tplehman
Is there a way to get the filename associated with a task from Basic Script?

Task Object Properties

Posted: Fri Mar 18, 2005 6:05 am
by Oleg
Files of tasks has a formal names, based on internal ID of task. This value is useless for you at all.
But you can get an "External name" of task. It is important, because this parameter is used in methods StartTask, StopTask and property TaskEnabled.
External name is unique. You can set its manually in task editor at Advanced tab.
See script below:
'begin of script
Public Declare Function GetCurrentThreadId Lib "kernel32" Alias "GetCurrentThreadId" () As Long

Sub Main
   Dim ExName As String
   ExName = RoboTaskApp.ExternalName(GetCurrentThreadId)
   MsgBox(ExName)
End Sub
'end of script

Also you can enumerate all tasks. See this script:
'begin of script
Public Declare Function GetCurrentThreadId Lib "kernel32" Alias "GetCurrentThreadId" () As Long
Sub Main
   Dim exname As String
   Dim ID As Long
   Dim Name As String
   Dim cnt As Long
   
   cnt = RoboTaskApp.TaskCount
   For i = 0 To cnt - 1
       RoboTaskApp.TaskIn fo( i, exname, Name, ID )
       RoboTaskApp.WriteT oLog(2 , CStr(i) +";"+exname+";"+Name+";"+CStr(ID), GetCurrentThreadId)
   Next
End Sub
'end of script

Task Object Properties

Posted: Fri Mar 18, 2005 7:11 am
by tplehman
Let me explain what I am trying to accomplish.  I want to be able to update a task in an automated fashion.  Say I have a task with ext name "ABC", I would like to be able to get an updated .tsk file via ftp, copy it to a temp dir, stop robotask service, replace current .tsk file with updated one, start Robotask service and viola, task is updated.
Also, I am having issues with the Text Loop functionality.  I am pasting the task below; When i run this task using the NT service or the ROBOTASK APP, either one they crash.  I am attempting to read the robotask .tsk files and discern an association between the tasks and their corresponding files, so that the files can be replaced with updated versions while robotask is shut down.  It seems that robotaskwill overwrite its .tsk files with data from memory when it exits.
 

Code: Select all

;**********************
;* RoboTask Task file *
;* Do not edit! *
;**********************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task4"
Hide=INTEGER|0
ID=INTEGER|625749591
Name=STRING|"Copy of Update_ALL"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create variable ""TASK_NAME_FROM_FILE"" with value ""0"""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"TASK_NAME_FROM_FILE"
varvalue=STRING|"0"
[Actions\Action2]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER
[Actions\Action2\Params]
createmode=STRING|"1"
date1=STRING|"20050316"
date2=STRING|"20050316"
destvar=STRING|"CURFILE"
DuringDays=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"C:\Program Files\RoboTask\Tasks\*.tsk"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"
[Actions\Action3]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER
[Actions\Action3\Params]
destvar=STRING|"CURLINE"
line0=STRING|"{TextFile({CURFILE})}"
linecount=STRING|"1"
sourcetext=STRING|"1"
[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action4\Params]
case=STRING|"0"
operator=STRING|"6"
type=STRING|"0"
value1=STRING|"Name=STRING|"
value2=STRING|"{CURLINE}"
[Actions\Action5]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""[{CURLINE}]"""
Params=FOLDER
[Actions\Action5\Params]
icon=STRING|"1"
msg0=STRING|"[{CURLINE}]"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action6]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action7]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action8]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
 

Task Object Properties

Posted: Fri Mar 18, 2005 7:56 am
by Oleg
Also, I am having issues with the Text Loop functionality....
In text loop action use "external text file" {curfile} instead of {TextFile({CURFILE})}. We had fixed this bug. Wait for new release on next week.
Ok. Robotask really keeps all tasks in memory and rewrites these at shutdown. So if you want to update some tasks you must stop RoboTask, update tasks and run RoboTask again.
Name of task is forming so: TaskID_as_Hex.Tsk
For example:
in your task ID = 625749591 (see string [ID=INTEGER|625749591])
in HEX ID = 254C2E57. Therefore name of your task is "254C2E57.tsk"

Task Object Properties

Posted: Fri Mar 18, 2005 8:08 am
by tplehman
I will try that.
Thanks for your help!!
There are some issues with regard to the Basic Script interface, but I will leave those for another time.
I would like to see some kind of script repository created.  Judging from other users comments, I think they would welcome this as well.
 
Thanks again,
tplehman

Task Object Properties

Posted: Fri Mar 18, 2005 8:12 am
by tplehman
By the way,
In text loop action use "external fext file" {curfile} instead of {TextFile({CURFILE})}.
does not fix the issue, just takes longer to crash.
=-(
I am using VB to work around this, I let you know the outcome.
 

Task Object Properties

Posted: Wed Nov 21, 2007 11:15 am
by dennis2003a
'*********************************************************** ************************************
' Simple workaround the Get the logfile
' This code will make a Variable For RoboTask {GET_LOG_FILE_ENVIROnMENT_SCRIPT} witch contains the proper logname....
'*********************************************************** ************************************
' API to retrieve the current Threadid
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
'Main events that have to be executed for errorhandling
Sub Main()
    Dim Cnt As Long
    Dim ThreadId As Long
    Dim ThreadName As String
 Dim Exname As String
    For X = 0 To RoboTaskApp.TaskCount - 1
        RoboTaskApp.TaskInfo( X, Exname, ThreadName, ThreadId )
    'Could be used to create a standalone logfile
     '   If (Exname = RoboTaskApp.ExternalName(GetCurrentThreadId)) Then
              RoboTaskApp.SetUserVariable("Logfile" +"_" + ThreadName, sDecToHex(CStr(ThreadId))+".log")
     '   End If
    Next
End Sub
'Converting Decimal to Hexadecimal and return it as a string to fill the variable GET_LOG_FILE_ENVIROnMENT_SCRIPT
Public Function sDecToHex(ByVal nSource As Double) As String
    Const BASECHAR As String = "0123456789ABCDEF"
    Dim n As Double
    Dim nSrc As Double
    If (nSource = 0) Then
        sDecToHex = "00"
        Exit Function
    End If
    If (nSource < 2147483648#) Then
        sDecToHex = Hex(nSource)
    Else
        nSrc = nSource
        Do
              n = CDec(nSrc - (16 * Int(nSrc / 16)))
              sDecToHex = Mid$(BASECHAR, n + 1, 1) & sDecToHex
              nSrc = CDec(Int(nSrc / 16))
        Loop While (nSrc > 0)
    End If
    If (Len(sDecToHex) Mod 2) Then sDecToHex = "0" & sDecToHex
     Exit Function
End Function