@@ -14,9 +14,13 @@ You may obtain a copy of the License at
1414 limitations under the License.
1515*/
1616using System ;
17+ using System . Linq ;
18+ using System . Collections . Generic ;
19+ using Newtonsoft . Json ;
1720using Newtonsoft . Json . Linq ;
1821using TinCan . Json ;
1922
23+
2024namespace 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 }
0 commit comments