IRepositoryScriptCallback.OnStart

Syntax

OnStart(Error: RepsitoryScriptInitError; FilesToProcess: Integer);

OnStart(Error: Prognoz.Platform.Interop.KeFore.RepsitoryScriptInitError; FilesToProcess: Integer);

Parameters

Error. is a parameter that returns an error that can occur when preparing to execute the script and that does not enable to do the further script executing.

FilesToProcess. Number of processes that will be executed. This parameter returns 0 value, if any error occurs when preparing the script or if the repository has already the latest version.

Description

The OnStart method implements an event that takes place during the preparation of the script to execution.

Example

Executing the example requires the Oracle server named Test. Platform repository was created within the TestSchema scheme on the server. The root of disk C contains the current.rm4 file that includes the script for repository creating and updating.

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

Sub Main;
Var
    Rsm: IRepositoryScriptManager;
    Driv: IDalDriver;
    ConDesc: IDalConnectionDescriptor;
    Params: IDalConnectionDescriptorParams;
    Con: IDalConnection;
    CallBack: IRepositoryScriptCallback;
Begin
    
//Connection to schema on the Oracle server
    Driv := New DalOrcl8Driver.Create As IDalDriver;
    ConDesc := Driv.CreateDescriptor;
    Params := ConDesc.Params;
    Params.Find(
"User Name").Value := "TestSchema";
    Params.Find(
"Password").Value := "TestSchema";
    Params.Find(
"Host BSTR").Value := "Test";
    Params.Find(
"Schema").Value := "TestSchema";
    Con := ConDesc.CreateConnection;
    
//Repository manager settings
    Rsm := New RepositoryScriptManager.Create;
    Rsm.Connection := Con;
    Rsm.Driver := RepositoryDriverType.ORCL9;
    Rsm.Operation := RepositoryOperationType.Update;
    
//Repository update
    Rsm.Repository := RepositoryType.Metabase;
    Rsm.LoadScript(
New FileStream.Create("c:\current.rm4", FileOpenMode.Read, FileShare.Exclusive));
    CallBack := 
New ScrCallback.Create;
    Rsm.Execute(CallBack);
End Sub Main;

Class ScrCallback: RepositoryScriptCallback
    s: String;

    
Public Sub OnStart(Error: RepsitoryScriptInitError; FilesToProcess: Integer);
    
Begin
        Debug.WriteLine(
"Start update");
        
Select Case Error
        
Case RepsitoryScriptInitError.None:
            Debug.WriteLine(
"Number of requests that will be executed: " + FilesToProcess.ToString);
        
Case RepsitoryScriptInitError.NoTables:
            Debug.WriteLine(
"In the specified base there is no repository tables");
        
Case RepsitoryScriptInitError.TablesAlreadyExist:
            Debug.WriteLine(
"The specified base already contains repository tables");
        
Case RepsitoryScriptInitError.EmptyRepository:
            Debug.WriteLine(
"Empty repository for update");
        
Case RepsitoryScriptInitError.CannotUpdateVers:
            Debug.WriteLine(
"Cannot update repository version");
        
Case RepsitoryScriptInitError.UnicodeMismatch:
            Debug.WriteLine(
"Unicode of repository version in base and update file are different");
        
End Select;
    
End Sub OnStart;

    
Public Sub BeginStatement(Statement: String);
    
Begin
        s := Statement;
    
End Sub BeginStatement;
    
    
Public Sub EndStatement(bError: Boolean; Message: String; Var Cancel: Boolean);
    
Begin
        
If bError = True Then
            Debug.WriteLine(
"Error occurred on code execution!");
            Debug.Indent;
            Debug.WriteLine(
"Request: " + s);
            Debug.WriteLine(
"Error: " + Message);
            Debug.Unindent;
            Cancel := 
False;
        
End If;
    
End Sub EndStatement;

    
Public Sub OnFinish;
    
Begin
        Debug.WriteLine(
"Update is finished");
    
End Sub OnFinish;
End Class ScrCallback;

Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.KeFore;

Public Sub UserProc();
Var
    Rsm: IRepositoryScriptManager = 
New RepositoryScriptManagerClass();
    Driv: IDalDriver = 
New DalOrcl8DriverClass();
    ConDesc: IDalConnectionDescriptor;
    Params: IDalConnectionDescriptorParams;
    Con: IDalConnection;
    CallBack: IRepositoryScriptCallback;
Begin
    
//Connection to schema on the Oracle server
    ConDesc := Driv.CreateDescriptor();
    Params := ConDesc.Params;
    Params.Find(
"User Name").Value := "TestSchema";
    Params.Find(
"Password").Value := "TestSchema";
    Params.Find(
"Host BSTR").Value := "Test";
    Params.Find(
"Schema").Value := "TestSchema";
    Con := ConDesc.CreateConnection();
    
//Repository manager settings
    Rsm.Connection := Con;
    Rsm.Driver := RepositoryDriverType.repwelknodritypORCL9;
    Rsm.Operation := RepositoryOperationType.repopetypUpdate;
    
//Repository update
    Rsm.Repository := RepositoryType.reptypMetabase;
    Rsm.LoadScript(
New FileStream("c:\current.rm4", FileMode.Open, FileAccess.Read));
    CallBack := 
New ScrCallback();
    Rsm.Execute(CallBack);
End Sub;

Class ScrCallback: IRepositoryScriptCallback
    s: String;

    
Public Sub OnStart(Error: RepsitoryScriptInitError; FilesToProcess: Integer);
    
Begin
        System.Diagnostics.Debug.WriteLine(
"Start update");
        
Select Case Error
        
Case RepsitoryScriptInitError.repscrinierrNone:
            System.Diagnostics.Debug.WriteLine(
"Number of requests that will be executed: " + FilesToProcess.ToString());
        
Case RepsitoryScriptInitError.repscrinierrNoTables:
            System.Diagnostics.Debug.WriteLine(
"The specified base do not have any repository tables");
        
Case RepsitoryScriptInitError.repscrinierrTablesAlreadyExist:
            System.Diagnostics.Debug.WriteLine(
"The specified base already contains repository tables");
        
Case RepsitoryScriptInitError.repscrinierrEmptyRepository:
            System.Diagnostics.Debug.WriteLine(
"Empty repository for update");
        
Case RepsitoryScriptInitError.repscrinierrCannotUpdateVers:
            System.Diagnostics.Debug.WriteLine(
"Cannot update repository version");
        
Case RepsitoryScriptInitError.repscrinierrUnicodeMismatch:
            System.Diagnostics.Debug.WriteLine(
"Unicode of repository version in base and update file are different");
        
End Select;
    
End Sub;

    
Public Sub BeginStatement(Statement: String);
    
Begin
        s := Statement;
    
End Sub;
    
    
Public Sub EndStatement(bError: Boolean; Message: String; Var Cancel: Boolean);
    
Begin
        
If bError = True Then
            System.Diagnostics.Debug.WriteLine(
"Error occurred on code execution!");
            System.Diagnostics.Debug.Indent();
            System.Diagnostics.Debug.WriteLine(
"Request: " + s);
            System.Diagnostics.Debug.WriteLine(
"Error: " + Message);
            System.Diagnostics.Debug.Unindent();
            Cancel := 
False;
        
End If;
    
End Sub;

    
Public Sub OnFinish();
    
Begin
        System.Diagnostics.Debug.WriteLine(
"Update is finished");
    
End Sub;
End Class;

After executing the example the repository version is updated in accordance with the contents of the current.rm4 file. The ScrCallback custom class is used to track the process of update. Information about readiness for updating and about errors that can occur when executing the queries is displayed in the development environment console.

See also:

IRepositoryScriptCallback