/// <summary> /// Initializes a new Context instance. /// </summary> /// <param name="registration">The registration that the Statement is associated with.</param> /// <param name="instructor">Instructor that the Statement relates to, if not included as the Actor of the Statement.</param> /// <param name="team">Team that this Statement relates to, if not included as the Actor of the Statement.</param> /// <param name="contextActivities">A map of the types of learning activity context that this Statement is related to. Valid context types are: "parent", "grouping", "category" and "other".</param> /// <param name="revision">Revision of the learning activity associated with this Statement. Format is free.</param> /// <param name="platform">Platform used in the experience of this learning activity.</param> /// <param name="language">Code representing the language in which the experience being recorded in this Statement (mainly) occurred in, if applicable and known.</param> /// <param name="statement">Another Statement to be considered as context for this Statement.</param> /// <param name="extensions">A map of any other domain-specific context relevant to this Statement. <para>For example, in a flight simulator altitude, airspeed, wind, attitude, GPS coordinates might all be relevant.</para></param> public Context( Guid?registration = null, Actor instructor = null, Group team = null, ContextActivities contextActivities = null, string revision = null, string platform = null, string language = null, StatementReference statement = null, Extension extensions = null) { Registration = registration; Instructor = instructor; Team = team; ContextActivities = contextActivities; Revision = revision; Platform = platform; Language = language; Statement = statement; if (extensions != null && extensions.Any()) { Extensions = extensions; } }
public void TestWithResult() { var actor = new Agent(new Mailbox(new Uri("mailto:[email protected]")), null); var verb = new Verb(new VerbId("http://example.com/commented"), new LanguageMap(LanguageTag.EnglishUS, "commented")); var statementRef = new StatementReference(new Guid("8f87ccde-bb56-4c2e-ab83-44982ef22df0")); var result = new Result(response: "Wow, nice work!"); var statement = new Statement(actor, verb, statementRef, result: result); }
public void TestVoid() { var actor = new Agent(new Mailbox(new Uri("mailto:[email protected]")), "Example Admin"); var obj = new StatementReference(new Guid("e05aa883-acaf-40ad-bf54-02c8ce485fb0")); var statement = new Statement(actor, Verb.Voided, obj); Assert.Equal(actor, statement.Actor.Item); Assert.Equal(Verb.Voided, statement.Verb); Assert.Equal(obj, statement.Object); Assert.Equal(ObjectType.StatementReference, statement.Object.ObjectType); Assert.Equal(ObjectType.Agent, statement.Actor.Item.ObjectType); Assert.Equal("example.adlnet.gov", ((statement.Actor.Item as IAgent).IFI.Item as IMailbox).Address.Host); Assert.Equal("admin", ((statement.Actor.Item as IAgent).IFI.Item as IMailbox).Address.UserInfo); }
/// <summary> /// Finds the next node in common in the two branches. Can be used to help optimise the generation of branching flow statements /// such as if conditions, etc. Returns null if there is no common node. /// </summary> internal static StatementReference? FindNextSharedNode(VisualProgram context, StatementReference branch1, StatementReference branch2) { // Early return if either branch doesn't have any attached nodes - there cannot be a shared node if there are no nodes. if (!branch1.HasValue || !branch2.HasValue) return null; // Get a flat list of all Guids in the first branch var nodesIn1 = new List<Guid>(); StatementReference? currentRef = branch1; while (currentRef.HasValue && currentRef.Value.HasValue) { nodesIn1.Add(currentRef?.nodeId!.Value); // Note that we use GetNextStatement here instead of NextStatement since, if it is a branch, we want the next shared statement of that branch currentRef = (currentRef?.ResolveNode(context) as VisualStatement)?.GetCompilerNextStatement(context); } // Search the second branch until we find the first occurance of the same node in the first branch currentRef = branch2; while (currentRef.HasValue && currentRef.Value.HasValue) { if (nodesIn1.Contains(currentRef.Value.nodeId!.Value)) return currentRef.Value; currentRef = (currentRef?.ResolveNode(context) as VisualStatement)?.GetCompilerNextStatement(context); } return null; }
/// <summary> /// Starting at the given branch entry points, gets a list of <see cref="Expression"/>s that include and follow the branch, UNTIL a shared /// node is found. The shared node will not be included in the returned lists. /// </summary> internal static (IEnumerable<Expression> branch1Flattened, IEnumerable<Expression> branch2Flattened) FlattenExpressions(VisualProgram context, StatementReference branch1, StatementReference branch2) { var firstShared = FindNextSharedNode(context, branch1, branch2); // Early return if there is no shared node if (firstShared == null) return (FlattenExpressions(context, branch1), FlattenExpressions(context, branch2)); List<Expression> flatten(StatementReference start) { var list = new List<Expression>(); StatementReference? curRef = start; while (curRef.HasValue && curRef.Value.HasValue && curRef != firstShared && curRef.Value.ResolveNode(context) is VisualStatement statement) { list.Add(statement.CreateExpression(context)); curRef = statement.GetCompilerNextStatement(context); } return list; } return (flatten(branch1), flatten(branch2)); }
/// <summary> /// Starting at the given node, gets a list of <see cref="Expression"/>s that include and follow this node's references. /// </summary> internal static IEnumerable<Expression> FlattenExpressions(VisualProgram context, StatementReference firstStatement) { var list = new List<Expression>(); var currentNode = firstStatement.ResolveNode(context); while (currentNode is VisualStatement currentStatement) { list.Add(currentStatement.CreateExpression(context)); currentNode = currentStatement.GetCompilerNextStatement(context)?.ResolveNode(context); } return list; }