Esempio n. 1
0
        private ElementIdentifier zGetElementSetContainer(ElementSetIteration iteration)
        {
            ElementIdentifier containerIdentifier = null;

            if (CurrentScope.ElementSetContainerIdentifier != null)
            {
                containerIdentifier = iteration.ElementSetContainer.RelativeTo(CurrentScope.ElementSetContainerIdentifier);
            }
            else
            {
                containerIdentifier = iteration.ElementSetContainer;
            }
            return(containerIdentifier);
        }
Esempio n. 2
0
        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);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public override void SetContext(StepEditContext context, ElementSetIteration iteration)
        {
            base.SetContext(context, iteration);
            m_ContainerIdentifier = this.Target.ElementSetContainer;
            if (m_ContainerIdentifier != null)
            {
                txtElementSetContainer.Text = m_ContainerIdentifier.PrimaryIdentifier;
                btnEdit.Enabled             = true;
            }
            rbStaticElement.Checked  = this.Target.ElementType == ElementType.Static;
            rbDynamicElement.Checked = this.Target.ElementType == ElementType.Dynamic;
            ipPollingTimeout.Enabled = rbDynamicElement.Checked;
            if (rbDynamicElement.Checked && this.Target.PollingTimeout != null)
            {
                ipPollingTimeout.SetValue(this.Target.PollingTimeout.Value);
            }
            else
            {
                ipPollingTimeout.SetValue(TimeSpan.FromSeconds(5));
            }

            if (this.Target.ObjectSetClassName != null)
            {
                txtObjectClassName.Text = this.Target.ObjectSetClassName;
            }
            if (this.Target.ObjectSetScopeName != null)
            {
                txtScopeName.Text = this.Target.ObjectSetScopeName;
            }

            cbListName.BindEditableStateVariables(this.StepEditContext.StateVariables.Lists(), this.Target.ObjectSetListName, true);

            cbPersistList.Checked = iteration.PersistenceMode == PersistenceMode.Persisted;

            cbIncludeInXML.Checked = iteration.IncludeInXML;
        }
Esempio n. 4
0
        private void zCreateElementSetIterator(ElementSetIteration iteration)
        {
            ListStateVariable listStateVariable = null;

            if (iteration.IsSetIteration)
            {
                listStateVariable = (ListStateVariable)CurrentScope.DataScope.GetStateVariable(iteration.ObjectSetListName);
                if (listStateVariable == null)
                {
                    listStateVariable = new ListStateVariable(DataUtils.GetUnscopedVariableName(iteration.ObjectSetListName), iteration.PersistenceMode, new List <IStateVariable>());
                    CurrentScope.DataScope.SetStateVariable(iteration.ObjectSetListName, listStateVariable);
                }
                listStateVariable.IncludeInXML = iteration.IncludeInXML;
            }
            ElementSetIterator iterator = new ElementSetIterator(iteration, listStateVariable);

            ElementIdentifier containerIdentifier = zGetElementSetContainer(iteration);

            ThreadingUtils.InvokeControlAction(m_Context.BrowserHelper.Browser, ctl =>
            {
                if (iteration.ElementType == Model.Automation.ElementType.Static)
                {
                    List <HtmlElement> containerElements = m_Context.BrowserHelper.FindElements(containerIdentifier, CurrentScope.ElementSetIteratorItem);
                    iterator.SetElements(containerElements);
                    zCompleteGroupStep(iterator);
                }
                else
                {
                    m_Context.BrowserHelper.PollElements(containerIdentifier, CurrentScope.ElementSetIteratorItem, iteration.PollingTimeout.Value, containerElements =>
                    {
                        iterator.SetElements(containerElements);
                        zCompleteGroupStep(iterator);
                    });
                }
            });
        }
Esempio n. 5
0
 public ElementSetIterationEditor(StepEditContext context, ElementSetIteration iteration)
     : this()
 {
     this.SetContext(context, iteration);
 }
        private void zTranslateRecursive(XElement containerElement, List <Step> steps, string templateName, ElementIdentifier templateSelectorIdentifier)
        {
            foreach (GetValueStep getValueStep in steps.OfType <GetValueStep>())
            {
                if (getValueStep.XMLFieldOutputMode != XMLFieldOutputMode.None)
                {
                    string elementName = getValueStep.StateVariable;

                    XElement dataElement;
                    if (getValueStep.XMLFieldOutputMode == XMLFieldOutputMode.Element)
                    {
                        dataElement = new XElement(elementName);
                    }
                    else
                    {
                        dataElement = new XElement(xsl + "attribute",
                                                   new XAttribute("name", elementName));
                    }
                    dataElement.Add(zGetNormalizedDataSelector(getValueStep, templateSelectorIdentifier));
                    containerElement.Add(dataElement);
                }
            }
            foreach (GroupStep groupStep in steps.OfType <GroupStep>())
            {
                if (groupStep.Iteration is ElementSetIteration &&
                    groupStep.Iteration.IsSetIteration &&
                    ((ElementSetIteration)groupStep.Iteration).IncludeInXML)
                {
                    ElementSetIteration iteration = (ElementSetIteration)groupStep.Iteration;

                    string   childTemplateName       = String.Format("{0}.{1}", templateName, iteration.ObjectSetClassName.ToLower());
                    string   childTemplateSelectPath = zGetRelativeSelectorPathForXSLT(templateSelectorIdentifier, iteration.ElementSetContainer);
                    XElement listDataElement         = new XElement(iteration.ObjectSetListName,
                                                                    new XElement(xsl + "for-each",
                                                                                 new XAttribute("select", childTemplateSelectPath),
                                                                                 new XElement(xsl + "call-template",
                                                                                              new XAttribute("name", childTemplateName))));
                    containerElement.Add(listDataElement);

                    XElement childTemplate = new XElement(xsl + "template",
                                                          new XAttribute("name", childTemplateName));
                    m_Stylesheet.Add(childTemplate);
                    XElement childContainerElement    = new XElement(iteration.ObjectSetClassName);
                    XElement childTemplateConditional = zGetTemplateConditional(groupStep.Steps, iteration.ElementSetContainer);
                    if (childTemplateConditional != null)
                    {
                        childTemplate.Add(childTemplateConditional);
                        childTemplateConditional.Add(childContainerElement);
                    }
                    else
                    {
                        childTemplate.Add(childContainerElement);
                    }
                    zTranslateRecursive(childContainerElement, groupStep.Steps, childTemplateName, iteration.ElementSetContainer);
                }
                else
                {
                    zTranslateRecursive(containerElement, groupStep.Steps, templateName, templateSelectorIdentifier);
                }
            }
        }
Esempio n. 7
0
 private void zAddVariableToScopeFromElementSetIteration(ElementSetIteration elementSetIteration)
 {
     zAddVariableToScope(m_CurrentScope.ScopeName,
                         new StateVariableInfo(elementSetIteration.ObjectSetListName, DataType.List, elementSetIteration.PersistenceMode));
 }
Esempio n. 8
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();
            }
        }