Skip to content

Commit 27262b3

Browse files
authored
Merge pull request #40 from reedmclean/MinorVersionChanges
Consolidating open PRs
2 parents a0f5997 + fa0d377 commit 27262b3

File tree

9 files changed

+386
-9
lines changed

9 files changed

+386
-9
lines changed

TinCan/ActivityDefinition.cs

Lines changed: 117 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ You may obtain a copy of the License at
1414
limitations under the License.
1515
*/
1616
using System;
17+
using System.Linq;
18+
using System.Collections.Generic;
19+
using Newtonsoft.Json;
1720
using Newtonsoft.Json.Linq;
1821
using TinCan.Json;
1922

23+
2024
namespace TinCan
2125
{
2226
public class ActivityDefinition : JsonModel
@@ -26,13 +30,13 @@ public class ActivityDefinition : JsonModel
2630
public LanguageMap name { get; set; }
2731
public LanguageMap description { get; set; }
2832
public Extensions extensions { get; set; }
29-
//public InteractionType interactionType { get; set; }
30-
//public List<String> correctResponsesPattern { get; set; }
31-
//public List<InteractionComponent> choices { get; set; }
32-
//public List<InteractionComponent> scale { get; set; }
33-
//public List<InteractionComponent> source { get; set; }
34-
//public List<InteractionComponent> target { get; set; }
35-
//public List<InteractionComponent> steps { get; set; }
33+
public InteractionType interactionType { get; set; }
34+
public List<String> correctResponsesPattern { get; set; }
35+
public List<InteractionComponent> choices { get; set; }
36+
public List<InteractionComponent> scale { get; set; }
37+
public List<InteractionComponent> source { get; set; }
38+
public List<InteractionComponent> target { get; set; }
39+
public List<InteractionComponent> steps { get; set; }
3640

3741
public ActivityDefinition() {}
3842

@@ -60,6 +64,54 @@ public ActivityDefinition(JObject jobj)
6064
{
6165
extensions = (Extensions)jobj.Value<JObject>("extensions");
6266
}
67+
if (jobj["interactionType"] != null)
68+
{
69+
interactionType = InteractionType.FromValue(jobj.Value<String>("interactionType"));
70+
}
71+
if (jobj["correctResponsesPattern"] != null)
72+
{
73+
correctResponsesPattern = ((JArray)jobj["correctResponsesPattern"]).Select(x => x.Value<String>()).ToList<String>();
74+
}
75+
if (jobj["choices"] != null)
76+
{
77+
choices = new List<InteractionComponent>();
78+
foreach (JObject jchoice in jobj["choices"])
79+
{
80+
choices.Add(new InteractionComponent(jchoice));
81+
}
82+
}
83+
if (jobj["scale"] != null)
84+
{
85+
scale = new List<InteractionComponent>();
86+
foreach (JObject jscale in jobj["scale"])
87+
{
88+
scale.Add(new InteractionComponent(jscale));
89+
}
90+
}
91+
if (jobj["source"] != null)
92+
{
93+
source = new List<InteractionComponent>();
94+
foreach (JObject jsource in jobj["source"])
95+
{
96+
source.Add(new InteractionComponent(jsource));
97+
}
98+
}
99+
if (jobj["target"] != null)
100+
{
101+
target = new List<InteractionComponent>();
102+
foreach (JObject jtarget in jobj["target"])
103+
{
104+
target.Add(new InteractionComponent(jtarget));
105+
}
106+
}
107+
if (jobj["steps"] != null)
108+
{
109+
steps = new List<InteractionComponent>();
110+
foreach (JObject jstep in jobj["steps"])
111+
{
112+
steps.Add(new InteractionComponent(jstep));
113+
}
114+
}
63115
}
64116

65117
public override JObject ToJObject(TCAPIVersion version) {
@@ -85,6 +137,64 @@ public override JObject ToJObject(TCAPIVersion version) {
85137
{
86138
result.Add("extensions", extensions.ToJObject(version));
87139
}
140+
if (interactionType != null)
141+
{
142+
result.Add("interactionType", interactionType.Value);
143+
}
144+
if (correctResponsesPattern != null && correctResponsesPattern.Count > 0)
145+
{
146+
result.Add("correctResponsesPattern", JToken.FromObject(correctResponsesPattern));
147+
}
148+
if (choices != null && choices.Count > 0)
149+
{
150+
var jchoices = new JArray();
151+
result.Add("choices", jchoices);
152+
153+
foreach (InteractionComponent ichoice in choices)
154+
{
155+
jchoices.Add(ichoice.ToJObject(version));
156+
}
157+
}
158+
if (scale != null && scale.Count > 0)
159+
{
160+
var jscale = new JArray();
161+
result.Add("scale", jscale);
162+
163+
foreach (InteractionComponent iscale in scale)
164+
{
165+
jscale.Add(iscale.ToJObject(version));
166+
}
167+
}
168+
if (source != null && source.Count > 0)
169+
{
170+
var jsource = new JArray();
171+
result.Add("source", jsource);
172+
173+
foreach (InteractionComponent isource in source)
174+
{
175+
jsource.Add(isource.ToJObject(version));
176+
}
177+
}
178+
if (target != null && target.Count > 0)
179+
{
180+
var jtarget = new JArray();
181+
result.Add("target", jtarget);
182+
183+
foreach (InteractionComponent itarget in target)
184+
{
185+
jtarget.Add(itarget.ToJObject(version));
186+
}
187+
}
188+
if (steps != null && steps.Count > 0)
189+
{
190+
var jsteps = new JArray();
191+
result.Add("steps", jsteps);
192+
193+
foreach (InteractionComponent istep in steps)
194+
{
195+
jsteps.Add(istep.ToJObject(version));
196+
}
197+
}
88198

89199
return result;
90200
}

TinCan/InteractionComponent.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2018 Rustici Software
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
using System;
17+
using System.Collections.Generic;
18+
using Newtonsoft.Json.Linq;
19+
using TinCan.Json;
20+
21+
namespace TinCan
22+
{
23+
public class InteractionComponent : JsonModel
24+
{
25+
public String id;
26+
public LanguageMap description { get; set; }
27+
28+
public InteractionComponent()
29+
{
30+
31+
}
32+
33+
public InteractionComponent(JObject jobj)
34+
{
35+
if (jobj["id"] != null)
36+
{
37+
id = jobj.Value<String>("id");
38+
}
39+
if (jobj["description"] != null)
40+
{
41+
description = (LanguageMap)jobj.Value<JObject>("description");
42+
}
43+
}
44+
45+
public override JObject ToJObject(TCAPIVersion version)
46+
{
47+
JObject result = new JObject();
48+
49+
if (id != null)
50+
{
51+
result.Add("id", id);
52+
}
53+
if (description != null && !description.isEmpty())
54+
{
55+
result.Add("description", description.ToJObject(version));
56+
}
57+
58+
return result;
59+
}
60+
61+
public static explicit operator InteractionComponent(JObject jobj)
62+
{
63+
return new InteractionComponent(jobj);
64+
}
65+
66+
}
67+
68+
}

TinCan/InteractionType.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
3+
namespace TinCan
4+
{
5+
public sealed class InteractionType
6+
{
7+
private const string CHOICE = "choice";
8+
private const string SEQUENCING = "sequencing";
9+
private const string LIKERT = "likert";
10+
private const string MATCHING = "matching";
11+
private const string PERFORMANCE = "performance";
12+
private const string TRUEFALSE = "true-false";
13+
private const string FILLIN = "fill-in";
14+
private const string LONGFILLIN = "long-fill-in";
15+
private const string NUMERIC = "numeric";
16+
private const string OTHER = "other";
17+
18+
public static readonly InteractionType Choice = new InteractionType(CHOICE);
19+
public static readonly InteractionType Sequencing = new InteractionType(SEQUENCING);
20+
public static readonly InteractionType Likert = new InteractionType(LIKERT);
21+
public static readonly InteractionType Matching = new InteractionType(MATCHING);
22+
public static readonly InteractionType Performance = new InteractionType(PERFORMANCE);
23+
public static readonly InteractionType TrueFalse = new InteractionType(TRUEFALSE);
24+
public static readonly InteractionType FillIn = new InteractionType(FILLIN);
25+
public static readonly InteractionType LongFillIn = new InteractionType(LONGFILLIN);
26+
public static readonly InteractionType Numeric = new InteractionType(NUMERIC);
27+
public static readonly InteractionType Other = new InteractionType(OTHER);
28+
29+
private InteractionType(string value)
30+
{
31+
Value = value;
32+
}
33+
34+
public static InteractionType FromValue(string value)
35+
{
36+
switch (value)
37+
{
38+
case CHOICE:
39+
return Choice;
40+
41+
case SEQUENCING:
42+
return Sequencing;
43+
44+
case LIKERT:
45+
return Likert;
46+
47+
case MATCHING:
48+
return Matching;
49+
50+
case PERFORMANCE:
51+
return Performance;
52+
53+
case TRUEFALSE:
54+
return TrueFalse;
55+
56+
case FILLIN:
57+
return FillIn;
58+
59+
case LONGFILLIN:
60+
return LongFillIn;
61+
62+
case NUMERIC:
63+
return Numeric;
64+
65+
case OTHER:
66+
return Other;
67+
68+
default:
69+
throw new ArgumentOutOfRangeException(nameof(value),
70+
$"'{value}' is not a valid interactionType.");
71+
}
72+
}
73+
74+
public string Value { get; private set; }
75+
}
76+
}

TinCan/TCAPIVersion.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace TinCan
2020
{
2121
public sealed class TCAPIVersion
2222
{
23+
public static readonly TCAPIVersion V103 = new TCAPIVersion("1.0.3");
2324
public static readonly TCAPIVersion V102 = new TCAPIVersion("1.0.2");
2425
public static readonly TCAPIVersion V101 = new TCAPIVersion("1.0.1");
2526
public static readonly TCAPIVersion V100 = new TCAPIVersion("1.0.0");
@@ -28,7 +29,7 @@ public sealed class TCAPIVersion
2829

2930
public static TCAPIVersion latest()
3031
{
31-
return V101;
32+
return V103;
3233
}
3334

3435
private static Dictionary<String, TCAPIVersion> known;
@@ -41,6 +42,7 @@ public static Dictionary<String, TCAPIVersion> GetKnown()
4142
}
4243

4344
known = new Dictionary<String, TCAPIVersion>();
45+
known.Add("1.0.3", V103);
4446
known.Add("1.0.2", V102);
4547
known.Add("1.0.1", V101);
4648
known.Add("1.0.0", V100);
@@ -57,6 +59,7 @@ public static Dictionary<String, TCAPIVersion> GetSupported()
5759
}
5860

5961
supported = new Dictionary<String, TCAPIVersion>();
62+
supported.Add("1.0.3", V103);
6063
supported.Add("1.0.2", V102);
6164
supported.Add("1.0.1", V101);
6265
supported.Add("1.0.0", V100);

TinCan/TinCan.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
<Compile Include="ActivityDefinition.cs" />
9595
<Compile Include="Context.cs" />
9696
<Compile Include="ContextActivities.cs" />
97+
<Compile Include="InteractionComponent.cs" />
98+
<Compile Include="InteractionType.cs" />
9799
<Compile Include="StatementsQueryResultFormat.cs" />
98100
<Compile Include="StatementsQuery.cs" />
99101
<Compile Include="SubStatement.cs" />

0 commit comments

Comments
 (0)