public static void RegisterAll()
        {
            var task = new Task(() =>
            {
                var tenants = CoreContext.TenantManager.GetTenants();
                foreach (var t in tenants)
                {
                    var tId = t.TenantId;

                    var cronSettings = LdapCronSettings.LoadForTenant(tId);

                    if (string.IsNullOrEmpty(cronSettings.Cron))
                    {
                        continue;
                    }

                    if (LdapSettings.LoadForTenant(tId).EnableLdapAuthentication)
                    {
                        RegisterAutoSync(t, cronSettings.Cron);
                    }
                    else
                    {
                        cronSettings.Cron = null;
                        cronSettings.Save();
                    }
                }
            }, TaskCreationOptions.LongRunning);

            task.Start();
        }
        public static void AutoSync(Tenant tenant)
        {
            var ldapSettings = LdapSettings.LoadForTenant(tenant.TenantId);

            if (!ldapSettings.EnableLdapAuthentication)
            {
                var cronSettings = LdapCronSettings.LoadForTenant(tenant.TenantId);
                cronSettings.Cron = "";
                cronSettings.SaveForTenant(tenant.TenantId);
                UnregisterAutoSync(tenant);
                return;
            }

            var op = new LdapSaveSyncOperation(ldapSettings, tenant, LdapOperationType.Sync);

            ldapTasks.QueueTask(op.RunJob, op.GetDistributedTask());
        }