无法使用.NET Tin Can Library连接到LRS

时间:2014-06-04 08:53:17

标签: c# nuget tin-can-api

我正在尝试使用.NET TinCan库在我自己的学习管理系统中使用。我在我的应用程序中包含了TinCan 0.0.2 Nuget包,并上传了GolfExample_TCAPI测试课程。在本地测试时,GolfExample课程将加载以下URL:

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

在查看我可以找到的启动文档时,似乎至少需要传入端点,auth和actor,所以我尝试在我的viewmodel中使用dll进行如下操作。

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();  

调试时我可以看到这创建了启动窗口的URL,如下所示:

"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\"}"

根据我可以看到的文档,这看起来是正确的格式,但当我继续使用URL启动窗口时:

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;}

然后我收到如下警告信息:

[警告]与学习记录存储区通信时出现问题。 (400 |陈述3bd49829-dc0b-4daa-a689-71a84c44e6ad没有分配演员。)

如果有人能够看到我在这里做错了什么,我将不胜感激。

2 个答案:

答案 0 :(得分:3)

最小的查询字符串参数需要URLEncoded。您需要在lrs.endpoint中包含lrs.authactor.ToJSON()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());

基于警告信息,听起来你正在将此传递给TinCanJS。我们需要查看该代码以进一步排除故障。实例化TinCan对象的代码需要将url传递给parse,这似乎有效,但是由于URL编码不正确而找不到actor。

请注意,您使用该响应获得400状态意味着它已成功连接到LRS,只是请求中发送的内容无效。

答案 1 :(得分:0)

我通过在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;

然后在启动TinCan窗口的视图中,我有以下内容:

$(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');
}