IMetabaseUsersUpdate.Callback

Syntax

Callback: IMetabaseUsersUpdateCallback;

Callback: Prognoz.Platform.Interop.Metabase.IMetabaseUsersUpdateCallback;

Description

The Callback property determines the object, performing the handling of errors that may occur on updating users.

Comments

As the value of the property it is necessary to specify the instance of the custom class, realizing properties and methods of the IMetabaseUsersUpdateCallback interfaces.

Example

To execute the example, make sure that the security manager contains users.

Add links to the Metabase, ForeSystem (for the Fore.NET example) system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    Sec: IMetabaseSecurity;
    Users: IMetabaseUsers;
    User: IMetabaseUser;
    UsUpdate: IMetabaseUsersUpdate;
    UpdateCallback: IMetabaseUsersUpdateCallback;
    Results: IMetabaseUsersUpdateErrors;
    Error: IMetabaseUsersUpdateError;
    Lic: Object;
Begin
    MB := MetabaseClass.Active;
    
// Get license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.Adm);
    Sec := MB.Security;
    Users := Sec.Users;
    
// Create an update
    UsUpdate := Sec.CreateUsersUpdate;
    
For Each User In Users Do
        UsUpdate.Add(User);
    
End For;
    UpdateCallback := 
New UserUpdateClb.Create;
    UpdateCallback.CallbackResult := MetabaseUsersUpdateCallbackResult.SilentContinue;
    UsUpdate.Callback := UpdateCallback;
    
// Refresh all users
    Sec.UpdateUsers(UsUpdate);
    Results := UsUpdate.Errors;
    
// Set file for loading updating errors
    If Results.Count <> 0 Then
        Results.SaveToFile(
"c:\UpdateUsersResult.txt"True);
    
End If;
    
For Each Error In Results Do
        
If Error.Type = MetabaseUsersUpdateErrorType.Error Then
            Debug.WriteLine(
"Error: " + Error.Message + ". Additional information: " + Error.DetailText);
        
Else
            Debug.WriteLine(
"Warning: " + Error.Message + ". Additional information: " + Error.DetailText);
        
End If;
    
End For;
    
// Save changes
    Sec.Apply;
    
// Check in license
    Lic := Null;
End Sub UserProc;

Class UserUpdateClb: Object, IMetabaseUsersUpdateCallback
    _ClbResult: MetabaseUsersUpdateCallbackResult;

    
Sub Process(Subject: ISecuritySubject);
    
Begin
        Debug.WriteLine(
"Update user: " + Subject.Name);
    
End Sub Process;

    
Function RequestAction(Error: IMetabaseUsersUpdateError): MetabaseUsersUpdateCallbackResult;
    
Begin
        
Select Case Error.Type
            
Case MetabaseUsersUpdateErrorType.Warning:
                Debug.WriteLine(
"Warning: " + Error.Message);
            
Case MetabaseUsersUpdateErrorType.Error:
                Debug.WriteLine(
"Error: " + Error.Message);
        
End Select;
        
Return _ClbResult;
    
End Function RequestAction;

    
Function get_CallbackResult: MetabaseUsersUpdateCallbackResult;
    
Begin
        
Return _ClbResult;
    
End Function get_CallbackResult;

    
Sub set_CallbackResult(Result: MetabaseUsersUpdateCallbackResult);
    
Begin
        _ClbResult := Result;
    
End Sub set_CallbackResult;
End Class UserUpdateClb;

Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.ForeSystem;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    Sec: IMetabaseSecurity;
    Users: IMetabaseUsers;
    User: IMetabaseUser;
    UsUpdate: IMetabaseUsersUpdate;
    UpdateCallback: IMetabaseUsersUpdateCallback = 
New UserUpdateClb();
    Results: IMetabaseUsersUpdateErrors;
    Error: IMetabaseUsersUpdateError;
    Lic: Object;
Begin
    MB := Params.Metabase;
    
// Get license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.lftAdm);
    Sec := MB.Security;
    Users := Sec.Users;
    
// Create an update
    UsUpdate := Sec.CreateUsersUpdate();
    
For Each User In Users Do
        UsUpdate.Add(User);
    
End For;
    UpdateCallback.CallbackResult := MetabaseUsersUpdateCallbackResult.muucrSilentContinue;
    UsUpdate.Callback := UpdateCallback;
    
// Refresh all users
    Sec.UpdateUsers(UsUpdate);
    Results := UsUpdate.Errors;
    
// Set file for loading updating errors
    If Results.Count <> 0 Then
        Results.SaveToFile(
"c:\\UpdateUsersResult.txt"True);
    
End If;
    
For Each Error In Results Do
        
If Error.Type = MetabaseUsersUpdateErrorType.muuetError Then
            System.Diagnostics.Debug.WriteLine(
"Error: " + Error.Message + ". Additional information: " + Error.DetailText);
        
Else
            System.Diagnostics.Debug.WriteLine(
"Warning: " + Error.Message + ". Additional information: " + Error.DetailText);
        
End If;
    
End For;
    
// Save changes
    Sec.Apply();
    
// Check in license
    Lic := Null;
End Sub;
   
Class UserUpdateClb: IMetabaseUsersUpdateCallback
    _ClbResult: MetabaseUsersUpdateCallbackResult;
    
    
Public Sub Process(Subject: ISecuritySubject);
    
Begin
        System.Diagnostics.Debug.WriteLine(
"Update user: " + Subject.Name);
    
End Sub;
 
    
Public Function RequestAction(Error: IMetabaseUsersUpdateError): MetabaseUsersUpdateCallbackResult;
    
Begin
        
Select Case Error.Type
            
Case MetabaseUsersUpdateErrorType.muuetWarning:
                System.Diagnostics.Debug.WriteLine(
"Warning: " + Error.Message);
            
Case MetabaseUsersUpdateErrorType.muuetError:
                System.Diagnostics.Debug.WriteLine(
"Error: " + Error.Message);
        
End Select;
        
Return _ClbResult;
    
End Function;
 
    
Public Property CallbackResult: MetabaseUsersUpdateCallbackResult
        
Get
        
Begin
            
Return _ClbResult;
        
End Get
        
Set
        
Begin
            _ClbResult := Value;
        
End Set
    
End Property;
End Class;

After executing the example all users created in the repository security manager are updated. To track the process of updating the object of the UserUpdateClb custom class is created. On occurring any problems the update process will be resumed. When finished, if during the update any errors/warnings appeared then the information on them would be displayed in the development environment console and saved to the file.

See also:

IMetabaseUsersUpdate