ILogonHoursPeriods.CreateHours

Syntax

CreateHours: ILogonHours;

CreateHours: Prognoz.Platform.Interop.Metabase.ILogonHours;

Description

The CreateHours method creates an object used to set up access by hours during the day.

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;
    LHP: ILogonHoursPeriods;
    d1, d2, d3, d4: DateTime;
    Lic: Object;
Begin
    MB := MetabaseClass.Active;
    
// Check out license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.Adm);
    MS := MB.Security;
    MP := MS.Policy;
    
// Get user parameters
    User := MS.ResolveName("USER");
    LogonHP := MP.LogonHoursPolicy(User);
    LHP := LogonHP.Periods;
    
// Add a period to enable access
    LH := LHP.CreateHours;
    d1 := DateTime.ComposeTimeOfDay(
0000);
    d2 := DateTime.ComposeTimeOfDay(
9000);
    d3 := DateTime.ComposeTimeOfDay(
18000);
    d4 := DateTime.ComposeTimeOfDay(
235900);
    LH.SetPeriodAccess(d1, d2, 
False);
    LH.SetPeriodAccess(d2, d3, 
True);
    LH.SetPeriodAccess(d3, d4, 
False);
    d1 := DateTime.Now;
    d2 := DateTime.AddDays(d1, 
30);
    LHP.SetPeriodAccess(d1, d2, 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;
    LHP: ILogonHoursPeriods;
    d1, d2, d3, d4: DateTime;
    Lic: Object;
Begin
    MB := Params.Metabase;
    
// Check out license to work with security manager
    Lic := MB.RequestLicense(UiLicenseFeatureType.lftAdm);
    MS := MB.Security;
    MP := MS.Policy;
    
// Get user parameters
    User := MS.ResolveName("USER");
    LogonHP := MP.LogonHoursPolicy[User];
    LHP := LogonHP.Periods;
    
// Add a period to enable access
    LH := LHP.CreateHours();
    d1 := DateTime.Parse(
"0:00:00");
    d2 := DateTime.Parse(
"9:00:00");
    d3 := DateTime.Parse(
"18:00:00");
    d4 := DateTime.Parse(
"23:59:59");
    LH.SetPeriodAccess(d1, d2, 
False);
    LH.SetPeriodAccess(d2, d3, 
True);
    LH.SetPeriodAccess(d3, d4, 
False);
    d1 := DateTime.Now;
    d2 := d1.AddDays(
30);
    LHP.SetPeriodAccess(d1, d2, LH);
    
// Save changes
    MS.Apply();
    
// Check in license
    Lic := Null;
End Sub;

After executing this example access parameters are changed in a certain period of time for the USER user. Since this day and during the next 30 days access under this user has been possible from 9 a.m. to 6 p.m.

See also:

ILogonHoursPeriods