Callback: IMetabaseUsersUpdateCallback;
The Callback property determines an object that handles errors that may occur on updating users.
As a value of the property, specify the instance of the custom class that implements properties and methods of the IMetabaseUsersUpdateCallback interface.
To execute the example, make sure that the security manager contains users.
Add a link to the Metabase system assembly.
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;
// Check out 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;
// Update 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;
After executing the example all users created in the repository security manager are updated. An object of the UserUpdateClb custom class is created to track the update progress. The update will be resumed on occurring any errors. When finished, if during the update any errors or warnings occurred, the information on them will be displayed in the development environment console and saved to the file.
See also: