private void zGroupSteps(List <Step> steps) { if (steps.Count > 0) { GroupStep groupStep = new GroupStep(); List <Step> container = AutomationUtils.GetStepParent(m_AutomationEngine.Sequence, steps.First()); int groupIndex = container.IndexOf(steps.First()); foreach (Step step in steps) { if (AutomationUtils.GetStepParent(m_AutomationEngine.Sequence, step) == container) { container.Remove(step); groupStep.Steps.Add(step); } } container.Insert(groupIndex, groupStep); m_CurrentStep = steps.Last(); m_AutomationEngine.ResetSequence(); zFullRefreshSteps(); zOnSequenceChanged(EventArgs.Empty); } }
private void zPasteSteps(IEnumerable <Step> stepsToPaste, Step pasteTarget, int siblingOffset) { if (stepsToPaste != null && stepsToPaste.Count() > 0) { if (pasteTarget != null) { if (siblingOffset == -1) { GroupStep targetGroupStep = (GroupStep)pasteTarget; targetGroupStep.Steps.AddRange(stepsToPaste); } else { List <Step> container = AutomationUtils.GetStepParent(m_AutomationEngine.Sequence, pasteTarget); container.InsertRange(container.IndexOf(pasteTarget) + siblingOffset, stepsToPaste); } } else { m_AutomationEngine.Sequence.AddRange(stepsToPaste); } m_CurrentStep = stepsToPaste.Last(); m_AutomationEngine.ResetSequence(); IList selectedObjects = tlvSequence.SelectedObjects; zFullRefreshSteps(); tlvSequence.SelectedObjects = selectedObjects; zOnSequenceChanged(EventArgs.Empty); } }
public GetValueSuggestor(StepEditContext stepEditContext, ElementIdentifier elementIdentifier, ElementValueMode elementValueMode, string attributeName) : this() { m_StepEditContext = stepEditContext; GroupStep parentGroupStep = AutomationUtils.GetParentGroupStep(m_StepEditContext.Sequence, m_StepEditContext.Step); if (parentGroupStep != null && parentGroupStep.Iteration != null && parentGroupStep.Iteration is ElementSetIteration) { m_GroupStepEditContext = new StepEditContext(parentGroupStep, m_StepEditContext.Sequence, m_StepEditContext.StepIndex, m_StepEditContext.StateVariables); } m_ElementIdentifier = elementIdentifier; m_ElementValueMode = elementValueMode; m_AttributeName = attributeName; }
private List <Step> zCopySteps(IEnumerable <Step> stepsToCopy, bool isCut) { List <Step> copiedSteps = new List <Step>(); if (stepsToCopy.Count() > 0) { //Copy operation Dictionary <Guid, Step> steps = stepsToCopy.ToDictionary(s => Guid.NewGuid(), s => s); byte[] stepsDeepCopyBytes = Converter.ToBinary(steps); Dictionary <Guid, Step> stepsLookup = Converter.FromBinary <Dictionary <Guid, Step> >(stepsDeepCopyBytes); foreach (KeyValuePair <Guid, Step> stepKVP in stepsLookup) { if (stepKVP.Value is GroupStep) { ((GroupStep)stepKVP.Value).Steps.Clear(); } Step originalStep = steps[stepKVP.Key]; GroupStep originalStepAncestor; while (true) { originalStepAncestor = AutomationUtils.GetParentGroupStep(m_AutomationEngine.Sequence, originalStep); if (originalStepAncestor == null) { copiedSteps.Add(stepKVP.Value); break; } if (steps.ContainsValue(originalStepAncestor)) { Guid originalStepAncestorKey = steps.First(kvp => kvp.Value == originalStepAncestor).Key; GroupStep parentCopiedStep = (GroupStep)stepsLookup[originalStepAncestorKey]; parentCopiedStep.Steps.Add(stepKVP.Value); break; } originalStep = originalStepAncestor; } } //Cut operation if (isCut) { zRemoveSteps(steps.Values); } //Cleanup & persist to clipboard steps.Clear(); stepsLookup.Clear(); } return(copiedSteps); }
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); } } } } }
public static GroupStep GetParentGroupStep(List <Step> container, Step step) { foreach (GroupStep iStep in container.OfType <GroupStep>()) { if (iStep.Steps.Contains(step)) { return(iStep); } GroupStep parentGroupStep = GetParentGroupStep(iStep.Steps, step); if (parentGroupStep != null) { return(parentGroupStep); } } return(null); }
void m_AutomationEngine_ExecutionComplete(object sender, ExecutionCompleteEventArgs e) { m_AutomationEngine.ExecutionComplete -= m_AutomationEngine_ExecutionComplete; ElementIdentifier containerIdentifier = null; if (m_GroupStepEditContext != null) { GroupStep groupStep = (GroupStep)m_GroupStepEditContext.Step; containerIdentifier = ((ElementSetIteration)groupStep.Iteration).ElementSetContainer; } ThreadingUtils.InvokeControlAction(this, ctl => { zDetect(containerIdentifier); }); }
void m_AutomationEngine_ExecutionComplete(object sender, ExecutionCompleteEventArgs e) { m_AutomationEngine.ExecutionComplete -= m_AutomationEngine_ExecutionComplete; GroupStep groupStep = (GroupStep)m_StepEditContext.Step; m_Pattern = groupStep.Steps.OfType <ElementStep>().Select(gvs => gvs.Element).ToList(); ThreadingUtils.InvokeControlAction(this, ctl => { if (m_ContainerIdentifier != null) { zElementSelected(); } zPreview(); pbLoading.Visible = false; EditorPanel.Visible = true; }); }
private void zRemoveSteps(IEnumerable <Step> steps) { if (steps.Count() > 0) { foreach (Step step in steps) { List <Step> stepContainer = AutomationUtils.GetStepParent(m_AutomationEngine.Sequence, step); int containerIndex = stepContainer.IndexOf(step); stepContainer.Remove(step); containerIndex = stepContainer.Count > containerIndex ? containerIndex : stepContainer.Count - 1; if (containerIndex > -1) { m_CurrentStep = stepContainer[containerIndex]; } else { m_CurrentStep = null; } if (step is GroupStep) { GroupStep groupStep = (GroupStep)step; if (groupStep.Steps.Count > 0) { stepContainer.AddRange(groupStep.Steps); } } } m_AutomationEngine.ResetSequence(); IList selectedObjects = tlvSequence.SelectedObjects; zFullRefreshSteps(); tlvSequence.SelectedObjects = selectedObjects; zOnSequenceChanged(EventArgs.Empty); } }
/// <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(); } }