Example #1
0
        protected override void LoadUserPools()
        {
            userPool_ComboBox.DisplayMember = "Description";
            DomainAccountPool selectedPool = null;

            List <DomainAccountPool> userPools = null;

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                userPools = context.DomainAccountPools.OrderBy(x => x.Description).ToList();
            }

            if (userPools.Count > 0)
            {
                bool testerHasUserPool = !string.IsNullOrEmpty(_tester.UserPool);
                if (testerHasUserPool)
                {
                    //If tester has a User Pool setting, select it if it's in the list
                    if (userPools.Any(x => x.DomainAccountKey.Equals(_tester.UserPool)))
                    {
                        selectedPool = userPools.First(x => x.DomainAccountKey.Equals(_tester.UserPool));
                    }
                }
                else
                {
                    selectedPool = userPools.First();
                }
            }

            userPool_ComboBox.DataSource   = userPools;
            userPool_ComboBox.SelectedItem = selectedPool;
        }
Example #2
0
        private DomainAccountReservationSet GetReservedAccounts(bool mockReserve = false)
        {
            DomainAccountReservationSet result = new DomainAccountReservationSet(Ticket.SessionId);

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                if (mockReserve)
                {
                    //Build a mock reservation
                    foreach (var poolType in Quantities.DomainAccountQuantity.Keys)
                    {
                        DomainAccountPool pool = DomainAccountService.SelectPool(context, poolType);
                        result.Add(poolType, pool, 0, Quantities.DomainAccountQuantity[poolType]);
                    }
                }
                else
                {
                    foreach (DomainAccountReservation reservation in DomainAccountService.SelectReservationsBySession(context, Ticket.SessionId))
                    {
                        DomainAccountPool pool = DomainAccountService.SelectPool(context, reservation.DomainAccountKey);
                        result.Add(reservation.DomainAccountKey, pool, reservation.StartIndex, reservation.Count);
                    }
                }
            }

            return(result);
        }
        private void add_Button_Click(object sender, EventArgs e)
        {
            var pool = new DomainAccountPool();

            if (EditEntry(pool) == DialogResult.OK)
            {
                AddPool(pool);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainAccountReservationListForm"/> class.
 /// </summary>
 public DomainAccountReservationListForm(DomainAccountPool pool)
 {
     InitializeComponent();
     UserInterfaceStyler.Configure(this, FormStyle.SizeableDialog);
     UserInterfaceStyler.Configure(radGridViewDomainAccountReservation, GridViewStyle.ReadOnly);
     ShowIcon = true;
     radGridViewDomainAccountReservation.AutoGenerateColumns = false;
     _domainAccountReservations = new SortableBindingList <DomainAccountReservation>();
     _pool = pool;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="VirtualPrinterEditForm"/> class.
        /// </summary>
        /// <param name="pool">The account pool.</param>
        /// <param name="context">The context.</param>
        public DomainAccountEditForm(DomainAccountPool pool, AssetInventoryContext context)
        {
            InitializeComponent();
            UserInterfaceStyler.Configure(this, FormStyle.FixedDialog);
            ShowIcon             = true;
            _provider            = new ErrorProvider();
            _provider.BlinkStyle = ErrorBlinkStyle.NeverBlink;
            _provider.SetIconAlignment(poolNameTextBox, ErrorIconAlignment.MiddleLeft);
            _provider.SetIconAlignment(formatTextBox, ErrorIconAlignment.MiddleLeft);
            _provider.SetIconAlignment(startTextBox, ErrorIconAlignment.MiddleLeft);
            _provider.SetIconAlignment(endTextBox, ErrorIconAlignment.MiddleLeft);

            _pool    = pool;
            _context = context;
        }
        private DialogResult EditEntry(DomainAccountPool pool)
        {
            DialogResult result = DialogResult.None;

            using (DomainAccountEditForm form = new DomainAccountEditForm(pool, _context))
            {
                result = form.ShowDialog();
                if (result == DialogResult.OK)
                {
                    _bindingSource.ResetBindings(false);
                    //SetDefault();
                    _unsavedChanges = true;
                }
            }

            return(result);
        }
Example #7
0
        /// <summary>
        /// Reserves a block of users.  This MUST be called before being able to get user credentials.
        /// </summary>
        /// <param name="sessionId">The session id.</param>
        /// <param name="accountQuantity">The account quantity which is separated by account pool.</param>
        /// <returns>A <see cref="DomainAccountReservationSet"/> containing information on the reserved accounts.</returns>
        /// <exception cref="System.ArgumentNullException">accountQuantity</exception>
        /// <exception cref="System.InvalidOperationException">Domain accounts have already been reserved for this Session Id</exception>
        public static DomainAccountReservationSet Reserve(string sessionId, DomainAccountQuantityDictionary accountQuantity)
        {
            if (accountQuantity == null)
            {
                throw new ArgumentNullException("accountQuantity");
            }

            DomainAccountReservationSet reservedBlock = new DomainAccountReservationSet(sessionId);

            Action action = new Action(() =>
            {
                try
                {
                    using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                    {
                        if (context.DomainAccountReservations.Any(e => e.SessionId.Equals(sessionId, StringComparison.OrdinalIgnoreCase)))
                        {
                            //This could be a subsequent call to reserve.  Clear all reservations before proceeding.
                            Release(sessionId);
                        }

                        foreach (var poolType in accountQuantity.Keys)
                        {
                            int userCount          = accountQuantity[poolType];
                            DomainAccountPool pool = SelectPool(context, poolType);
                            int startIndex         = ReserveBlock(context, sessionId, pool, userCount);

                            TraceFactory.Logger.Debug($"New pool reserved: StartIndex: {startIndex}, UserCount: {userCount}, PoolName: {pool.DomainAccountKey}");

                            reservedBlock.Add(poolType, pool, startIndex, userCount);
                        }
                    }
                }
                catch (InsufficientDomainAccountsException)
                {
                    ReleaseSessionReservations(sessionId);
                    throw;
                }
            });

            var token = new GlobalLockToken("DomainAccountReservation", TimeSpan.FromMinutes(11), TimeSpan.FromMinutes(2));

            ExecutionServices.CriticalSection.Run(token, action);

            return(reservedBlock);
        }
Example #8
0
        private void ValidateUserPool()
        {
            List <DomainAccountPool> userPools    = (List <DomainAccountPool>)userPool_ComboBox.DataSource;
            DomainAccountPool        selectedPool = null;

            if (userPools.Any(x => x.DomainAccountKey.Equals(_tester.UserPool, StringComparison.OrdinalIgnoreCase)))
            {
                selectedPool = userPools.First(x => x.DomainAccountKey.Equals(_tester.UserPool, StringComparison.OrdinalIgnoreCase));
                userPool_ComboBox.SelectedItem = selectedPool;
            }
            else if (userPools.Count > 0) //No user pools match the tester's pool, but there are pools available.  Assign the first one.
            {
                selectedPool = userPools.First();
                userPool_ComboBox.SelectedItem = selectedPool;
            }
            // We're not worried about the case of no pools in the database because the User Pools radio button
            // is not enabled unless there is at least one pool in the system.
        }
        private void AddPool(DomainAccountPool pool)
        {
            if (!_context.DomainAccountPools.Any(x => x.DomainAccountKey.Equals(pool.DomainAccountKey, StringComparison.OrdinalIgnoreCase)))
            {
                _context.DomainAccountPools.Add(pool);
                _userPools.Add(pool);

                int index = domainAccount_RadGridView.Rows.Count - 1;

                domainAccount_RadGridView.Rows[index].IsSelected = true;

                //In case if you want to scroll down as well.
                domainAccount_RadGridView.TableElement.ScrollToRow(index);
            }
            else
            {
                MessageBox.Show("A user pool with the name '{0}' already exists in the database.".FormatWith(pool.DomainAccountKey), "Unable to Add", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Example #10
0
        /// <summary>
        /// Reserves a block of User Ids for the given session.
        /// </summary>
        /// <param name="context">The data context.</param>
        /// <param name="sessionId">The session id.</param>
        /// <param name="accountPool">The account pool.</param>
        /// <param name="requestedSize">The size of reservation block being requested.</param>
        /// <returns>The start index for the reserved block</returns>
        private static int ReserveBlock(AssetInventoryContext context, string sessionId, DomainAccountPool accountPool, int requestedSize)
        {
            if (accountPool == null)
            {
                throw new ArgumentNullException("accountPool");
            }

            // Calculate the start index of the new block
            int startIndex = accountPool.MinimumUserNumber;

            foreach (DomainAccountReservation reservation in SelectReservationsByKey(context, accountPool.DomainAccountKey))
            {
                // Check to see if there are any users between reservations that we can utilize.
                // For example, say there were 2 reservations against this DomainAccountKey, but the first one got released
                // Now there is a gap between the minimum user number and the start index of the reservation we are looking at.
                // We want to utilize that block, if possible.
                if ((reservation.StartIndex - startIndex) >= requestedSize)
                {
                    break;
                }
                // Not enough space for the requested size, so check the next one.
                startIndex = reservation.StartIndex + reservation.Count;
            }

            // Now that we have the start index for our new block, we need to see if there is enough room
            // for the block before we hit the "ceiling" of our domain users.
            int available = accountPool.MaximumUserNumber - startIndex + 1;

            if (available < requestedSize)
            {
                throw new InsufficientDomainAccountsException($"There were not enough domain accounts available to run this scenario. PoolName: {accountPool.DomainAccountKey} Available: {available} Number Requested: {requestedSize}");
            }

            DomainAccountReservation newReservation = new DomainAccountReservation
            {
                SessionId        = sessionId,
                DomainAccountKey = accountPool.DomainAccountKey,
                StartIndex       = startIndex,
                Count            = requestedSize
            };

            context.DomainAccountReservations.Add(newReservation);
            context.SaveChanges();

            return(startIndex);
        }
 /// <summary>
 /// Creates a reservation entry for the specified account pool.
 /// </summary>
 /// <param name="userPool">The account pool type.</param>
 /// <param name="accountPool">The account pool.</param>
 /// <param name="startIndex">The start index.</param>
 /// <param name="userCount">The number of user accounts to reserve.</param>
 public void Add(string userPool, DomainAccountPool accountPool, int startIndex, int userCount)
 {
     _accounts.Add(userPool, new DomainAccount(startIndex, userCount, accountPool));
 }
 public DomainAccount(int startIndex, int userCount, DomainAccountPool accountPool)
 {
     TotalAccounts = _userCount = userCount;
     StartIndex    = _currentIndex = startIndex;
     _accountPool  = accountPool;
 }