ILogonHours.SetPeriodAccess

Syntax

SetPeriodAccess(Begin_: DateTime; End_: DateTime; Grant: Boolean);

SetPeriodAccess(@Begin: System.DateTime; @End: System.DateTime; Grant: boolean);

Parameters

Begin_. Start time of time period.

End_. End time of time period.

Grant. Parameter determines accessibility in this time interval. If value of the parameter is True, the access in this time interval is allowed. If value of the parameter is False, the access will be denied.

Description

The SetPeriodAccess method sets parameters of the user access for the specified time interval.

Comments

Time interval is formed setting initial and final time in the Begin_ and End_ parameters, respectively. The Grant parameter determines whether this time interval is available to access.

The SetPeriodAccess method sets time interval with accuracy up to a second, the millisecond field must contain the 0 value.

Example

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

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

Sub UserProc;
Var
    MB: IMetabase;
    MS: IMetabaseSecurity;
    MP: IMetabasePolicy;
    User: ISecuritySubject;
    LogonHP: ILogonHoursPolicy;
    LH: ILogonHours;
    d1, d2, d3, d4: DateTime;
    i: Integer;
    Lic: Object;
Begin
    MB := MetabaseClass.Active;
    
// Get license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.Adm);
    MS := MB.Security;
    MP := MS.Policy;
    
// Get user parameters
    User := MS.ResolveName("USER");
    
// Add schedule to enable access
    LogonHP := MP.LogonHoursPolicy(User);
    d1 := DateTime.ComposeTimeOfDay(
0000);
    d2 := DateTime.ComposeTimeOfDay(
9000);
    d3 := DateTime.ComposeTimeOfDay(
18000);
    d4 := DateTime.ComposeTimeOfDay(
235900);
    
For i := 1 To 5 Do
        LH := LogonHP.WeekDayHours(i 
As CalendarDayOfWeek);
        LH.SetPeriodAccess(d1, d2, 
False);
        LH.SetPeriodAccess(d2, d3, 
True);
        LH.SetPeriodAccess(d3, d4, 
False);
        LogonHP.WeekDayHours(i 
As CalendarDayOfWeek) := LH;
    
End For;
    LH := LogonHP.WeekDayHours(CalendarDayOfWeek.Saturday); 
// Saturday
    LH.SetPeriodAccess(d1, d4, False);
    LogonHP.WeekDayHours(CalendarDayOfWeek.Saturday) := LH;

    LH := LogonHP.WeekDayHours(CalendarDayOfWeek.Sunday); // Sunday
    LH.SetPeriodAccess(d1, d4, 
False);
    LogonHP.WeekDayHours(CalendarDayOfWeek.Sunday) := LH;
    
// Save changes
    MS.Apply;
    
// Check in license
    Lic := Null;
End Sub UserProc;

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

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    MS: IMetabaseSecurity;
    MP: IMetabasePolicy;
    User: ISecuritySubject;
    LogonHP: ILogonHoursPolicy;
    LH: ILogonHours;
    d1, d2, d3, d4: DateTime;
    i: Integer;
    Lic: Object;
Begin
    MB := Params.Metabase;
    
// Get license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.lftAdm);
    MS := MB.Security;
    MP := MS.Policy;
    
// Get user parameters
    User := MS.ResolveName("USER");
    
// Add schedule to enable access
    LogonHP := MP.LogonHoursPolicy[User];
    d1 := DateTime.Parse(
"0:00:00");
    d2 := DateTime.Parse(
"9:00:00");
    d3 := DateTime.Parse(
"18:00:00");
    d4 := DateTime.Parse(
"23:59:59");
    
For i := 1 To 5 Do
        LH := LogonHP.WeekDayHours[i 
As CalendarDayOfWeek];
        LH.SetPeriodAccess(d1, d2, 
False);
        LH.SetPeriodAccess(d2, d3, 
True);
        LH.SetPeriodAccess(d3, d4, 
False);
        LogonHP.WeekDayHours[i 
As CalendarDayOfWeek] := LH;
    
End For;
    LH := LogonHP.WeekDayHours[CalendarDayOfWeek.dowSaturday]; 
// Saturday
    LH.SetPeriodAccess(d1, d4, False);
    LogonHP.WeekDayHours[CalendarDayOfWeek.dowSaturday] := LH;
    LH := LogonHP.WeekDayHours[CalendarDayOfWeek.dowSunday]; 
// Sunday
    LH.SetPeriodAccess(d1, d4, False);
    LogonHP.WeekDayHours[CalendarDayOfWeek.dowSunday] := LH;
    
// Save changes
    MS.Apply();
    
// Check in license
    Lic := Null;
End Sub;

After executing the example access parameters by weekdays are changed for the USER user. Access from this user's account is available from Monday to Friday, from 9 AM till 6 PM.

See also:

ILogonHours