Beispiel #1
0
 public AnswerService(IAnswerRepository answerRepository,
                      IForumTopicRepository forumTopicRepository)
 {
     _answerRepository     = answerRepository;
     _forumTopicRepository = forumTopicRepository;
     _answerFactory        = new AnswerFactory();
 }
Beispiel #2
0
        public QuestionService(IDbContext dbContext)
        {
            _answerFactory   = new AnswerFactory();
            _questionFactory = new QuestionFactory();


            _answerRepository   = new AnswerRepository(dbContext);
            _questionRepository = new QuestionRepository(dbContext);
        }
Beispiel #3
0
        public Yw_StudentWrongSubjectExt MakeTranslator(Yw_StudentWrongSubject entity)
        {
            Yw_StudentWrongSubjectExt realEntity = entity.ConvertTo <Yw_StudentWrongSubjectExt>();

            if (!string.IsNullOrEmpty(entity.Yws_StudentAnswer))
            {
                realEntity.Yws_Answer_Obj = AnswerFactory.ConvertByType((SubjectTypeEnum)entity.Yws_SubjectType, entity.Yws_StudentAnswer);
            }
            return(realEntity);
        }
        /// <summary>
        /// Get a list of answers for the given question
        /// </summary>
        /// <param name="questionId">question which is owning the answers</param>
        /// <returns></returns>
        public AnswerData GetAnswersList(int questionId)
        {
            AnswerData answersList = AnswerFactory.Create().GetAnswersList(questionId);

            foreach (AnswerData.AnswersRow row in answersList.Answers)
            {
                row.AnswerText = Regex.Replace(row.AnswerText, "<[^>]*>", " ");
            }
            return(answersList);
        }
        /// <summary>
        /// Get all answers and randomize them
        /// </summary>
        /// <param name="questionId">question which is owning the answers</param>
        /// <param name="randomSeed"></param>
        /// <returns></returns>
        public AnswerData GetRandomAnswers(int questionId, int randomSeed, string languageCode)
        {
            Random     random  = new Random(randomSeed);
            AnswerData answers = AnswerFactory.Create().GetAnswers(questionId, languageCode);

            answers.EnforceConstraints = false;
            for (int i = 0; i < answers.Answers.Rows.Count; i++)
            {
                int index = random.Next(0, answers.Answers.Rows.Count - 1);
                answers.Answers.Rows.Add(answers.Answers.Rows[index].ItemArray);
                answers.Answers.Rows.RemoveAt(index);
            }
            answers.EnforceConstraints = true;
            return(answers);
        }
Beispiel #6
0
 public bool AddCollection(string name, object type)
 {
     try
     {
         var info    = Reflector.GetCollectionInfo(name, type);
         var command = CommandFactory.GetCommand(Commands.AddNewCollection, info, name);
         _transport.SendMessage(command);
         var answer = _transport.GetAnswer();
         return(AnswerFactory.IsOk(answer));
     }
     catch (Exception e)
     {
         throw new Exception($"DataWellClient AddCollection Error: {e.Message}");
     }
 }
Beispiel #7
0
        /// <summary>
        /// Handler for reading bytes from connection
        /// </summary>
        private void DataReceivedHandler()
        {
            int readlenght = SerialPortConnection.BytesToRead;

            byte[] read = new byte[readlenght];
            if (readlenght > 0)
            {
                SerialPortConnection.Read(ref read, 0, readlenght);
                LastAnswer = AnswerFactory.CreateNew(read);
                if (LastAnswer != null && (LastAnswer as AnswerBase).IsBroadCast)
                {
                    ProcessBroadCast();
                }
            }
        }
Beispiel #8
0
 public DataWellInfo GetInfo()
 {
     try
     {
         var command = CommandFactory.GetCommand(Commands.GetInfo);
         _transport.SendMessage(command);
         var answer = _transport.GetAnswer();
         if (AnswerFactory.CheckAnswerType(AnswerTypes.Info, answer))
         {
             var objAnswer = JsonConvert.DeserializeObject <DataWellInfoAnswer>(answer);
             var result    = objAnswer.DataWellInfo;
             return(result);
         }
         else
         {
             throw new Exception($"Answer Type Error");
         }
     }
     catch (Exception e)
     {
         throw new Exception($"DataWellClient GetInfo Error: {e.Message}");
     }
 }
 /// <summary>
 /// Update the matrix column in the database
 /// </summary>
 /// <param name="updatedAnswer">Answer to update, must specify the answer id</param>
 public void UpdateMatrixAnswer(AnswerData updatedAnswer, string languageCode)
 {
     AnswerFactory.Create().UpdateMatrixAnswer(updatedAnswer, languageCode);
 }
 /// <summary>
 /// Unsubscribe from the given answer publisher
 /// </summary>
 public void UnSubscribeFromPublisher(int publisherAnswerId, int subscriberAnswerId)
 {
     AnswerFactory.Create().UnSubscribeFromPublisher(publisherAnswerId, subscriberAnswerId);
 }
 /// <summary>
 /// Subscribe to a new answer publisher
 /// </summary>
 public void SubscribeToPublisher(int publisherAnswerId, int subscriberAnswerId)
 {
     AnswerFactory.Create().SubscribeToPublisher(publisherAnswerId, subscriberAnswerId);
 }
 /// <summary>
 /// Stores properties in the database
 /// </summary>
 public void StoreAnswerProperties(int answerId, byte[] properties)
 {
     AnswerFactory.Create().StoreAnswerProperties(answerId, properties);
 }
 /// <summary>
 /// Get all answers for a given question
 /// </summary>
 /// <param name="questionId">question which is owning the answers</param>
 /// <param name="languageId">Language in which to return the answers, -1 act as the default language</param>
 /// <returns></returns>
 public AnswerData GetAnswers(int questionId, string languageCode)
 {
     return(AnswerFactory.Create().GetAnswers(questionId, languageCode));
 }
 /// <summary>
 /// Restores properties in the database
 /// </summary>
 public byte[] RestoreAnswerProperties(int answerId)
 {
     return(AnswerFactory.Create().RestoreAnswerProperties(answerId));
 }
Beispiel #15
0
        public string Handle(string message)
        {
            try
            {
                var result      = string.Empty;
                var baseCommand = JsonConvert.DeserializeObject <BaseCommand>(message);
                switch (baseCommand.CommandName)
                {
                case Commands.AddNewCollection:
                {
                    var addCommand    = JsonConvert.DeserializeObject <AddNewCollectionCommand>(message);
                    var commandResult = DataEnvironment.MemStorage.AddCollection(addCommand.CollectionInfo);
                    return(commandResult ? JsonConvert.SerializeObject(new OkAnswer()) : JsonConvert.SerializeObject(new ErrorAnswer()));
                }
                break;

                case Commands.AddNewDataItem:
                {
                    var addItemCommand = JsonConvert.DeserializeObject <AddNewDataItemCommand>(message);
                    DataEnvironment.MemStorage.AddDataItem(addItemCommand.DataItem, addItemCommand.Collection);
                }
                break;

                case Commands.AddNewDataItems:
                {
                    var addItemsCommand = JsonConvert.DeserializeObject <AddNewDataItemsCommand>(message);
                    DataEnvironment.MemStorage.AddDataItems(addItemsCommand.DataItems, addItemsCommand.Collection);
                }
                break;

                case Commands.GetItem:
                {
                    var getItemCommand = JsonConvert.DeserializeObject <GetItemCommand>(message);
                    var dataItem       = DataEnvironment.MemStorage.GetItem(getItemCommand.Collection, getItemCommand.DWID);
                    var answer         = AnswerFactory.GetDataItemAnswer(dataItem);
                    result = JsonConvert.SerializeObject(answer);
                }
                break;

                case Commands.GetAll:
                {
                    var getAllCommand = JsonConvert.DeserializeObject <GetAllItemsCommand>(message);
                    var dataItems     = DataEnvironment.MemStorage.GetAll(getAllCommand.Collection);
                    var answerList    = AnswerFactory.GetDataItemsAnswer(dataItems);
                    result = JsonConvert.SerializeObject(answerList);
                }
                break;

                case Commands.Filter:
                {
                    var filterCommand      = JsonConvert.DeserializeObject <FilterCommand>(message);
                    var dataFilteredItems  = DataEnvironment.MemStorage.GetFilteredItems(filterCommand.Collection, filterCommand.FilterParameters);
                    var answerFilteredList = AnswerFactory.GetDataItemsAnswer(dataFilteredItems);
                    result = JsonConvert.SerializeObject(answerFilteredList);
                }
                break;

                case Commands.RemoveItem:
                {
                    var command = JsonConvert.DeserializeObject <RemoveItemCommand>(message);
                    DataEnvironment.MemStorage.RemoveItem(command.Collection, command.DWID);
                }
                break;

                case Commands.UpdateItem:
                {
                    var command = JsonConvert.DeserializeObject <UpdateItemCommand>(message);
                    DataEnvironment.MemStorage.UpdateItem(command.Collection, command.DataItem);
                }
                break;

                case Commands.RemoveCollection:
                {
                    var command = JsonConvert.DeserializeObject <RemoveCollectionCommand>(message);
                    DataEnvironment.MemStorage.RemoveCollection(command.Collection);
                }
                break;

                case Commands.GetInfo:
                {
                    var command       = JsonConvert.DeserializeObject <GetInfoCommand>(message);
                    var obj           = DataEnvironment.MemStorage.GetInfo();
                    var answerGetInfo = AnswerFactory.GetDataWellInfoAnswer(obj);
                    result = JsonConvert.SerializeObject(answerGetInfo);
                }
                break;

                default: break;
                }

                return(result);
            }
            catch (Exception e)
            {
                throw new Exception($"DataWellServer Handle Error: {e.Message}");
            }
        }
 /// <summary>
 /// Deletes the persisted answer properties from the DB
 /// </summary>
 public void DeleteAnswerProperties(int answerId)
 {
     AnswerFactory.Create().DeleteAnswerProperties(answerId);
 }
 /// <summary>
 /// Adds a new answer to the matrix question specified by the question id property in the database
 /// </summary>
 /// <param name="newAnswer">Answer object with information about what to add. Only Id must be ommited</param>
 public void AddMatrixAnswer(AnswerData newAnswer)
 {
     AnswerFactory.Create().AddMatrixAnswer(newAnswer);
 }
 /// <summary>
 /// Return an answer object that reflects the database answer
 /// </summary>
 /// <param name="answeriD">Id of the answer you need</param>
 /// <returns>An answer object with the current database values</returns>
 public AnswerData GetAnswerById(int answerId, string languageCode)
 {
     return(AnswerFactory.Create().GetAnswerById(answerId, languageCode));
 }
 /// <summary>
 /// Get a list of all files associated with this guidto
 /// </summary>
 public FileData GetGuidFiles(string groupGuid)
 {
     return(AnswerFactory.Create().GetGuidFiles(groupGuid));
 }
 /// <summary>
 /// returns the type mode of the answer
 /// </summary>
 public int GetAnswerTypeMode(int answerId)
 {
     return(AnswerFactory.Create().GetAnswerTypeMode(answerId));
 }
 /// <summary>
 /// Return the total score of the given answers
 /// </summary>
 /// <param name="answersIdValues">CSV of answer ids to get the total score from</param>
 /// <returns></returns>
 public int GetAnswersScoreTotal(string answersIdValues)
 {
     return(AnswerFactory.Create().GetAnswersScoreTotal(answersIdValues));
 }
 /// <summary>
 /// Get the count of files in a group
 /// </summary>
 public int GetAnswerFileCount(string groupGuid)
 {
     return(AnswerFactory.Create().GetAnswerFileCount(groupGuid));
 }
 /// <summary>
 /// delete all file data
 /// </summary>
 public void DeleteAnswerFile(int fileId, string groupGuid)
 {
     AnswerFactory.Create().DeleteAnswerFile(fileId, groupGuid);
 }
Beispiel #24
0
 public void CreateAnswer(AnswerEdit model)
 {
     _repo.Add(AnswerFactory.CreateAnswerFromAnswerEdit(model));
 }
 /// <summary>
 /// Remove one answer column of the matrix from the database
 /// </summary>
 /// <param name="answerId">Answer column to delete from the database</param>
 public void DeleteMatrixAnswer(int answerId)
 {
     AnswerFactory.Create().DeleteMatrixAnswer(answerId);
 }
 /// <summary>
 /// Returns all the files that have already been validated
 /// </summary>
 public FileData GetValidatedFileAnswers(int surveyId, int pageNumber, int pageSize, out int totalRecords)
 {
     return(AnswerFactory.Create().GetValidatedFileAnswers(surveyId, pageNumber, pageSize, out totalRecords));
 }
 /// <summary>
 /// Moves up the answer's display position
 /// </summary>
 /// <param name="answerId"></param>
 public void MoveAnswerUp(int answerId)
 {
     AnswerFactory.Create().MoveAnswerUp(answerId);
 }
 /// <summary>
 /// Stores a file in the database
 /// </summary>
 public int StoreAnswerFile(string groupGuid, string fileName, int fileSize, string fileType, byte[] fileData, int uploadedFileTimeOut, int sessionUploadedFileTimeOut)
 {
     return(AnswerFactory.Create().StoreAnswerFile(groupGuid, fileName, fileSize, fileType, fileData, uploadedFileTimeOut, sessionUploadedFileTimeOut));
 }
 public InspectionController(IQuestionnaireService questionnaireService, AnswerFactory answerFactory)
 {
     _questionnaireService = questionnaireService;
     _answerFactory        = answerFactory;
 }
 /// <summary>
 /// Get the binarie data of the file
 /// </summary>
 public byte[] GetAnswerFileData(int fileId, string groupGuid)
 {
     return(AnswerFactory.Create().GetAnswerFileData(fileId, groupGuid));
 }