Created
November 4, 2012 19:51
-
-
Save andyfmiller/4013308 to your computer and use it in GitHub Desktop.
AddLti11Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Add optional parameters that are specific to an LTI 1.1 request. | |
/// </summary> | |
/// <param name="assignment">The Assignment to be launched.</param> | |
/// <param name="parameters">The partially filled OAuthParameters object | |
/// that is being used to collect the data.</param> | |
private void AddLti11Parameters(Assignment assignment, OAuthParameters parameters) | |
{ | |
// LTI 1.1 does support custom parameter substitution | |
if (!string.IsNullOrWhiteSpace(assignment.CustomParameters)) | |
{ | |
var customParams = assignment.CustomParameters.Split(new[] { ",", "\r\n", "\n" }, | |
StringSplitOptions.RemoveEmptyEntries); | |
foreach (var customParam in customParams) | |
{ | |
var namevalue = customParam.Split(new[] { "=" }, | |
StringSplitOptions.RemoveEmptyEntries); | |
if (namevalue.Length == 2) | |
{ | |
// Note that per the LTI 1.x specs, custom parameter | |
// names must be lowercase letters or numbers. Any other | |
// character is replaced with an underscore. | |
var name = "custom_" + | |
Regex.Replace(namevalue[0].ToLower(), "[^0-9a-zA-Z]", "_"); | |
var value = SubstituteCustomValue(namevalue[1]); | |
parameters.AdditionalParameters.Add(name, value); | |
} | |
} | |
} | |
// Basic Outcomes Service: These parameters tell the provider where to | |
// send outcomes (if any) for this assignment. | |
var urlHelper = new UrlHelper(Request.RequestContext); | |
parameters.AdditionalParameters.Add("lis_outcome_service_url", | |
urlHelper.Action("Outcome", "Assignment", null, Request.Url.Scheme)); | |
parameters.AdditionalParameters.Add("lis_result_sourcedid", | |
assignment.AssignmentId.ToString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment