コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QuestionDTO"/> class.
        /// </summary>
        /// <param name="question">
        /// The question.
        /// </param>
        /// <param name="instance">
        /// The instance.
        /// </param>
        public QuestionDTO(Question question, QuestionFor instance)
        {
            this.questionId       = question.Id;
            this.question         = question.QuestionName;
            this.questionTypeId   = question.QuestionType.Id;
            this.questionOrder    = question.QuestionOrder;
            this.subModuleItemId  = question.SubModuleItem.With(x => x.Id);
            this.imageId          = question.Image.Return(x => x.Id, (Guid?)null);
            this.instruction      = question.Instruction;
            this.correctMessage   = question.CorrectMessage;
            this.incorrectMessage = question.IncorrectMessage;
            this.hint             = question.Hint;
            this.createdBy        = question.CreatedBy.Return(x => x.Id, (int?)null);
            this.modifiedBy       = question.ModifiedBy.Return(x => x.Id, (int?)null);
            this.dateCreated      = question.DateCreated.With(x => x.ConvertToUnixTimestamp());
            this.dateModified     = question.DateModified.With(x => x.ConvertToUnixTimestamp());
            this.isActive         = question.IsActive;
            this.scoreValue       = question.ScoreValue;
            this.imageVO          = question.Image.Return(x => new FileDTO(x), null);
            this.distractors      = question.Distractors.Select(x => new DistractorDTO(x)).ToArray();
            this.correctReference = question.CorrectReference;
            this.randomizeAnswers = question.RandomizeAnswers;
            rows = question.Rows;

            this.FillCustomProperties(instance);
        }
コード例 #2
0
        /// <summary>
        /// The fill custom properties.
        /// </summary>
        /// <param name="instance">
        /// The instance.
        /// </param>
        private void FillCustomProperties(QuestionFor instance)
        {
            if (instance != null)
            {
                foreach (QuestionTypeEnum questionType in instance.QuestionTypes)
                {
                    switch (questionType)
                    {
                    case QuestionTypeEnum.Rate:
                        var qr = (QuestionForRate)instance;
                        this.restrictions = qr.Restrictions;
                        this.allowOther   = qr.AllowOther.HasValue && qr.AllowOther.Value;
                        break;

                    case QuestionTypeEnum.RateScaleLikert:
                        var ql = (QuestionForLikert)instance;
                        this.allowOther = ql.AllowOther.HasValue && ql.AllowOther.Value;
                        break;

                    case QuestionTypeEnum.OpenAnswerMultiLine:
                    case QuestionTypeEnum.OpenAnswerSingleLine:
                        var qoa = (QuestionForOpenAnswer)instance;
                        this.restrictions = qoa.Restrictions;
                        break;

                    case QuestionTypeEnum.WeightedBucketRatio:
                        var qwb = (QuestionForWeightBucket)instance;
                        this.totalWeightBucket = qwb.TotalWeightBucket;
                        this.weightBucketType  = qwb.WeightBucketType;
                        this.allowOther        = qwb.AllowOther.HasValue && qwb.AllowOther.Value;
                        break;

                    case QuestionTypeEnum.SingleMultipleChoiceImage:
                    case QuestionTypeEnum.SingleMultipleChoiceText:
                        var qs = (QuestionForSingleMultipleChoice)instance;
                        this.allowOther   = qs.AllowOther.HasValue && qs.AllowOther.Value;
                        this.restrictions = qs.Restrictions;
                        break;
                    }
                }

                this.pageNumber  = instance.PageNumber;
                this.isMandatory = instance.IsMandatory;
            }
        }
コード例 #3
0
        /// <summary>
        /// Get questions from imported file.
        /// </summary>
        /// <param name="fileId">
        /// Imported file id.
        /// </param>
        /// <param name="smiId">
        /// Sub module item id.
        /// </param>
        /// <param name="userId">
        /// The user Id.
        /// </param>
        /// <param name="format">
        /// Questions format.
        /// </param>
        /// <returns>
        /// The <see cref="ServiceResponse"/>.
        /// </returns>
        protected QuestionDTO[] Import(string fileId, int?smiId, int?userId, FormatsEnum format)
        {
            var   questionDtos = new List <QuestionDTO>();
            Error error        = null;

            try
            {
                SubModuleItem subModuleItem = smiId.HasValue
                                                  ? this.SubModuleItemModel.GetOneById(smiId.Value).Value
                                                  : null;
                User   creator    = userId.HasValue ? this.UserModel.GetOneById(userId.Value).Value : null;
                string fileName   = fileId + ".xml";
                string filePath   = Path.Combine(this.ImportPath, fileName);
                string schemaPath = Path.Combine(this.SchemasPath, format + ".xsd");

                if (subModuleItem == null && creator == null)
                {
                    throw new ArgumentException();
                }

                EdugameQuestions questions = this.DeserializeEdugameQuestions(format, filePath, schemaPath);

                QuestionModel   questionModel   = this.QuestionModel;
                DistractorModel distractorModel = this.DistractorModel;

                Func <string, string, File> saveImage = this.GetSaveImageRutine(subModuleItem, creator);

                List <QuestionType> questionTypes = this.QuestionTypeModel.GetAllActive().ToList();

                foreach (EdugameQuestion question in questions.Questions)
                {
                    Question convertedQuestion = EdugameConverter.Convert(question, questionTypes);
                    convertedQuestion.SubModuleItem = subModuleItem;
                    if (convertedQuestion.CreatedBy == null)
                    {
                        convertedQuestion.CreatedBy = subModuleItem.Return(x => x.CreatedBy, creator);
                    }

                    if (convertedQuestion.ModifiedBy == null)
                    {
                        convertedQuestion.ModifiedBy = convertedQuestion.CreatedBy;
                    }

                    File questionImage = saveImage(question.ImageName, question.Image);
                    if (questionImage != null)
                    {
                        convertedQuestion.Image = questionImage;
                    }
                    convertedQuestion.RandomizeAnswers =
                        convertedQuestion.QuestionType.Id == (int)QuestionTypeEnum.Sequence
                            ? (bool?)true
                            : null;

                    if (subModuleItem != null)
                    {
                        questionModel.RegisterSave(convertedQuestion);
                    }

                    QuestionFor customQuestion = this.ProcessCustomQuestionType(convertedQuestion, question);

                    ProcessDistractors(question, convertedQuestion, saveImage, subModuleItem, creator, distractorModel);

                    questionDtos.Add(new QuestionDTO(convertedQuestion, customQuestion));
                }

                System.IO.File.Delete(filePath);
            }
            catch (ArgumentException)
            {
                error = new Error(
                    Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED,
                    ErrorsTexts.ImportError_Subject,
                    ErrorsTexts.ImportError_NoData);
            }
            catch (SerializationException)
            {
                error = new Error(
                    Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED,
                    ErrorsTexts.ImportError_Subject,
                    ErrorsTexts.ImportError_InvalidFormat);
            }
            catch (FileNotFoundException)
            {
                error = new Error(
                    Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED,
                    ErrorsTexts.ImportError_Subject,
                    ErrorsTexts.ImportError_NotFound);
            }
            catch (Exception ex)
            {
                Logger.Error("Import", ex);
                error = new Error(
                    Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED,
                    ErrorsTexts.ImportError_Subject,
                    ErrorsTexts.ImportError_Unknown);
            }

            if (error != null)
            {
                this.LogError("Export.Import", error);
                throw new FaultException <Error>(error, error.errorMessage);
            }

            return(questionDtos.ToArray());
        }