Class Model
DCR Model
public class Model
- Inheritance
-
Model
- Inherited Members
- Extension Methods
Remarks
This class is the canonical C# representation of a DCR model.
Caution
If at all possible, work with DCR models through this class:
- DO NOT manipulate the DCR XML format directly
- DO NOT reference the underlying F# implementation directly
- AVOID the older DCR.Engine.Graph representation.
Constructors
Model(Model)
public Model(Model other)
Parameters
other
Model
Properties
Activities
Return material activities in the model
[NotMapped]
public IEnumerable<Activity> Activities { get; }
Property Value
AllActivities
Return all activities in the model
[NotMapped]
public IEnumerable<Activity> AllActivities { get; }
Property Value
CurrentPhase
[NotMapped]
public Phase? CurrentPhase { get; }
Property Value
- Phase
CurrentPhaseTitle
[Column("Phase")]
public string? CurrentPhaseTitle { get; }
Property Value
Deadline
Return the earliest point in time at which a pending included activity has a deadline.
public DateTimeOffset? Deadline { get; }
Property Value
Groups
[NotMapped]
public Group[] Groups { get; }
Property Value
- Group[]
Id
public int Id { get; set; }
Property Value
IsAccepting
public bool IsAccepting { get; }
Property Value
IsBlocked
public bool IsBlocked { get; }
Property Value
this[int]
public Activity this[int id] { get; }
Parameters
id
int
Property Value
this[string]
public Activity this[string path] { get; }
Parameters
path
string
Property Value
NextDeadline
Returns the earliest point in the future at which an including pending activity has a deadline or null if no such point exists.
[NotMapped]
public DateTimeOffset? NextDeadline { get; }
Property Value
Remarks
"The future" is relative to current graph time. This property is
different from Deadline
in that here we ignore deadlines in the
past, that is, if current time is later than all deadlines, we
return null.
NextDelay
public DateTimeOffset? NextDelay { get; }
Property Value
Phases
[NotMapped]
public Phase[] Phases { get; }
Property Value
- Phase[]
Roles
[NotMapped]
public Role[] Roles { get; }
Property Value
- Role[]
Time
public DateTimeOffset Time { get; set; }
Property Value
Title
public string Title { get; }
Property Value
XmlString
[Column("Xml", TypeName = "xml")]
public string XmlString { get; set; }
Property Value
Methods
BlockContainer(Activity)
public void BlockContainer(Activity a)
Parameters
a
Activity
Execute(Activity, value?, string?)
public void Execute(Activity a, value? v = null, string? user = null)
Parameters
Find(IEnumerable<int>)
public IEnumerable<Activity?> Find(IEnumerable<int> idx)
Parameters
idx
IEnumerable<int>
Returns
Find(string)
public Activity? Find(string path)
Parameters
path
string
Returns
FindPhase(int)
public Phase? FindPhase(int index)
Parameters
index
int
Returns
- Phase
FindPhase(string)
public Phase? FindPhase(string title)
Parameters
title
string
Returns
- Phase
Generalize(Predicate<Activity>)
Creates a predicate that returns true for a given activity, its ancestors, and all its descendants
if the initial predicate
is true at that activity.
This is a generalization that expands the truth of a predicate downwards as well as upwards in a tree structure.
For example, given a tree:
1
/ | \
... 2 ...
/ \
3 4
If predicate
is true at node 2, this method ensures the
returned predicate will be true at nodes {1, 2, 3, 4}, generalizing the truth value
to include the root and all descendants.
public Predicate<Activity> Generalize(Predicate<Activity> predicate)
Parameters
Returns
- Predicate<Activity>
A new predicate that is true for activities satisfying
predicate
, their ancestors, and all descendants.
GeneralizeUpwards(Predicate<Activity>)
Creates a predicate that returns true for a given leaf activity and all its ancestors
if the initial leafPredicate
is true at that activity.
This is a generalization that lifts the truth of a predicate upwards in a tree structure.
For example, given a tree:
1
/ | \
... 2 ...
/ \
3 4
If leafPredicate
is true at node 3, this method ensures the
returned predicate will be true at nodes {1, 2, 3}, lifting the truth value upwards
to the root.
OBS: This method only checks the leaf activities!
public Predicate<Activity> GeneralizeUpwards(Predicate<Activity> leafPredicate)
Parameters
Returns
- Predicate<Activity>
A new predicate that is true for activities satisfying
leafPredicate
and all of their ancestors.
GetByteCode()
public VM.Process<Vm.Info> GetByteCode()
Returns
- VM.Process<Vm.Info>
GetOrigin()
public Origin? GetOrigin()
Returns
- Origin
GetUnderRoot(Activity)
public IEnumerable<Activity> GetUnderRoot(Activity act)
Parameters
act
Activity
Returns
ReplaceParameters(string)
Replace all occurrences of '$(<eid>)' with the value of the event eid.
public string ReplaceParameters(string s)
Parameters
s
string
Returns
- string
) The string s, with all occurrences of '<eid>' replaced with the value of 'eid'. If eid has no value, the empty string is returned.
Replay(Log)
public ReplayResult[] Replay(Log log)
Parameters
log
Log
Returns
Replay1(IEnumerable<LogEntry>, out Model, out List<Violation>, out int, Recover)
Replays the provided trace against this model. The replay continues as long as the log conforms to the model. This model is never updated.
public bool Replay1(IEnumerable<LogEntry> trace, out Model result, out List<LogModule.Violation> violations, out int index, LogModule.Recover recover = (LogModule.Recover)7)
Parameters
trace
IEnumerable<LogEntry>The trace to replay.
result
ModelA copy of the input
model
advanced to the last successful replay step. The origin (GetOrigin()) of the input model will be copied to this result model.violations
List<LogModule.Violation>If the replay was unsuccessful, the list of violations encountered at the first unsuccessful replay step; otherwise, an empty list.
index
intThe index of the first unsuccessful replay step, or -1 if the replay was successful. If the underlying log contains index pointers, this index pointer is returned; otherwise, simply the index into
trace
of the unsuccessful step is returned.recover
LogModule.RecoverFlags for the replay engine indicating which violations to consider acceptable. See DCR.Core.LogModule.Recover.
Returns
- bool
True if the replay was successful; otherwise, false.
Replay1(IEnumerable<LogEntry>, out List<Violation>, out int, Recover)
In-place replay
public bool Replay1(IEnumerable<LogEntry> trace, out List<LogModule.Violation> violations, out int index, LogModule.Recover recover = (LogModule.Recover)7)
Parameters
trace
IEnumerable<LogEntry>violations
List<LogModule.Violation>index
intrecover
LogModule.Recover
Returns
Search(TraceSearchParameters)
Search through the graph looking for a path from start state to the designated end point of the search, if that is an activity or graph accepting. Search have to go through the activities in "hit" and avoid those in "excl".
public TraceSearchResult Search(TraceSearchParameters param)
Parameters
param
TraceSearchParameters
Returns
- TraceSearchResult
a tuple containing a bool saying if a trace was found or not. Int saying how many executions was done to complete the search, String xml representation of the trace (if any) that was found.
SetConfiguration(RuntimeConfiguration)
Set necessary configuration. You generally should not call this.
public void SetConfiguration(RuntimeConfiguration config)
Parameters
config
RuntimeConfiguration
Remarks
Necessary configuration is set up by Runtime in its various Load and Parse methods. The one situation where you may need to set this manually is if you are deserializing models from DB using EF, in which case you need to manually add configuration.
As of 2024-08-13, the necessary configuration currently comprises only TimeOptions (timezone, holidays).
Splice(Activity, XDocument, Dictionary<string, string>?)
Splice child model into the current model.
public void Splice(Activity root, XDocument childAsXml, Dictionary<string, string>? substitutions = null)
Parameters
root
ActivitychildAsXml
XDocumentsubstitutions
Dictionary<string, string>
Remarks
The child
parameter is provided as an XML-serialized model
because in cases we can think of where you want to do this,
you're loading the child model from persistant storage.
ToString()
public override string ToString()
Returns
ToXDocument()
public XDocument ToXDocument()
Returns
TryEvaluateExpression(string, out value?, out typ?, out string?)
Attempt to parse and evaluate an expression in the context of the current graph
public bool TryEvaluateExpression(string expression, out value? result, out typ? t, out string? error)
Parameters
expression
stringThe expression to evaluate
result
valueThe value of the expression, or null if parsing or evaluation failed
t
typThe type of the value of the expression, or null if parsing or evaluation failed
error
stringAn error message or null if parsing and evaluation succeeded
Returns
- bool
True if parsing and evaluation succeeded, otherweise false
Typecheck(string, out typ?, out string?)
public bool Typecheck(string input, out typ? typ, out string? err)
Parameters
Returns
UnblockContainer(Activity)
public void UnblockContainer(Activity a)
Parameters
a
Activity
ValidateExpression(string)
Check that given expression is syntactically correct, and references only activities in the graph.
public string? ValidateExpression(string src)
Parameters
src
string