Пример #1
0
        protected internal virtual ISet <string> CollectVariableNames(ISet <string> variableNames)
        {
            if (transientVariabes != null)
            {
                transientVariabes.Keys.ToList().ForEach(x =>
                {
                    variableNames.Add(x);
                });
            }

            EnsureVariableInstancesInitialized();
            VariableScopeImpl parentScope = ParentVariableScope;

            if (parentScope != null)
            {
                parentScope.CollectVariableNames(variableNames).ToList().ForEach(x =>
                {
                    variableNames.Add(x);
                });
            }
            foreach (IVariableInstanceEntity variableInstance in variableInstances.Values)
            {
                variableNames.Add(variableInstance.Name);
            }
            return(variableNames);
        }
Пример #2
0
        protected internal virtual IDictionary <string, IVariableInstance> CollectVariableInstances(Dictionary <string, IVariableInstance> variables)
        {
            EnsureVariableInstancesInitialized();
            VariableScopeImpl parentScope = ParentVariableScope;

            if (parentScope != null)
            {
                variables.PutAll(parentScope.CollectVariableInstances(variables));
            }

            foreach (IVariableInstance variableInstance in variableInstances.Values)
            {
                variables[variableInstance.Name] = variableInstance;
            }

            foreach (string variableName in usedVariablesCache.Keys)
            {
                variables[variableName] = usedVariablesCache[variableName];
            }

            if (transientVariabes != null)
            {
                variables.PutAll(transientVariabes);
            }

            return(variables);
        }
Пример #3
0
        public virtual void RemoveTransientVariables()
        {
            RemoveTransientVariablesLocal();
            VariableScopeImpl parentVariableScope = ParentVariableScope;

            if (parentVariableScope != null)
            {
                parentVariableScope.RemoveTransientVariablesLocal();
            }
        }
Пример #4
0
        public virtual void SetTransientVariable(string variableName, object variableValue)
        {
            VariableScopeImpl parentVariableScope = ParentVariableScope;

            if (parentVariableScope != null)
            {
                parentVariableScope.SetTransientVariable(variableName, variableValue);
                return;
            }
            SetTransientVariableLocal(variableName, variableValue);
        }
Пример #5
0
        public virtual void RemoveTransientVariable(string variableName)
        {
            if (transientVariabes != null && transientVariabes.ContainsKey(variableName))
            {
                RemoveTransientVariableLocal(variableName);
                return;
            }
            VariableScopeImpl parentVariableScope = ParentVariableScope;

            if (parentVariableScope != null)
            {
                parentVariableScope.RemoveTransientVariable(variableName);
            }
        }
Пример #6
0
        public virtual object GetTransientVariable(string variableName)
        {
            if (transientVariabes != null && transientVariabes.ContainsKey(variableName))
            {
                return(transientVariabes[variableName].Value);
            }

            VariableScopeImpl parentScope = ParentVariableScope;

            if (parentScope != null)
            {
                return(parentScope.GetTransientVariable(variableName));
            }

            return(null);
        }
Пример #7
0
        protected internal virtual IDictionary <string, object> CollectTransientVariables(Dictionary <string, object> variables)
        {
            VariableScopeImpl parentScope = ParentVariableScope;

            if (parentScope != null)
            {
                variables.PutAll(parentScope.CollectVariables(variables));
            }

            if (transientVariabes != null)
            {
                foreach (string variableName in transientVariabes.Keys)
                {
                    variables[variableName] = transientVariabes[variableName].Value;
                }
            }

            return(variables);
        }
Пример #8
0
        protected internal virtual void RemoveVariable(string variableName, IExecutionEntity sourceActivityExecution)
        {
            EnsureVariableInstancesInitialized();
            if (variableInstances.ContainsKey(variableName))
            {
                RemoveVariableLocal(variableName);
                return;
            }
            VariableScopeImpl parentVariableScope = ParentVariableScope;

            if (parentVariableScope != null)
            {
                if (sourceActivityExecution == null)
                {
                    parentVariableScope.RemoveVariable(variableName);
                }
                else
                {
                    parentVariableScope.RemoveVariable(variableName, sourceActivityExecution);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Sets a variable as high as possible (highest parent).
        /// </summary>
        ///  <param name="sourceExecution"> The execution where the variable was originally set, used for history data. </param>
        ///  <param name="fetchAllVariables"> If true, all existing variables will be fetched when setting the variable. </param>
        protected internal virtual void SetVariable(string variableName, object value, IExecutionEntity sourceExecution, bool fetchAllVariables)
        {
            if (fetchAllVariables == true)
            {
                // If it's in the cache, it's more recent
                if (usedVariablesCache.ContainsKey(variableName))
                {
                    UpdateVariableInstance(usedVariablesCache[variableName], value, sourceExecution);
                }

                // If the variable exists on this scope, replace it
                if (HasVariableLocal(variableName))
                {
                    SetVariableLocal(variableName, value, sourceExecution, true);
                    return;
                }

                // Otherwise, go up the hierarchy (we're trying to put it as high as possible)
                VariableScopeImpl parentVariableScope = ParentVariableScope;
                if (parentVariableScope != null)
                {
                    if (sourceExecution == null)
                    {
                        parentVariableScope.SetVariable(variableName, value);
                    }
                    else
                    {
                        parentVariableScope.SetVariable(variableName, value, sourceExecution, true);
                    }
                    return;
                }

                // We're as high as possible and the variable doesn't exist yet, so
                // we're creating it
                if (sourceExecution != null)
                {
                    CreateVariableLocal(variableName, value, sourceExecution);
                }
                else
                {
                    CreateVariableLocal(variableName, value);
                }
            }
            else
            {
                // Check local cache first
                if (usedVariablesCache.ContainsKey(variableName))
                {
                    UpdateVariableInstance(usedVariablesCache[variableName], value, sourceExecution);
                }
                else if (variableInstances != null && variableInstances.ContainsKey(variableName))
                {
                    UpdateVariableInstance(variableInstances[variableName], value, sourceExecution);
                }
                else
                {
                    // Not in local cache, check if defined on this scope
                    // Create it if it doesn't exist yet
                    IVariableInstanceEntity variable = GetSpecificVariable(variableName);
                    if (variable != null)
                    {
                        UpdateVariableInstance(variable, value, sourceExecution);
                        usedVariablesCache[variableName] = variable;
                    }
                    else
                    {
                        VariableScopeImpl parent = ParentVariableScope;
                        if (parent != null)
                        {
                            if (sourceExecution == null)
                            {
                                parent.SetVariable(variableName, value, fetchAllVariables);
                            }
                            else
                            {
                                parent.SetVariable(variableName, value, sourceExecution, fetchAllVariables);
                            }

                            return;
                        }

                        variable = CreateVariableInstance(variableName, value, sourceExecution);
                        usedVariablesCache[variableName] = variable;
                    }
                }
            }
        }