Ejemplo n.º 1
0
        public void LmsGetLoggedApplicationStop()
        {
            var a        = Assembly.GetExecutingAssembly();
            var fullPath = a.CodeBase;

            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.Combine(fullPath, "IUDICO.LMS", "log.xml");
            ILmsService service = new LmsService(new WindsorContainer());

            fullPath = fullPath.Remove(0, 6);
            XmlConfigurator.Configure(new FileInfo(fullPath));
            var log = LogManager.GetLogger(typeof(ILmsService));

            service.Inform(LMSNotifications.ApplicationStop);
            var rootAppender = (FileAppender)((Hierarchy)LogManager.GetRepository()).Root.Appenders[0];

            fullPath = rootAppender.File;
            rootAppender.Close();
            var reader = new StreamReader(fullPath);
            var toRead = reader.ReadToEnd();

            Assert.IsTrue(toRead.IndexOf("Notification:application/stop") != -1);
        }
Ejemplo n.º 2
0
        public ActionResult ShowDiscipline(long selectDisciplineId)
        {
            IEnumerable <Topic> temp_allowedTopics = LmsService.FindService <IDisciplineService>().GetTopicsByDisciplineId((int)selectDisciplineId);
            var    disciplineName    = LmsService.FindService <IDisciplineService>().GetDiscipline((int)selectDisciplineId).Name;
            var    groups            = LmsService.FindService <IUserService>().GetGroups();
            double disciplineQuality = 0;
            var    allowedTopics     = new List <KeyValuePair <Topic, List <double> > >();

            if (temp_allowedTopics != null & temp_allowedTopics.Count() != 0)
            {
                double tempDisciplineQuality = 0;
                var    temp = new List <KeyValuePair <Topic, List <double> > >();
                foreach (var topic in temp_allowedTopics)
                {
                    List <double> quality = new List <double>();
                    quality.Add(Math.Round(this.storage.GetTopicTagStatistic(topic), 3) * 100);
                    quality.Add(Math.Round(this.storage.GetCorrTopicStatistic(topic, groups), 3) * 100);
                    quality.Add(Math.Round(this.storage.GetDiffTopicStatistic(topic, groups), 3) * 100);
                    quality.Add(Math.Round(this.storage.GaussianDistribution(topic), 3) * 100);
                    tempDisciplineQuality += quality.Sum() / quality.Count;
                    temp.Add(new KeyValuePair <Topic, List <double> >(topic, quality));
                }
                disciplineQuality = tempDisciplineQuality / temp.Count;
                allowedTopics     = temp;
            }

            DisciplineModel model = new DisciplineModel(allowedTopics, disciplineName, disciplineQuality);

            return(View(model));
        }
Ejemplo n.º 3
0
        protected void Application_Start()
        {
            AppDomain.CurrentDomain.AppendPrivatePath(Server.MapPath("/Plugins"));
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            InitializeWindsor();

            Common.Log4NetLoggerService.InitLogger();
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("log.xml")));

            ViewEngines.Engines.Add(new PluginViewEngine());
            HostingEnvironment.RegisterVirtualPathProvider(new AssemblyResourceProvider());
            ControllerBuilder.Current.SetControllerFactory(
                Container.Resolve <IControllerFactory>()
                );
            ModelMetadataProviders.Current = new FieldTemplateMetadataProvider();

            LoadProviders();

            RegisterRoutes(RouteTable.Routes);
            object[] tmp = new object[2];
            tmp[0] = Container;
            tmp[1] = Application;

            LmsService.Inform(LMSNotifications.ApplicationStart, tmp);
        }
Ejemplo n.º 4
0
        public ActionResult LoginDefault(string loginUsername, string loginPassword)
        {
            if (Membership.ValidateUser(loginUsername, loginPassword))
            {
                LmsService.Inform(UserNotifications.UserLogin, this.storage.GetCurrentUser());

                if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                {
                    FormsAuthentication.RedirectFromLoginPage(loginUsername, false);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(loginUsername, false);

                    Logger log = Logger.Instance;
                    log.Info(this, loginUsername + " logged in.");

                    return(this.Redirect("/"));
                }
            }
            else
            {
                this.ModelState.AddModelError(string.Empty, Localization.GetMessage("InvalidUsernameAndPassword"));
            }

            return(this.View("Login"));
        }
Ejemplo n.º 5
0
        public ActionResult Play(int id)
        {
            var disciplineService = LmsService.FindService <ICurriculumService>();

            var topic = disciplineService.GetTopic(id);

            if (topic == null)
            {
                return(View("Error", "~/Views/Shared/Site.Master", Localization.getMessage("Topic_Not_Found")));
            }

            var currentUser   = UserService.GetCurrentUser();
            var topics        = disciplineService.GetTopicsAvailableForUser(currentUser).Select(t => t.Topic).Where(t => t.Id == topic.Id);
            var containsTopic = topics.Count() == 1;

            if (!containsTopic)
            {
                return(View("Error", "~/Views/Shared/Site.Master", Localization.getMessage("Not_Allowed_Pass_Topic")));
            }

            long attemptId = MlcProxy.GetAttemptId(topic);

            ServicesProxy.Instance.Initialize(LmsService);

            return(View("Play", new PlayModel {
                AttemptId = attemptId, TopicId = topic.Id
            }));
        }
Ejemplo n.º 6
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            LmsService.Inform(LMSNotifications.ApplicationRequestStart);

            /*
             * var securityService = Container.Resolve<ISecurityService>();
             * var plugins = Container.ResolveAll<IPlugin>();
             * var currentRole = Role.None;
             * var userRoles = HttpContext.Current.User != null
             *                  ? Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name)
             *                  : new[] {Role.None.ToString()};
             *
             * lock (Actions)
             * {
             *  Actions.Clear();
             *
             *  foreach (var plugin in plugins)
             *  {
             *      plugin.Setup(Container);
             *
             *      var actions = plugin.BuildActions(currentRole).Where(a => IsAllowed(a, userRoles));
             *
             *      if (Actions.ContainsKey(plugin))
             *      {
             *          Actions[plugin] = actions;
             *      }
             *      else
             *      {
             *          Actions.Add(plugin, actions);
             *      }
             *  }
             * }
             */
        }
Ejemplo n.º 7
0
        public ActionResult LoginDefault(string loginUsername, string loginPassword)
        {
            if (Membership.ValidateUser(loginUsername, loginPassword))
            {
                LmsService.Inform(UserNotifications.UserLogin, _Storage.GetCurrentUser());

                if (Request.QueryString["ReturnUrl"] != null)
                {
                    FormsAuthentication.RedirectFromLoginPage(loginUsername, false);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(loginUsername, false);

                    ILog log = LogManager.GetLogger(typeof(AccountController));
                    log.Info(loginUsername + " logged in.");
                    return(Redirect("/"));
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, Localization.getMessage("InvalidUsernameAndPassword"));
            }

            return(View("Login"));
        }
Ejemplo n.º 8
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            LmsService.Inform(LMSNotifications.ApplicationRequestStart, HttpContext.Current);

            Localization.Init(this.Container.Resolve <IControllerFactory>());

            this.Container.Resolve <LinqLogger>().WriteLine("==== Begin request ====");
        }
Ejemplo n.º 9
0
        public ActionResult Index()
        {
            var userService = LmsService.FindService <IUserService>();
            var userId      = userService.GetUsers().Single(i => i.Username == User.Identity.Name).Id;
            var courses     = _Storage.GetCourses(userId);

            return(View(courses.Union(_Storage.GetCourses(User.Identity.Name))));
        }
Ejemplo n.º 10
0
        public ActionResult SelectCurriculums(int id)
        {
            ViewData["Group"] = LmsService.FindService <IUserService>().GetGroup(id).Name;
            var curriculums = _Proxy.GetCurrilulumsByGroupId(id);

            HttpContext.Session["SelectedGroupId"] = id;
            return(View(curriculums));
        }
Ejemplo n.º 11
0
        public ActionResult Index()
        {
            IEnumerable <Discipline> allowedDisciplines;

            allowedDisciplines = LmsService.FindService <IDisciplineService>().GetDisciplines();

            return(View(allowedDisciplines));
        }
Ejemplo n.º 12
0
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            this.Session.Clear();

            LmsService.Inform(UserNotifications.UserLogout);

            return(this.Redirect("/"));
        }
Ejemplo n.º 13
0
        public ActionResult AddUsersToRole(string usersId, int?roleRef)
        {
            var ids = usersId.Split(',');

            List <Guid> usersIds = new List <Guid>();

            foreach (var id in ids)
            {
                try
                {
                    usersIds.Add(Guid.Parse(id));
                }
                catch (Exception)
                {
                }
            }

            if (roleRef == null)
            {
                var list = new List <Role> {
                    Role.Student, Role.Teacher, Role.CourseCreator, Role.Admin
                }.Select(r =>
                         new SelectListItem
                {
                    Text     = Localization.GetMessage(r.ToString()),
                    Value    = ((int)r).ToString(),
                    Selected = false
                });

                var userRole = new UserRoleModel {
                    RoleList = list
                };

                this.ModelState.AddModelError("RoleRef", Localization.GetMessage("SelectRole"));

                return(View(userRole));
            }


            var role = UserRoles.GetRole(roleRef.Value);

            foreach (var id in usersIds)
            {
                var user = this.storage.GetUser(u => u.Id == id);

                if (!this.storage.GetRolesAvailableToUser(user).Contains(role))
                {
                    continue;
                }

                this.storage.AddUserToRole(role, user);
            }

            LmsService.Inform(LMSNotifications.ActionsChanged);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
        protected void Application_End()
        {
            LmsService.Inform(LMSNotifications.ApplicationStop);

            if (_Container != null)
            {
                _Container.Dispose();
                _Container = null;
            }
        }
Ejemplo n.º 15
0
        public ActionResult ShowCurriculumStatistic(int[] selectCurriculumId)
        {
            ViewData["selectGroupName"] = LmsService.FindService <IUserService>().GetGroup((int)HttpContext.Session["SelectedGroupId"]).Name;
            IEnumerable <User>     users      = LmsService.FindService <IUserService>().GetUsersByGroup(LmsService.FindService <IUserService>().GetGroup((int)HttpContext.Session["SelectedGroupId"]));
            AllSpecializedResults  allSpecRes = new AllSpecializedResults();
            SpecializedResultProxy srp        = new SpecializedResultProxy();

            allSpecRes = srp.GetResults(users, selectCurriculumId, LmsService);

            return(View(allSpecRes));
        }
Ejemplo n.º 16
0
        public ActionResult ShowDisciplineStatistic(int[] selectDisciplineId)
        {
            var selectedGroup = LmsService.FindService <IUserService>().GetGroup((int)HttpContext.Session["SelectedGroupId"]);

            ViewData["selectGroupName"] = selectedGroup.Name;
            IEnumerable <User>     users      = LmsService.FindService <IUserService>().GetUsersByGroup(selectedGroup);
            SpecializedResultProxy srp        = new SpecializedResultProxy();
            AllSpecializedResults  allSpecRes = srp.GetResults(users, selectDisciplineId, LmsService);

            return(View(allSpecRes));
        }
Ejemplo n.º 17
0
        public ActionResult TeacherToAdminUpgrade()
        {
            var allow = (bool)(this.Session["AllowAdmin"] ?? false);

            if (!allow && !Roles.IsUserInRole(Role.Admin.ToString()))
            {
                this.Session["AllowAdmin"] = true;
                LmsService.Inform(LMSNotifications.ActionsChanged);
            }

            return(this.RedirectToAction("Index"));
        }
Ejemplo n.º 18
0
        public ActionResult Login()
        {
            var response = this.openId.GetResponse();

            if (response != null)
            {
                switch (response.Status)
                {
                case AuthenticationStatus.Authenticated:

                    var openId = response.FriendlyIdentifierForDisplay;

                    var user = this.storage.GetUser(u => u.OpenId == openId);

                    if (user == null)
                    {
                        this.ModelState.AddModelError(string.Empty, Localization.GetMessage("NoUserOpenID"));

                        break;
                    }

                    LmsService.Inform(UserNotifications.UserLogin, user);

                    if (!string.IsNullOrEmpty(this.Request.QueryString["ReturnUrl"]))
                    {
                        FormsAuthentication.RedirectFromLoginPage(user.Username, false);
                    }
                    else
                    {
                        FormsAuthentication.SetAuthCookie(user.Username, false);
                        Logger log = Logger.Instance;
                        log.Info(this, "OpenID user " + user.Username + " logged in.");

                        return(this.Redirect("/"));
                    }

                    break;

                case AuthenticationStatus.Canceled:
                    this.ModelState.AddModelError(string.Empty, "Login was cancelled at the provider");

                    break;

                case AuthenticationStatus.Failed:
                    this.ModelState.AddModelError(string.Empty, "Login failed using the provided OpenID identifier");

                    break;
                }
            }

            return(this.View());
        }
Ejemplo n.º 19
0
 public void LmsRemainsTellsWhenNoServiceFound()
 {
     LmsService service = new LmsService(new WindsorContainer());
     try
     {
         service.FindService<IUserService>();
     }
     catch
     {
         Assert.Pass();
     }
     Assert.Fail();
 }
Ejemplo n.º 20
0
        public ActionResult Login()
        {
            var response = _OpenId.GetResponse();

            if (response != null)
            {
                switch (response.Status)
                {
                case AuthenticationStatus.Authenticated:

                    var openId = response.FriendlyIdentifierForDisplay;

                    var user = _Storage.GetUser(u => u.OpenId == openId);

                    if (user == null)
                    {
                        ModelState.AddModelError(string.Empty, "Login failed using the provided OpenID identifier");

                        break;
                    }

                    LmsService.Inform(UserNotifications.UserLogin, user);

                    if (Request.QueryString["ReturnUrl"] != null)
                    {
                        FormsAuthentication.RedirectFromLoginPage(user.Username, false);
                    }
                    else
                    {
                        FormsAuthentication.SetAuthCookie(user.Username, false);
                        ILog log = LogManager.GetLogger(typeof(AccountController));
                        log.Info("OpenID user " + user.Username + " logged in.");
                        return(Redirect("/"));
                    }

                    break;

                case AuthenticationStatus.Canceled:
                    ModelState.AddModelError(string.Empty, "Login was cancelled at the provider");

                    break;

                case AuthenticationStatus.Failed:
                    ModelState.AddModelError(string.Empty, "Login failed using the provided OpenID identifier");

                    break;
                }
            }

            return(View());
        }
Ejemplo n.º 21
0
        public void LmsRemainsTellsWhenNoServiceFound()
        {
            LmsService service = new LmsService(new WindsorContainer());

            try
            {
                service.FindService <IUserService>();
            }
            catch
            {
                Assert.Pass();
            }
            Assert.Fail();
        }
Ejemplo n.º 22
0
        public JsonResult RateTopic(int topicId, int score)
        {
            score = Math.Min(0, score);
            score = Math.Max(score, 5);

            var topics =
                LmsService.FindService <ICurriculumService>().GetTopicDescriptions(this.storage.GetCurrentUser());

            if (topics.Select(t => t.Topic.Id).Contains(topicId))
            {
                this.storage.RateTopic(topicId, score);

                return(this.Json("success"));
            }

            return(this.Json("fail"));
        }
Ejemplo n.º 23
0
        public ActionResult Play(int id)
        {
            var curriculumService = LmsService.FindService <ICurriculumService>();

            var theme = curriculumService.GetTheme(id);

            if (!curriculumService.GetThemesAvailableForUser(UserService.GetCurrentUser()).Select(t => t.Theme).Contains(theme))
            {
                return(View("Error", "You are not allowed to pass this theme."));
            }

            long attemptId = MlcProxy.GetAttemptId(theme);

            ServicesProxy.Instance.Initialize(LmsService);

            return(View("Play", new PlayModel {
                AttemptId = attemptId, ThemeId = theme.Id
            }));
        }
Ejemplo n.º 24
0
        public ActionResult RecommendedTopics()
        {
            var user = LmsService.FindService <IUserService>().GetCurrentUser();

            if (user == null)
            {
                return(new EmptyResult());
            }

            var roles = LmsService.FindService <IUserService>().GetCurrentUserRoles();

            if (!roles.Contains(Role.Student))
            {
                return(new EmptyResult());
            }

            var topics = this.storage.GetRecommenderTopics(user);

            return(PartialView(topics));
        }
Ejemplo n.º 25
0
        public ActionResult RemoveFromRole(Guid id, int?roleRef)
        {
            var user = this.storage.GetUser(u => u.Id == id);

            if (user == null)
            {
                return(this.RedirectToAction("Index"));
            }

            if (roleRef == null)
            {
                return(this.RedirectToAction("Details", new { id }));
            }

            var role = UserRoles.GetRole(roleRef.Value);

            this.storage.RemoveUserFromRole(role, user);
            LmsService.Inform(LMSNotifications.ActionsChanged);

            return(this.RedirectToAction("Details", new { id }));
        }
Ejemplo n.º 26
0
 public void LmsGetLoggedApplicationStop()
 {
     Assembly a = Assembly.GetExecutingAssembly();
     string fullPath = a.CodeBase;
     fullPath = Path.GetDirectoryName(fullPath);
     fullPath = Path.GetDirectoryName(fullPath);
     fullPath = Path.GetDirectoryName(fullPath);
     fullPath = Path.GetDirectoryName(fullPath);
     fullPath = Path.Combine(fullPath, "IUDICO.LMS", "log.xml");
     ILmsService service = new LmsService(new WindsorContainer());
     fullPath = fullPath.Remove(0, 6);
     XmlConfigurator.Configure(new FileInfo(fullPath));
     ILog log = LogManager.GetLogger(typeof (ILmsService));
     service.Inform(LMSNotifications.ApplicationStop);
     FileAppender rootAppender = (FileAppender) ((Hierarchy) LogManager.GetRepository()).Root.Appenders[0];
     fullPath = rootAppender.File;
     rootAppender.Close();
     StreamReader reader = new StreamReader(fullPath);
     string toRead = reader.ReadToEnd();
     Assert.IsTrue(toRead.IndexOf("Notification:application/stop") != -1);
 }
Ejemplo n.º 27
0
        public ActionResult AddToRole(Guid id, int?roleRef)
        {
            var user = this.storage.GetUser(u => u.Id == id);

            if (user == null)
            {
                return(this.RedirectToAction("Index"));
            }

            if (roleRef == null)
            {
                var userList =
                    this.storage.GetRolesAvailableToUser(user).Select(
                        r =>
                        new SelectListItem
                {
                    Text     = Localization.GetMessage(r.ToString()),
                    Value    = ((int)r).ToString(),
                    Selected = false
                });

                var userRole = new UserRoleModel {
                    RoleList = userList
                };

                this.ModelState.AddModelError("RoleRef", "Please select role from list");

                return(this.View(userRole));
            }

            var role = UserRoles.GetRole(roleRef.Value);

            this.storage.AddUserToRole(role, user);
            LmsService.Inform(LMSNotifications.ActionsChanged);

            return(this.RedirectToAction("Details", new { Id = id }));
        }
Ejemplo n.º 28
0
        public ActionResult AddToRole(Guid id)
        {
            var user = this.storage.GetUser(u => u.Id == id);

            if (user == null)
            {
                return(this.RedirectToAction("Index"));
            }

            var roleList =
                this.storage.GetRolesAvailableToUser(user).Select(
                    r =>
                    new SelectListItem {
                Text = Localization.GetMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false
            });

            var userRole = new UserRoleModel {
                RoleList = roleList
            };

            LmsService.Inform(LMSNotifications.ActionsChanged);

            return(this.View(userRole));
        }
Ejemplo n.º 29
0
 void Application_EndRequest(object sender, EventArgs e)
 {
     this.Container.Resolve <LinqLogger>().WriteLine("==== End request ====");
     LmsService.Inform(LMSNotifications.ApplicationRequestEnd, HttpContext.Current, Request);
 }
Ejemplo n.º 30
0
 public SearchController()
 {
     _CourseService    = LmsService.FindService <ICourseService>();
     _CurriculmService = LmsService.FindService <ICurriculumService>();
     _UserService      = LmsService.FindService <IUserService>();
 }
Ejemplo n.º 31
0
 void Application_EndRequest(Object Sender, EventArgs e)
 {
     log4net.ILog log = log4net.LogManager.GetLogger(typeof(MvcApplication));
     log.Info(Request.HttpMethod + ": " + Request.Path);
     LmsService.Inform(LMSNotifications.ApplicationRequestEnd);
 }
Ejemplo n.º 32
0
 public CourseController(ICourseStorage courseStorage)
 {
     _Storage     = courseStorage;
     _UserService = LmsService.FindService <IUserService>();
 }