private XElement zGetNormalizedDataSelector(GetValueStep getValueStep, ElementIdentifier templateSelectorIdentifier)
        {
            string   selectPath      = zGetSelectPathForGetValueStep(getValueStep, templateSelectorIdentifier);
            XElement defaultSelector = getValueStep.UseNormalizationDefault
                ? new XElement(xsl + "text", getValueStep.NormalizationDefault)
                : new XElement(xsl + "value-of",
                               new XAttribute("select", selectPath));

            if (getValueStep.NormalizationRules.Count > 0)
            {
                XElement choose = new XElement(xsl + "choose");
                foreach (GetValueNormalizationRule normalizationRule in getValueStep.NormalizationRules)
                {
                    choose.Add(new XElement(xsl + "when",
                                            new XAttribute("test", zGetNormalizationRuleTestCondition(normalizationRule, selectPath)),
                                            new XElement(xsl + "text", normalizationRule.ReplacementValue)));
                }
                choose.Add(new XElement(xsl + "otherwise", defaultSelector));
                return(choose);
            }
            else
            {
                return(defaultSelector);
            }
        }
        private string zGetSelectPathForGetValueStep(GetValueStep getValueStep, ElementIdentifier templateSelectorIdentifier)
        {
            string selectPath = zGetRelativeSelectorPathForXSLT(templateSelectorIdentifier, getValueStep.Element);

            if (getValueStep.Mode == ElementValueMode.Attribute && !String.IsNullOrEmpty(getValueStep.AttributeName))
            {
                selectPath = String.Format("{0}/@{1}", selectPath, getValueStep.AttributeName);
            }
            return(selectPath);
        }
        private void zTryAddPersistedVariableToScope(Step step, Dictionary <string, StepScope> scopeDictionaryAsOfTargetStep)
        {
            //Check if step sets a persisted variable
            StateVariableInfo variableInfo = null;

            if (step is GetValueStep)
            {
                GetValueStep getValueStep = (GetValueStep)step;
                if (getValueStep.PersistenceMode == PersistenceMode.Persisted)
                {
                    variableInfo = new StateVariableInfo(getValueStep.StateVariable, DataType.String, getValueStep.PersistenceMode); //TODO: get actual datatype
                }
            }
            if (step is GroupStep)
            {
                GroupStep groupStep = (GroupStep)step;
                if (groupStep.Iteration is ElementSetIteration)
                {
                    ElementSetIteration elementSetIteration = (ElementSetIteration)groupStep.Iteration;
                    if (elementSetIteration.PersistenceMode == PersistenceMode.Persisted)
                    {
                        variableInfo = new StateVariableInfo(elementSetIteration.ObjectSetListName, DataType.List, elementSetIteration.PersistenceMode);
                    }
                }
            }

            if (variableInfo != null)
            {
                //If step sets a persisted variable, check if it is within the target step's scope visbility
                string scopeNamePart;
                string variableNamePart;
                DataUtils.ParseStateVariableName(m_CurrentScope.ScopeName, variableInfo.StateVariableName, out scopeNamePart, out variableNamePart);
                variableInfo.StateVariableName = String.Format("{0}.{1}", scopeNamePart, variableNamePart);
                StepScope scopeAsOfAnalyzer, scopeAsOfTargetStep;
                if (m_ScopeDictionary.TryGetValue(scopeNamePart, out scopeAsOfAnalyzer) && scopeDictionaryAsOfTargetStep.TryGetValue(scopeNamePart, out scopeAsOfTargetStep))
                {
                    if (scopeNamePart == DataScope.RootScopeName ||
                        (scopeAsOfTargetStep.CacheKey == scopeAsOfAnalyzer.CacheKey &&
                         (scopeAsOfTargetStep.ClassName == null || scopeAsOfTargetStep.ClassName == scopeAsOfAnalyzer.ClassName)))
                    {
                        //If step sets a persisted variable and it is within the target step's scope visbility, add it to the appropriate scope's variable list
                        if (!scopeAsOfTargetStep.VariableList.Contains(variableInfo))
                        {
                            scopeAsOfTargetStep.VariableList.Add(variableInfo);
                        }
                    }
                }
            }
        }
 void m_ElementSelector_ElementSelected(object sender, ElementSelectorEventArgs e)
 {
     if (e.FromUserAction)
     {
         //TODO: refactor this so that code is not repeated.
         if (m_ElementSelectMode == ElementSelectMode.Get)
         {
             GetValueStep getValueStep = new GetValueStep()
             {
                 StateVariable      = zGenerateVariableName(),
                 Element            = ElementIdentifier.FromHtmlElement(e.Element),
                 XMLFieldOutputMode = XMLFieldOutputMode.Attribute,
                 PersistenceMode    = PersistenceMode.None
             };
             //Default mode & attribute based on tag type
             if (e.Element.TagName.ToLower() == "input")
             {
                 getValueStep.Mode          = ElementValueMode.Attribute;
                 getValueStep.AttributeName = "value";
             }
             else
             {
                 getValueStep.Mode = ElementValueMode.InnerText;
             }
             zAddStep(getValueStep);
         }
         else
         {
             SetValueStep setValueStep = new SetValueStep()
             {
                 Element = ElementIdentifier.FromHtmlElement(e.Element)
             };
             //Default mode & attribute based on tag type
             if (e.Element.TagName.ToLower() == "input")
             {
                 setValueStep.Mode          = ElementValueMode.Attribute;
                 setValueStep.AttributeName = "value";
             }
             else
             {
                 setValueStep.Mode = ElementValueMode.InnerText;
             }
             zAddStep(setValueStep);
         }
     }
 }
 private void zAddVariableToScopeFromGetValueStep(GetValueStep getValueStep)
 {
     zAddVariableToScope(m_CurrentScope.ScopeName,
                         new StateVariableInfo(getValueStep.StateVariable, DataType.String, getValueStep.PersistenceMode)); //TODO: get actual datatype
 }
        /// <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();
            }
        }