Beispiel #1
0
        public Result(JToken result, ApiVersion version)
        {
            GuardType(result, JTokenType.Object);

            var score = result["score"];

            if (score != null)
            {
                Score = new Score(score, version);
            }

            var success = result["success"];

            if (success != null)
            {
                GuardType(success, JTokenType.Boolean);
                Success = success.Value <bool?>();
            }

            var completion = result["completion"];

            if (completion != null)
            {
                GuardType(completion, JTokenType.Boolean);
                Completion = completion.Value <bool?>();
            }

            var response = result["response"];

            if (response != null)
            {
                GuardType(response, JTokenType.String);
                Response = response.Value <string>();
            }

            var duration = result["duration"];

            if (duration != null)
            {
                GuardType(duration, JTokenType.String);
                Duration = new Duration(duration.Value <string>());
            }

            var extensions = result["extensions"];

            if (extensions != null)
            {
                Extensions = new ExtensionsDictionary(extensions, version);
            }

            GuardAdditionalProperties((JObject)result, "score", "success", "completion", "response", "duration", "extensions");
        }
Beispiel #2
0
        public ActivityDefinition(JToken obj, ApiVersion version)
        {
            GuardType(obj, JTokenType.Object);

            var type = obj["type"];

            if (type != null)
            {
                GuardType(type, JTokenType.String);
                Type = new Iri(type.Value <string>());
            }

            var moreInfo = obj["moreInfo"];

            if (moreInfo != null)
            {
                GuardType(moreInfo, JTokenType.String);
                try
                {
                    MoreInfo = new Uri(moreInfo.Value <string>());
                }
                catch (UriFormatException ex)
                {
                    throw new JsonTokenModelException(moreInfo, ex);
                }
            }

            var name = obj["name"];

            if (name != null)
            {
                Name = new LanguageMap(name, version);
            }

            var description = obj["description"];

            if (description != null)
            {
                Description = new LanguageMap(description, version);
            }

            var extensions = obj["extensions"];

            if (extensions != null)
            {
                Extensions = new ExtensionsDictionary(extensions, version);
            }
        }
Beispiel #3
0
        public override JToken ToJToken(ApiVersion version, ResultFormat format)
        {
            var jobj = new JObject();

            if (Score != null)
            {
                jobj["score"] = Score.ToJToken(version, format);
            }

            if (Success.HasValue)
            {
                jobj["success"] = Success;
            }

            if (Completion.HasValue)
            {
                jobj["completion"] = Completion;
            }

            if (!string.IsNullOrEmpty(Response))
            {
                jobj["response"] = Response;
            }

            if (Duration != null)
            {
                jobj["duration"] = Duration.ToString();
            }

            if (jobj["extensions"] != null)
            {
                Extensions = new ExtensionsDictionary(jobj.Value <JObject>("extenions"), version);
            }

            return(jobj);
        }
Beispiel #4
0
 About()
 {
     Version   = ApiVersion.GetSupported().Select(x => x.Key);
     Extension = new ExtensionsDictionary();
 }
Beispiel #5
0
        public Context(JToken context, ApiVersion version)
        {
            GuardType(context, JTokenType.Object);

            var registration = context["registration"];

            if (registration != null)
            {
                GuardType(registration, JTokenType.String);

                Registration = ParseGuid(registration);
            }

            var instructor = context["instructor"];

            if (instructor != null)
            {
                GuardType(instructor, JTokenType.Object);
                ObjectType objectType = ParseObjectType(instructor["objectType"], ObjectType.Agent, ObjectType.Group);

                if (objectType != null && objectType == ObjectType.Group)
                {
                    Instructor = new Group(instructor, version);
                }
                else
                {
                    Instructor = new Agent(instructor, version);
                }
            }

            var team = context["team"];

            if (team != null)
            {
                Instructor = new Group(team, version);
            }

            var contextActivities = context["contextActivities"];

            if (contextActivities != null)
            {
                ContextActivities = new ContextActivities(contextActivities, version);
            }

            var revision = context["revision"];

            if (revision != null)
            {
                GuardType(revision, JTokenType.String);
                Revision = revision.Value <string>();
            }

            var platform = context["platform"];

            if (platform != null)
            {
                GuardType(platform, JTokenType.String);
                Platform = platform.Value <string>();
            }

            var language = context["language"];

            if (language != null)
            {
                GuardType(language, JTokenType.String);
                Language = language.Value <string>();
            }

            var statement = context["statement"];

            if (statement != null)
            {
                ParseObjectType(statement["objectType"], ObjectType.StatementRef);
                Statement = new StatementRef(statement, version);
            }

            var extensions = context["extensions"];

            if (extensions != null)
            {
                Extensions = new ExtensionsDictionary(extensions, version);
            }
        }