Created
November 4, 2012 19:50
-
-
Save andyfmiller/4013303 to your computer and use it in GitHub Desktop.
AddLti10Parameters
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.0 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 AddLti10Parameters(Assignment assignment, OAuthParameters parameters) | |
{ | |
// LTI 1.0 does not include custom parameter substitution, so the custom parameter | |
// values are added as-is. | |
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 = namevalue[1]; | |
parameters.AdditionalParameters.Add(name, value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment