protected void Page_Load(object sender, EventArgs e)
    {
        // set <currentUser> to information about the current user, and add the current user's list
        // of training to the TrainingGrid table; for best performance, both these requests are
        // done in a single call to the database
        LearningStoreJob job = LStore.CreateJob();

        RequestCurrentUserInfo(job);
        RequestMyTraining(job, null);
        ReadOnlyCollection <object> results = job.Execute();
        LStoreUserInfo currentUser          = GetCurrentUserInfoResults((DataTable)results[0]);

        GetMyTrainingResultsToHtml((DataTable)results[1], TrainingGrid);

        // update the title
        MyUserName.Text = Server.HtmlEncode(currentUser.Name);

        // if there is no training (i.e. if TrainingGrid contains only the header row), initially
        // hide TrainingGrid and show a message instructing the user to upload content
        if (TrainingGrid.Rows.Count == 1)
        {
            TrainingPanel.Attributes.Add("style", "display: none");
        }
        else
        {
            NoTrainingMessage.Attributes.Add("style", "display: none");
        }

        // since there is no initial selection, intially disable the "Delete Packages" link
        DeletePackagesLink.Attributes.Add("disabled", "true");

        // set the version number
        VersionNumber.Text = System.Text.RegularExpressions.Regex.Match(
            typeof(LearningStore).Assembly.FullName, @"\bVersion=(\d+\.\d+.\d+)\.").Groups[1].Value;
    }
示例#2
0
        /// <summary>
        /// Adds package to the database
        /// </summary>
        /// <param name="package">Package value represents package object with necessary information.</param>
        public Training AddPackage(Package package)
        {
            PackageItemIdentifier packageId;
            ValidationResults     importLog;

            using (PackageReader packageReader = package.GetPackageReader())
            {
                AddPackageResult result = PStore.AddPackage(packageReader, new PackageEnforcement(false, false, false));
                packageId = result.PackageId;
                importLog = result.Log;
            }

            // fill in the application-specific columns of the PackageItem table
            LearningStoreJob            job        = LStore.CreateJob();
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties[Schema.PackageItem.Owner]          = new UserItemIdentifier(package.Owner);
            properties[Schema.PackageItem.FileName]       = package.FileName;
            properties[Schema.PackageItem.UploadDateTime] = package.UploadDateTime;
            job.UpdateItem(packageId, properties);
            job.Execute();

            // retrieve information about the package
            job = LStore.CreateJob();
            RequestMyTraining(job, packageId);

            DataTable dataTableResults = job.Execute <DataTable>();
            Training  training         = new Training(dataTableResults.Rows[0]);

            return(training);
        }
示例#3
0
    /// <summary>
    /// Retrieves information about the current user from the LearningStore
    /// database.
    /// </summary>
    ///
    public LStoreUserInfo GetCurrentUserInfo()
    {
        LearningStoreJob job = LStore.CreateJob();

        RequestCurrentUserInfo(job);
        return(GetCurrentUserInfoResults(job.Execute <DataTable>()));
    }
示例#4
0
        public void SimpleLoadTypesUnequal_Expected_Exception()
        {
            LStore store;

            Assert.Throws <Exception>(() =>
                                      store = new LStore(_src, new LPointerRef(_dst, "%ptr1"))
                                      );
        }
示例#5
0
        public IEnumerable <AttemptResult> GetAllAttempts()
        {
            List <AttemptResult> result = new List <AttemptResult>();
            LearningStoreJob     job    = LStore.CreateJob();

            RequestAllAttempts(job);
            DataTable dataTable = job.Execute <DataTable>();

            foreach (DataRow dataRow in dataTable.AsEnumerable())
            {
                AttemptItemIdentifier attemptItemId;
                LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.AttemptId], out attemptItemId);
                long attemptId = attemptItemId.GetKey();

                String userKey;
                LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.UserItemKey], out userKey);
                User user = UserService.GetUsers().Single(curr => curr.Id.ToString() == userKey);
                if (user == null)
                {
                    throw new NoNullAllowedException("Error while getting user with id = " + userKey);
                }

                Int32 topicId;
                LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.ThemeId], out topicId);
                Topic topic = DisciplineService.GetTopic(topicId);
                if (topic == null)
                {
                    throw new NoNullAllowedException("Error while getting topic with id = " + topicId);
                }

                Microsoft.LearningComponents.CompletionStatus completionStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.CompletionStatus], out completionStatus);
                IUDICO.Common.Models.Shared.Statistics.CompletionStatus iudicoCompletionStatus = (IUDICO.Common.Models.Shared.Statistics.CompletionStatus)completionStatus;

                Microsoft.LearningComponents.AttemptStatus attemptStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.AttemptStatus], out attemptStatus);
                IUDICO.Common.Models.Shared.Statistics.AttemptStatus iudicoAttemptStatus = (IUDICO.Common.Models.Shared.Statistics.AttemptStatus)attemptStatus;

                Microsoft.LearningComponents.SuccessStatus successStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AllAttemptsResults.SuccessStatus], out successStatus);
                IUDICO.Common.Models.Shared.Statistics.SuccessStatus iudicoSuccessStatus = (IUDICO.Common.Models.Shared.Statistics.SuccessStatus)successStatus;

                DateTime?startTime;
                LStoreHelper.Cast(dataRow[Schema.AllAttemptsResults.StartedTimestamp], out startTime);

                DateTime?finishTime;
                LStoreHelper.Cast(dataRow[Schema.AllAttemptsResults.FinishedTimestamp], out finishTime);


                float?scaledScore;
                LStoreHelper.Cast <float>(dataRow[Schema.AllAttemptsResults.Score], out scaledScore);

                // Create AttemptResult object
                AttemptResult attemptResult = new AttemptResult(attemptId, user, topic, iudicoCompletionStatus, iudicoAttemptStatus, iudicoSuccessStatus, startTime, finishTime, scaledScore);
                result.Add(attemptResult);
            }
            return(result);
        }
示例#6
0
    /// <summary>
    /// Reads a <c>DataTable</c>, returned by <c>Job.Execute</c>, containing
    /// the results requested by a previous call to
    /// <c>RequestCurrentUserInfo</c>.  Returns an <c>LStoreUserInfo</c>
    /// object containing information about the user.  If the user isn't
    /// already listed in LearningStore, a separate call to the database is
    /// made to add them.
    /// </summary>
    ///
    /// <param name="dataTable">A <c>DataTable</c> returned from
    ///     <c>Job.Execute</c>.</param>
    ///
    protected LStoreUserInfo GetCurrentUserInfoResults(DataTable dataTable)
    {
        DataRowCollection  results = dataTable.Rows;
        LearningStoreJob   job     = LStore.CreateJob();
        UserItemIdentifier userId;
        string             userName;

        if (results.Count == 0)
        {
            // the user isn't listed in the UserItem table -- add them...

            // set <userName> to the name of the user that SCORM will use
#if false
            // the following code queries Active Directory for the full name
            // of the user (for example, "Karen Berg") -- this code assumes a
            // particular Active Directory configuration which may or may not
            // work in your situation
            string adsiPath = String.Format("WinNT://{0},user",
                                            UserIdentity.Name.Replace(@"\", "/"));
            using (DirectoryEntry de = new DirectoryEntry(adsiPath))
                userName = (string)de.Properties["FullName"].Value;
#else
            // the following code uses the "name" portion of the user's
            // "domain\name" network account name as the name of the user
            userName = UserName;
            int backslash = userName.IndexOf('\\');
            if (backslash >= 0)
            {
                userName = userName.Substring(backslash + 1);
            }
#endif

            // create the UserItem for this user in LearningStore; we use
            // AddOrUpdateItem() instead of AddItem() in case this learner
            // was added by another application between the check above and
            // the code below
            job = LStore.CreateJob();
            Dictionary <string, object> uniqueValues =
                new Dictionary <string, object>();
            uniqueValues[Schema.UserItem.Key] = UserKey;
            Dictionary <string, object> addValues =
                new Dictionary <string, object>();
            addValues[Schema.UserItem.Name] = userName;
            job.AddOrUpdateItem(Schema.UserItem.ItemTypeName,
                                uniqueValues, addValues, null, true);
            userId = new UserItemIdentifier(job.Execute <LearningStoreItemIdentifier>());
        }
        else
        {
            userId = new UserItemIdentifier((LearningStoreItemIdentifier)
                                            results[0][Schema.Me.UserId]);
            userName = (string)results[0][Schema.Me.UserName];
        }

        // return a LStoreUserInfo object
        return(new LStoreUserInfo(userId, userName));
    }
示例#7
0
        /// <summary>
        /// Uses <c>RequestCurrentUserInfo</c> and checks user existance
        /// by calling <c>CheckCurrentUserIdentifier</c> which returns user id based
        /// on currently iudico-authorized user.
        /// </summary>
        /// <returns>UserItemIdentifier value which represents UserItem primary ID.</returns>
        protected UserItemIdentifier GetCurrentUserIdentifier()
        {
            LearningStoreJob job = LStore.CreateJob();

            RequestCurrentUserInfo(job);
            ReadOnlyCollection <object> results = job.Execute();
            UserItemIdentifier          result  = CheckCurrentUserIdentifier((DataTable)results[0]);

            return(result);
        }
示例#8
0
        public void SimpleLoadAlignmentExceeded_Expected_Exception()
        {
            LStore store;

            Assert.Throws <Exception>(() =>
                                      store = new LStore(_src, _dst)
            {
                Alignment = 1 << 30
            });
        }
示例#9
0
        public void StoreIsAtomic_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                IsAtomic = true
            };

            Assert.AreEqual(
                $"{LKeywords.Store} {LKeywords.Atomic} {_src.ParseType()} {_src.ValueOrIdentifier}, {_dst.ParseType()} {_dst.Identifier}",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#10
0
        public void StoreAlignment_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                Alignment = 5012
            };

            Assert.AreEqual(
                $"{LKeywords.Store} {_src.ParseType()} {_src.ValueOrIdentifier}, {_dst.ParseType()} {_dst.Identifier}, {LKeywords.Align} 5012",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#11
0
        public void StoreIsAtomicVolatileAlignment_Hardcoded_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                IsAtomic   = true,
                IsVolatile = true,
                Alignment  = 5012
            };

            Assert.AreEqual(
                $"store atomic volatile i32 {_src.ValueOrIdentifier}, i32* {_dst.Identifier}, align 5012",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#12
0
        public IEnumerable <AttemptResult> GetResults(User user, Topic topic)
        {
            List <AttemptResult> result = new List <AttemptResult>();
            LearningStoreJob     job    = LStore.CreateJob();

            RequestAttemptsByTopicAndUser(job, user.Id.ToString(), topic.Id);
            DataTable dataTable = job.Execute <DataTable>();

            foreach (DataRow dataRow in dataTable.AsEnumerable())
            {
                AttemptItemIdentifier attemptItemId;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.AttemptId], out attemptItemId);
                long attemptId = attemptItemId.GetKey();

                Microsoft.LearningComponents.CompletionStatus completionStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.CompletionStatus], out completionStatus);
                IUDICO.Common.Models.Shared.Statistics.CompletionStatus iudicoCompletionStatus = (IUDICO.Common.Models.Shared.Statistics.CompletionStatus)completionStatus;

                Microsoft.LearningComponents.AttemptStatus attemptStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.AttemptStatus], out attemptStatus);
                IUDICO.Common.Models.Shared.Statistics.AttemptStatus iudicoAttemptStatus = (IUDICO.Common.Models.Shared.Statistics.AttemptStatus)attemptStatus;

                Microsoft.LearningComponents.SuccessStatus successStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.SuccessStatus], out successStatus);
                IUDICO.Common.Models.Shared.Statistics.SuccessStatus iudicoSuccessStatus = (IUDICO.Common.Models.Shared.Statistics.SuccessStatus)successStatus;

                DateTime?startTime;
                LStoreHelper.Cast(dataRow[Schema.AttemptsResultsByThemeAndUser.StartedTimestamp], out startTime);

                DateTime?finishTime;
                LStoreHelper.Cast(dataRow[Schema.AllAttemptsResults.FinishedTimestamp], out finishTime);

                float?score;
                LStoreHelper.Cast <float>(dataRow[Schema.AttemptsResultsByThemeAndUser.Score], out score);
                float?scaledScore = null;

                if (score != null)
                {
                    scaledScore = score / 100;
                }

                // Create AttemptResult object
                AttemptResult attemptResult = new AttemptResult(attemptId, user, topic, iudicoCompletionStatus, iudicoAttemptStatus, iudicoSuccessStatus, startTime, finishTime, scaledScore);

                result.Add(attemptResult);
            }

            return(result);
        }
示例#13
0
        /// <summary>
        /// Requests that the list of all attempts all users have performed on all organizaions.
        /// Adds the request to a given <c>LearningStoreJob</c> for later execution.
        /// </summary>
        /// <param name="job">A <c>LearningStoreJob</c> to add the new query to.</param>
        protected void RequestAllAttempts(LearningStoreJob job)
        {
            LearningStoreQuery query = LStore.CreateQuery(Schema.AllAttemptsResults.ViewName);

            query.AddColumn(Schema.AllAttemptsResults.AttemptId);
            query.AddColumn(Schema.AllAttemptsResults.UserItemKey);
            query.AddColumn(Schema.AllAttemptsResults.ThemeId);
            query.AddColumn(Schema.AllAttemptsResults.CompletionStatus);
            query.AddColumn(Schema.AllAttemptsResults.AttemptStatus);
            query.AddColumn(Schema.AllAttemptsResults.SuccessStatus);
            query.AddColumn(Schema.AllAttemptsResults.StartedTimestamp);
            query.AddColumn(Schema.AllAttemptsResults.Score);

            job.PerformQuery(query);
        }
示例#14
0
        protected void RequestAttemptsByTopic(LearningStoreJob job, Int32 topicId)
        {
            LearningStoreQuery query = LStore.CreateQuery(Schema.AttemptsResultsByThemeAndUser.ViewName);

            query.AddColumn(Schema.AttemptsResultsByThemeAndUser.AttemptId);
            query.AddColumn(Schema.AttemptsResultsByThemeAndUser.CompletionStatus);
            query.AddColumn(Schema.AttemptsResultsByThemeAndUser.AttemptStatus);
            query.AddColumn(Schema.AttemptsResultsByThemeAndUser.SuccessStatus);
            query.AddColumn(Schema.AttemptsResultsByThemeAndUser.StartedTimestamp);
            query.AddColumn(Schema.AttemptsResultsByThemeAndUser.Score);

            query.SetParameter(Schema.AttemptsResultsByThemeAndUser.ThemeIdParam, topicId);

            job.PerformQuery(query);
        }
示例#15
0
    ///////////////////////////////////////////////////////////////////////////
    // Public Methods
    //

    /// <summary>
    /// Requests that information about the current user be retrieved from the
    /// LearningStore database.  Adds the request to a given
    /// <c>LearningStoreJob</c> for later execution.
    /// </summary>
    ///
    /// <param name="job">A <c>LearningStoreJob</c> to add the new query to.
    ///     </param>
    ///
    /// <remarks>
    /// After executing this method, and later calling <c>Job.Execute</c>,
    /// call <c>GetCurrentUserInfoResults</c> to convert the <c>DataTable</c>
    /// returned by <c>Job.Execute</c> into an <c>LStoreUserInfo</c> object.
    /// </remarks>
    ///
    protected void RequestCurrentUserInfo(LearningStoreJob job)
    {
        // look up the user in the UserItem table in the database using their
        // user key, and set <userId> to the LearningStore numeric identifier
        // of the user (i.e. UserItem.Id -- the "Id" column of the UserItem
        // table) and <userName> to their full name (e.g. "Karen Berg"); if
        // there's no UserItem for the user, add one and set <userId> to its
        // ID
        LearningStoreQuery query = LStore.CreateQuery(
            Schema.Me.ViewName);

        query.AddColumn(Schema.Me.UserId);
        query.AddColumn(Schema.Me.UserName);
        job.PerformQuery(query);
    }
示例#16
0
        /// <summary>
        /// Creates attempt on given organization and returns attempt identifier.
        /// </summary>
        /// <param name="orgID">Long integer value represents organization identifier to create attempt on.</param>
        /// <returns>Long integer value, representing attempt identifier of created attempt.</returns>
        protected AttemptItemIdentifier CreateAttempt(long orgID, int topicId)
        {
            ActivityPackageItemIdentifier organizationID = new ActivityPackageItemIdentifier(orgID);

            StoredLearningSession session = StoredLearningSession.CreateAttempt(this.PStore, this.GetCurrentUserIdentifier(), organizationID, LoggingOptions.LogAll);
            // TODO: add IudicoTopicRef
            LearningStoreJob            job = LStore.CreateJob();
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add(Schema.AttemptItem.IudicoThemeRef, topicId);
            job.UpdateItem(session.AttemptId, dic);
            job.Execute();

            return(session.AttemptId);
        }
示例#17
0
        /// <summary>
        /// Deletes pacakge and related attempts from database.
        /// </summary>
        /// <param name="packId">Long integer value represents package identifier.</param>
        protected void DeletePackage(long packId)
        {
            // set <packageId> to the ID of this package
            PackageItemIdentifier packageId = new PackageItemIdentifier(packId);

            // before we delete the package, we need to delete all attempts on the package --
            // the following query looks for those attempts
            LearningStoreJob   job   = LStore.CreateJob();
            LearningStoreQuery query = LStore.CreateQuery(
                Schema.MyAttempts.ViewName);

            query.AddCondition(Schema.MyAttempts.PackageId,
                               LearningStoreConditionOperator.Equal, packageId);
            query.AddCondition(Schema.MyAttempts.AttemptId,
                               LearningStoreConditionOperator.NotEqual, null);
            query.AddColumn(Schema.MyAttempts.AttemptId);
            query.AddSort(Schema.MyAttempts.AttemptId,
                          LearningStoreSortDirection.Ascending);
            job.PerformQuery(query);
            DataTable             dataTable         = job.Execute <DataTable>();
            AttemptItemIdentifier previousAttemptId = null;

            // loop once for each attempt on this package
            foreach (DataRow dataRow in dataTable.Rows)
            {
                // set <attemptId> to the ID of this attempt
                AttemptItemIdentifier attemptId;
                LStoreHelper.CastNonNull(dataRow["AttemptId"], out attemptId);

                // if <attemptId> is a duplicate attempt ID, skip it; note that the query
                // results are sorted by attempt ID (see above)
                if ((previousAttemptId != null) &&
                    (previousAttemptId.GetKey() == attemptId.GetKey()))
                {
                    continue;
                }

                // delete this attempt
                StoredLearningSession.DeleteAttempt(LStore, attemptId);

                // continue to the next attempt
                previousAttemptId = attemptId;
            }

            // delete the package
            PStore.DeletePackage(packageId);
        }
示例#18
0
        /// <summary>
        /// Retrieves collection of trainings for current user.
        /// </summary>
        /// <returns>IEnumerable collection of Training objects.</returns>
        public IEnumerable <Training> GetTrainings()
        {
            LearningStoreJob job = LStore.CreateJob();

            RequestMyTraining(job, null);
            DataTable       results  = job.Execute <DataTable>();
            List <Training> packages = new List <Training>();

            foreach (DataRow dataRow in results.AsEnumerable())
            {
                // Create Training object
                Training training = new Training(dataRow);
                packages.Add(training);
            }

            return(packages);
        }
示例#19
0
        /// <summary>
        /// Requests that the list of training for the current user be retrieved from the LearningStore
        /// database.  Adds the request to a given <c>LearningStoreJob</c> for later execution.
        /// </summary>
        /// <param name="job">A <c>LearningStoreJob</c> to add the new query to.</param>
        /// <param name="packageId">To request information related to a single pass the
        ///     <c>PackageItemIdentifier</c> of the package as this parameter.  Otherwise, leave this
        ///     parameter <c>null</c>.</param>
        protected void RequestMyTraining(LearningStoreJob job,
                                         PackageItemIdentifier packageId)
        {
            LearningStoreQuery query = LStore.CreateQuery(Schema.MyAttempts.ViewName);

            query.AddColumn(Schema.MyAttempts.PackageId);
            query.AddColumn(Schema.MyAttempts.OrganizationId);
            query.AddColumn(Schema.MyAttempts.AttemptId);
            query.AddColumn(Schema.MyAttempts.AttemptStatus);
            query.AddColumn(Schema.MyAttempts.TotalPoints);
            if (packageId != null)
            {
                query.AddCondition(Schema.MyAttempts.PackageId,
                                   LearningStoreConditionOperator.Equal, packageId);
            }
            job.PerformQuery(query);
        }
示例#20
0
        /// <summary>
        /// Adds package to the database.
        /// </summary>
        /// <param name="package">Package value represents package object with necessary information.</param>
        protected PackageItemIdentifier AddPackage(Package package)
        {
            PackageItemIdentifier packageId = null;
            ValidationResults     importLog;

            using (PackageReader packageReader = package.GetPackageReader())
            {
                AddPackageResult result = PStore.AddPackage(packageReader, new PackageEnforcement(false, false, false));
                packageId = result.PackageId;
                importLog = result.Log;
            }

            LearningStoreJob            job = LStore.CreateJob();
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add(Schema.PackageItem.IudicoCourseRef, package.CourseID);
            job.UpdateItem(packageId, dic);
            job.Execute();

            return(packageId);
        }
示例#21
0
        /// <summary>
        /// Requests that the list of all answers by specified attempt on organization.
        /// Adds the request to a given <c>LearningStoreJob</c> for later execution.
        /// </summary>
        /// <param name="job">A <c>LearningStoreJob</c> to add the new query to.</param>
        /// <param name="attemptId"><c>AttemptItemIdentifier</c> represents id of attempt.</param>
        protected void RequestInteractionResultsByAttempt(LearningStoreJob job, AttemptItemIdentifier attemptId)
        {
            LearningStoreQuery query = LStore.CreateQuery(Schema.InteractionResultsByAttempt.ViewName);

            query.AddColumn(Schema.InteractionResultsByAttempt.ActivityAttemptId);
            query.AddColumn(Schema.InteractionResultsByAttempt.ActivityPackageId);
            query.AddColumn(Schema.InteractionResultsByAttempt.ActivityTitle);
            query.AddColumn(Schema.InteractionResultsByAttempt.InteractionId);
            query.AddColumn(Schema.InteractionResultsByAttempt.CompletionStatus);
            query.AddColumn(Schema.InteractionResultsByAttempt.SuccessStatus);
            query.AddColumn(Schema.InteractionResultsByAttempt.LearnerResponseBool);
            query.AddColumn(Schema.InteractionResultsByAttempt.LearnerResponseString);
            query.AddColumn(Schema.InteractionResultsByAttempt.LearnerResponseNumeric);
            query.AddColumn(Schema.InteractionResultsByAttempt.CorrectResponse);
            query.AddColumn(Schema.InteractionResultsByAttempt.InteractionType);
            query.AddColumn(Schema.InteractionResultsByAttempt.ScaledScore);

            query.SetParameter(Schema.InteractionResultsByAttempt.AttemptIdParam, attemptId);

            job.PerformQuery(query);
        }
示例#22
0
        /// <summary>
        /// Retrieves package id by specified IUDICO course.
        /// </summary>
        /// <param name="course">Course object represents iudico course entity.</param>
        /// <returns>PackageItemIdentifier value representing corresponding MLC Package ID.</returns>
        protected PackageItemIdentifier GetPackageIdentifier(int courseId)
        {
            PackageItemIdentifier result = null;
            LearningStoreJob      job    = LStore.CreateJob();

            LearningStoreQuery query = LStore.CreateQuery(Schema.PackageIdByCourse.ViewName);

            query.AddColumn(Schema.PackageIdByCourse.PackageId);
            query.SetParameter(Schema.PackageIdByCourse.IudicoCourseRef, courseId);

            job.PerformQuery(query);

            ReadOnlyCollection <object> resultList = job.Execute();

            DataTable dataTable = (DataTable)resultList[0];

            if (dataTable.Rows.Count > 0)
            {
                LStoreHelper.Cast(dataTable.Rows[0][Schema.PackageIdByCourse.PackageId], out result);
            }
            return(result);
        }
示例#23
0
        /// <summary>
        /// Reads a <c>DataTable</c>, returned by <c>Job.Execute</c>, containing
        /// the results requested by a previous call to
        /// <c>RequestCurrentUserInfo</c>.  Returns an <c>UserItemIdentifier</c>
        /// object containing identifier of user. If the user isn't
        /// already listed in LearningStore, a separate call to the database is
        /// made to add them.
        /// </summary>
        ///
        /// <param name="dataTable">A <c>DataTable</c> returned from
        ///     <c>Job.Execute</c>.</param>
        ///
        private UserItemIdentifier CheckCurrentUserIdentifier(DataTable dataTable)
        {
            DataRowCollection  results = dataTable.Rows;
            LearningStoreJob   job     = LStore.CreateJob();
            UserItemIdentifier userId;
            string             userName;

            if (results.Count == 0)
            {
                // the user isn't listed in the UserItem table -- add them...

                // set <userName> to the name of the user that SCORM will use
                userName = GetCurrentIudicoUser().Name;

                // create the UserItem for this user in LearningStore; we use
                // AddOrUpdateItem() instead of AddItem() in case this learner
                // was added by another application between the check above and
                // the code below
                job = LStore.CreateJob();
                Dictionary <string, object> uniqueValues =
                    new Dictionary <string, object>();
                uniqueValues[Schema.UserItem.Key] = CurrentIudicoUserKey.ToString();
                Dictionary <string, object> addValues =
                    new Dictionary <string, object>();
                addValues[Schema.UserItem.Name] = userName;
                job.AddOrUpdateItem(Schema.UserItem.ItemTypeName,
                                    uniqueValues, addValues, null, true);
                userId = new UserItemIdentifier(job.Execute <LearningStoreItemIdentifier>());
            }
            else
            {
                userId = new UserItemIdentifier((LearningStoreItemIdentifier)
                                                results[0][Schema.Me.UserId]);
            }

            // return a UserItemIdentifier object
            return(userId);
        }
示例#24
0
        /// <summary>
        /// Retrieves Organization Id by specified package oidentifier.
        /// </summary>
        /// <param name="packageId"><c>PackageItemIdentifier</c> value representing package id, organization is being searched by.</param>
        /// <returns><c>ActivityPackageItemIdentifier</c> value, which represents organization identifier of specified package.</returns>
        protected ActivityPackageItemIdentifier GetOrganizationIdentifier(PackageItemIdentifier packageId)
        {
            ActivityPackageItemIdentifier result = null;
            LearningStoreJob job = LStore.CreateJob();

            LearningStoreQuery query = LStore.CreateQuery(Schema.RootActivityByPackage.ViewName);

            query.AddColumn(Schema.RootActivityByPackage.RootActivity);
            query.SetParameter(Schema.RootActivityByPackage.PackageId, packageId);

            job.PerformQuery(query);

            var resultList = job.Execute();

            DataTable dataTable = (DataTable)resultList[0];

            if (dataTable.Rows.Count > 0)
            {
                LStoreHelper.Cast(dataTable.Rows[0][Schema.RootActivityByPackage.RootActivity], out result);
            }

            return(result);
        }
示例#25
0
        /// <summary>
        /// Retrieves attempt identifier for specified organization id and Iudico topic id.
        /// </summary>
        /// <param name="orgId"><c>ActivityPackageItemIdentifier</c> value representing Organization ID.</param>
        /// <param name="topicId">Integer value - IUDICO topic id.</param>
        /// <returns><c>AttemptItemIdentifier</c> value representing Attempt Identifier.</returns>
        protected AttemptItemIdentifier GetAttemptIdentifier(ActivityPackageItemIdentifier orgId, int topicId)
        {
            AttemptItemIdentifier result = null;
            LearningStoreJob      job    = LStore.CreateJob();

            LearningStoreQuery query = LStore.CreateQuery(Schema.MyAttempts.ViewName);

            query.AddColumn(Schema.MyAttempts.AttemptId);
            query.AddCondition(Schema.MyAttempts.OrganizationId, LearningStoreConditionOperator.Equal, orgId);
            query.AddCondition(Schema.MyAttempts.ThemeId, LearningStoreConditionOperator.Equal, topicId);

            job.PerformQuery(query);

            ReadOnlyCollection <object> resultList = job.Execute();

            DataTable dataTable = (DataTable)resultList[0];

            if (dataTable.Rows.Count > 0)
            {
                // get last result
                LStoreHelper.Cast(dataTable.Rows[dataTable.Rows.Count - 1][Schema.MyAttempts.AttemptId], out result);
            }
            return(result);
        }
示例#26
0
    protected void DeletePackagesButton_Click(object sender, EventArgs e)
    {
        // the user clicked "Upload"...

        // hide the confirmation panel
        ConfirmMessage.Visible = false;

        // the PackagesToDelete hidden form element contains a comma-delimited list of IDs of
        // packages to delete (copied from <dialogArguments> on the client) -- attempt to delete
        // those packages, and set <deleted> to the IDs of packages successfully deleted
        List <string> deleted = new List <string>();

        try
        {
            // loop once for each package to delete
            foreach (string id in PackagesToDelete.Value.Split(','))
            {
                // set <packageId> to the ID of this package
                PackageItemIdentifier packageId = new PackageItemIdentifier(
                    Convert.ToInt64(id, CultureInfo.InvariantCulture));

                // before we delete the package, we need to delete all attempts on the package --
                // the following query looks for those attempts
                LearningStoreJob   job   = LStore.CreateJob();
                LearningStoreQuery query = LStore.CreateQuery(
                    Schema.MyAttemptsAndPackages.ViewName);
                query.AddCondition(Schema.MyAttemptsAndPackages.PackageId,
                                   LearningStoreConditionOperator.Equal, packageId);
                query.AddCondition(Schema.MyAttemptsAndPackages.AttemptId,
                                   LearningStoreConditionOperator.NotEqual, null);
                query.AddColumn(Schema.MyAttemptsAndPackages.AttemptId);
                query.AddSort(Schema.MyAttemptsAndPackages.AttemptId,
                              LearningStoreSortDirection.Ascending);
                job.PerformQuery(query);
                DataTable             dataTable         = job.Execute <DataTable>();
                AttemptItemIdentifier previousAttemptId = null;

                // loop once for each attempt on this package
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    // set <attemptId> to the ID of this attempt
                    AttemptItemIdentifier attemptId;
                    LStoreHelper.CastNonNull(dataRow["AttemptId"], out attemptId);

                    // if <attemptId> is a duplicate attempt ID, skip it; note that the query
                    // results are sorted by attempt ID (see above)
                    if ((previousAttemptId != null) &&
                        (previousAttemptId.GetKey() == attemptId.GetKey()))
                    {
                        continue;
                    }

                    // delete this attempt
                    StoredLearningSession.DeleteAttempt(LStore, attemptId);

                    // continue to the next attempt
                    previousAttemptId = attemptId;
                }

                // delete the package
                PStore.DeletePackage(packageId);

                // add the package ID to the list of deleted packages
                deleted.Add(id);
            }

            // the operation was successful, and there are no messages to
            // display to the user, so close the dialog
            CloseDialogScript.Visible = true;
        }
        catch (Exception ex)
        {
            // an unexpected error occurred -- display a generic message that
            // doesn't include the exception message (since that message may
            // include sensitive information), and write the exception message
            // to the event log
            ErrorIntro.Visible   = true;
            ErrorMessage.Visible = true;
            ErrorMessage.Controls.Add(new System.Web.UI.LiteralControl(
                                          Server.HtmlEncode("A serious error occurred.  Please contact your system administrator.  More information has been written to the server event log.")));
            LogEvent(System.Diagnostics.EventLogEntryType.Error,
                     "An exception occurred while deleting a package:\n\n{0}\n\n", ex.ToString());
        }

        // update the buttons
        DeletePackagesButton.Visible = false;
        CloseButton.Text             = "OK";

        // set the hidden form element PackagesSuccessfullyDeleted to a
        // comma-separated list of IDs of packages that were successfully
        // deleted, and enable the client-side script that communicates this
        // information to the parent page
        PackagesSuccessfullyDeleted.Value = String.Join(",", deleted.ToArray());
        UpdateParentPageScript.Visible    = true;
    }
示例#27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // set <attemptId> to the ID of this attempt
        AttemptItemIdentifier attemptId = new AttemptItemIdentifier(
            Convert.ToInt64(Request.QueryString["AttemptId"], CultureInfo.InvariantCulture));

        // set <previousEntryId> to the ID of the sequencing log entry that we most recently
        // displayed; newer entries than that will be highlighted
        long   previousEntryId;
        string value = Request.QueryString["PreviousEntryId"];

        if (value == null)
        {
            previousEntryId = long.MaxValue;
        }
        else
        {
            previousEntryId = Convert.ToInt64(value, CultureInfo.InvariantCulture);
        }

        try
        {
            // create a job to execute two queries
            LearningStoreJob job = LStore.CreateJob();

            // first query: get the package name and organization title of this attempt
            LearningStoreQuery query = LStore.CreateQuery(Schema.MyAttemptsAndPackages.ViewName);
            query.AddColumn(Schema.MyAttemptsAndPackages.PackageFileName);
            query.AddColumn(Schema.MyAttemptsAndPackages.OrganizationTitle);
            query.AddCondition(Schema.MyAttemptsAndPackages.AttemptId,
                               LearningStoreConditionOperator.Equal, attemptId);
            job.PerformQuery(query);

            // second query: get the contents of the sequencing log for this attempt
            query = LStore.CreateQuery(Schema.SequencingLog.ViewName);
            query.AddColumn(Schema.SequencingLog.Id);
            query.AddColumn(Schema.SequencingLog.Timestamp);
            query.AddColumn(Schema.SequencingLog.EventType);
            query.AddColumn(Schema.SequencingLog.NavigationCommand);
            query.AddColumn(Schema.SequencingLog.Message);
            query.SetParameter(Schema.SequencingLog.AttemptId, attemptId);
            query.AddSort(Schema.SequencingLog.Id,
                          LearningStoreSortDirection.Descending);
            job.PerformQuery(query);

            // execute the job
            ReadOnlyCollection <object> results = job.Execute();
            DataTable attemptInfoDataTable      = (DataTable)results[0];
            DataTable sequencingLogDataTable    = (DataTable)results[1];

            // extract information from the first query into local variables
            DataRow attemptInfo = attemptInfoDataTable.Rows[0];
            string  packageFileName;
            LStoreHelper.CastNonNull(attemptInfo[Schema.MyAttemptsAndPackages.PackageFileName],
                                     out packageFileName);
            string organizationTitle;
            LStoreHelper.CastNonNull(attemptInfo[Schema.MyAttemptsAndPackages.OrganizationTitle],
                                     out organizationTitle);

            // set <trainingName> to the name to use for this attempt
            string trainingName;
            if (organizationTitle.Length == 0)
            {
                trainingName = packageFileName;
            }
            else
            {
                trainingName = String.Format("{0} - {1}", packageFileName, organizationTitle);
            }

            // copy <trainingName> to the UI
            TrainingName.Text = Server.HtmlEncode(trainingName);

            // set <maxLogEntryId> to the highest-numbered log entry ID -- which is the first one,
            // since they're sorted by descending entry ID
            SequencingLogEntryItemIdentifier maxLogEntryId;
            if (sequencingLogDataTable.Rows.Count > 0)
            {
                DataRow dataRow = sequencingLogDataTable.Rows[0];
                LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Id],
                                         out maxLogEntryId);
            }
            else
            {
                maxLogEntryId = new SequencingLogEntryItemIdentifier(-1);
            }

            // loop once for each item in the sequencing log
            foreach (DataRow dataRow in sequencingLogDataTable.Rows)
            {
                // extract information from <dataRow> into local variables
                SequencingLogEntryItemIdentifier logEntryId;
                LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Id],
                                         out logEntryId);
                DateTime?time;
                LStoreHelper.Cast(dataRow[Schema.SequencingLog.Timestamp],
                                  out time);
                SequencingEventType?eventType;
                LStoreHelper.Cast(dataRow[Schema.SequencingLog.EventType],
                                  out eventType);
                NavigationCommand?navigationCommand;
                LStoreHelper.Cast(dataRow[Schema.SequencingLog.NavigationCommand],
                                  out navigationCommand);
                string message;
                LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Message],
                                         out message);

                // begin the HTML table row
                TableRow htmlRow = new TableRow();

                // highlight this row if it's new since the last refresh
                if (logEntryId.GetKey() > previousEntryId)
                {
                    htmlRow.CssClass = "Highlight";
                }

                // add the "ID" HTML cell
                TableCell htmlCell = new TableCell();
                htmlCell.CssClass = "Id_";
                htmlCell.Wrap     = false;
                htmlCell.Text     = NoBr(Server.HtmlEncode(logEntryId.GetKey().ToString()));
                htmlRow.Cells.Add(htmlCell);

                // add the "Time" HTML cell
                htmlCell          = new TableCell();
                htmlCell.CssClass = "Time_";
                htmlCell.Wrap     = false;
                htmlCell.Text     = NoBr(Server.HtmlEncode(String.Format("{0:d} {0:t}", time)));
                htmlRow.Cells.Add(htmlCell);

                // add the "EventType" HTML cell
                htmlCell          = new TableCell();
                htmlCell.CssClass = "EventType_";
                htmlCell.Wrap     = false;
                htmlCell.Text     = NoBr(Server.HtmlEncode(eventType.ToString()));
                htmlRow.Cells.Add(htmlCell);

                // add the "NavigationCommand" HTML cell
                htmlCell          = new TableCell();
                htmlCell.CssClass = "NavigationCommand_";
                htmlCell.Wrap     = false;
                htmlCell.Text     = NoBr(Server.HtmlEncode(navigationCommand.ToString()));
                htmlRow.Cells.Add(htmlCell);

                // add the "Message" HTML cell
                htmlCell          = new TableCell();
                htmlCell.CssClass = "Message_";
                htmlCell.Wrap     = false;
                htmlCell.Text     = Server.HtmlEncode(message);
                htmlRow.Cells.Add(htmlCell);

                // end the table HTML row; add it to the HTML table
                LogGrid.Rows.Add(htmlRow);
            }

            // update <RefreshLink>
            RefreshLink.NavigateUrl = String.Format("?AttemptId={0}&PreviousEntryId={1}",
                                                    attemptId.GetKey(), maxLogEntryId.GetKey());
        }
        catch (Exception ex)
        {
            // an unexpected error occurred -- display a generic message that doesn't include the
            // exception message (since that message may include sensitive information), and write
            // the exception message to the event log
            LogTitle.Visible     = false;
            LogContents.Visible  = false;
            ErrorMessage.Visible = true;
            ErrorMessage.Controls.Add(new System.Web.UI.LiteralControl(
                                          Server.HtmlEncode("A serious error occurred.  Please contact your system administrator.  More information has been written to the server event log.")));
            LogEvent(System.Diagnostics.EventLogEntryType.Error,
                     "An exception occurred while accessing the sequencing log for attempt #{0}:\n\n{1}\n\n",
                     attemptId.GetKey(), ex.ToString());
        }
    }
    protected void UploadPackageButton_OnClick(object sender, EventArgs e)
    {
        // the user clicked "Upload"...

        // do nothing if the user didn't select a file to upload
        if (!UploadedPackageFile.HasFile)
        {
            return;
        }

        // hide the upload panel and show the message panel; the message panel will hold
        // information about the success or failure of the package upload operation
        UploadPanel.Visible  = false;
        MessagePanel.Visible = true;

        // attempt to import the uploaded file into PackageStore
        try
        {
            // set <currentUser> to information about the current user; we need the current user's
            // UserItemIdentifier
            LStoreUserInfo currentUser = GetCurrentUserInfo();

            // import the package file; set packageId to the ID of the uploaded
            // package; set importLog to a collection of warnings (if any)
            // about the import process
            PackageItemIdentifier packageId;
            ValidationResults     importLog;
            using (PackageReader packageReader = PackageReader.Create(UploadedPackageFile.FileContent))
            {
                // Add package, asking to fix anything that can be fixed.
                AddPackageResult result = PStore.AddPackage(packageReader, new PackageEnforcement(false, false, false));
                packageId = result.PackageId;
                importLog = result.Log;
            }

            // fill in the application-specific columns of the PackageItem table
            LearningStoreJob            job        = LStore.CreateJob();
            Dictionary <string, object> properties = new Dictionary <string, object>();
            properties[Schema.PackageItem.Owner]          = currentUser.Id;
            properties[Schema.PackageItem.FileName]       = UploadedPackageFile.FileName;
            properties[Schema.PackageItem.UploadDateTime] = DateTime.Now;
            job.UpdateItem(packageId, properties);
            job.Execute();

            // retrieve information about the package
            job = LStore.CreateJob();
            RequestMyTraining(job, packageId);
            GetMyTrainingResultsToHtml(job.Execute <DataTable>(), TrainingGrid);

            // when the page loads in the browser, copy information about the from the TrainingGrid
            // hidden table to the main page using client-side script
            UpdateParentPageScript.Visible = true;

            // provide user feedback
            if (importLog.HasWarnings)
            {
                // display warnings
                WarningIntro.Visible    = true;
                WarningMessages.Visible = true;
                foreach (ValidationResult result in importLog.Results)
                {
                    ScrollingMessagesList.Items.Add(new ListItem(result.Message));
                }
            }
            else
            {
                // the operation was successful, and there are no messages to display to the user,
                // so close the dialog
                CloseDialogScript.Visible = true;
            }
        }
        catch (PackageImportException ex)
        {
            // a package import failure occurred -- display the error message
            ErrorIntro.Visible   = true;
            ErrorMessage.Visible = true;

            foreach (ValidationResult result in ex.Log.Results)
            {
                ErrorMessageScrollingList.Items.Add(new ListItem(result.Message));
            }

            if (ex.InnerException != null)
            {
                ErrorMessageScrollingList.Items.Add(new ListItem(
                                                        Server.HtmlEncode(ex.InnerException.Message)));
            }
        }
        catch (Exception ex)
        {
            // an unexpected error occurred -- display a generic message that doesn't include the
            // exception message (since that message may include sensitive information), and write
            // the exception message to the event log
            ErrorIntro.Visible   = true;
            ErrorMessage.Visible = true;
            ErrorMessage.Controls.Add(new System.Web.UI.LiteralControl(
                                          Server.HtmlEncode("A serious error occurred.  Please contact your system administrator.  More information has been written to the server event log.")));
            LogEvent(System.Diagnostics.EventLogEntryType.Error,
                     "An exception occurred while uploading a package:\n\n{0}\n\n", ex.ToString());
        }
    }
示例#29
0
        public IEnumerable <AnswerResult> GetAnswers(AttemptResult attemptResult)
        {
            List <AnswerResult>   result    = new List <AnswerResult>();
            LearningStoreJob      job       = LStore.CreateJob();
            AttemptItemIdentifier attemptId = new AttemptItemIdentifier(attemptResult.AttemptId);

            RequestInteractionResultsByAttempt(job, attemptId);
            DataTable dataTable = job.Execute <DataTable>();

            foreach (DataRow dataRow in dataTable.AsEnumerable())
            {
                ActivityAttemptItemIdentifier activityAttemptItemId;
                LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.ActivityAttemptId], out activityAttemptItemId);
                long activityAttemptId = activityAttemptItemId.GetKey();

                ActivityPackageItemIdentifier activityPackageItemId;
                LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.ActivityPackageId], out activityPackageItemId);
                long activityPackageId = activityPackageItemId.GetKey();

                String activityTitle;
                LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.ActivityTitle], out activityTitle);

                InteractionItemIdentifier interactionItemId;
                LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.InteractionId], out interactionItemId);
                long?interactionId = null;
                if (interactionItemId != null)
                {
                    interactionId = interactionItemId.GetKey();
                }

                Microsoft.LearningComponents.CompletionStatus completionStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.InteractionResultsByAttempt.CompletionStatus], out completionStatus);
                IUDICO.Common.Models.Shared.Statistics.CompletionStatus iudicoCompletionStatus = (IUDICO.Common.Models.Shared.Statistics.CompletionStatus)completionStatus;

                Microsoft.LearningComponents.SuccessStatus?successStatus;
                LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.SuccessStatus], out successStatus);
                IUDICO.Common.Models.Shared.Statistics.SuccessStatus?iudicoSuccessStatus = (IUDICO.Common.Models.Shared.Statistics.SuccessStatus?)successStatus;

                bool?learnerResponseBool = null;
                LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.LearnerResponseBool], out learnerResponseBool);

                string learnerResponseString = null;
                LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.LearnerResponseString], out learnerResponseString);

                double?learnerResponseNumeric = null;
                LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.LearnerResponseNumeric], out learnerResponseNumeric);

                object learnerResponse = null;
                if (learnerResponseBool != null)
                {
                    learnerResponse = learnerResponseBool;
                }
                if (learnerResponseString != null)
                {
                    learnerResponse = learnerResponseString;
                }
                if (learnerResponseNumeric != null)
                {
                    learnerResponse = learnerResponseNumeric;
                }

                string correctResponse;
                LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.CorrectResponse], out correctResponse);

                Microsoft.LearningComponents.InteractionType?interactionType = null;
                LStoreHelper.Cast(dataRow[Schema.InteractionResultsByAttempt.InteractionType], out interactionType);
                IUDICO.Common.Models.Shared.Statistics.InteractionType?learnerResponseType = null;
                if (interactionType != null)
                {
                    learnerResponseType = (IUDICO.Common.Models.Shared.Statistics.InteractionType)interactionType;
                }

                float?scaledScore;
                LStoreHelper.Cast <float>(dataRow[Schema.InteractionResultsByAttempt.ScaledScore], out scaledScore);

                // Create AnswerResult object
                AnswerResult answerResult = new AnswerResult(activityAttemptId, activityPackageId, activityTitle, interactionId, iudicoCompletionStatus, iudicoSuccessStatus, attemptResult, learnerResponse, correctResponse, learnerResponseType, scaledScore);
                result.Add(answerResult);
            }

            return(result);
        }