Exemplo n.º 1
0
        protected virtual string GetContextToken(ReponseRepoMonitor repoMon, ScorableResponse scorableResponse)
        {
            WebValueCollection tokenData = new WebValueCollection();

            tokenData.Set("oppKey", scorableResponse.OppKey);
            tokenData.Set("itemKey", scorableResponse.ItemKey);
            tokenData.Set("position", scorableResponse.Position);
            tokenData.Set("sequence", scorableResponse.ResponseSequence);
            tokenData.Set("scoremark", scorableResponse.ScoreMark);
            tokenData.Set("hubDBIP", repoMon.DBIP);
            tokenData.Set("hubDBName", repoMon.DBName);
            tokenData.Set("clientName", repoMon.ClientName);
            tokenData.Set("environment", repoMon.Environment);
            return(EncryptionHelper.EncryptToBase64(tokenData.ToString(false))); // encrypt token (do not url encode)
        }
        public List <ScorableResponse> GetScoreItems(int pendingMinutes, int minAttempts, int maxAttempts, int sessionType, int maxItemsReturned)
        {
            SqlCommand cmd = CreateCommand(CommandType.StoredProcedure, "SD_GetScoreItems");

            AddClientParameter(cmd);
            cmd.AddInt("pendingMinutes", pendingMinutes);
            cmd.AddInt("minAttempts", minAttempts);
            cmd.AddInt("maxAttempts", maxAttempts);
            //cmd.AddInt("sessionType", sessionType);
            cmd.AddInt("maxItemsReturned", maxItemsReturned);

            List <ScorableResponse> scorableResponses = new List <ScorableResponse>();

            ExecuteReader(cmd, delegate(IColumnReader reader)
            {
                while (reader.Read())
                {
                    ScorableResponse scorableResponse = new ScorableResponse
                    {
                        OppKey = reader.GetGuid("OppKey"),
                        //TODO: this is probably a good thing to have for item resolution rules.  Can add this to the contextToken
                        //  so that we can key off of it in the callback handler to determine which rule to create.  We'll want to store
                        //  it though in TestOpportunityItemScore to avoid joins, and we don't need it right now since there's only 1 item resolution
                        //  rule that keys off of the item type.
                        //TestKey = reader.GetString("testkey"),
                        TestId           = reader.GetString("testID"),
                        Position         = reader.GetInt32("position"),
                        ResponseSequence = reader.GetInt32("reportingversion"),
                        Response         = !reader.IsDBNull("response") ? reader.GetString("response") : null, // Response can be NULL so making sure we dont error out because of that.
                        //ScoreMark = reader.GetGuid("scoremark"),
                        ItemKey = reader.GetString("itemKey"),
                        Format  = reader.GetString("ItemType"),
                        //Language = reader.GetString("Language"),
                        Attempts = reader.GetInt32("attempts"),
                        //SegmentId = reader.GetString("segmentID"),
                        //note: this is currently being set to a bogus, static value, but it needs to be non-blank/null
                        //  in order for the scoring request to be made.
                        ItemFile = !reader.IsDBNull("itemFile") ? reader.GetString("itemFile") : null
                    };

                    scorableResponses.Add(scorableResponse);
                }
            });

            return(scorableResponses);
        }
        protected override string GetContextToken(ReponseRepoMonitor repoMon, ScorableResponse scorableResponse)
        {
            int[] itemKey = scorableResponse.GetItemKeyTokens();

            ItemScoreRequestContextToken contextToken = new ItemScoreRequestContextToken()
            {
                clientName       = repoMon.ClientName,
                oppKey           = scorableResponse.OppKey,
                reportingVersion = scorableResponse.ResponseSequence,
                itemBank         = itemKey[0],
                itemID           = itemKey[1],
                TISIP            = repoMon.DBIP,
                TISDbName        = repoMon.DBName,
                environment      = repoMon.Environment,
                itemType         = scorableResponse.Format
            };

            return(EncryptionHelper.EncryptToBase64(JsonHelper.Serialize <ItemScoreRequestContextToken>(contextToken)));  // encrypt token (do not url encode)
        }
Exemplo n.º 4
0
        public virtual ItemScoreRequest MakeItemScoreRequest(ReponseRepoMonitor repoMon, ScorableResponse scorableResponse, ItemScoringRule scoringRule, string itemScoringServerUrl)
        {
            // Check if we have a call back url. Without that, ISE can't send us back a score
            if (ScoringDaemonSettings.ItemScoringCallBackHostUrl == null)
            {
                return(null);
            }

            //The actual rubric is retrieved from the satellites student app. We send the item file path and let the student app give us the rubric
            string itemFile      = EncryptionHelper.EncodeToBase64(scorableResponse.ItemFile);
            string studentAppUrl = ScoringDaemonSettings.StudentAppUrlOverride ?? scoringRule.StudentAppUrl;
            Uri    rubricUri;

            if (!Uri.TryCreate(studentAppUrl + "ItemScoringRubric.axd?item=" + itemFile, UriKind.Absolute, out rubricUri))
            {
                return(null);
            }

            // If the item scoring server and the student app are colocated, check if we can use localhost to talk between the 2 instead of thier public URLs
            if (ScoringDaemonSettings.EnableLocalHostUsageForColocatedApps)
            {
                Uri itemScoringServerUri;
                if (Uri.TryCreate(itemScoringServerUrl, UriKind.Absolute, out itemScoringServerUri) &&
                    itemScoringServerUri.Host == rubricUri.Host)
                {
                    rubricUri = (new UriBuilder(rubricUri)
                    {
                        Host = "localhost"
                    }).Uri;
                }
            }

            // If the item format is one that is scored using our Java ISE, we need to send the item bank and key in the rubric URI as opposed to the itemFile
            // Rewrite the rubricUri accordingly
            if (ScoringDaemonSettings.ItemFormatsRequiringItemKeysForRubric.Contains(scorableResponse.Format))
            {
                string[] tokens = scorableResponse.ItemKey.Split('-');  // Item key is something like 195-3456
                if (tokens.Length != 2)
                {
                    return(null);                      // the item key is not parseable
                }
                if (!Uri.TryCreate(studentAppUrl + String.Format("ItemScoringRubric.axd?itembank={0}&itemid={1}", tokens[0], tokens[1]), UriKind.Absolute, out rubricUri))
                {
                    return(null);
                }
            }

            // Create a context token with enough info in it for the item scoring callback handler to persist the score
            // when it receives it
            string contextToken = GetContextToken(repoMon, scorableResponse);

            ResponseInfo responseInfo = new ResponseInfo(scorableResponse.Format, scorableResponse.ItemKey,
                                                         scorableResponse.Response, rubricUri, RubricContentType.Uri,
                                                         contextToken, true);

            return(new ItemScoreRequest
            {
                ResponseInfo = responseInfo,
                CallbackUrl = ScoringDaemonSettings.ItemScoringCallBackHostUrl + "ItemScoringCallback.axd"
            });
        }