سؤال

I am trying to use the .NET TinCan Library for use within my own Learning Management System. I have included the TinCan 0.0.2 Nuget package in my application and uploaded the GolfExample_TCAPI test course. The GolfExample course loads at the following URL when testing locally:

https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI%20(1)/index.html?

On looking at the launch documentation that I could find it seems that at a minimum you are required to pass in the endpoint, the auth, and the actor so I have attempted to do so using the dll as follows within my viewmodel.

var lrs = new RemoteLRS("https://cloud.scorm.com/tc/public/", "<username>", "<password>");

var actor = new TinCan.Agent();
actor.name = "John Paul Mc Feely";
actor.mbox = "jpmcfeely@hsl-data.com";

TINCANStartPage = HttpContext.Current.Request.Url.Scheme + "://" + @HttpContext.Current.Request.Url.Host + ":" +
                @HttpContext.Current.Request.Url.Port + HttpContext.Current.Request.ApplicationPath + this.Course.BlobURL + "/index.html" + "?endpoint=" + lrs.endpoint + "&auth=" + lrs.auth + "&actor=" + actor.ToJSON();  

When debugging I can see that this created the URL for the launch window as follows:

"https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI (1)/index.html?endpoint=https://cloud.scorm.com/tc/public/&auth=Basic anBtY2ZlZWx5QGhzbC1kYXRhLmNvbTpwbGFzbWExMQ==&actor={\"objectType\":\"Agent\",\"name\":\"John Paul Mc Feely\",\"mbox\":\"jpmcfeely@hsl-data.com\"}"

This looks like the correct format according to the documentation that I can see but when I proceed the window launches with the URL as:

https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI%20(1)/index.html?endpoint=https://cloud.scorm.com/tc/public/&amp;auth=Basic%20anBtY2ZlZWx5QGhzbC1kYXRhLmNvbTpwbGFzbWExMQ==&amp;actor={&quot;objectType&quot;:&quot;Agent&quot;,&quot;name&quot;:&quot;John%20Paul%20Mc%20Feely&quot;,&quot;mbox&quot;:&quot;jpmcfeely@hsl-data.com&quot;}

I then get a warning message as follows:

[warning] There was a problem communicating with the Learning Record Store. (400 | Statement 3bd49829-dc0b-4daa-a689-71a84c44e6ad does not have an actor assigned.)

If anyone could see what I am doing wrong here it would be greatly appreciated.

هل كانت مفيدة؟

المحلول

Minimally the query string parameters need to be URLEncoded. You would need to wrap lrs.endpoint, lrs.auth and actor.ToJSON() in HttpUtility.UrlEncode().

using System.Web;

TINCANStartPage = HttpContext.Current.Request.Url.Scheme + 
    "://" + 
    @HttpContext.Current.Request.Url.Host +
    ":" +
    @HttpContext.Current.Request.Url.Port + 
    HttpContext.Current.Request.ApplicationPath + 
    this.Course.BlobURL + 
    "/index.html" + 
    "?endpoint=" + 
    HttpUtility.UrlEncode(lrs.endpoint) + 
    "&auth=" + 
    HttpUtility.UrlEncode(lrs.auth) + 
    "&actor=" + 
    HttpUtility.UrlEncode(actor.ToJSON());

Based on the warning message it sounds like you are passing this through to TinCanJS. We'd need to see that code to troubleshoot further. The code that is instantiating the TinCan object needs to pass it the url to parse, which seems to be working, but the actor is not being found possibly because of the incorrect URL encoding.

Note that the fact that you are getting a 400 status with that response means it is connecting to the LRS successfully, just what is sent in the request isn't valid.

نصائح أخرى

I got this working by doing the following on the ViewModel:

//Initialize the LRS
var lrs = new RemoteLRS("https://cloud.scorm.com/tc/public/", "<username>", "<password>");  

//Initialize the TinCan Actor for Launch String
this.Actor = new TinCan.Agent();
this.Actor.name = this.User.Forename + " " + this.User.Surname;
this.Actor.mbox = this.User.Email;

//Construct the TinCanStartPage
TINCANStartPage = HttpContext.Current.Request.Url.Scheme + "://" + @HttpContext.Current.Request.Url.Host + ":" +
                @HttpContext.Current.Request.Url.Port + HttpContext.Current.Request.ApplicationPath + this.Course.BlobURL + this.LaunchPage;

Then on the view where the TinCan window is launched from I have the following:

$(document).ready(function () {

    var myActor = '@Html.Raw(Model.Actor.ToJSON())';        
    var launchLink = '@Model.TINCANStartPage' + '?endpoint=' + '@Model.LRS.endpoint' + '&auth=' + '@Model.LRS.auth' + '&actor=' + myActor;
    window.open(launchLink, "SCORM", "width=1140,height=760,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0");

});

function relaunch() {        
    var relaunchLink = '@Model.TINCANStartPage' + '?endpoint=' + '@Model.LRS.endpoint' + '&auth=' + '@Model.LRS.auth' + '&actor=' + myActor;
    window.open(relaunchLink, 'SCORM', 'width=1140,height=760,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
} 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top