Skip to content

Commit

Permalink
added in case insensitivity for XML tags as well as attribute values
Browse files Browse the repository at this point in the history
added in the ability to define constants in the definition xml by added the extenedelements tag to definitions and defining either a DefinitionVariable or DefinitionFile
added in the ability to define runtime constants for a process at the point of creation

Both tweaks above now mean variables are obtained form the process variable container in the following order (Container->Runtime->Definition Constants), so during any process run new variables with the same name can be defined and they will be returned when accessing the variable.  If the variable name is not contained within the process variables, the runtime constants are checked, still not found, definition constants are checked, still not found, return null.
  • Loading branch information
roger-castaldo committed May 10, 2017
1 parent 16e9e41 commit 321f226
Show file tree
Hide file tree
Showing 39 changed files with 988 additions and 744 deletions.
2 changes: 1 addition & 1 deletion Attributes/AttributeRegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AttributeRegex(string name, string regex)

public bool IsValid(AElement elem)
{
return _reg.IsMatch(elem.Element.Attributes[_name].Value);
return _reg.IsMatch(elem[_name]);
}
}
}
2 changes: 1 addition & 1 deletion Attributes/XMLTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override string ToString()

internal bool Matches(XmlPrefixMap map, string tagName)
{
if (tagName == ToString())
if (tagName.ToLower() == ToString().ToLower())
return true;
else if (_prefix!=null)
return map.isMatch(_prefix, _name, tagName);
Expand Down
7 changes: 6 additions & 1 deletion BpmEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
<Compile Include="Drawing\Gif\Encoder.cs" />
<Compile Include="Drawing\Gif\LZWEncoder.cs" />
<Compile Include="Drawing\Gif\NeuQuant.cs" />
<Compile Include="Elements\Processes\AParentFlowNode.cs" />
<Compile Include="Elements\Collaborations\Text.cs" />
<Compile Include="Elements\DefinitionFile.cs" />
<Compile Include="Elements\DefinitionVariable.cs" />
<Compile Include="Elements\Processes\Conditions\ACompareCondition.cs" />
<Compile Include="Elements\Processes\Conditions\ACondition.cs" />
<Compile Include="Elements\Processes\Conditions\AConditionSet.cs" />
Expand All @@ -70,9 +72,12 @@
<Compile Include="Elements\Processes\Events\Definitions\MessageEventDefinition.cs" />
<Compile Include="Elements\Processes\Events\IntermediateCatchEvent.cs" />
<Compile Include="Elements\Processes\ExtensionElements.cs" />
<Compile Include="Elements\Processes\FlowNodeRef.cs" />
<Compile Include="Elements\Processes\Gateways\EventBasedGateway.cs" />
<Compile Include="Elements\Processes\Gateways\ComplexGateway.cs" />
<Compile Include="Elements\Processes\Gateways\InclusiveGateway.cs" />
<Compile Include="Elements\Processes\IncomingFlow.cs" />
<Compile Include="Elements\Processes\OutgoingFlow.cs" />
<Compile Include="Elements\Processes\Scripts\Javascript.cs" />
<Compile Include="Elements\Processes\Tasks\BusinessRuleTask.cs" />
<Compile Include="Elements\Processes\Scripts\ACompiledScript.cs" />
Expand Down
94 changes: 74 additions & 20 deletions BusinessProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,51 @@ private void _RecurAddChildren(IElement parent, ref List<IElement> elems)

private ManualResetEvent _processLock;

private sProcessRuntimeConstant[] _constants;
public object this[string name]
{
get
{
if (_constants != null)
{
foreach (sProcessRuntimeConstant sprc in _constants)
{
if (sprc.Name == name)
return sprc.Value;
}
}
if (_Elements != null)
{
foreach (IElement elem in _Elements)
{
if (elem is Definition)
{
Definition def = (Definition)elem;
if (def.ExtensionElement != null)
{
foreach (IElement e in ((ExtensionElements)def.ExtensionElement).Children)
{
if (e is DefinitionVariable)
{
DefinitionVariable dv = (DefinitionVariable)e;
if (dv.Name == name)
return dv.Value;
}else if (e is DefinitionFile)
{
DefinitionFile df = (DefinitionFile)e;
if (string.Format("{0}.{1}", df.Name, df.Extension) == name || df.Name == name)
return new sFile(df.Name, df.Extension, df.ContentType, df.Content);
}
}
}
break;
}
}
}
return null;
}
}

[ThreadStatic()]
private static BusinessProcess _current;
public static BusinessProcess Current { get { return _current; } }
Expand Down Expand Up @@ -208,7 +253,7 @@ private void _ErrorExternalTask(string taskID, Exception ex)
if (elem.id == taskID && elem is ATask)
{
if (_onTaskError != null)
_onTaskError((ATask)elem, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onTaskError((ATask)elem, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
lock (_state)
{
_state.Path.FailTask((ATask)elem);
Expand Down Expand Up @@ -261,9 +306,16 @@ private BusinessProcess() {
public BusinessProcess(XmlDocument doc)
:this(doc,LogLevels.None) { }

public BusinessProcess(XmlDocument doc,sProcessRuntimeConstant[] constants)
: this(doc, LogLevels.None,constants) { }

public BusinessProcess(XmlDocument doc, LogLevels stateLogLevel)
: this(doc, LogLevels.None, null) { }

public BusinessProcess(XmlDocument doc, LogLevels stateLogLevel,sProcessRuntimeConstant[] constants)
{
_stateLogLevel = stateLogLevel;
_constants = constants;
List<Exception> exceptions = new List<Exception>();
_processLock = new ManualResetEvent(false);
_mreSuspend = new ManualResetEvent(false);
Expand Down Expand Up @@ -318,7 +370,7 @@ private void _ValidateElement(AElement elem,ref List<Exception> exceptions)
WriteLogLine(LogLevels.Debug, new StackFrame(1, true), DateTime.Now, string.Format("Validating element {0}", new object[] { elem.id }));
foreach (RequiredAttribute ra in Utility.GetCustomAttributesForClass(elem.GetType(),typeof(RequiredAttribute)))
{
if (elem.Element.Attributes[ra.Name]==null)
if (elem[ra.Name]==null)
exceptions.Add(new MissingAttributeException(elem.Element,ra));
}
foreach (AttributeRegex ar in Utility.GetCustomAttributesForClass(elem.GetType(), typeof(AttributeRegex)))
Expand Down Expand Up @@ -401,7 +453,7 @@ private void _suspendEvent(object parameters)
AEvent evnt = (AEvent)ie;
lock (_state) { _state.Path.SucceedEvent(evnt); }
if (_onEventCompleted != null)
_onEventCompleted(evnt,new ReadOnlyProcessVariablesContainer(ie.id,_state));
_onEventCompleted(evnt,new ReadOnlyProcessVariablesContainer(ie.id,_state,this));
break;
}
}
Expand Down Expand Up @@ -523,6 +575,7 @@ public BusinessProcess Clone(bool includeState,bool includeDelegates)
BusinessProcess ret = new BusinessProcess();
ret._doc = _doc;
ret._components = new List<object>(_components.ToArray());
ret._constants = _constants;
if (includeState)
ret._state = _state;
else
Expand Down Expand Up @@ -560,6 +613,7 @@ public BusinessProcess Clone(bool includeState,bool includeDelegates)
public bool BeginProcess(ProcessVariablesContainer variables)
{
_current = this;
variables.SetProcess(this);
WriteLogLine(LogLevels.Debug, new StackFrame(1, true), DateTime.Now, "Attempting to begin process");
bool ret = false;
foreach (IElement elem in _FullElements)
Expand All @@ -583,7 +637,7 @@ public bool BeginProcess(ProcessVariablesContainer variables)
_state[se.id,str]=variables[str];
_state.Path.SucceedEvent(se);
if (_onEventCompleted!=null)
_onEventCompleted(se, new ReadOnlyProcessVariablesContainer(se.id, _state));
_onEventCompleted(se, new ReadOnlyProcessVariablesContainer(se.id, _state,this));
ret=true;
}
}
Expand Down Expand Up @@ -670,7 +724,7 @@ private void _ProcessStepError(IElement step) {
{
if (elem is IntermediateCatchEvent)
{
if (_isEventStartValid(elem, new ProcessVariablesContainer(step.id, _state)))
if (_isEventStartValid(elem, new ProcessVariablesContainer(step.id, _state,this)))
{
WriteLogLine(LogLevels.Debug, new StackFrame(1, true), DateTime.Now, string.Format("Valid Error handle located at {0}", elem.id));
_ProcessElement(step.id, elem);
Expand Down Expand Up @@ -701,7 +755,7 @@ private void _ProcessElement(string sourceID,IElement elem)
_state.Path.ProcessSequenceFlow(sf);
}
if (_onSequenceFlowCompleted != null)
_onSequenceFlowCompleted(sf,new ReadOnlyProcessVariablesContainer(elem.id,_state));
_onSequenceFlowCompleted(sf,new ReadOnlyProcessVariablesContainer(elem.id,_state,this));
}
else if (elem is MessageFlow)
{
Expand All @@ -711,7 +765,7 @@ private void _ProcessElement(string sourceID,IElement elem)
_state.Path.ProcessMessageFlow(mf);
}
if (_onMessageFlowCompleted != null)
_onMessageFlowCompleted(mf, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onMessageFlowCompleted(mf, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
}
else if (elem is AGateway)
{
Expand All @@ -733,17 +787,17 @@ private void _ProcessElement(string sourceID,IElement elem)
_state.Path.StartGateway(gw, sourceID);
}
if (_onGatewayStarted != null)
_onGatewayStarted(gw, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onGatewayStarted(gw, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
string[] outgoings = null;
try
{
outgoings = gw.EvaulateOutgoingPaths(def, _isFlowValid, new ProcessVariablesContainer(elem.id, _state));
outgoings = gw.EvaulateOutgoingPaths(def, _isFlowValid, new ProcessVariablesContainer(elem.id, _state,this));
}
catch (Exception e)
{
WriteLogException(new StackFrame(1, true), DateTime.Now, e);
if (_onGatewayError != null)
_onGatewayError(gw, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onGatewayError(gw, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
outgoings = null;
}
lock (_state)
Expand All @@ -758,7 +812,7 @@ private void _ProcessElement(string sourceID,IElement elem)
{
AEvent evnt = (AEvent)elem;
if (_onEventStarted != null)
_onEventStarted(evnt, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onEventStarted(evnt, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
lock (_state)
{
_state.Path.StartEvent(evnt, sourceID);
Expand All @@ -768,7 +822,7 @@ private void _ProcessElement(string sourceID,IElement elem)
{
try
{
success = _isEventStartValid(evnt, new ProcessVariablesContainer(evnt.id, _state));
success = _isEventStartValid(evnt, new ProcessVariablesContainer(evnt.id, _state,this));
}
catch (Exception e)
{
Expand All @@ -778,7 +832,7 @@ private void _ProcessElement(string sourceID,IElement elem)
}
else if (evnt is IntermediateThrowEvent)
{
TimeSpan? ts = evnt.GetTimeout(new ProcessVariablesContainer(evnt.id, _state));
TimeSpan? ts = evnt.GetTimeout(new ProcessVariablesContainer(evnt.id, _state,this));
if (ts.HasValue)
{
lock (_state)
Expand All @@ -794,17 +848,17 @@ private void _ProcessElement(string sourceID,IElement elem)
{
lock (_state) { _state.Path.FailEvent(evnt); }
if (_onEventError != null)
_onEventError(evnt, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onEventError(evnt, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
}
else
{
lock (_state) { _state.Path.SucceedEvent(evnt); }
if (_onEventCompleted != null)
_onEventCompleted(evnt, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onEventCompleted(evnt, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
if (evnt is EndEvent)
{
if (_onProcessCompleted != null)
_onProcessCompleted(((EndEvent)evnt).Process, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onProcessCompleted(((EndEvent)evnt).Process, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
_processLock.Set();
}
}
Expand All @@ -813,14 +867,14 @@ private void _ProcessElement(string sourceID,IElement elem)
{
ATask tsk = (ATask)elem;
if (_onTaskStarted != null)
_onTaskStarted(tsk, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onTaskStarted(tsk, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
lock (_state)
{
_state.Path.StartTask(tsk, sourceID);
}
try
{
ProcessVariablesContainer variables = new ProcessVariablesContainer(tsk.id, _state);
ProcessVariablesContainer variables = new ProcessVariablesContainer(tsk.id, _state,this);
switch (elem.GetType().Name)
{
case "BusinessRuleTask":
Expand Down Expand Up @@ -871,7 +925,7 @@ private void _ProcessElement(string sourceID,IElement elem)
{
WriteLogException(new StackFrame(1, true), DateTime.Now, e);
if (_onTaskError != null)
_onTaskError(tsk, new ReadOnlyProcessVariablesContainer(elem.id, _state));
_onTaskError(tsk, new ReadOnlyProcessVariablesContainer(elem.id, _state,this));
lock (_state) { _state.Path.FailTask(tsk); }
}
}
Expand Down Expand Up @@ -913,7 +967,7 @@ private void _MergeVariables(ATask task, ProcessVariablesContainer variables,str
}
}
if (_onTaskCompleted != null)
_onTaskCompleted(task, new ReadOnlyProcessVariablesContainer(task.id, _state));
_onTaskCompleted(task, new ReadOnlyProcessVariablesContainer(task.id, _state,this));
if (task is UserTask)
_state.Path.SucceedTask((UserTask)task,completedByID);
else
Expand Down
23 changes: 12 additions & 11 deletions Elements/AElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Definition Definition

public string id
{
get { return (_GetAttributeValue("id")==null ? Utility.FindXPath(_element) : _GetAttributeValue("id")); }
get { return (this["id"]==null ? Utility.FindXPath(_element) : this["id"]); }
}

public XmlNode[] SubNodes
Expand All @@ -43,14 +43,20 @@ public XmlNode[] SubNodes
}
}

public XmlAttribute[] Attributes
public string this[string attributeName]
{
get
{
List<XmlAttribute> ret = new List<XmlAttribute>();
string value = null;
foreach (XmlAttribute att in _element.Attributes)
ret.Add(att);
return ret.ToArray();
{
if (att.Name.ToLower()==attributeName.ToLower())
{
value = att.Value;
break;
}
}
return value;
}
}

Expand Down Expand Up @@ -84,16 +90,11 @@ public AElement(XmlElement elem,XmlPrefixMap map,AElement parent)
}
}

protected string _GetAttributeValue(string name)
{
return (_element.Attributes[name] == null ? null : _element.Attributes[name].Value);
}

public sealed override string ToString()
{
if (this.GetType().Name == "TextAnnotation")
return (string)this.GetType().GetProperty("Content").GetValue(this, new object[] { });
return _GetAttributeValue("name");
return this["name"];
}

public virtual bool IsValid(out string[] err)
Expand Down
4 changes: 2 additions & 2 deletions Elements/Collaborations/MessageFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Org.Reddragonit.BpmEngine.Elements.Collaborations
[RequiredAttribute("id")]
internal class MessageFlow : AElement
{
public string sourceRef { get { return _GetAttributeValue("sourceRef"); } }
public string targetRef { get { return _GetAttributeValue("targetRef"); } }
public string sourceRef { get { return this["sourceRef"]; } }
public string targetRef { get { return this["targetRef"]; } }

public MessageFlow(XmlElement elem, XmlPrefixMap map,AElement parent)
: base(elem, map,parent) { }
Expand Down
4 changes: 2 additions & 2 deletions Elements/Collaborations/Participant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Org.Reddragonit.BpmEngine.Elements.Collaborations
[RequiredAttribute("id")]
internal class Participant : AElement
{
public string Name { get { return _GetAttributeValue("name"); } }
public string ProcessRef { get { return _GetAttributeValue("processRef"); } }
public string Name { get { return this["name"]; } }
public string ProcessRef { get { return this["processRef"]; } }

public Participant(XmlElement elem, XmlPrefixMap map, AElement parent)
: base(elem, map, parent)
Expand Down
18 changes: 18 additions & 0 deletions Elements/Collaborations/Text.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Org.Reddragonit.BpmEngine.Attributes;
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Org.Reddragonit.BpmEngine.Elements.Collaborations
{
[XMLTag("bpmn", "text")]
internal class Text : AElement
{

public string Value { get { return Element.InnerText; } }
public Text(XmlElement elem, XmlPrefixMap map, AElement parent) : base(elem, map, parent)
{
}
}
}
Loading

0 comments on commit 321f226

Please sign in to comment.