예제 #1
0
        public ActionResult ModalUserInfo(int id = 0)
        {
            LabUser user = db.LabUser.Find(id);
            if (user == null)
            {
                return Json(new { success = false });
            }
            LabUserViewModel luvm = new LabUserViewModel();

            luvm.User = user;
            UseInstance laststart = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_1 && (t.Active ?? true));
            UseInstance lastfinish = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
            if (laststart == null || lastfinish == null)
            {
                Module dummyMod = new Module() {
                    ModuleName = Constants.Null_Instance
                };
                UseInstance dummyIns = new UseInstance() {
                    Browser = Constants.Null_Instance,
                    OS = Constants.Null_Instance,
                    IP = Constants.Null_Instance
                };
                luvm.Module = dummyMod;
                luvm.LastStart = Constants.Null_Instance;
                luvm.LastFinish = Constants.Null_Instance;
                luvm.LabsCompleted = 0;
                luvm.lastInstance = dummyIns;
            }
            else
            {
                luvm.Module = laststart.Module;
                luvm.LabsCompleted = user.UseInstances.Count(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
                luvm.LastStart = laststart.Time.ToString();
                luvm.LastFinish = DateTime.Compare(lastfinish.Time, laststart.Time) > 0 ? lastfinish.Time.ToString() : Constants.Null_Instance;
                luvm.lastInstance = laststart;
            }

            return PartialView("_FullInfo", luvm);
        }
예제 #2
0
        /// <summary>
        /// Logs a lab's activity to a UseInstance, which is tied to a user profile. Stores a few browser metrics as well
        /// </summary>
        /// <param name="p_module">The Module being used in the current UseInstance</param>
        /// <param name="p_generation">The generation of flies being produced currently</param>
        /// <param name="p_instance">The Instance being updated with Fly data</param>
        /// <returns>A code, where 0 = success and anything else = failure </returns>
        private int RecordLog(Module p_module, int p_generation, out UseInstance p_instance)
        {
            UseInstance instance = new UseInstance();
            LabUser labUser = new LabUser();
            try
            {
                labUser = db.LabUser.OrderByDescending(t => t.Id).FirstOrDefault(t => t.GID == (CWSToolkit.AuthUser.GetUsername() ?? "_Guest_"));
            }
            catch (ArgumentNullException e)
            {
                Exception ex = new Exception("The log recorder exited with error code 2.", e);
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                p_instance = null;
                return 2;
            }
            catch (InvalidOperationException)
            {
                //no labuser profile, so we will make one here
                labUser.GID = CWSToolkit.AuthUser.GetUsername() ?? Constants.Guest;
                labUser.Name = CWSToolkit.AuthUser.GetFullName() ?? Constants.Guest;
                labUser.Active = (labUser.Name != Constants.Guest);
                db.LabUser.Add(labUser);
            }
            catch (Exception e)
            {
                Exception ex = new Exception("The log recorder exited with error code 3.", e);
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                p_instance = null;
                return 3;
            }

            //now we have a user to add an instance to

            //check if its an old user and reactivate them
            if (!labUser.Active && labUser.Name != Constants.Guest)
            {
                labUser.Active = true;
                db.Entry(labUser).State = EntityState.Modified;
            }

            instance.Module = p_module;
            instance.Time = DateTime.Now;
            switch (p_generation)
            {
                case 1:
                    instance.Stage = Constants.Stage_1;
                    break;
                case 2:
                    instance.Stage = Constants.Stage_2;
                    break;
                case 3:
                    instance.Stage = Constants.Stage_3;
                    break;
                default:
                    instance.Stage = "Error";
                    break;
            }

            //grab some browser info
            try
            {
                var bc = Request.Browser;
                instance.OS = bc.Platform;
                instance.Browser = bc.Type;
                instance.IP = Request.UserHostAddress;
                p_instance = instance;
            }
            catch (NotImplementedException e)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
                instance.OS = "";
                instance.Browser = "";
                instance.IP = "";
            }
            catch (Exception e)
            {
                Exception ex = new InvalidOperationException("The log recorder exited with error code 4.", e);
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                p_instance = null;
                return 4;
            }
            p_instance = instance;
            labUser.UseInstances.Add(instance);
            db.UseInstance.Add(instance);

            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Exception ex = new Exception("The log recorder exited with error code 5.", e);
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return 5;
            }

            return 0;
        }
예제 #3
0
 public ActionResult Index()
 {
     List<LabUser> allLabs = db.LabUser.ToList();
     List<LabUserViewModel> allLabsVM = new List<LabUserViewModel>();
     foreach (LabUser user in allLabs)
     {
         if (user.Active)
         {
             LabUserViewModel luvm = new LabUserViewModel();
             luvm.User = user;
             UseInstance laststart = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_1 && (t.Active ?? true));
             UseInstance lastfinish = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
             if (laststart == null || lastfinish == null)
             {
                 Module dummy = new Module() { ModuleName = Constants.Null_Instance };
                 luvm.Module = dummy;
                 luvm.LastStart = Constants.Null_Instance;
                 luvm.LastFinish = Constants.Null_Instance;
                 luvm.LabsCompleted = 0;
             }
             else
             {
                 luvm.Module = laststart.Module;
                 luvm.LabsCompleted = user.UseInstances.Count(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
                 luvm.LastStart = laststart.Time.ToString();
                 luvm.LastFinish = DateTime.Compare(lastfinish.Time, laststart.Time) > 0 ? lastfinish.Time.ToString() : Constants.Null_Instance;
             }
             allLabsVM.Add(luvm);
         }
     }
     return View(allLabsVM);
 }