示例#1
0
        private void zCleanup()
        {
            m_ElementSetVariableListCache.Clear();

            while (m_CurrentScope != null)
            {
                zRemoveCurrentScope();
            }

            if (m_ExecutionStack != null)
            {
                m_ExecutionStack.Reset();
                m_ExecutionStack.BranchEnded -= m_ExecutionStack_BranchEnded;
                m_ExecutionStack              = null;
            }
        }
示例#2
0
        /// <summary>
        /// Main sequence analysis loop, or an "Analysis Pass". This method "passes" through the sequence step by step,
        /// keeps track of the sequence structurally (scope list, scope dictionary),
        /// and fires delegates for each step and for completion.
        /// </summary>
        /// <param name="sequence"></param>
        /// <param name="onStepScope"></param>
        /// <param name="onSequenceComplete"></param>
        private void zAnalyzeSequence(List <Step> sequence, Func <Step, bool> onStepScope, Action onSequenceComplete)
        {
            //Make sure this SequenceAnalyzer is not being used by another thread. It is not thread safe! All concurrent usage must be done on separate instances.
            if (m_ExecutionStack != null)
            {
                throw new InvalidOperationException("A zAnalyzeSequence call is already in progress. If you need to use this method concurrently, use a separate SequenceAnalyzer instance for each concurrent call.");
            }

            try
            {
                if (sequence.Count > 0)
                {
                    m_ExecutionStack              = new ExecutionStack();
                    m_ExecutionStack.BranchEnded += m_ExecutionStack_BranchEnded;
                    m_ExecutionStack.SetSequence(sequence);

                    zSetCurrentScope(new StepScope(DataScope.RootScopeName,
                                                   DataScope.RootScopeName,
                                                   null,
                                                   m_ExecutionStack.CurrentBranch));

                    do
                    {
                        if (onStepScope != null && !onStepScope(m_ExecutionStack.CurrentStep))
                        {
                            break;
                        }

                        if (m_ExecutionStack.CurrentStep is GetValueStep)
                        {
                            GetValueStep getValueStep = (GetValueStep)m_ExecutionStack.CurrentStep;
                            zAddVariableToScopeFromGetValueStep(getValueStep);
                        }

                        if (m_ExecutionStack.CurrentStep is DatabaseStep)
                        {
                            DatabaseStep databaseStep = (DatabaseStep)m_ExecutionStack.CurrentStep;
                            zAddVariablesToScopeFromDatabaseStep(databaseStep);
                        }

                        if (m_ExecutionStack.CurrentStep is GroupStep)
                        {
                            GroupStep groupStep = (GroupStep)m_ExecutionStack.CurrentStep;
                            if (groupStep.Steps.Count > 0)
                            {
                                m_ExecutionStack.SetNewBranch(groupStep.Steps);
                            }

                            if (groupStep.Iteration is ObjectSetIteration && groupStep.Iteration.IsSetIteration)
                            {
                                ObjectSetIteration objectSetIteration = (ObjectSetIteration)groupStep.Iteration;

                                if (objectSetIteration is ElementSetIteration)
                                {
                                    ElementSetIteration elementSetIteration = (ElementSetIteration)objectSetIteration;
                                    zAddVariableToScopeFromElementSetIteration(elementSetIteration);
                                }

                                if (groupStep.Steps.Count > 0)
                                {
                                    string    newScopeCacheKey = zGetCacheKey(m_CurrentScope.ScopeName, objectSetIteration.ObjectSetListName);
                                    StepScope newScope         = new StepScope(objectSetIteration.ObjectSetScopeName,
                                                                               objectSetIteration.ObjectSetClassName,
                                                                               newScopeCacheKey,
                                                                               m_ExecutionStack.PendingBranch);

                                    if (objectSetIteration is DataSetIteration)
                                    {
                                        List <StateVariableInfo> cacheList;
                                        if (newScope.CacheKey != null && m_ElementSetVariableListCache.TryGetValue(newScope.CacheKey, out cacheList))
                                        {
                                            foreach (StateVariableInfo cachedVariable in cacheList)
                                            {
                                                if (newScope.ClassName == null || DataUtils.GetVariableNameScope(cachedVariable.StateVariableName) == newScope.ClassName)
                                                {
                                                    StateVariableInfo variableForNewScope = zRescopeVariable(cachedVariable, objectSetIteration.ObjectSetScopeName);
                                                    if (!newScope.VariableList.Contains(variableForNewScope))
                                                    {
                                                        newScope.VariableList.Add(variableForNewScope);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    zSetCurrentScope(newScope);
                                }
                            }
                        }
                    } while (m_ExecutionStack.MoveNext());
                }

                if (onSequenceComplete != null)
                {
                    onSequenceComplete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                zCleanup();
            }
        }