static void TempTest()
        {
            using (var ctx = new ComplianceFactorsEntities())
            {
                //var curriculum_path_courses = ctx.c_tb_curriculum_path_courses.;
                string queryString =
                    @"select VALUE e_tb_curricula_assign FROM e_tb_curricula_assign where e_tb_curricula_assign.e_curriculum_assign_curriculum_id_fk in 
                                                set(select VALUE (c_tb_curriculum_path_courses.c_curricula_id_fk) from c_tb_curriculum_path_courses 
                                                    where c_tb_curriculum_path_courses.c_curricula_path_course_id_fk = @courseid) 
                                                and e_tb_curricula_assign.e_curriculum_assign_user_id_fk = @userid";
                Guid course_id = Guid.Parse("d18e9bc8-4cca-4770-8bb7-010504e341d5");
                Guid user_id   = Guid.Parse("48433026-7d99-4cc1-ade7-09b23b1bc5ef");

                ObjectQuery <e_tb_curricula_assign> assignedCurricula =
                    ctx.CreateQuery <e_tb_curricula_assign>(queryString, new ObjectParameter[]
                {
                    new ObjectParameter("courseid", course_id),
                    new ObjectParameter("userid", user_id)
                });

                //if (assignedCurricula.)

                // Iterate through the collection.
                foreach (e_tb_curricula_assign curriculum in assignedCurricula)
                {
                    Console.WriteLine("pk: {0}, uid: {1}, curr_id: {2}, assign_date: {3}",
                                      curriculum.e_curriculum_assign_system_id_pk,
                                      curriculum.e_curriculum_assign_user_id_fk,
                                      curriculum.e_curriculum_assign_curriculum_id_fk,
                                      curriculum.e_curriculum_assign_date_time);
                }
            }
        }
        private static void AuditTest()
        {
            Dictionary <string, string> json = new Dictionary <string, string>();

            json.Add("cmi.core.lesson_location", "end");
            json.Add("cmi.core.credit", "credit");
            json.Add("cmi.core.lesson_status", "attempted");
            json.Add("cmi.core.score.raw", "8.5");
            json.Add("cmi.core.score.min", "0");
            json.Add("cmi.core.score.max", "10");
            json.Add("cmi.core.session_time", "00:47:00");
            json.Add("cmi.core.total_time", "1:23:00");
            json.Add("cmi.core.lesson_mode", "normal");
            json.Add("cmi.student_data.mastery_score", "8");
            json.Add("cmi.suspend_data",
                     "9 00 001010101100110\r\n000 001010101100110\r\n000001010101100110\r\ngl’;sdfgl’;sdfhgl’;sdfhgls’;df");
            json.Add("cmi.comments",
                     "<1>The background color is too blue!<1.e><2>The CDU\r\npanel has the incorrect ‘way points’ displayed for\r\nthis route. <2.e><3>The CDU panel has the incorrect\r\n‘way points’ displayed for this route. <3.e><4>The\r\nCDU panel has the incorrect ‘way points’ displayed\r\nfor this route. <e.4>");
            json.Add("cmi.terminate", "true");

            HACP_Logic hacp_logic = new HACP_Logic();

            hacp_logic.ConsumeJSObj(json);
            // use same method as in JS API, since the HACP parser returns a flattened dict with the same data model (and names) as JS API

            string enrollment_id = "71dc1b30-b013-4848-9155-17ae45330ca3";

            using (var ctx = new ComplianceFactorsEntities())
            {
                var enroll = (from en in ctx.e_tb_enrollments
                              where en.e_enroll_system_id_pk == new Guid(enrollment_id)
                              select en).FirstOrDefault();

                int?total_time = enroll.e_enroll_time_spent;

                hacp_logic.ConsumeJSObj(json);

                hacp_logic.Persist(enrollment_id);

                ctx.Refresh(System.Data.Objects.RefreshMode.StoreWins, enroll);

                var eid = Guid.Parse(enrollment_id);
                // check audit table, get last record with object_id_fk matching enrollment_id
                var a = (from audit in ctx.a_tb_audit_log
                         where audit.a_affected_object_id_fk == eid &&
                         audit.a_action_desc == "Marked Completion / Type (OLT Player)"
                         orderby audit.a_date_time descending
                         select audit).FirstOrDefault();
                Debug.Assert(a != null);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string command   = Request.Params["command"];
            string sessionid = Request.Params["session_id"];
            string aiccdata  = Request.Params["aicc_data"];

            Dictionary <string, string> parsed_dictionary = null;
            HACP_Parser hacpParser = new HACP_Parser();
            HACP_Logic  hacp       = new HACP_Logic();

            if (String.IsNullOrEmpty(command))
            {
                sendOutput(error_invalid_command);
            }
            if (String.IsNullOrEmpty(sessionid))
            {
                sendOutput(error_invalid_session_id);
            }

            switch (command.ToLower())
            {
            case "getparam":
                using (ComplianceFactorsEntities context = new ComplianceFactorsEntities())
                {
                    var enroll = (from en in context.e_tb_enrollments
                                  where en.e_enroll_system_id_pk == new Guid(sessionid)
                                  select en).FirstOrDefault();

                    if (enroll == null)     //no record found, invalid eid
                    {
                        sendOutput(error_invalid_session_id);
                    }

                    student_id   = enroll.e_enroll_user_id_fk.ToString();
                    student_name = enroll.u_tb_users_master.u_last_name + ", "
                                   + enroll.u_tb_users_master.u_first_name
                                   + " " + enroll.u_tb_users_master.u_middle_name;
                    lesson_location = enroll.e_enroll_lesson_location ?? "";
                    credit          = ((bool)(enroll.e_enroll_credit ?? true)) ? "credit" : "no-credit";

                    // Status
                    //  account for null/empty value
                    if (String.IsNullOrEmpty(enroll.e_enroll_lesson_status))
                    {
                        lesson_status = "not attempted";
                    }
                    // set status to 'incomplete'
                    if (enroll.e_enroll_lesson_status == "not attempted")
                    {
                        lesson_status = "incomplete";
                    }


                    vExit = enroll.e_enroll_exit;
                    if (vExit == "time-out" || vExit == "logout" || String.IsNullOrEmpty(vExit))
                    {
                        vEntry = "";
                    }
                    else if (vExit == "suspend")
                    {
                        vEntry = "resume";
                        //enroll.e_enroll_entry = true;
                    }
                    else
                    {
                        vEntry = "ab-initio";
                        //enroll.e_enroll_entry = false;
                    }

                    //vEntry = ((bool)(enroll.e_enroll_entry ?? false)) ? "resume" : "ab-initio"; // ab-initio, resume, or ""->neither of the former
                    suspend_data = enroll.e_enroll_suspend_data ?? "";
                    launch_data  = enroll.e_enroll_launch_data ?? "";

                    score_raw = Convert.ToString(enroll.e_enroll_score);
                    score_max = Convert.ToString(enroll.e_enroll_score_max);
                    score_min = Convert.ToString(enroll.e_enroll_score_min);

                    lesson_mode = (enroll.e_enroll_lesson_mode ?? "normal");     //for now...
                    total_time  = TimeSpan.FromSeconds((double)(enroll.e_enroll_time_spent ?? 0)).ToString(@"hh\:mm\:ss");

                    //context.SaveChanges();
                }

                responseString += no_error_output + "aicc_data=";
                responseString += "[Core]\r\n";
                responseString += "Student_ID=" + student_id + "\r\n";
                responseString += "Student_Name=" + student_name + "\r\n";
                responseString += "Lesson_Location=" + lesson_location + "\r\n";
                responseString += "Credit=" + credit + "\r\n";
                responseString += "Lesson_Status=" + lesson_status + ", " + vExit + "\r\n";;

                var score = score_raw;
                if (!String.IsNullOrEmpty(score_max))
                {
                    score += ", " + score_max;
                }
                if (!String.IsNullOrEmpty(score_min))
                {
                    score += ", " + score_min;
                }
                responseString += "Score=" + score + "\r\n";

                responseString += "Time=" + total_time + "\r\n";
                responseString += "Lesson_Mode=" + lesson_mode + "\r\n";
                responseString += "[Core_Lesson]\r\n";
                if (suspend_data != "")
                {
                    responseString += suspend_data + "\r\n";
                }
                responseString += "[Core_Vendor]\r\n" + launch_data + "\r\n";

                /*
                 * "[Evaluation]\r\nCourse_ID = {".."}\r\n";
                 * "[Student_Data]\r\n";
                 * 'Mastery_Score='.."\r\n";
                 * 'Max_Time_Allowed='.."\r\n";
                 * 'Time_Limit_Action='.."\r\n";
                 */

                sendOutput(responseString);

                break;

            case "putparam":
                //save passed parameters

                //parse putparam
                parsed_dictionary = hacpParser.parsePutParam(sessionid, HttpUtility.UrlDecode(aiccdata));
                parsed_dictionary.Add("cmi.terminate", "false");

                //persist values...
                hacp.ConsumeJSObj(parsed_dictionary);
                hacp.Persist(sessionid);

                sendOutput(no_error_output);

                break;

            case "putcomments":
                // parse CSV
                break;


            case "putinteractions":
                // parse CSV
                break;

            case "exitau":
                //parse putparam
                parsed_dictionary = hacpParser.parsePutParam(sessionid, HttpUtility.UrlDecode(aiccdata));
                parsed_dictionary.Add("cmi.terminate", "true");

                //persist values...
                hacp.ConsumeJSObj(parsed_dictionary);
                hacp.Persist(sessionid);

                sendOutput(no_error_output);

                break;

            default:
                sendOutput(error_invalid_command);
                break;
            }



            // TODO: handle 'running' and 'terminated'...
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            enrollment_id = this.Request["eid"]; // accepts 'eid' guid value from GET or POST (should be GET, due to AICC_URL/SID)
            //enrollment_id = "49e8ae11-ecfa-4c08-8bd9-bba9a8521414";
            //string student_id, student_name, lesson_location, credit, lesson_status, vExit, vEntry;

            var status_incomplete = Guid.Parse("655f1d57-1a6e-498f-b341-33c8c04ab430"); //Incomplete

            // AICC HACP URL Parse
            aicc_url = this.Request["aicc_url"];
            aicc_sid = this.Request["aicc_sid"];

            using (ComplianceFactorsEntities context = new ComplianceFactorsEntities())
            {
                var enroll = (from en in context.e_tb_enrollments
                              where en.e_enroll_system_id_pk == new Guid(enrollment_id)
                              select en).FirstOrDefault();

                if (enroll == null) //no record found, invalid eid
                {
                    Response.Write("Invalid Enrollment");
                    Response.End();
                }

                content_url = enroll.c_tb_deliveries_master.c_olt_launch_url;

                course_title = enroll.c_tb_courses_master.c_course_title;

                student_id   = enroll.e_enroll_user_id_fk.ToString();
                student_name = enroll.u_tb_users_master.u_last_name + ", "
                               + enroll.u_tb_users_master.u_first_name
                               + " " + enroll.u_tb_users_master.u_middle_name;
                lesson_location = enroll.e_enroll_lesson_location ?? "";
                credit          = ((bool)(enroll.e_enroll_credit ?? true)) ? "credit" : "no-credit";

                // Status
                //  account for null/empty value
                if (String.IsNullOrEmpty(enroll.e_enroll_lesson_status))
                {
                    lesson_status = "not attempted";
                    enroll.e_enroll_lesson_status = "not attempted";
                    enroll.e_enroll_status_id_fk  = status_incomplete;
                    context.SaveChanges();
                }
                // set status to 'incomplete'
                if (enroll.e_enroll_lesson_status == "not attempted")
                {
                    lesson_status = "incomplete";
                    enroll.e_enroll_status_id_fk = status_incomplete;
                    context.SaveChanges();
                }

                // temp: for backwards compatibility of test data
                if (enroll.e_enroll_lesson_status == "incomplete")
                {
                    lesson_status = "incomplete";
                    enroll.e_enroll_status_id_fk = status_incomplete;
                    context.SaveChanges();
                }

                vExit = enroll.e_enroll_exit;
                if (vExit == "time-out" || vExit == "logout" || String.IsNullOrEmpty(vExit))
                {
                    vEntry = "";
                }
                else if (vExit == "suspend")
                {
                    vEntry = "resume";
                    //enroll.e_enroll_entry = true;
                }
                else
                {
                    vEntry = "ab-initio";
                    //enroll.e_enroll_entry = false;
                }
                //vEntry = ((bool)(enroll.e_enroll_entry ?? false)) ? "resume" : "ab-initio"; // ab-initio, resume, or ""->neither of the former
                launch_data  = enroll.e_enroll_launch_data ?? "";
                suspend_data = enroll.e_enroll_suspend_data ?? "";

                score_raw = Convert.ToString(enroll.e_enroll_score);
                score_max = Convert.ToString(enroll.e_enroll_score_max);
                score_min = Convert.ToString(enroll.e_enroll_score_min);

                lesson_mode = (enroll.e_enroll_lesson_mode ?? "normal"); //for now...
                total_time  = TimeSpan.FromSeconds((double)(enroll.e_enroll_time_spent ?? 0)).ToString(@"hh\:mm\:ss");

                context.SaveChanges();
            }
        }
        static void JSAPILogicTest()
        {
            Dictionary <string, string> json = new Dictionary <string, string>();

            json.Add("cmi.core.lesson_location", "end");
            json.Add("cmi.core.credit", "credit");
            json.Add("cmi.core.lesson_status", "attempted");
            json.Add("cmi.core.score.raw", "8.5");
            json.Add("cmi.core.score.min", "0");
            json.Add("cmi.core.score.max", "10");
            json.Add("cmi.core.session_time", "00:47:00");
            json.Add("cmi.core.total_time", "1:23:00");
            json.Add("cmi.core.lesson_mode", "normal");
            json.Add("cmi.student_data.mastery_score", "8");
            json.Add("cmi.suspend_data", "9 00 001010101100110\r\n000 001010101100110\r\n000001010101100110\r\ngl’;sdfgl’;sdfhgl’;sdfhgls’;df");
            json.Add("cmi.comments", "<1>The background color is too blue!<1.e><2>The CDU\r\npanel has the incorrect ‘way points’ displayed for\r\nthis route. <2.e><3>The CDU panel has the incorrect\r\n‘way points’ displayed for this route. <3.e><4>The\r\nCDU panel has the incorrect ‘way points’ displayed\r\nfor this route. <e.4>");
            json.Add("cmi.terminate", "true");

            AICC_CMI.JS_API_Logic jslogic = new AICC_CMI.JS_API_Logic();
            jslogic.ConsumeJSObj(json);

            Debug.Assert(((string)jslogic.GetValue("cmi.core.lesson_location") == "end"));
            Debug.Assert(((bool)jslogic.GetValue("cmi.core.credit")));
            Debug.Assert(((string)jslogic.GetValue("cmi.core.lesson_status") == "passed"));
            Debug.Assert(((double)jslogic.GetValue("cmi.core.score.raw") == 8.5d));
            Debug.Assert(((double)jslogic.GetValue("cmi.core.score.min") == 0d));
            Debug.Assert(((double)jslogic.GetValue("cmi.core.score.max") == 10d));
            Debug.Assert(((int)jslogic.GetValue("cmi.core.session_time") == 2820));
            //Debug.Assert(((string)jslogic.GetValue("cmi.core.total_time", "1:23:00");
            Debug.Assert(((string)jslogic.GetValue("cmi.core.lesson_mode") == "normal"));
            Debug.Assert(((double)jslogic.GetValue("cmi.student_data.mastery_score") == 8d));
            Debug.Assert(((string)jslogic.GetValue("cmi.suspend_data") == "9 00 001010101100110\r\n000 001010101100110\r\n000001010101100110\r\ngl’;sdfgl’;sdfhgl’;sdfhgls’;df"));
            Debug.Assert(((string)jslogic.GetValue("cmi.comments") == "<1>The background color is too blue!<1.e><2>The CDU\r\npanel has the incorrect ‘way points’ displayed for\r\nthis route. <2.e><3>The CDU panel has the incorrect\r\n‘way points’ displayed for this route. <3.e><4>The\r\nCDU panel has the incorrect ‘way points’ displayed\r\nfor this route. <e.4>"));

            json.Remove("cmi.core.lesson_location");
            json.Remove("cmi.core.lesson_status");
            json.Add("cmi.core.lesson_location", "somewhere before the end");
            json.Add("cmi.core.lesson_status", "incomplete");

            jslogic.ConsumeJSObj(json);

            Debug.Assert(((string)jslogic.GetValue("cmi.core.lesson_status") == "incomplete"));

            json.Remove("cmi.core.credit");
            json.Add("cmi.core.credit", "asdf");

            jslogic.ConsumeJSObj(json);

            Debug.Assert(((bool)jslogic.GetValue("cmi.core.credit") == true));

            json.Remove("cmi.core.credit");
            json.Add("cmi.core.credit", null);

            jslogic.ConsumeJSObj(json);

            Debug.Assert(((bool)jslogic.GetValue("cmi.core.credit") == true));

            json.Remove("cmi.core.credit");
            json.Add("cmi.core.credit", "no-credit");

            jslogic.ConsumeJSObj(json);

            Debug.Assert(((bool)jslogic.GetValue("cmi.core.credit") == false));

            json.Remove("cmi.core.credit");
            json.Remove("cmi.core.lesson_mode");
            json.Add("cmi.core.credit", "credit");
            json.Add("cmi.core.lesson_mode", "browsed");

            jslogic.ConsumeJSObj(json);

            Debug.Assert(((bool)jslogic.GetValue("cmi.core.credit") == false));

            json.Add("cmi.core.exit", "Logout");
            jslogic.ConsumeJSObj(json);
            Debug.Assert(((string)jslogic.GetValue("cmi.core.exit") == "logout"));

            json["cmi.core.exit"] = "boguscrap";
            jslogic.ConsumeJSObj(json);
            Debug.Assert(((string)jslogic.GetValue("cmi.core.exit") == ""));

            json["cmi.terminate"] = "true";
            jslogic.ConsumeJSObj(json);
            Debug.Assert((bool)jslogic.GetValue("cmi.terminate") == true);

            json["cmi.terminate"] = "asdfasdf";
            jslogic.ConsumeJSObj(json);
            Debug.Assert((bool)jslogic.GetValue("cmi.terminate") == false);

            // Testing entire unit
            json.Clear();
            json["cmi.core.lesson_location"] = "end";
            json["cmi.core.credit"]          = "credit";
            json["cmi.core.lesson_status"]   = "attempted";
            json["cmi.core.score.raw"]       = "8.5";
            json["cmi.core.score.min"]       = "0";
            json["cmi.core.score.max"]       = "10";
            json["cmi.core.session_time"]    = "00:47:00"; // 2820
            //json["cmi.core.total_time"] = "1:23:00";    // 4980   ... can't simply declare this if pulling from the database...
            json["cmi.core.lesson_mode"]           = "normal";
            json["cmi.student_data.mastery_score"] = "8";
            json["cmi.suspend_data"] = "9 00 001010101100110\r\n000 001010101100110\r\n000001010101100110\r\ngl’;sdfgl’;sdfhgl’;sdfhgls’;df";
            json["cmi.comments"]     = "<1>The background color is too blue!<1.e><2>The CDU\r\npanel has the incorrect ‘way points’ displayed for\r\nthis route. <2.e><3>The CDU panel has the incorrect\r\n‘way points’ displayed for this route. <3.e><4>The\r\nCDU panel has the incorrect ‘way points’ displayed\r\nfor this route. <e.4>";
            json["cmi.terminate"]    = "true";

            string enrollment_id = "71dc1b30-b013-4848-9155-17ae45330ca3";

            using (var ctx = new ComplianceFactorsEntities())
            {
                var enroll = (from en in ctx.e_tb_enrollments
                              where en.e_enroll_system_id_pk == new Guid(enrollment_id)
                              select en).FirstOrDefault();

                int?total_time = enroll.e_enroll_time_spent;

                jslogic.ConsumeJSObj(json);

                jslogic.Persist(enrollment_id);

                ctx.Refresh(System.Data.Objects.RefreshMode.StoreWins, enroll);

                Debug.Assert(enroll.e_enroll_lesson_location == "end");
                Debug.Assert(enroll.e_enroll_credit == true);
                Debug.Assert(enroll.e_enroll_lesson_status == "passed");
                Debug.Assert(enroll.e_enroll_score == 8.5m); // m --> decimal
                Debug.Assert(enroll.e_enroll_score_min == 0m);
                Debug.Assert(enroll.e_enroll_score_max == 10m);
                Debug.Assert(enroll.e_enroll_time_spent == total_time + 2820);
                Debug.Assert(enroll.e_enroll_lesson_mode == "normal");
                //Debug.Assert(enroll.cmi.student_data.mastery_score == "8");
                Debug.Assert(enroll.e_enroll_suspend_data == "9 00 001010101100110\r\n000 001010101100110\r\n000001010101100110\r\ngl’;sdfgl’;sdfhgl’;sdfhgls’;df");
                Debug.Assert(enroll.e_enroll_student_comments == "<1>The background color is too blue!<1.e><2>The CDU\r\npanel has the incorrect ‘way points’ displayed for\r\nthis route. <2.e><3>The CDU panel has the incorrect\r\n‘way points’ displayed for this route. <3.e><4>The\r\nCDU panel has the incorrect ‘way points’ displayed\r\nfor this route. <e.4>");
            }
        }