-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for interaction components #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,16 @@ You may obtain a copy of the License at | |
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
/* | ||
* Modified by Paul Carpenter 2015 | ||
* | ||
* Includes support for Activity Interactions | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json.Linq; | ||
using TinCan.Json; | ||
|
||
|
@@ -26,13 +35,13 @@ public class ActivityDefinition : JsonModel | |
public LanguageMap name { get; set; } | ||
public LanguageMap description { get; set; } | ||
public Extensions extensions { get; set; } | ||
//public InteractionType interactionType { get; set; } | ||
//public List<String> correctResponsesPattern { get; set; } | ||
//public List<InteractionComponent> choices { get; set; } | ||
//public List<InteractionComponent> scale { get; set; } | ||
//public List<InteractionComponent> source { get; set; } | ||
//public List<InteractionComponent> target { get; set; } | ||
//public List<InteractionComponent> steps { get; set; } | ||
public String interactionType { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to make |
||
public List<String> correctResponsesPattern { get; set; } | ||
public List<InteractionComponent> choices { get; set; } | ||
public List<InteractionComponent> scale { get; set; } | ||
public List<InteractionComponent> source { get; set; } | ||
public List<InteractionComponent> target { get; set; } | ||
public List<InteractionComponent> steps { get; set; } | ||
|
||
public ActivityDefinition() {} | ||
|
||
|
@@ -60,6 +69,58 @@ public ActivityDefinition(JObject jobj) | |
{ | ||
extensions = (Extensions)jobj.Value<JObject>("extensions"); | ||
} | ||
if (jobj["interactionType"] != null) | ||
{ | ||
interactionType = jobj.Value<String>("interactionType"); | ||
} | ||
if (jobj["correctResponsesPattern"] != null) | ||
{ | ||
correctResponsesPattern = new List<String>(); | ||
foreach (JValue jcorrectResponsesPattern in jobj["correctResponsesPattern"]) | ||
{ | ||
correctResponsesPattern.Add(jcorrectResponsesPattern.ToString()); | ||
} | ||
} | ||
if (jobj["choices"] != null) | ||
{ | ||
choices = new List<InteractionComponent>(); | ||
foreach (JObject jchoices in jobj["choices"]) | ||
{ | ||
choices.Add((InteractionComponent)jchoices); | ||
} | ||
} | ||
if (jobj["scale"] != null) | ||
{ | ||
scale = new List<InteractionComponent>(); | ||
foreach (JObject jscale in jobj["scale"]) | ||
{ | ||
scale.Add((InteractionComponent)jscale); | ||
} | ||
} | ||
if (jobj["source"] != null) | ||
{ | ||
source = new List<InteractionComponent>(); | ||
foreach (JObject jsource in jobj["source"]) | ||
{ | ||
source.Add((InteractionComponent)jsource); | ||
} | ||
} | ||
if (jobj["target"] != null) | ||
{ | ||
target = new List<InteractionComponent>(); | ||
foreach (JObject jtarget in jobj["target"]) | ||
{ | ||
target.Add((InteractionComponent)jtarget); | ||
} | ||
} | ||
if (jobj["steps"] != null) | ||
{ | ||
steps = new List<InteractionComponent>(); | ||
foreach (JObject jsteps in jobj["steps"]) | ||
{ | ||
steps.Add((InteractionComponent)jsteps); | ||
} | ||
} | ||
} | ||
|
||
public override JObject ToJObject(TCAPIVersion version) { | ||
|
@@ -85,6 +146,70 @@ public override JObject ToJObject(TCAPIVersion version) { | |
{ | ||
result.Add("extensions", extensions.ToJObject(version)); | ||
} | ||
if (interactionType != null) | ||
{ | ||
result.Add("interactionType", interactionType.ToString()); | ||
} | ||
if (correctResponsesPattern != null && correctResponsesPattern.Count > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just hit this on the spec, but we need to leave it open to allow for an empty array in 'correctResponsesPattern', see adlnet/xAPI-Spec#698 |
||
{ | ||
var jcorrectResponsesPattern = new JArray(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would prefer to avoid the use of |
||
result.Add("correctResponsesPattern", jcorrectResponsesPattern); | ||
|
||
foreach (String correctReponse in correctResponsesPattern) | ||
{ | ||
jcorrectResponsesPattern.Add(correctReponse.ToString()); | ||
} | ||
} | ||
if (choices != null && choices.Count > 0) | ||
{ | ||
var jchoices = new JArray(); | ||
result.Add("choices", jchoices); | ||
|
||
foreach (InteractionComponent c in choices) | ||
{ | ||
jchoices.Add(c.ToJObject(version)); | ||
} | ||
} | ||
if (scale != null && scale.Count > 0) | ||
{ | ||
var jscale = new JArray(); | ||
result.Add("scale", jscale); | ||
|
||
foreach (InteractionComponent s in scale) | ||
{ | ||
jscale.Add(s.ToJObject(version)); | ||
} | ||
} | ||
if (source != null && source.Count > 0) | ||
{ | ||
var jsource = new JArray(); | ||
result.Add("source", jsource); | ||
|
||
foreach (InteractionComponent s in source) | ||
{ | ||
jsource.Add(s.ToJObject(version)); | ||
} | ||
} | ||
if (target != null && target.Count > 0) | ||
{ | ||
var jtarget = new JArray(); | ||
result.Add("target", jtarget); | ||
|
||
foreach (InteractionComponent t in target) | ||
{ | ||
jtarget.Add(t.ToJObject(version)); | ||
} | ||
} | ||
if (steps != null && steps.Count > 0) | ||
{ | ||
var jsteps = new JArray(); | ||
result.Add("steps", jsteps); | ||
|
||
foreach (InteractionComponent s in steps) | ||
{ | ||
jsteps.Add(s.ToJObject(version)); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Created by Paul Carpenter 2015 | ||
* | ||
* Includes support for Activity Interaction Components | ||
* | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above comment about attributions. This file still needs the Apache license header to match the others. |
||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Newtonsoft.Json.Linq; | ||
using TinCan.Json; | ||
|
||
namespace TinCan | ||
{ | ||
public class InteractionComponent : JsonModel | ||
{ | ||
public String id { get; set; } | ||
public LanguageMap description { get; set; } | ||
|
||
public InteractionComponent() { } | ||
|
||
public InteractionComponent(StringOfJSON json): this(json.toJObject()) {} | ||
|
||
public InteractionComponent(JObject jobj) | ||
{ | ||
if (jobj["id"] != null) | ||
{ | ||
id = jobj.Value<String>("id"); | ||
} | ||
if (jobj["description"] != null) | ||
{ | ||
description = (LanguageMap)jobj.Value<JObject>("description"); | ||
} | ||
} | ||
|
||
public override JObject ToJObject(TCAPIVersion version) | ||
{ | ||
JObject result = new JObject(); | ||
|
||
if (id != null) | ||
{ | ||
result.Add("id", id); | ||
} | ||
if (description != null && !description.isEmpty()) | ||
{ | ||
result.Add("description", description.ToJObject(version)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static explicit operator InteractionComponent(JObject jobj) | ||
{ | ||
return new InteractionComponent(jobj); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,9 @@ | |
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Newtonsoft.Json"> | ||
<HintPath>..\packages\Newtonsoft.Json.6.0.2\lib\net35\Newtonsoft.Json.dll</HintPath> | ||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were these automatically done by VS or intentional? What effect (if any) do they have? |
||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
|
@@ -60,6 +61,7 @@ | |
<Compile Include="ActivityDefinition.cs" /> | ||
<Compile Include="Context.cs" /> | ||
<Compile Include="ContextActivities.cs" /> | ||
<Compile Include="InteractionComponent.cs" /> | ||
<Compile Include="StatementsQueryResultFormat.cs" /> | ||
<Compile Include="StatementsQuery.cs" /> | ||
<Compile Include="SubStatement.cs" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net35" /> | ||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" /> | ||
</packages> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer to keep this out of the source, git should be able to track these types of changes easily. If we need new attribution it can go somewhere outside of the source itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check with Oliver about this. It may be that this was just intended to be an internal note so they know what they changed from the library, which becomes unnecessary if/when this is merged anyway.