diff --git a/TinCan/ActivityDefinition.cs b/TinCan/ActivityDefinition.cs index a9fe2af..db986be 100644 --- a/TinCan/ActivityDefinition.cs +++ b/TinCan/ActivityDefinition.cs @@ -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 correctResponsesPattern { get; set; } - //public List choices { get; set; } - //public List scale { get; set; } - //public List source { get; set; } - //public List target { get; set; } - //public List steps { get; set; } + public String interactionType { get; set; } + public List correctResponsesPattern { get; set; } + public List choices { get; set; } + public List scale { get; set; } + public List source { get; set; } + public List target { get; set; } + public List steps { get; set; } public ActivityDefinition() {} @@ -60,6 +69,58 @@ public ActivityDefinition(JObject jobj) { extensions = (Extensions)jobj.Value("extensions"); } + if (jobj["interactionType"] != null) + { + interactionType = jobj.Value("interactionType"); + } + if (jobj["correctResponsesPattern"] != null) + { + correctResponsesPattern = new List(); + foreach (JValue jcorrectResponsesPattern in jobj["correctResponsesPattern"]) + { + correctResponsesPattern.Add(jcorrectResponsesPattern.ToString()); + } + } + if (jobj["choices"] != null) + { + choices = new List(); + foreach (JObject jchoices in jobj["choices"]) + { + choices.Add((InteractionComponent)jchoices); + } + } + if (jobj["scale"] != null) + { + scale = new List(); + foreach (JObject jscale in jobj["scale"]) + { + scale.Add((InteractionComponent)jscale); + } + } + if (jobj["source"] != null) + { + source = new List(); + foreach (JObject jsource in jobj["source"]) + { + source.Add((InteractionComponent)jsource); + } + } + if (jobj["target"] != null) + { + target = new List(); + foreach (JObject jtarget in jobj["target"]) + { + target.Add((InteractionComponent)jtarget); + } + } + if (jobj["steps"] != null) + { + steps = new List(); + 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) + { + var jcorrectResponsesPattern = new JArray(); + 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; } diff --git a/TinCan/InteractionComponent.cs b/TinCan/InteractionComponent.cs new file mode 100644 index 0000000..aa8c54e --- /dev/null +++ b/TinCan/InteractionComponent.cs @@ -0,0 +1,59 @@ +/* + * Created by Paul Carpenter 2015 + * + * Includes support for Activity Interaction Components + * + */ + +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("id"); + } + if (jobj["description"] != null) + { + description = (LanguageMap)jobj.Value("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); + } + } +} diff --git a/TinCan/TinCan.csproj b/TinCan/TinCan.csproj index 1fe1a35..da3b9ce 100644 --- a/TinCan/TinCan.csproj +++ b/TinCan/TinCan.csproj @@ -41,8 +41,9 @@ MinimumRecommendedRules.ruleset - - ..\packages\Newtonsoft.Json.6.0.2\lib\net35\Newtonsoft.Json.dll + + False + ..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll @@ -60,6 +61,7 @@ + diff --git a/TinCan/packages.config b/TinCan/packages.config index 62fcc5b..7a13476 100644 --- a/TinCan/packages.config +++ b/TinCan/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file