Beispiel #1
0
        public async Task HandleObject(StatementBase statement, IStatementBaseEntity newStatement, CancellationToken cancellationToken)
        {
            var objType = statement.Object.ObjectType;

            if (objType == ObjectType.Activity)
            {
                var activity = await _mediator.Send(UpsertActivityCommand.Create((Activity)statement.Object), cancellationToken);

                newStatement.ObjectType = EntityObjectType.Activity;
                newStatement.ObjectId   = activity.ActivityId;
            }
            else if (objType == ObjectType.Agent || objType == ObjectType.Group)
            {
                AgentEntity agent = await _mediator.Send(UpsertActorCommand.Create((Agent)statement.Object), cancellationToken);;
                newStatement.ObjectType = EntityObjectType.Agent;
                newStatement.ObjectId   = agent.AgentId;
            }
            else if (objType == ObjectType.SubStatement)
            {
                SubStatementEntity subStatement = await _mediator.Send(CreateSubStatementCommand.Create((SubStatement)statement.Object), cancellationToken);

                newStatement.ObjectType = EntityObjectType.SubStatement;
                newStatement.ObjectId   = subStatement.SubStatementId;
            }
            else if (objType == ObjectType.StatementRef)
            {
                StatementRef statementRef = (StatementRef)statement.Object;
                newStatement.ObjectType = EntityObjectType.StatementRef;
                newStatement.ObjectId   = statementRef.Id;
            }
        }
Beispiel #2
0
        static Support()
        {
            agent      = new Agent();
            agent.mbox = "mailto:[email protected]";

            verb         = new Verb("http://adlnet.gov/expapi/verbs/experienced");
            verb.display = new LanguageMap();
            verb.display.Add("en-US", "experienced");

            activity                 = new Activity();
            activity.id              = "http://tincanapi.com/TinCanCSharp/Test/Unit/0";
            activity.definition      = new ActivityDefinition();
            activity.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test");
            activity.definition.name = new LanguageMap();
            activity.definition.name.Add("en-US", "Tin Can C# Tests: Unit 0");
            activity.definition.description = new LanguageMap();
            activity.definition.description.Add("en-US", "Unit test 0 in the test suite for the Tin Can C# library.");

            parent                 = new Activity();
            parent.id              = "http://tincanapi.com/TinCanCSharp/Test";
            parent.definition      = new ActivityDefinition();
            parent.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test-suite");
            //parent.definition.moreInfo = new Uri("http://rusticisoftware.github.io/TinCanCSharp/");
            parent.definition.name = new LanguageMap();
            parent.definition.name.Add("en-US", "Tin Can C# Tests");
            parent.definition.description = new LanguageMap();
            parent.definition.description.Add("en-US", "Unit test suite for the Tin Can C# library.");

            statementRef = new StatementRef(Guid.NewGuid());

            context = new Context();
            context.registration             = Guid.NewGuid();
            context.statement                = statementRef;
            context.contextActivities        = new ContextActivities();
            context.contextActivities.parent = new List <Activity>();
            context.contextActivities.parent.Add(parent);

            score        = new Score();
            score.raw    = 97;
            score.scaled = 0.97;
            score.max    = 100;
            score.min    = 0;

            result            = new Result();
            result.score      = score;
            result.success    = true;
            result.completion = true;
            result.duration   = new TimeSpan(1, 2, 16, 43);

            subStatement        = new SubStatement();
            subStatement.actor  = agent;
            subStatement.verb   = verb;
            subStatement.target = parent;
        }
        public bool PutStatement(Guid?statementId, Statement statement, out HttpStatusCode statusCode)
        {
            statusCode   = HttpStatusCode.Conflict;
            statement.Id = statementId;

            if (statement.Id.HasValue)
            {
                if (CheckIfExists(statementId))
                {
                    return(true);
                }
            }

            if (statement.Verb.Id == KnownVerbs.Voided)
            {
                StatementRef stRf = statement.Object as StatementRef;
                if (IsVoidedOrVoiding(stRf.Id))
                {
                    return(true);
                }
            }

            statement.Stamp();
            // Ensure statement version and stored date
            statement.Version = statement.Version ?? ApiVersion.GetLatest().ToString();
            statement.Stored  = statement.Stored ?? DateTimeOffset.UtcNow;

            if (statement.Authority == null)
            {
                // Set authority before saving JSON encoded statement
                var agent = new Agent();
                agent.Mbox          = new Mbox("mailto:" + "*****@*****.**");
                agent.Name          = "Manu";
                statement.Authority = agent;
            }


            //to do map to Statement Entity
            StatementEntity newStatement = new StatementEntity();

            newStatement.Id            = statement.Id;
            newStatement.Stored        = statement.Stored;
            newStatement.Version       = statement.Version.ToString();
            newStatement.FullStatement = statement.ToJson();

            StoreStatement(newStatement);


            return(false);
        }
Beispiel #4
0
        private Context BuildTextContext()
        {
            Guid registration = new Guid("42c0855b-8f64-47f3-b0e2-3f337930045a");
            ContextActivities contextActivities = new ContextActivities();
            string            revision          = "";
            string            platform          = "";
            string            language          = "";
            StatementRef      statement         = new StatementRef();

            TinCan.Extensions extensions = new TinCan.Extensions();

            Context context = new Context();

            context.registration      = registration;
            context.contextActivities = contextActivities;
            context.revision          = revision;
            context.platform          = platform;
            context.language          = language;
            context.statement         = statement;
            context.extensions        = extensions;

            return(context);
        }
        private Context BuildTextContext()
        {
            var registration      = new Guid("42c0855b-8f64-47f3-b0e2-3f337930045a");
            var contextActivities = new ContextActivities();
            var revision          = "";
            var platform          = "";
            var language          = "";
            var statement         = new StatementRef();
            var extensions        = new Extensions();

            var context = new Context
            {
                Registration      = registration,
                ContextActivities = contextActivities,
                Revision          = revision,
                Platform          = platform,
                Language          = language,
                Statement         = statement,
                Extensions        = extensions
            };

            return(context);
        }
Beispiel #6
0
        /// <summary>
        /// Initializes static members of the <see cref="Support"/> class.
        /// </summary>
        static Support()
        {
            Agent = new Agent {
                Mbox = "mailto:[email protected]"
            };

            Verb = new Verb("http://adlnet.gov/expapi/verbs/experienced")
            {
                Display = new LanguageMap()
            };
            Verb.Display.Add("en-US", "experienced");

            Activity = new Activity
            {
                ID         = "http://tincanapi.com/TinCanCSharp/Test/Unit/0",
                Definition = new ActivityDefinition
                {
                    Type = new Uri("http://id.tincanapi.com/activitytype/unit-test"),
                    Name = new LanguageMap()
                }
            };
            Activity.Definition.Name.Add("en-US", "Tin Can C# Tests: Unit 0");
            Activity.Definition.Description = new LanguageMap();
            Activity.Definition.Description.Add("en-US", "Unit test 0 in the test suite for the Tin Can C# library.");

            Parent = new Activity
            {
                ID         = "http://tincanapi.com/TinCanCSharp/Test",
                Definition = new ActivityDefinition
                {
                    Type = new Uri("http://id.tincanapi.com/activitytype/unit-test-suite"),
                    Name = new LanguageMap()
                }
            };
            Parent.Definition.Name.Add("en-US", "Tin Can C# Tests");
            Parent.Definition.Description = new LanguageMap();
            Parent.Definition.Description.Add("en-US", "Unit test suite for the Tin Can C# library.");

            StatementRef = new StatementRef(Guid.NewGuid());

            Context = new Context
            {
                Registration      = Guid.NewGuid(),
                Statement         = StatementRef,
                ContextActivities = new ContextActivities {
                    Parent = new List <Activity> {
                        Parent
                    }
                }
            };

            Score = new Score
            {
                Raw    = 97,
                Scaled = 0.97,
                Max    = 100,
                Min    = 0
            };

            Result = new Result
            {
                Score      = Score,
                Success    = true,
                Completion = true,
                Duration   = new TimeSpan(1, 2, 16, 43)
            };

            SubStatement = new SubStatement
            {
                Actor  = Agent,
                Verb   = Verb,
                Target = Parent
            };
        }
Beispiel #7
0
        static Support()
        {
            Agent = new Agent
            {
                Mbox = "mailto:[email protected]"
            };

            Verb = new Verb("http://adlnet.gov/expapi/verbs/experienced")
            {
                Display = new LanguageMap()
            };
            Verb.Display.Add("en-US", "experienced");

            Activity = new Activity
            {
                Id         = "http://tincanapi.com/TinCanCSharp/Test/Unit/0",
                Definition = new ActivityDefinition
                {
                    Type = new Uri("http://id.tincanapi.com/activitytype/unit-test"),
                    Name = new LanguageMap()
                }
            };
            Activity.Definition.Name.Add("en-US", "Tin Can C# Tests: Unit 0");
            Activity.Definition.Description =
                new LanguageMap {
                { "en-US", "Unit test 0 in the test suite for the Tin Can C# library." }
            };

            Activity.Definition.InteractionType = InteractionType.ChoiceType;
            Activity.Definition.Choices         = new List <InteractionComponent>();

            for (int i = 1; i <= 3; i++)
            {
                var interactionComponent = new InteractionComponent
                {
                    Id          = "choice-" + i.ToString(),
                    Description = new LanguageMap()
                };

                interactionComponent.Description.Add("en-US", "Choice " + i.ToString());

                Activity.Definition.Choices.Add(interactionComponent);
            }

            Activity.Definition.CorrectResponsesPattern = new List <string>();

            for (int i = 1; i <= 2; i++)
            {
                Activity.Definition.CorrectResponsesPattern.Add("choice-" + i.ToString());
            }

            Parent = new Activity
            {
                Id         = "http://tincanapi.com/TinCanCSharp/Test",
                Definition = new ActivityDefinition
                {
                    Type = new Uri("http://id.tincanapi.com/activitytype/unit-test-suite"),
                    Name = new LanguageMap()
                }
            };
            Parent.Definition.Name.Add("en-US", "Tin Can C# Tests");
            Parent.Definition.Description = new LanguageMap {
                { "en-US", "Unit test suite for the Tin Can C# library." }
            };

            StatementRef = new StatementRef(Guid.NewGuid());

            Context = new Context
            {
                Registration      = Guid.NewGuid(),
                Statement         = StatementRef,
                ContextActivities = new ContextActivities
                {
                    Parent = new List <Activity>()
                }
            };
            Context.ContextActivities.Parent.Add(Parent);

            Score = new Score
            {
                Raw    = 97,
                Scaled = 0.97,
                Max    = 100,
                Min    = 0
            };

            Result = new Result
            {
                Score      = Score,
                Success    = true,
                Completion = true,
                Duration   = new TimeSpan(1, 2, 16, 43),
                Response   = "choice-2"
            };

            SubStatement = new SubStatement
            {
                Actor  = Agent,
                Verb   = Verb,
                Target = Parent
            };
        }