@@ -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,11 +64,62 @@ 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+ }
115+
116+
117+
63118 }
64119
65120 public override JObject ToJObject ( TCAPIVersion version ) {
66121 JObject result = new JObject ( ) ;
67-
122+
68123 if ( type != null )
69124 {
70125 result . Add ( "type" , type . ToString ( ) ) ;
@@ -85,6 +140,64 @@ public override JObject ToJObject(TCAPIVersion version) {
85140 {
86141 result . Add ( "extensions" , extensions . ToJObject ( version ) ) ;
87142 }
143+ if ( interactionType != null )
144+ {
145+ result . Add ( "interactionType" , interactionType . Value ) ;
146+ }
147+ if ( correctResponsesPattern != null && correctResponsesPattern . Count > 0 )
148+ {
149+ result . Add ( "correctResponsesPattern" , JToken . FromObject ( correctResponsesPattern ) ) ;
150+ }
151+ if ( choices != null && choices . Count > 0 )
152+ {
153+ var jchoices = new JArray ( ) ;
154+ result . Add ( "choices" , jchoices ) ;
155+
156+ foreach ( InteractionComponent ichoice in choices )
157+ {
158+ jchoices . Add ( ichoice . ToJObject ( version ) ) ;
159+ }
160+ }
161+ if ( scale != null && scale . Count > 0 )
162+ {
163+ var jscale = new JArray ( ) ;
164+ result . Add ( "scale" , jscale ) ;
165+
166+ foreach ( InteractionComponent iscale in scale )
167+ {
168+ jscale . Add ( iscale . ToJObject ( version ) ) ;
169+ }
170+ }
171+ if ( source != null && source . Count > 0 )
172+ {
173+ var jsource = new JArray ( ) ;
174+ result . Add ( "source" , jsource ) ;
175+
176+ foreach ( InteractionComponent isource in source )
177+ {
178+ jsource . Add ( isource . ToJObject ( version ) ) ;
179+ }
180+ }
181+ if ( target != null && target . Count > 0 )
182+ {
183+ var jtarget = new JArray ( ) ;
184+ result . Add ( "target" , jtarget ) ;
185+
186+ foreach ( InteractionComponent itarget in target )
187+ {
188+ jtarget . Add ( itarget . ToJObject ( version ) ) ;
189+ }
190+ }
191+ if ( steps != null && steps . Count > 0 )
192+ {
193+ var jsteps = new JArray ( ) ;
194+ result . Add ( "steps" , jsteps ) ;
195+
196+ foreach ( InteractionComponent istep in steps )
197+ {
198+ jsteps . Add ( istep . ToJObject ( version ) ) ;
199+ }
200+ }
88201
89202 return result ;
90203 }
0 commit comments