コード例 #1
0
ファイル: MembershipEngine.cs プロジェクト: eakarpov/Web
        private Session CreateSession(IEntityFactory factory, User user, string ip)
        {
            var now     = _systemDateService.Now();
            var session = factory.Create <Session>();

            session.Guid         = Guid.NewGuid();
            session.User         = user;
            session.IP           = ip;
            session.CreationTime = now;
            session.LastAction   = now;

            return(session);
        }
コード例 #2
0
        public EditLabScheduleModelBase CreateEmptyModel(EditLabScheduleModelBase.Kind kind)
        {
            EditLabScheduleModelBase model;

            switch (kind)
            {
            case EditLabScheduleModelBase.Kind.Individual:
                model = new EditIndividualLabScheduleModel
                {
                    Doers = _query.OfEntities <Student>()
                            .Where(s => !s.IsDismissed && s.IsVerified)
                            .ToArray()
                            .ToDictionary(s => s.Id, s => $"[{s.Group.Name}] {s.GetShortName()}")
                };
                break;

            case EditLabScheduleModelBase.Kind.Group:
                model = new EditGroupLabScheduleModel
                {
                    Doers = _query.OfEntities <Group>()
                            .ToArray()
                            .ToDictionary(g => g.Id, g => g.Name)
                };
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(kind));
            }

            model.LabWorks = _query.OfEntities <LabWork>()
                             .OrderBy(lr => lr.Name)
                             .ToArray()
                             .ToDictionary(lr => lr.Id, lr => lr.Name);

            model.DateFrom = _systemDate.Now();
            model.DateTill = _systemDate.Now();

            return(model);
        }
コード例 #3
0
        /// <summary> Создать сессию </summary>
        public Session Create(User user, string ip)
        {
            CheckNotDisposed();

            var now     = _systemDateService.Now();
            var session = Context.Sessions.Create();

            session.Guid         = Guid.NewGuid();
            session.User         = user;
            session.IP           = ip;
            session.CreationTime = now;
            session.LastAction   = now;
            Context.Sessions.Add(session);

            return(session);
        }
コード例 #4
0
        /// <summary> Регистрирует действия студента </summary>
        /// <param name="taskId"> Идентификатор модуля-задания </param>
        /// <param name="sessionGuid"> Идентификатор сессии </param>
        /// <param name="actions"> Действия для регистрации </param>
        /// <param name="isTaskFinished"> Задание завершено? </param>
        /// <returns> Количество баллов студента </returns>
        /// <remarks> От этой штуки зависит GraphLabs.Components </remarks>
        public int?RegisterUserActions(long taskId, Guid sessionGuid, ActionDescription[] actions, bool isTaskFinished = false)
        {
            using (var op = _operationFactory.Create())
            {
                var task          = op.DataContext.Query.Get <Task>(taskId);
                var session       = GetSessionWithChecks(op.DataContext.Query, sessionGuid);
                var resultLog     = GetCurrentResultLog(op.DataContext.Query, session);
                var taskResultLog = GetCurrentTaskResultLog(resultLog, task);
                if (taskResultLog.Score == null)
                {
                    taskResultLog.Score = StartingScore;
                }

                if (actions.Any())
                {
                    foreach (var actionDescription in actions)
                    {
                        var newAction = op.DataContext.Factory.Create <StudentAction>();
                        newAction.Description = actionDescription.Description;
                        newAction.Penalty     = actionDescription.Penalty;
                        newAction.TaskResult  = taskResultLog;
                        newAction.Time        = actionDescription.TimeStamp;

                        taskResultLog.StudentActions.Add(newAction);
                    }

                    taskResultLog.Score -= actions.Last().Penalty;
                }

                if (isTaskFinished)
                {
                    var newAction = op.DataContext.Factory.Create <StudentAction>();
                    newAction.Description = $"Задание {task.Name} выполнено.";
                    newAction.Penalty     = 0;
                    newAction.TaskResult  = taskResultLog;
                    newAction.Time        = _systemDate.Now();
                    taskResultLog.Status  = ExecutionStatus.Complete;
                    taskResultLog.StudentActions.Add(newAction);
                }

                op.Complete();

                return(taskResultLog.Score);
            }
        }
コード例 #5
0
        /// <summary> Регистрирует начало выполнения задания </summary>
        /// <param name="taskId"> Идентификатор модуля-задания </param>
        /// <param name="sessionGuid"> Идентификатор сессии </param>
        /// <returns> Данные для задания - как правило, исходный граф, или что-то типа того </returns>
        public TaskVariantDto GetVariant(long taskId, Guid sessionGuid)
        {
            using (var op = _operationFactory.Create())
            {
                var         session     = GetSessionWithChecks(op.DataContext.Query, sessionGuid);
                TaskVariant taskVariant = null;
                if (new [] { UserRole.Teacher, UserRole.Administrator }.Contains(session.User.Role))//вообще должен быть Teacher/Admin
                {
                    var task = op.DataContext.Query.Get <Task>(taskId);
                    taskVariant = op.DataContext.Query.OfEntities <TaskVariant>().First(v => v.Task == task);
                }
                else if (session.User.Role == UserRole.Student)
                {
                    var task          = op.DataContext.Query.Get <Task>(taskId);
                    var resultLog     = GetCurrentResultLog(op.DataContext.Query, session);
                    var taskResultLog = GetCurrentTaskResultLog(resultLog, task);

                    var variant = resultLog.LabVariant;
                    taskVariant = variant.TaskVariants.Single(v => v.Task == task);

                    var action = op.DataContext.Factory.Create <StudentAction>();
                    action.TaskResult  = taskResultLog;
                    action.Time        = _systemDate.Now();
                    action.Description = "$['Task {task.Id}' -> Variant {taskVariant.Number}]";
                    action.Penalty     = 0;
                    taskResultLog.StudentActions.Add(action);

                    op.Complete();
                }
                else
                {
                    throw new NotSupportedException("Неизвестный науке зверь!");
                }
                return(new TaskVariantDto
                {
                    Data = taskVariant.Data,
                    GeneratorVersion = taskVariant.GeneratorVersion,
                    Id = taskVariant.Id,
                    Number = taskVariant.Number,
                    Version = taskVariant.Version
                });
            }
        }
コード例 #6
0
ファイル: AvailableLabListModel.cs プロジェクト: eakarpov/Web
        /// <summary> Загружает демонстрационные лабораторные работы </summary>
        protected override TAvalilableLab[] LoadItems()
        {
            var currentStudent = _query.OfEntities <Student>().SingleOrDefault(s => s.Email == _currentUser.Identity.Name);

            if (currentStudent == null)
            {
                throw new GraphLabsException("Данная страница имеет смысл только для залогиненных студентов.");
            }

            var currentTime = _dateService.Now();
            var models      = _query.OfEntities <IndividualLabSchedule>()
                              .Where(s => s.Student.Id == currentStudent.Id)
                              .Cast <AbstractLabSchedule>()
                              .Union(_query.OfEntities <GroupLabSchedule>().Where(g => g.Group.Id == currentStudent.Group.Id))
                              .Where(sch => sch.Mode == ExecutionMode &&
                                     sch.DateFrom <= currentTime && sch.DateTill >= currentTime)
                              .Where(GetAdditionalScheduleFilter(_query, currentStudent))
                              .ToArray()
                              .Select(l => _modelLoader.Load(l))
                              .ToArray();

            return(models);
        }