|
| 1 | +/* |
| 2 | + Copyright 2014 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 Newtonsoft.Json.Linq; |
| 18 | +using TinCan.Json; |
| 19 | + |
| 20 | +namespace TinCan |
| 21 | +{ |
| 22 | + public class ActivityDefinition : JsonModel |
| 23 | + { |
| 24 | + public Uri type { get; set; } |
| 25 | + public Uri moreInfo { get; set; } |
| 26 | + public LanguageMap name { get; set; } |
| 27 | + public LanguageMap description { get; set; } |
| 28 | + 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; } |
| 36 | + |
| 37 | + public ActivityDefinition() {} |
| 38 | + |
| 39 | + public ActivityDefinition(StringOfJSON json): this(json.toJObject()) {} |
| 40 | + |
| 41 | + public ActivityDefinition(JObject jobj) |
| 42 | + { |
| 43 | + if (jobj["type"] != null) |
| 44 | + { |
| 45 | + type = new Uri(jobj.Value<String>("type")); |
| 46 | + } |
| 47 | + if (jobj["moreInfo"] != null) |
| 48 | + { |
| 49 | + moreInfo = new Uri(jobj.Value<String>("moreInfo")); |
| 50 | + } |
| 51 | + if (jobj["name"] != null) |
| 52 | + { |
| 53 | + name = (LanguageMap)jobj.Value<JObject>("name"); |
| 54 | + } |
| 55 | + if (jobj["description"] != null) |
| 56 | + { |
| 57 | + description = (LanguageMap)jobj.Value<JObject>("description"); |
| 58 | + } |
| 59 | + if (jobj["extensions"] != null) |
| 60 | + { |
| 61 | + extensions = (Extensions)jobj.Value<JObject>("extensions"); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + public override JObject ToJObject(TCAPIVersion version) { |
| 66 | + JObject result = new JObject(); |
| 67 | + |
| 68 | + if (type != null) |
| 69 | + { |
| 70 | + result.Add("type", type.ToString()); |
| 71 | + } |
| 72 | + if (moreInfo != null) |
| 73 | + { |
| 74 | + result.Add("moreInfo", moreInfo.ToString()); |
| 75 | + } |
| 76 | + if (name != null && ! name.isEmpty()) |
| 77 | + { |
| 78 | + result.Add("name", name.ToJObject(version)); |
| 79 | + } |
| 80 | + if (description != null && ! description.isEmpty()) |
| 81 | + { |
| 82 | + result.Add("description", description.ToJObject(version)); |
| 83 | + } |
| 84 | + if (extensions != null && ! extensions.isEmpty()) |
| 85 | + { |
| 86 | + result.Add("extensions", extensions.ToJObject(version)); |
| 87 | + } |
| 88 | + |
| 89 | + return result; |
| 90 | + } |
| 91 | + |
| 92 | + public static explicit operator ActivityDefinition(JObject jobj) |
| 93 | + { |
| 94 | + return new ActivityDefinition(jobj); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments