示例#1
0
 public async Task <Computer> GetNewReservationAsync(RemoteLabViewModel rvm)
 {
     return(await this.Db.Computers.Where(c =>
                                          c.Pool.PoolName.Equals(rvm.Pool.PoolName, StringComparison.InvariantCultureIgnoreCase) &&
                                          c.UserName == null
                                          ).OrderBy(c => c.ComputerName).FirstOrDefaultAsync());
 }
示例#2
0
        public async Task <ActionResult> NewRez()
        {
            RemoteLabViewModel rvm = (RemoteLabViewModel)TempData[RVM];

            if (rvm == null || rvm.ReservationStatus != ReservationStatus.NewReservation)
            {
                return(RedirectToAction("Index"));
            }

            var stats = await Svc.GetPoolSummaryAsync(rvm.Pool.PoolName);

            ViewBag.WelcomeMessage = rvm.Pool.WelcomeMessage;
            ViewBag.CurrentPool    = rvm.Pool.PoolName;
            ViewBag.Available      = stats.PoolAvailable;
            ViewBag.Total          = stats.PoolCount;
            ViewBag.InUse          = stats.PoolInUse;

            return(View());
        }
示例#3
0
        public async Task <RemoteLabViewModel> PopulateRemoteLabViewModelAsync(String PoolName, String CurrentUser)
        {
            var rvm = new RemoteLabViewModel()
            {
                CurrentUser       = CurrentUser,
                ReservationStatus = ReservationStatus.NoPoolSelected
            };

            rvm.Pool = await this.GetPoolByIdAsync(PoolName ?? String.Empty);

            if (rvm.Pool == null)
            {
                // no pool selected
                rvm.ReservationStatus = ReservationStatus.NoPoolSelected;
            }
            else // we have selected a pool, so we can continue
            {
                rvm.RemoteLabComputer = await this.GetExistingReservationAsync(rvm);

                await this.ReservationCleanupAsync(rvm.Pool.PoolName, rvm.Pool.CleanupInMinutes);

                if (rvm.RemoteLabComputer != null)
                {
                    // we have a reservation
                    rvm.ReservationStatus = ReservationStatus.ExistingReservation;
                }
                else
                {
                    // you are here for the new reservation
                    rvm.ReservationStatus = ReservationStatus.NewReservation;
                    rvm.RemoteLabComputer = await this.GetNewReservationAsync(rvm);
                }

                if (rvm.RemoteLabComputer == null)
                {
                    // The pool is full
                    rvm.ReservationStatus = ReservationStatus.PoolFull;
                }
            }
            return(rvm);
        }
示例#4
0
        // GET / PoolFull
        public async Task <ActionResult> PoolFull()
        {
            RemoteLabViewModel rvm = (RemoteLabViewModel)TempData[RVM];

            if (rvm == null || rvm.ReservationStatus != ReservationStatus.PoolFull)
            {
                return(RedirectToAction("Index"));
            }

            await Svc.LogAndEmailPoolFullEventAsync(rvm.Pool.PoolName.ToLowerInvariant(), "N/A", rvm.CurrentUser, System.DateTime.Now);

            var stats = await Svc.GetPoolSummaryAsync(rvm.Pool.PoolName);

            ViewBag.CurrentPool = rvm.Pool.PoolName;
            ViewBag.Available   = stats.PoolAvailable;
            ViewBag.Total       = stats.PoolCount;
            ViewBag.InUse       = stats.PoolInUse;


            return(View());
        }
示例#5
0
        public async Task <ActionResult> MakeRez(FormCollection form)
        {
            bool               success      = false;
            bool               rebootResult = false;
            string             PoolName     = (string)HttpContext.Session[CHOSEN_POOL];
            RemoteLabViewModel rvm          = new RemoteLabViewModel();

            do
            {
                rvm = await Svc.PopulateRemoteLabViewModelAsync(PoolName, HttpContext.User.Identity.Name);

                if (rvm == null || rvm.ReservationStatus != ReservationStatus.NewReservation)
                {
                    return(RedirectToAction("Index"));
                }

                success = await Svc.CheckRdpPortAndRebootIfUnresponsiveAsync(rvm.RemoteLabComputer.ComputerName, Properties.Settings.Default.ActiveDirectoryDNSDomain,
                                                                             rvm.CurrentUser, rvm.Pool.PoolName, rvm.Pool.RdpTcpPort);
            } while (!success);
            // when you make it here, you have a valid computer, so make the reservation
            await Svc.MakeReservationAsync(rvm.RemoteLabComputer.ComputerName, rvm.CurrentUser);

            return(RedirectToAction("Index"));
        }