diff --git a/src/Console/Program.cs b/src/Console/Program.cs index a28b97a3..9e1a0325 100644 --- a/src/Console/Program.cs +++ b/src/Console/Program.cs @@ -220,6 +220,7 @@ namespace Bit.Console { Con.WriteLine("{0}. {1}", i + 1, result.Organizations[i].Name); } + Con.WriteLine(); Con.Write("Select your organization: "); var orgIndexInput = Con.ReadLine().Trim(); int orgIndex; @@ -488,6 +489,12 @@ namespace Bit.Console config.SyncGroups = parameters.ContainsKey("g"); config.SyncUsers = parameters.ContainsKey("u"); + int intervalMinutes; + if(parameters.ContainsKey("i") && int.TryParse(parameters["i"], out intervalMinutes)) + { + config.IntervalMinutes = intervalMinutes; + } + if(Core.Services.SettingsService.Instance.Server.Type != Core.Enums.DirectoryType.AzureActiveDirectory) { if(parameters.ContainsKey("gf")) @@ -607,6 +614,15 @@ namespace Bit.Console } } + Con.Write("Sync interval (minutes, minimum {1}) [{0}]: ", config.IntervalMinutes, + SettingsService.Instance.Server.Type == Core.Enums.DirectoryType.Other ? "30" : "1"); + input = Con.ReadLine(); + int intervalMinutes; + if(!string.IsNullOrEmpty(input) && int.TryParse(input, out intervalMinutes)) + { + config.IntervalMinutes = intervalMinutes; + } + input = null; } diff --git a/src/Core/Models/SyncConfiguration.cs b/src/Core/Models/SyncConfiguration.cs index 62f11971..97e90655 100644 --- a/src/Core/Models/SyncConfiguration.cs +++ b/src/Core/Models/SyncConfiguration.cs @@ -33,6 +33,7 @@ namespace Bit.Core.Models UserEmailSuffix = null; break; case DirectoryType.Other: + IntervalMinutes = 30; break; default: break; @@ -51,5 +52,6 @@ namespace Bit.Core.Models public string UserEmailSuffix { get; set; } = "@companyname.com"; public string CreationDateAttribute { get; set; } public string RevisionDateAttribute { get; set; } + public int IntervalMinutes { get; set; } = 5; } } diff --git a/src/Service/Service.cs b/src/Service/Service.cs index ec7479e6..4aeb3126 100644 --- a/src/Service/Service.cs +++ b/src/Service/Service.cs @@ -77,8 +77,19 @@ namespace Service return; } + var intervalMinutes = SettingsService.Instance.Sync.IntervalMinutes; + if(SettingsService.Instance.Server.Type == Bit.Core.Enums.DirectoryType.Other && intervalMinutes < 30) + { + intervalMinutes = 30; + } + else if(intervalMinutes < 1) + { + intervalMinutes = 1; + } + + _eventLog.WriteEntry($"Starting timer with {intervalMinutes} minute interval.", EventLogEntryType.Information); var timerDelegate = new TimerCallback(Callback); - _timer = new Timer(timerDelegate, null, 1000, 60 * 1000); + _timer = new Timer(timerDelegate, null, 1000, 60 * 1000 * intervalMinutes); } protected override void OnStop()