/// <summary>
 /// GetUsers method implementation
 /// </summary>
 public static int GetUsersCount(int maxrows = 20000)
 {
     EnsureService();
     IAdministrationService svc = null;
     if (!Config.UseActiveDirectory)
         svc = new SQLAdminService(Config);
     else
         svc = new ADDSAdminService(Config);
     return svc.GetUserRegistrationsCount(Filter);
 }
 /// <summary>
 /// GetUsers method implementation
 /// </summary>
 public static MMCRegistrationList GetUsers(int maxrows = 20000)
 {
     EnsureService();
     IAdministrationService svc = null;
     if (!Config.UseActiveDirectory)
         svc = new SQLAdminService(Config);
     else
         svc = new ADDSAdminService(Config);
     return svc.GetUserRegistrations(Filter, Order, Paging, maxrows);
 }
 /// <summary>
 /// GetAllUsers method implementation
 /// </summary>
 public static MMCRegistrationList GetAllUsers(bool enabledonly = false)
 {
     EnsureService();
     IAdministrationService svc = null;
     if (!Config.UseActiveDirectory)
         svc = new SQLAdminService(Config);
     else
         svc = new ADDSAdminService(Config);
     return svc.GetAllUserRegistrations(Order, int.MaxValue, enabledonly);
 }
        /// <summary>
        /// SetUser method implementation
        /// </summary>
        public static void SetUser(MMCRegistrationList registrations)
        {
            EnsureService();
            IAdministrationService svc = null;
            if (!Config.UseActiveDirectory)
                svc = new SQLAdminService(Config);
            else
                svc = new ADDSAdminService(Config);

            foreach (MMCRegistration reg in registrations)
            {
                svc.SetUserRegistration(reg);
            }
        }
        /// <summary>
        /// EnableUser method implmentation
        /// </summary>
        public static MMCRegistrationList EnableUser(MMCRegistrationList registrations)
        {
            EnsureService();
            IAdministrationService svc = null;
            if (!Config.UseActiveDirectory)
                svc = new SQLAdminService(Config);
            else
                svc = new ADDSAdminService(Config);

            MMCRegistrationList lst = new MMCRegistrationList();
            foreach(MMCRegistration reg in registrations)
            {
                lst.Add(svc.EnableUserRegistration(reg));
            }
            return lst;
        }
        /// <summary>
        /// GetUser method implementation
        /// </summary>
        internal static MMCRegistrationList GetUser(MMCRegistrationList registrations)
        {
            EnsureService();
            IAdministrationService svc = null;
            if (!Config.UseActiveDirectory)
               svc = new SQLAdminService(Config);
            else
               svc = new ADDSAdminService(Config);

            MMCRegistrationList lst = new MMCRegistrationList();
            foreach(MMCRegistration reg in registrations)
            {
                MMCRegistration ret = svc.GetUserRegistration(reg.UPN);
                lst.Add(ret);
            }
            return lst;
        }
        /// <summary>
        /// AddUser method implmentation
        /// </summary>
        public static MMCRegistrationList AddUser(MMCRegistrationList registrations)
        {
            EnsureService();
            IAdministrationService svc = null;
            if (!Config.UseActiveDirectory)
                svc = new SQLAdminService(Config);
            else
                svc = new ADDSAdminService(Config);

            MMCRegistrationList lst = new MMCRegistrationList();
            foreach(MMCRegistration reg in registrations)
            {
                KeysManager.NewKey(reg.UPN);
                MMCRegistration ret = svc.AddUserRegistration(reg);
                lst.Add(ret);
            }
            return lst;
        }
        /// <summary>
        /// DeleteUser method implmentation
        /// </summary>
        public static bool DeleteUser(MMCRegistrationList registrations)
        {
            EnsureService();
            bool _ret = true;
            IAdministrationService svc = null;
            if (!Config.UseActiveDirectory)
                svc = new SQLAdminService(Config);
            else
                svc = new ADDSAdminService(Config);

            foreach(MMCRegistration reg in registrations)
            {
                bool ret = svc.DeleteUserRegistration(reg);
                if (!ret)
                    _ret = false;
                KeysManager.RemoveKey(reg.UPN);
            }
            return _ret;
        }