Example #1
0
        public Activity(JToken jobj, ApiVersion version) : base(jobj, version)
        {
            GuardType(jobj, JTokenType.Object);
            var id = jobj["id"];

            if (id != null)
            {
                GuardType(id, JTokenType.String);
                Id = new Iri(jobj.Value <string>("id"));
            }

            var definition = jobj["definition"];

            if (definition != null)
            {
                GuardType(definition, JTokenType.Object);
                JToken interactionType = definition["interactionType"];
                if (interactionType != null)
                {
                    GuardType(interactionType, JTokenType.String);
                    try
                    {
                        InteractionType type = interactionType.Value <string>();
                        Definition = type.CreateInstance(definition, version);
                    }
                    catch (InteractionTypeException ex)
                    {
                        throw new JsonTokenModelException(interactionType, ex.Message);
                    }
                }
                else
                {
                    GuardAdditionalProperties((JObject)definition,
                                              "type", "name", "description", "moreInfo", "extensions"
                                              );
                    Definition = new ActivityDefinition(definition, version);
                }
            }
        }
Example #2
0
        private ActivityDefinition GetActivityInteraction(int interactionIndex)
        {
            ActivityDefinition interactionDef = null;

            using (SqlConnection connection = new SqlConnection(DbUtils.GetConnectionString()))
            {
                SqlDataReader reader  = null;
                SqlCommand    command = new SqlCommand(GetActivityInteractionQuery, connection);
                command.Parameters.AddWithValue("@id", interactionIndex);
                try
                {
                    connection.Open();
                    reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        InteractionType type = reader.GetString(1);
                        interactionDef = type.CreateInstance(new JObject(), ApiVersion.GetLatest());
                        if (!reader.IsDBNull(2))
                        {
                            JsonString json  = reader.GetString(2);
                            var        sList = new List <string>();
                            var        crp   = json.ToJArray();
                            foreach (var jstring in crp)
                            {
                                sList.Add(jstring.Value <string>());
                            }
                            (interactionDef as InteractionActivityDefinitionBase).CorrectResponsesPattern = sList.ToArray();
                        }
                        if (!reader.IsDBNull(3))
                        {
                            Choice     cho = interactionDef as Choice;
                            Sequencing seq = interactionDef as Sequencing;
                            if (cho != null)
                            {
                                cho.Choices = new InteractionComponentCollection(reader.GetString(3));
                            }
                            else if (seq != null)
                            {
                                seq.Choices = new InteractionComponentCollection(reader.GetString(3));
                            }
                        }
                        if (!reader.IsDBNull(4))
                        {
                            Likert def = interactionDef as Likert;
                            if (def != null)
                            {
                                def.Scale = new InteractionComponentCollection(reader.GetString(4));
                            }
                        }
                        if (!reader.IsDBNull(5))
                        {
                            Matching match = interactionDef as Matching;
                            if (match != null)
                            {
                                match.Source = new InteractionComponentCollection(reader.GetString(5));
                            }
                        }
                        if (!reader.IsDBNull(6))
                        {
                            Matching match = interactionDef as Matching;
                            if (match != null)
                            {
                                match.Target = new InteractionComponentCollection(reader.GetString(6));
                            }
                        }
                        if (!reader.IsDBNull(7))
                        {
                            Performance perf = interactionDef as Performance;
                            if (perf != null)
                            {
                                perf.Steps = new InteractionComponentCollection(reader.GetString(7));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(null);
                }
                finally
                {
                    if (reader != null && !reader.IsClosed)
                    {
                        reader.Close();
                    }
                }
            }
            return(interactionDef);
        }