IScheduledTask.ExecuteImmediate

Fore Syntax

ExecuteImmediate(SaveResult: Boolean): IScheduledTaskResult;

Fore.NET Syntax

ExecuteImmediate(SaveResult: boolean): Prognoz.Platform.Interop.KeFore.IScheduledTaskResult;

Parameters

SaveResult. It determines whether the task execution result should be saved into the database. Available values:

Description

The ExecuteImmediate method executes a task in current repository.

Comments

The ExecuteImmediate method executes the task in the current process and current repository and running task scheduler is not required. Settings of the message sending about the task execution and saving of the result on the FTP server are ignored.

Fore Example

Executing the example requires that the repository has a scheduled tasks container with the SCHEDULEDTASKSCONTAINER identifier. and calculation task of regular report with the REPORT_TASK identifier. Any action with execution result should be set up for this task.

Add links to the Fore, IO, Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    Cont: IScheduledTasksContainer;
    Tasks: IMetabaseObjectDescriptors;
    i: Integer;
    Task: IScheduledTask;
    Result: IScheduledTaskResult;
    FileName: string;
    Stream: IIOStreamSys;
Begin
    
// Get current repository
    MB := MetabaseClass.Active;
    Cont := MB.ItemById(
"SCHEDULEDTASKSCONTAINER").Bind As IScheduledTasksContainer;
    
// Get task with the REPORT_TASK identifier
    Tasks := Cont.Tasks;
    
For i := 0 To Tasks.Count - 1 Do
        
If Tasks.Item(i).Id = "REPORT_TASK" Then
            Task := Tasks.Item(i).Edit 
As IScheduledTask;
        
End If;
    
End For;
    
// Perform task
    Result := Task.ExecuteImmediate(True);
    
// Save execution results to file
    If Result.HasDataStream Then
        FileName := 
"c:\" + (Task As IMetabaseObject).Name + "." + Result.FileExtension;
        Stream := 
New FileStream.Create(FileName, FileOpenMode.Create, FileShare.Exclusive) As IIOStreamSys;
        Result.ReadDataStream(Stream);
        Debug.WriteLine(
"Result is saved to file " + FileName);
    
End If;
End Sub UserProc;

After executing the example the task will be executed, the obtained result will be saved to the file which name will be displayed to the console window.

Fore.NET Example

The requirements and result of the Fore.NET Example execution match with those in the Fore Example.

Imports Prognoz.Platform.Interop.ForeIO;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.KeFore;
Imports System.IO;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    Cont: IScheduledTasksContainer;
    Tasks: IMetabaseObjectDescriptors;
    i: Integer;
    Task: IScheduledTask;
    Result: IScheduledTaskResult;
    FileName: string;
    Stream: System.IO.FileStream;
Begin
    
// Get current repository
    MB := Params.Metabase;
    Cont := MB.ItemById[
"SCHEDULEDTASKSCONTAINER"].Bind() As IScheduledTasksContainer;
    
// Get task with the REPORT_TASK identifier
    Tasks := Cont.Tasks;
    
For i := 0 To Tasks.Count - 1 Do
        
If Tasks.Item[i].Id = "REPORT_TASK" Then
            Task := Tasks.Item[i].Edit() 
As IScheduledTask;
        
End If;
    
End For;
    
// Perform task
    Result := Task.ExecuteImmediate(True);
    
// Save execution results to file
    If Result.HasDataStream Then
        FileName := 
"c:\" + (Task As IMetabaseObject).Name + "." + Result.FileExtension;
        Stream := 
New System.IO.FileStream.Create(FileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
        Result.ReadDataStream(Stream 
As System.IO.Stream);
        System.Diagnostics.Debug.WriteLine(
"Result is saved to the file " + FileName);
    
End If;
End Sub;

See also:

IScheduledTask