Exemplo n.º 1
0
        /// <summary>
        /// PERHAPS THE MOST IKPORTAN, WHERE QAS ARE GENERATED AND PASSWORDS TOO
        /// </summary>
        /// <param name="exams">         </param>
        /// <param name="pr">            </param>
        /// <param name="questionAnswer"></param>
        /// <returns></returns>
        private static string[] makeQAs(ref IEnumerable <ExamsRow> exams, ref PreferencesRow pr, out IList <string[]> questionAnswer)
        {
            bool   showPoints  = pr.showPoints;
            double pointFactor = pr.Factor;

            questionAnswer = new List <string[]>();

            int pregunta   = 1;
            int claveCount = 1;

            string Clave;
            string questionWeight;
            string qidString;

            Clave          = string.Empty;
            questionWeight = string.Empty;
            qidString      = string.Empty;

            foreach (DataRow row in exams)
            {
                string[] qAns   = new string[2];
                ExamsRow r      = (ExamsRow)row;
                string   examen = string.Empty;

                examen  = ExtractQuestionAndWeight(ref questionWeight, ref qidString, ref pregunta, showPoints, pointFactor, ref r);
                qAns[0] = examen;

                string[] answers = ExtractAnswersArray(ref r);

                examen  = ExtractAnswers(answers, ref r);
                qAns[1] = examen;

                ExtractKey(ref Clave, ref claveCount, answers, ref r);

                questionAnswer.Add(qAns);
            }

            if (qidString[qidString.Length - 1].Equals(SEP))
            {
                qidString = qidString.Substring(0, qidString.Length - 1); //erase last separator
            }

            if (questionWeight[questionWeight.Length - 1].Equals(SEP))
            {
                questionWeight = questionWeight.Substring(0, questionWeight.Length - 1); //erase last separator
            }

            questionWeight += SEP2.ToString() + pointFactor.ToString(); //KEEP THE FACTOR IN THE STRING!!!

            if (Clave[Clave.Length - 1].Equals(SEP))
            {
                Clave = Clave.Substring(0, Clave.Length - 1); //erase last separator
            }

            ///IMPORTANT CUMJULATIVE INFO
            return(new string[3] {
                Clave, questionWeight, qidString
            });                                                        // LAnswer , LQuestion,
        }
Exemplo n.º 2
0
        private static void FindFactor(ref PreferencesRow p, ref ExamsListRow ls)
        {
            ExamsRow[] arr      = ls.GetExamsRows();
            double     sumPoint = arr.Sum(o => o.QuestionsRow.Weight);
            double     factor   = Convert.ToDouble(p.Points);

            factor  /= (sumPoint);
            p.Factor = factor;
            arr      = null;
        }
Exemplo n.º 3
0
        private static void doOneEncriptExam(ref PreferencesRow p, ref ExamsListRow ls, out IList <string[]> questionAnswer, string password)
        {
            IEnumerable <DB.ExamsRow> join = ls.GetExamsRows();

            string[] ClaveWQID = null;

            ClaveWQID    = makeQAs(ref join, ref p, out questionAnswer);
            ls.LQuestion = ClaveWQID[1];                                                                     // question weight string
            string LAnswer   = ClaveWQID[0];                                                                 //clave verdadera sin encriptar
            string QIDString = ClaveWQID[2];                                                                 //secuencia de preguntas, importante guardar

            ls.CLAnswer   = Rsx.Encryption.AESThenHMAC.SimpleEncryptWithPassword(LAnswer, password, null);   //encripta
            ls.CQIDString = Rsx.Encryption.AESThenHMAC.SimpleEncryptWithPassword(QIDString, password, null); //encripta
        }
Exemplo n.º 4
0
Arquivo: DB.cs Projeto: hnjm/Exam
        public ExamsListRow AddExam(ref PreferencesRow p)
        {
            ExamsListRow ls = ExamsList.NewExamsListRow();

            ExamsList.AddExamsListRow(ls);
            Guid g = Guid.NewGuid();

            ls.PID = p.PID;
            ////MAKES THE DOC FILE
            ls.GUID  = g.ToString().Replace("-", null);//.Split('-')[4];
            ls.Time  = DateTime.Now;
            ls.Class = p.Class;
            return(ls);
        }
Exemplo n.º 5
0
        private static void updatePreferenceAndClone(ref PreferencesRow p)
        {
            // p.EndEdit();
            // p.Class = materiaBox.Text;
            p.DateTime = DateTime.Now;
            // p.AYearID = ayearID;
            p.Year = p.DateTime.Year;

            DB.TAM.PreferencesTableAdapter.Update(p);
            PreferencesRow clone = Tables.CloneARow(p.Table, p) as DB.PreferencesRow;

            p      = clone;
            p.Done = true;
            DB.TAM.PreferencesTableAdapter.Update(p);
        }
Exemplo n.º 6
0
        private void doOneDocExam(ref PreferencesRow p, ref ExamsListRow ls, ref IList <string[]> questionAnswer)
        {
            string filepathAux = examsPath + model + ls.GUID;

            string CryptoGUID = Rsx.Encryption.AESThenHMAC.SimpleEncryptWithPassword(ls.GUID, inter.Password, null);

            //     string jpgQRCodeFile = filepathAux + JPG_EXT;

            Image img = Tools.CreateQRCode(CryptoGUID, qrSise);

            img.Save(filepathAux + JPG_EXT);
            img.Dispose();

            //    string destFile = filepathAux + WORD_EXT;

            ///MAKE WORD DOCUMENT
            ///
            File.Copy(templateFile, filepathAux + WORD_EXT);

            string title      = p.Title + " (" + p.Class + ")";
            bool   showAnswer = p.showAnswer;
            string pass       = inter.Password;

            object doc = Generator.MakeDOC(ref ls, ref questionAnswer, filepathAux, title, showAnswer, pass);

            inter.Status = Resources.ExamenCreado;

            bool close = true;
            bool quit  = true;

            Generator.MakePDF(ref doc, close, quit);

            Byte[] rtf = IO.ReadFileBytes(filepathAux + PDF_EXT);
            ls.ExamFile = rtf; //salva una copia del archivo PDF en el servidor SQL
            DB.TAM.ExamsListTableAdapter.Update(ls);

            inter.Status = Resources.ExamenCreadoPDF;


            File.Delete(filepathAux + PDF_EXT);

            File.Delete(filepathAux + WORD_EXT);

            File.Delete(filepathAux + JPG_EXT);
        }
Exemplo n.º 7
0
        private static IList <ExamsRow> weightThem(ref PreferencesRow p, ref IList <ExamsRow> exams)
        {
            exams = exams.OrderBy(o => o.QuestionsRow.Weight).ToList();

            int multiplier = 10000;

            IList <ExamsRow>      rows = exams.ToList();
            Func <ExamsRow, bool> MID  = ex =>
            {
                ex.MID  = (ex.QuestionsRow.Weight * multiplier);
                ex.MID += rows.IndexOf(ex);
                return(true);
            };

            exams = exams.Where(MID).ToList();

            rows = null;

            /*
             * foreach (DB.ExamsRow ex in exams)
             * {
             *  ex.MID = (ex.QuestionsRow.Weight * multiplier);
             *  ex.MID += exams.IndexOf(ex);
             * }
             */

            ///FILTER ACCORDING TO PREFERENCES

            exams = exams.OrderBy(o => o.MID).ToList();

            IList <ExamsRow> join = null;

            join = GetByWeight(ref exams, multiplier, ref p);

            // else join = exams.ToList();
            return(join);
        }
Exemplo n.º 8
0
        public void DoExams()
        {
            PreferencesRow p = inter.IBS.CurrentPreference;

            inter.IBS.Working = true;

            updatePreferenceAndClone(ref p);

            inter.IBS.Working = false;

            inter.IBS.LogPref.Position = inter.IBS.LogPref.Find(inter.IdB.Preferences.PIDColumn.ColumnName, p.PID);

            inter.IBS.Working = true;


            inter.Status = "Empezando...";

            FillClassDataBase(p.Class);

            // inter.IBS.LogPref.MoveFirst(); //select item to clone Application.DoEvents();

            inter.ProgressHandler?.Invoke(p.Models, EventArgs.Empty);

            int mod = 0; //models

            for (mod = 0; mod < p.Models; mod++)
            {
                inter.IdB.Exams.Clear();

                inter.ProgressHandler?.Invoke(0, EventArgs.Empty);

                ExamsListRow ls = doOneExam(ref p);
                if (ls == null)
                {
                    continue;
                }

                inter.ProgressHandler?.Invoke(0, EventArgs.Empty);

                Generator.FindFactor(ref p, ref ls);


                ////ENCRIPTAMIENTOOOOOOO
                inter.Status = "Procesando examen...";

                IList <string[]> questionAnswer;
                doOneEncriptExam(ref p, ref ls, out questionAnswer, inter.Password);
                //SAVE COPY OF TABLE in EXAMLIST

                Generator.MakeTableBytes(ref ls, examsPath);

                DB.TAM.ExamsListTableAdapter.Update(inter.IdB.ExamsList);

                inter.ProgressHandler?.Invoke(0, EventArgs.Empty);
                inter.Status = Resources.Creando + "el examen " + ls.GUID;

                doOneDocExam(ref p, ref ls, ref questionAnswer);

                inter.Status = "Examen generado";
                inter.ProgressHandler?.Invoke(0, EventArgs.Empty);
            }

            Generator.MakeTableBytes(ref p, examsPath);

            int count = p.GetExamsListRows().Count();

            if (count != 0)
            {
                inter.Status = count + " Modelos generados";
            }

            DB.TAM.PreferencesTableAdapter.Update(p);


            inter.IdB.Exams.Clear();

            inter.IBS.Working = false;
        }
Exemplo n.º 9
0
        /// <summary>
        /// MAIN FILE FOR GENERATING AN EXAM
        /// </summary>
        /// <param name="p"></param>
        private ExamsListRow doOneExam(ref PreferencesRow p)
        {
            inter.Status = Resources.Creando + inter.IdB.Questions.Count + Resources.PregAleatorias;

            Func <DB.QuestionsRow, bool> selector = x =>
            {
                bool?ok = x.TopicsRow?.UseIt;
                if (ok == null)
                {
                    ok = false;
                }
                return((bool)ok);
            };
            ///RANDOMNIZE RAW QUESTIONS
            IEnumerable <DB.QuestionsRow> questions = inter.IdB.Questions.Where(selector).ToArray(); //toma todas las preguntas

            if (questions.Count() == 0)
            {
                inter.Status = "No hay preguntas seleccionadas";
                return(null);
            }

            int times = 3;

            questions = Tools.RandomnizeStringsTimes(questions, times);

            IList <ExamsRow> exams = new List <ExamsRow>(); //todas las preguntas randomnizadas seran guardadas primero en esta lista

            foreach (QuestionsRow q in questions)
            {
                ExamsRow er = inter.IdB.Exams.NewExamsRow(); //crea rows pero no los metas en la tabla
                er.QID = q.QID;                              //dales el id de la pregunta
                exams.Add(er);                               //agregalos a la lista
            }

            inter.Status = Resources.Filtrando;

            IEnumerable <ExamsRow> join = weightThem(ref p, ref exams); //not re-ordered // preguntas seleccionadas y filtradas

            Application.DoEvents();

            inter.Status = Resources.OrderAleatorio; // de las preguntas del examen ya pesadas (filtradaS)

            join = Tools.RandomnizeStringsTimes(join, times);

            inter.Status = Resources.Seleccionando + join.Count() + Resources.PregAleatorias;
            Application.DoEvents();

            foreach (ExamsRow ex in join)
            {
                inter.IdB.Exams.AddExamsRow(ex); //agregalas a la tabla para salvarlas

                DB.QuestionsRow          q    = ex.QuestionsRow;
                IEnumerable <AnswersRow> answ = q.GetAnswersRows();
                ///RANDOMIZE RAW ASWERS
                answ = Tools.RandomnizeStringsTimes(answ, times);
                //CREATE EXAM QUESTION CODE! AIDSTRING
                string code = CreateExamQuestionCode(ref answ);
                ex.AIDString = code;
                ExamsRow auxiliar = ex;
                MakeTableBytes(ref auxiliar, examsPath);
            }

            DB.TAM.ExamsTableAdapter.Update(inter.IdB.Exams);
            Application.DoEvents();

            ExamsListRow ls = inter.IdB.AddExam(ref p);

            // Image img = Tools.CreateQRCode(ls.GUID, qrSizeDB); ls.QRCode = Tools.imageToByteArray(img);
            DB.TAM.ExamsListTableAdapter.Update(inter.IdB.ExamsList);
            Application.DoEvents();
            //este orden es importante

            foreach (DB.ExamsRow re in join)
            {
                re.EID = ls.EID;                              //ahora asocia las preguntas a cada examen generado
            }
            DB.TAM.ExamsTableAdapter.Update(inter.IdB.Exams);
            Application.DoEvents();

            return(ls);
        }
Exemplo n.º 10
0
 public PreferencesRowChangeEvent(PreferencesRow row, global::System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }
Exemplo n.º 11
0
 public void RemovePreferencesRow(PreferencesRow row) {
     this.Rows.Remove(row);
 }
Exemplo n.º 12
0
 public void AddPreferencesRow(PreferencesRow row) {
     this.Rows.Add(row);
 }
Exemplo n.º 13
0
        private static void MakeTableBytes <T>(ref T l, string examPath)
        {
            Type tipo = l.GetType();

            byte[] arr2 = null;
            // string afile = string.Empty;

            if (tipo.Equals(typeof(ExamsListRow)))
            {
                ExamsListRow ls = l as ExamsListRow;

                IEnumerable <ExamsRow> rows = ls.GetExamsRows();

                ExamsDataTable exdt = new ExamsDataTable();
                foreach (var item in rows)
                {
                    exdt.ImportRow(item);
                }

                // afile = ExasmPath + ls.EID.ToString();

                arr2     = Tables.MakeDTBytes(ref exdt, examPath);
                ls.EData = arr2;
            }
            else if (tipo.Equals(typeof(ExamsRow)))
            {
                //SAVE COPY OF TABLE

                ExamsRow     ex = l as ExamsRow;
                QuestionsRow q  = ex.QuestionsRow;
                // afile = ExasmPath + ex.QID.ToString(); IEnumerable<DB.QuestionsRow> shortQlist =
                // new List<DB.QuestionsRow>(); ((IList<DB.QuestionsRow>)shortQlist).Add(ex.QuestionsRow);
                QuestionsDataTable qdt = new QuestionsDataTable();
                qdt.ImportRow(q);
                byte[] qarray = Tables.MakeDTBytes(ref qdt, examPath);
                ex.QData = qarray;
                Dumb.FD(ref qdt);

                AnswersDataTable         adt  = new AnswersDataTable();
                IEnumerable <AnswersRow> answ = q.GetAnswersRows();
                foreach (var item in answ)
                {
                    adt.ImportRow(item);
                }
                // afile = ExasmPath + ex.QueToString() + ".xml";
                arr2     = Tables.MakeDTBytes(ref adt, examPath);
                ex.AData = arr2;
                Dumb.FD(ref adt);
            }
            else if (tipo.Equals(typeof(PreferencesRow)))
            {
                PreferencesRow p = l as PreferencesRow;              //SAVE A COPY OF EXAMS LISTS
                IEnumerable <DB.ExamsListRow> rows = p.GetExamsListRows();

                ExamsListDataTable dt = new ExamsListDataTable();
                foreach (var item in rows)
                {
                    dt.ImportRow(item);
                }

                // afile = ExasmPath + p.PID.ToString() + ".xml";
                arr2     = Tables.MakeDTBytes(ref dt, examPath);
                p.ELData = arr2;

                Dumb.FD(ref dt);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// gets the questions that satisfy a given weight, based on the ExamRow.MID tag
        /// </summary>
        /// <param name="count">     how many questions to add from a given weight</param>
        /// <param name="exams">     a raw list of questions to weight in</param>
        /// <param name="multiplier">the factor to set MID range to search for</param>
        /// <param name="weight">    the weight</param>
        /// <returns>The weighted questions</returns>
        private static IList <ExamsRow> GetByWeight(ref IList <ExamsRow> exams, int multiplier, ref PreferencesRow p)
        {
            int min = 0;
            int max = 0;

            int howMany;
            List <DB.ExamsRow> join = new List <DB.ExamsRow>(); //the array that will contain the weighted questions;

            for (int x = 1; x <= 5; x++)
            {
                min = 0;
                min = x * multiplier;

                max = 0;
                max = (x + 1) * multiplier;

                howMany = 0;               //initialize
                howMany = (int)p["D" + x]; // questions to add from preferences

                IEnumerable <DB.ExamsRow> rows = exams.Where(o => o.MID >= min && o.MID <= max).Take(howMany);

                join.AddRange(rows);
            }

            return(join);
        }