Class Scenario
Partial part of the scenario class that handles compatibility with previous XSD versions
Inherited Members
Namespace: Xareus.Scenarios
Assembly: Xareus.Scenarios.dll
Syntax
[Serializable]
public class Scenario : Identifiable
Constructors
Scenario(string, string)
Constructor
Declaration
public Scenario(string id, string label = "")
Parameters
Type | Name | Description |
---|---|---|
string | id | The Id must be unique |
string | label | The label (optional) |
Properties
Enabled
True if the scenario is enabled (i.e. NextStep can be called) When set to false, all of the sensors will stop checking
Declaration
public bool Enabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
ExternalContext
The external context used by the scenario
Declaration
public IContext ExternalContext { get; }
Property Value
Type | Description |
---|---|
IContext |
InstanceId
The instanceId of the scenario (should be unique)
Declaration
public string InstanceId { get; }
Property Value
Type | Description |
---|---|
string |
IsDoingAStep
True if the scenario is currently performing a new step (i.e. NextStep has been called and is not finished yet)
Declaration
public bool IsDoingAStep { get; }
Property Value
Type | Description |
---|---|
bool |
IsExternalScenario
True if this scenario is used as an external scenario
Declaration
public bool IsExternalScenario { get; }
Property Value
Type | Description |
---|---|
bool |
LoadedScenarios
All Loaded Scenarios
Declaration
public static List<Scenario> LoadedScenarios { get; }
Property Value
Type | Description |
---|---|
List<Scenario> |
PathId
Complete (unique) path ID
Declaration
public override string PathId { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
ScenarioContext
The scenario context
Declaration
public IContext ScenarioContext { get; }
Property Value
Type | Description |
---|---|
IContext |
ScenarioFile
The file path of the current scenario (can be null)
Declaration
public string ScenarioFile { get; set; }
Property Value
Type | Description |
---|---|
string |
ScenarioState
The state of the current scenario
Declaration
public ScenarioState ScenarioState { get; set; }
Property Value
Type | Description |
---|---|
ScenarioState |
ScenarioText
The text representation of the scenario that has been loaded
Declaration
public string ScenarioText { get; }
Property Value
Type | Description |
---|---|
string |
Version
The version of the scenario. Can be used to update the XML data when needed for backward compatibility
Declaration
public Version Version { get; set; }
Property Value
Type | Description |
---|---|
Version |
assignment
Declaration
public virtual List<Assignment> assignment { get; set; }
Property Value
Type | Description |
---|---|
List<Assignment> |
contextInit
Declaration
public virtual Function contextInit { get; set; }
Property Value
Type | Description |
---|---|
Function |
sequence
Declaration
public virtual ASequence sequence { get; set; }
Property Value
Type | Description |
---|---|
ASequence |
version
Declaration
public virtual string version { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
AddScenarioText(string, string)
Reads a scenario text and stores it if the ID is not already present. Uses scenarioID as ID
Declaration
public static bool AddScenarioText(string scenarioID, string scenarioText)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioID | The ID of the scenario |
string | scenarioText | The XML contents defining the scenario |
Returns
Type | Description |
---|---|
bool | True if the file hase been read, false otherwise (already present or an error occured) |
AddScenarioTextFile(string, string)
Reads a scenario text and stores it.
Declaration
[Obsolete("AddScenarioTextFile is deprecated, please use AddScenarioText or ReadFileText instead.")]
public static bool AddScenarioTextFile(string scenarioFile, string scenarioText)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | The XML file containing the scenario text |
string | scenarioText | The XML contents defining the scenario |
Returns
Type | Description |
---|---|
bool | True if the file hase been read, false otherwise (already present or an error occured) |
AddScenarioTextForFile(string, string)
Reads a scenario text and stores it. Note that the file is not read but its name is used for reference This is kind of a hack for Unity that uses assets and looses relative paths in the process
Declaration
public static bool AddScenarioTextForFile(string scenarioFile, string scenarioText)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | The XML file containing the scenario text |
string | scenarioText | The XML contents defining the scenario |
Returns
Type | Description |
---|---|
bool | True if the file hase been read, false otherwise (already present or an error occured) |
ComputeDecorations(Transition)
Declaration
public Dictionary<string, List<Decoration>> ComputeDecorations(Transition transition)
Parameters
Type | Name | Description |
---|---|---|
Transition | transition |
Returns
Type | Description |
---|---|
Dictionary<string, List<Decoration>> |
ConvertTo4_1(XmlDocument, XmlNode, XmlNamespaceManager)
Convert document to 4.1
Declaration
protected static void ConvertTo4_1(XmlDocument inputDoc, XmlNode scenarioNode, XmlNamespaceManager nsManager)
Parameters
Type | Name | Description |
---|---|---|
XmlDocument | inputDoc | |
XmlNode | scenarioNode | |
XmlNamespaceManager | nsManager |
ConvertTo4_2(XmlDocument, XmlNode, XmlNamespaceManager)
Convert document to 4.2
Declaration
protected static void ConvertTo4_2(XmlDocument inputDoc, XmlNode scenarioNode, XmlNamespaceManager nsManager)
Parameters
Type | Name | Description |
---|---|---|
XmlDocument | inputDoc | |
XmlNode | scenarioNode | |
XmlNamespaceManager | nsManager |
ConvertTo5_0(XmlDocument, XmlNode, XmlNamespaceManager)
Convert document to 5.0
Declaration
protected static void ConvertTo5_0(XmlDocument inputDoc, XmlNode scenarioNode, XmlNamespaceManager nsManager)
Parameters
Type | Name | Description |
---|---|---|
XmlDocument | inputDoc | |
XmlNode | scenarioNode | |
XmlNamespaceManager | nsManager |
ConvertTo5_7_0(XmlDocument, XmlNode, XmlNamespaceManager)
Convert document to 5.0
Declaration
protected static void ConvertTo5_7_0(XmlDocument inputDoc, XmlNode scenarioNode, XmlNamespaceManager nsManager)
Parameters
Type | Name | Description |
---|---|---|
XmlDocument | inputDoc | |
XmlNode | scenarioNode | |
XmlNamespaceManager | nsManager |
GetActivableSensors()
Gets the conditions currently under validation in the execution of the scenario.
Declaration
public IEnumerable<ASensor> GetActivableSensors()
Returns
Type | Description |
---|---|
IEnumerable<ASensor> | The conditions under validation |
GetActivableSensors(List<Assignment>)
Gets the conditions currently under validation in the execution of the scenario. The result is filtered using a list of assignments.
Declaration
public IEnumerable<ASensor> GetActivableSensors(List<Assignment> assignmentList)
Parameters
Type | Name | Description |
---|---|---|
List<Assignment> | assignmentList | The list of assignments |
Returns
Type | Description |
---|---|
IEnumerable<ASensor> | The conditions under validation |
GetAllFunctions()
Get all the functions used in the scenario
Declaration
public IEnumerable<Function> GetAllFunctions()
Returns
Type | Description |
---|---|
IEnumerable<Function> | The functions used in the scenario |
GetAllInstantiatedFunctions()
Get all the instantiated functions used in the scenario
Declaration
public IEnumerable<AFunction> GetAllInstantiatedFunctions()
Returns
Type | Description |
---|---|
IEnumerable<AFunction> | The instantiated functions used in the scenario |
GetAllSequences()
Get all the sequences in the scenario
Declaration
public IEnumerable<ASequence> GetAllSequences()
Returns
Type | Description |
---|---|
IEnumerable<ASequence> | The sequences |
GetAllTransitions()
Get all the transitions of the sequence
Declaration
public IEnumerable<Transition> GetAllTransitions()
Returns
Type | Description |
---|---|
IEnumerable<Transition> | All the transitions |
GetEnabledTransitions()
Get the enabled transitions of the sequence
Declaration
public IEnumerable<Transition> GetEnabledTransitions()
Returns
Type | Description |
---|---|
IEnumerable<Transition> | The enabled transitions |
GetEnabledTransitions(List<Assignment>)
Get the enabled transitions of the sequence The result is filtered using a list of assignments.
Declaration
public IEnumerable<Transition> GetEnabledTransitions(List<Assignment> assignmentList)
Parameters
Type | Name | Description |
---|---|---|
List<Assignment> | assignmentList | The list of assignments |
Returns
Type | Description |
---|---|
IEnumerable<Transition> | The enabled transitions |
GetExternalScenariosFiles(bool)
Get all the external scenarios' files directly or indirectly referenced by this scenario
Declaration
public HashSet<string> GetExternalScenariosFiles(bool relativeToRoot = false)
Parameters
Type | Name | Description |
---|---|---|
bool | relativeToRoot | Get all paths relative to the root scenario |
Returns
Type | Description |
---|---|
HashSet<string> | The external scenarios files paths |
GetFiringTransitions()
Declaration
public IEnumerable<Transition> GetFiringTransitions()
Returns
Type | Description |
---|---|
IEnumerable<Transition> |
GetScenarioFromText(string)
Deserializes a scenario from an XML string. Updates the scenario xml if needed This doesn't load or initializes the scenario
Declaration
public static Scenario GetScenarioFromText(string scenarioText)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioText |
Returns
Type | Description |
---|---|
Scenario |
GetSequencesThatHoldTokens()
Get all the sequences that hold a token
Declaration
public IEnumerable<ASequence> GetSequencesThatHoldTokens()
Returns
Type | Description |
---|---|
IEnumerable<ASequence> | The sequences that hold a token |
GetTransitions(List<Assignment>)
Get all the transitions of the sequence The result is filtered using a list of assignments.
Declaration
public IEnumerable<Transition> GetTransitions(List<Assignment> assignmentList)
Parameters
Type | Name | Description |
---|---|---|
List<Assignment> | assignmentList | The list of assignments |
Returns
Type | Description |
---|---|
IEnumerable<Transition> | All the transitions with the given assignement |
IsFinished()
Checks if the scenario is finished
Declaration
public bool IsFinished()
Returns
Type | Description |
---|---|
bool |
|
LoadFromFile(string, object, ScenarioLoadingParameters, bool)
Declaration
[Obsolete("Use LoadFromFile(string, IContext, ScenarioLoadingParameters, bool) instead")]
public static Scenario LoadFromFile(string scenarioFile, object externalContext, ScenarioLoadingParameters loadingParameters = null, bool isExternal = false)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | |
object | externalContext | |
ScenarioLoadingParameters | loadingParameters | |
bool | isExternal |
Returns
Type | Description |
---|---|
Scenario |
LoadFromFile(string, string, object, ScenarioLoadingParameters, bool)
Declaration
[Obsolete("Use LoadFromFile(string, string, IContext, ScenarioLoadingParameters, bool) instead")]
public static Scenario LoadFromFile(string scenarioFile, string relativePath, object externalContext, ScenarioLoadingParameters loadingParameters = null, bool isExternal = false)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | |
string | relativePath | |
object | externalContext | |
ScenarioLoadingParameters | loadingParameters | |
bool | isExternal |
Returns
Type | Description |
---|---|
Scenario |
LoadFromFile(string, string, IContext, ScenarioLoadingParameters, bool)
Loads a scenario from its XML file and an external context. Uses scenarioFile as ID. If the ID doesn't already exists, reads the file first
Declaration
public static Scenario LoadFromFile(string scenarioFile, string relativePath, IContext externalContext, ScenarioLoadingParameters loadingParameters = null, bool isExternal = false)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | The XML file defining the scenario |
string | relativePath | The path relative to which to load the scenario file |
IContext | externalContext | The context external to the scenario |
ScenarioLoadingParameters | loadingParameters | |
bool | isExternal | If set to true, the scenario will be marked as external (i.e. loaded by another scenario) |
Returns
Type | Description |
---|---|
Scenario | The scenario |
LoadFromFile(string, IContext, ScenarioLoadingParameters, bool)
Loads a scenario from its XML file and an external context.. If the ID doesn't already exists, reads the file first
Declaration
public static Scenario LoadFromFile(string scenarioFile, IContext externalContext, ScenarioLoadingParameters loadingParameters = null, bool isExternal = false)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | The XML file defining the scenario |
IContext | externalContext | The context external to the scenario |
ScenarioLoadingParameters | loadingParameters | |
bool | isExternal | If set to true, the scenario will be marked as external (i.e. loaded by another scenario) |
Returns
Type | Description |
---|---|
Scenario | The scenario |
LoadFromText(string, object, ScenarioLoadingParameters, bool)
Declaration
[Obsolete("Use LoadFromText(string, IContext, ScenarioLoadingParameters, bool) instead")]
public static Scenario LoadFromText(string scenarioText, object externalContext, ScenarioLoadingParameters loadingParameters = null, bool isExternal = false)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioText | |
object | externalContext | |
ScenarioLoadingParameters | loadingParameters | |
bool | isExternal |
Returns
Type | Description |
---|---|
Scenario |
LoadFromText(string, IContext, ScenarioLoadingParameters, bool)
Loads a scenario from its XML contents and an external context.
Declaration
public static Scenario LoadFromText(string scenarioText, IContext externalContext, ScenarioLoadingParameters loadingParameters = null, bool isExternal = false)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioText | The XML contents defining the scenario |
IContext | externalContext | The context external to the scenario |
ScenarioLoadingParameters | loadingParameters | |
bool | isExternal | If set to true, the scenario will be marked as external (i.e. loaded by another scenario) |
Returns
Type | Description |
---|---|
Scenario | The scenario |
LoadScenario(Scenario, IContext, ScenarioLoadingParameters, bool, string)
Loads a scenario, meaning initializes it and loads its external scenarios
Declaration
public static Scenario LoadScenario(Scenario scenario, IContext externalContext, ScenarioLoadingParameters loadingParameters = null, bool isExternal = false, string scenarioFilePath = null)
Parameters
Type | Name | Description |
---|---|---|
Scenario | scenario | |
IContext | externalContext | |
ScenarioLoadingParameters | loadingParameters | The parameters to use to load the scenario |
bool | isExternal | If set to true, the scenario will be marked as external (i.e. loaded by another scenario) |
string | scenarioFilePath |
Returns
Type | Description |
---|---|
Scenario |
LoadScenarioState(string)
Reads and loads from an XML file the state of the scenario
Declaration
public void LoadScenarioState(string scenarioStateFile)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioStateFile | The input XML file |
NextStep(bool)
Performs a step of the execution of the scenario.
Declaration
public bool NextStep(bool oneStepOnly = false)
Parameters
Type | Name | Description |
---|---|---|
bool | oneStepOnly | If true, only performs one atomic step |
Returns
Type | Description |
---|---|
bool |
|
ReadFileText(string)
Reads a scenario file text, stores it and returns it
Declaration
public static Scenario ReadFileText(string scenarioFile)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | The XML file defining the scenario |
Returns
Type | Description |
---|---|
Scenario |
RenameXmlNode(XmlDocument, XmlNode, string)
Renames and XML node in the given document
Declaration
protected static void RenameXmlNode(XmlDocument doc, XmlNode nodeToRename, string newname)
Parameters
Type | Name | Description |
---|---|---|
XmlDocument | doc | |
XmlNode | nodeToRename | |
string | newname |
Reset()
Remove all tokens and recreate the initial ones
Declaration
public void Reset()
SaveScenarioState(string)
Extract and save to an XML file the state of the scenario
Declaration
public void SaveScenarioState(string scenarioStateFile)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioStateFile | The output XML file |
SaveToFile(string, Scenario)
Saves a scenario in an XML file
Declaration
public static bool SaveToFile(string scenarioFile, Scenario scenario)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioFile | The output XML file to save |
Scenario | scenario | The scenario to save |
Returns
Type | Description |
---|---|
bool | True if the operation succedded |
UpdateScenarioText(string)
This method will update the XML string depending on the scenario version detected
Declaration
public static string UpdateScenarioText(string scenarioText)
Parameters
Type | Name | Description |
---|---|---|
string | scenarioText | The complete XML scenario text that must be updated to the current version |
Returns
Type | Description |
---|---|
string |
Events
ScenarioBeforeLoadEvent
Event fire before a scenario is loaded
Declaration
public static event EventHandler ScenarioBeforeLoadEvent
Event Type
Type | Description |
---|---|
EventHandler |
See Also
ScenarioLoadedEvent
Event fired when a scenario is loaded
Declaration
public static event EventHandler<ScenarioLoadedEventArgs> ScenarioLoadedEvent
Event Type
Type | Description |
---|---|
EventHandler<ScenarioLoadedEventArgs> |
See Also
StateChangedEvent
Event fired when the scenario state is changed
Declaration
public event EventHandler StateChangedEvent
Event Type
Type | Description |
---|---|
EventHandler |