Пример #1
0
        public override void Execute(Context context)
        {
            _request = RequestBody.Load(context);

            context.LogXmlData("Request", _request, true);

            if (HasResponse)
            {
                _response = CallWebMethod(
                    _request,
                    ServiceUrl,
                    Action,
                    Username,
                    Password,
                    context);

                var responseForPostProcessing =
                    SubSteps.Aggregate(_response, (current, subStep) => subStep.Execute(current, context));
            }
            else
            {
                CallVoidWebMethod(
                    _request,
                    ServiceUrl,
                    Action,
                    Username,
                    Password,
                    context);
            }
        }
Пример #2
0
        protected override async Task <UpgradeStepInitializeResult> InitializeImplAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var project = context.CurrentProject.Required();

            var configPaths = _configFilePaths.Select(p => Path.Combine(project.FileInfo.DirectoryName, p)).Where(p => File.Exists(p));

            Logger.LogDebug("Loading config files: {ConfigFiles}", string.Join(", ", configPaths));
            ConfigFiles = ImmutableArray.CreateRange(configPaths.Select(p => new ConfigFile(p)));
            Logger.LogDebug("Loaded {ConfigCount} config files", ConfigFiles.Length);

            await FilterSubStepsByIsApplicableAsync(context, token).ConfigureAwait(false);

            foreach (var step in SubSteps)
            {
                await step.InitializeAsync(context, token).ConfigureAwait(false);
            }

            var incompleteSubSteps = SubSteps.Count(s => !s.IsDone);

            return(incompleteSubSteps == 0
                ? new UpgradeStepInitializeResult(UpgradeStepStatus.Complete, "No config updaters need applied", BuildBreakRisk.None)
                : new UpgradeStepInitializeResult(UpgradeStepStatus.Incomplete, $"{incompleteSubSteps} config updaters need applied", SubSteps.Where(s => !s.IsDone).Max(s => s.Risk)));
        }
Пример #3
0
        public virtual async Task RunTaskAsync(CancellationToken cancelToken)
        {
            var timer = new BrewTimer();

            timer.Start(ElapsedSeconds);

            while (!Finished)
            {
                if (SubSteps.Any())
                {
                    var step = SubSteps.FirstOrDefault(s => ElapsedSeconds >= (s.LengthMinutes * 60) && !s.Finished);
                    if (step != null)
                    {
                        step.RunTaskAsync(cancelToken);
                        Debug.WriteLine($"Sub step completed at {step.LengthMinutes} minutes");
                    }
                }

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () =>
                {
                    //Gather information on how long the step takes
                    ElapsedSeconds = timer.ElapsedSeconds;
                    ElapsedMinutes = timer.ElapsedMinutes;
                });

                await Task.Delay(100);
            }
        }
Пример #4
0
        protected override async Task <UpgradeStepInitializeResult> InitializeImplAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _razorEngine = RazorProjectEngine.Create(RazorConfiguration.Default, GetRazorFileSystem(context.CurrentProject.Required()), builder =>
            {
                // Add useful "MVC View-isms" like _ViewImports support, page models, etc.
                // https://github.com/dotnet/aspnetcore/blob/main/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs
                RazorExtensions.Register(builder);
            });

            // Process all Razor documents initially
            // SubSteps can call ProcessRazorDocuments with specific files that have changed later to re-process specific documents
            ProcessRazorDocuments(null);

            foreach (var step in SubSteps)
            {
                await step.InitializeAsync(context, token).ConfigureAwait(false);
            }

            var incompleteSubSteps = SubSteps.Count(s => !s.IsDone);

            return(incompleteSubSteps == 0
                ? new UpgradeStepInitializeResult(UpgradeStepStatus.Complete, "No Razor updaters need applied", BuildBreakRisk.None)
                : new UpgradeStepInitializeResult(UpgradeStepStatus.Incomplete, $"{incompleteSubSteps} Razor updaters need applied", SubSteps.Where(s => !s.IsDone).Max(s => s.Risk)));
        }
Пример #5
0
        protected override Task <bool> IsApplicableImplAsync(IUpgradeContext context, CancellationToken token)
        {
            var result = context?.CurrentProject is not null &&
                         SubSteps.Any() &&
                         _configFilePaths.Select(p => Path.Combine(context.CurrentProject.FileInfo.DirectoryName, p)).Any(f => File.Exists(f));

            return(Task.FromResult(result));
        }
Пример #6
0
        protected override Task <UpgradeStepApplyResult> ApplyImplAsync(IUpgradeContext context, CancellationToken token)
        {
            // Nothing needs applied here because the actual upgrade changes are applied by the substeps
            // (which should apply before this step).
            var incompleteSubSteps = SubSteps.Count(s => !s.IsDone);

            return(Task.FromResult(incompleteSubSteps == 0
                ? new UpgradeStepApplyResult(UpgradeStepStatus.Complete, string.Empty)
                : new UpgradeStepApplyResult(UpgradeStepStatus.Incomplete, $"{incompleteSubSteps} config updaters need applied")));
        }
Пример #7
0
        protected override Task <UpgradeStepApplyResult> ApplyImplAsync(IUpgradeContext context, CancellationToken token)
        {
            // Updates are made in sub-steps, so no changes need made in this apply step.
            // Just check that sub-steps executed correctly.
            var incompleteSubSteps = SubSteps.Count(s => !s.IsDone);

            return(incompleteSubSteps == 0
                ? Task.FromResult(new UpgradeStepApplyResult(UpgradeStepStatus.Complete, string.Empty))
                : Task.FromResult(new UpgradeStepApplyResult(UpgradeStepStatus.Incomplete, $"{incompleteSubSteps} VB updaters need applied")));
        }
Пример #8
0
        public new Object Clone()
        {
            var op   = base.Clone() as IOperator;
            var init = InitialStep.Clone() as IPlanStep;
            var goal = GoalStep.Clone() as IPlanStep;

            return(new Composite(op, init, goal, SubSteps.ToList(), SubOrderings.ToList(), SubLinks.ToList())
            {
                Height = this.Height,
                NonEqualities = this.NonEqualities
            });
        }
        protected override Task <UpgradeStepApplyResult> ApplyImplAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var incompleteSubSteps = SubSteps.Count(s => !s.IsDone);

            return(incompleteSubSteps == 0
                ? Task.FromResult(new UpgradeStepApplyResult(UpgradeStepStatus.Complete, string.Empty))
                : Task.FromResult(new UpgradeStepApplyResult(UpgradeStepStatus.Incomplete, $"{incompleteSubSteps} Winforms updaters need applied")));
        }
Пример #10
0
        /// <summary>
        /// Translates the current step according to the translation dictionary
        /// Removes all preconditions, actions and expectations
        /// </summary>
        /// <param name="translationDictionary"></param>
        public void Translate(Translations.TranslationDictionary translationDictionary)
        {
            if (getTranslationRequired())
            {
                SubSteps.Clear();

                Translations.Translation translation = translationDictionary.findTranslation(getDescription());
                if (translation != null)
                {
                    translation.UpdateStep(this);
                    setTranslated(true);
                }
            }
        }
Пример #11
0
        /// <summary>
        /// The compositeschedule has terms, preconditions, and effects.
        /// All preconditions and effects are expected to be ground because they are created based on the ground decomposition
        /// Thus, unlike the parent class, there is no need to propagate bindings to terms, preconditions, and effects.
        /// </summary>
        /// <param name="td"></param>
        public void ApplyDecomposition(TimelineDecomposition td)
        {
            subSteps     = td.SubSteps;
            subOrderings = td.SubOrderings;
            subLinks     = td.SubLinks;

            foreach (var substep in subSteps)
            {
                foreach (var term in substep.Terms)
                {
                    if (!td.Terms.Contains(term))
                    {
                        //var termAsPredicate = term as Predicate;
                        //if (termAsPredicate != null)
                        //{

                        //}
                        Terms.Add(term);
                    }
                }
            }

            Cntgs = td.fabCntgs;

            // The way things are done round here is just to group in discourse stuff with fabula stuff. We have two plans... but they can go in one plan.
            foreach (var camplanstep in td.discourseSubSteps)
            {
                SubSteps.Add(camplanstep as IPlanStep);
            }
            foreach (var dordering in td.discOrderings)
            {
                SubOrderings.Add(new Tuple <IPlanStep, IPlanStep>(dordering.First, dordering.Second));
            }
            foreach (var discCntg in td.discCntgs)
            {
                Cntgs.Add(new Tuple <IPlanStep, IPlanStep>(discCntg.First, discCntg.Second));
            }
            foreach (var dlink in td.discLinks)
            {
                SubLinks.Add(new CausalLink <IPlanStep>(dlink.Predicate, dlink.Head, dlink.Tail));
            }

            // these should already be ground.
            InitialActionSeg = td.InitialActionSeg.Clone();
            FinalActionSeg   = td.FinalActionSeg.Clone();
            InitialAction    = td.InitialAction.Clone() as IPlanStep;
            FinalAction      = td.FinalAction.Clone() as IPlanStep;
            InitialCamAction = td.InitialCamAction.Clone() as CamPlanStep;
            FinalCamAction   = td.FinalCamAction.Clone() as CamPlanStep;
        }
Пример #12
0
        private void AddSubSteps(List <SubSteps> subStepList, int recipeID)
        {
            foreach (SubSteps step in subStepList)
            {
                SubSteps s = new SubSteps()
                {
                    RecipeID    = recipeID,
                    LocalStepID = step.LocalStepID,
                    Contents    = step.Contents,
                    SubStepID   = step.SubStepID
                };

                _context.substeps.Add(s);
            }
        }
Пример #13
0
        protected override async Task <UpgradeStepInitializeResult> InitializeImplAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            foreach (var step in SubSteps)
            {
                await step.InitializeAsync(context, token).ConfigureAwait(false);
            }

            var incompleteSubSteps = SubSteps.Count(s => !s.IsDone);

            return(incompleteSubSteps == 0
                ? new UpgradeStepInitializeResult(UpgradeStepStatus.Complete, "No VB updaters need applied", BuildBreakRisk.None)
                : new UpgradeStepInitializeResult(UpgradeStepStatus.Incomplete, $"{incompleteSubSteps} VB updaters need applied", SubSteps.Where(s => !s.IsDone).Max(s => s.Risk)));
        }
Пример #14
0
        /// <summary>
        ///     Translates the current step according to the translation dictionary
        ///     Removes all preconditions, actions and expectations
        /// </summary>
        /// <param name="applyTranslation">Indicates that the translation should be applied. Otherwise, this method only cleans the step.
        /// This is used to handle the fact that a blocking error has been found, and translating the sub sequence should be stopped,
        /// but the next steps should be cleaned</param>
        /// <returns>False if an error has been found while translating this step, or if translations should not be applied</returns>
        public bool Translate(bool applyTranslation)
        {
            bool retVal = applyTranslation;

            Counter counter = new Counter();

            counter.visit(this);
            if (counter.Issues[IssueKind.Blocking] != 0)
            {
                retVal = false;
            }

            if (getTranslationRequired())
            {
                Util.DontNotify(() =>
                {
                    setTranslated(false);
                    SubSteps.Clear();

                    if (retVal)
                    {
                        Translation translation = EFSSystem.FindTranslation(this);
                        if (translation != null)
                        {
                            translation.UpdateStep(this);
                            setTranslated(true);
                        }
                        else
                        {
                            AddWarning("Cannot find translation for this step");
                        }
                    }
                });
            }

            return(retVal);
        }
Пример #15
0
        /// <summary>
        ///     ITestStep.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            var mapType = ObjectCreator.GetType(MapTypeName, MapAssemblyPath);

            var destDir = Path.GetDirectoryName(Destination);

            if ((destDir.Length > 0) && !Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            var bmt = new BizTalkMapTester(mapType);

            bmt.Execute(Source, Destination);

            using (var fs = new FileStream(Destination, FileMode.Open, FileAccess.Read))
            {
                using (var data = StreamHelper.LoadMemoryStream(fs))
                {
                    data.Seek(0, SeekOrigin.Begin);
                    SubSteps.Aggregate(data, (current, subStep) => subStep.Execute(current, context));
                }
            }
        }
Пример #16
0
 public void AddSubStep(Step step)
 {
     SubSteps.Add(step);
 }
        public override bool TryParse()
        {
            if (!base.TryParse())
            {
                return(false);
            }

            // update the duration for the last step
            TestReport ownerTest = (TestReport)OwnerTest;
            StepReport lastStep  = ownerTest.LastStep;

            if (lastStep != null)
            {
                TimeSpan ts = StartTime - lastStep.StartTime;
                lastStep.DurationSeconds = (decimal)ts.TotalSeconds;
            }
            ownerTest.LastStep = this;

            // test object path, operation and operation data
            TestObjectExtType testObj = Node.Data.Extension.TestObject;

            if (testObj != null)
            {
                TestObjectOperation = testObj.Operation;

                TestObjectOperationData = testObj.OperationData;
                if (!string.IsNullOrWhiteSpace(TestObjectOperationData) && Node.Status != ReportStatus.Failed)
                {
                    Name += " " + testObj.OperationData;
                }

                TestObjectPathObjects = testObj.Path;
                if (TestObjectPathObjects != null && TestObjectPathObjects.Count() > 0)
                {
                    TestObjectPath = string.Empty;
                    foreach (TestObjectPathObjectExtType pathObj in TestObjectPathObjects)
                    {
                        // sample of pathObjStr: Window("Notepad")
                        string pathObjStr = string.Empty;
                        if (!string.IsNullOrWhiteSpace(pathObj.Type))
                        {
                            pathObjStr = pathObj.Type;
                        }
                        if (!string.IsNullOrWhiteSpace(pathObj.Name))
                        {
                            if (string.IsNullOrWhiteSpace(pathObjStr))
                            {
                                pathObjStr = pathObj.Name;
                            }
                            else
                            {
                                pathObjStr += string.Format(" (\"{0}\")", pathObj.Name);
                            }
                        }
                        // sample of TestObjectPath: Window("Notepad").WinMenu("Menu")
                        if (!string.IsNullOrWhiteSpace(pathObjStr))
                        {
                            if (!string.IsNullOrWhiteSpace(TestObjectPath))
                            {
                                TestObjectPath += ".";
                            }
                            TestObjectPath += pathObjStr;
                        }
                    }
                }
            }

            // smart identification
            SmartIdentification = Node.Data.Extension.SmartIdentificationInfo;

            // contexts and sub-steps
            SubSteps.Clear();
            ReportNodeType[] childNodes = Node.ReportNode;
            if (childNodes != null)
            {
                foreach (ReportNodeType node in childNodes)
                {
                    // sub-steps
                    StepReport subStep = SubSteps.TryParseAndAdd(node, this.Node);
                    if (subStep != null)
                    {
                        AllStepsEnumerator.Add(subStep);
                        AllStepsEnumerator.Merge(subStep.AllStepsEnumerator);
                        continue;
                    }

                    // contexts
                    ContextReport context = Contexts.TryParseAndAdd(node, this.Node);
                    if (context != null)
                    {
                        AllStepsEnumerator.Merge(context.AllStepsEnumerator);
                        continue;
                    }
                }
            }

            return(true);
        }
Пример #18
0
        /// <summary>
        ///     TestStepBase.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            var fi = new FileInfo(RuleStoreName);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("RuleStoreName", RuleStoreName);
            }

            var ruleStore = new FileRuleStore(fi.FullName);
            var rsInfo    = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new InvalidOperationException(string.Format("RuleStore {0} did not contain RuleSet {1}",
                                                                  RuleStoreName, RuleSetInfoCollectionName));
            }

            var ruleset = ruleStore.GetRuleSet(rsInfo[0]);


            // load the facts into array
            var facts = new List <object>(FactsList.Count);

            // Create an instance of the Policy Tester class
            using (var policyTester = new PolicyTester(ruleset))
            {
                foreach (var currentFact in FactsList)
                {
                    switch (currentFact.GetType().ToString())
                    {
                    case "ObjectFact":
                    {
                        var fact = currentFact as ObjectFact;

                        object[] objectArgs = null;
                        if (null != fact.Args)
                        {
                            objectArgs = fact.Args.Split(',').Cast <object>().ToArray();
                        }

                        Type type;
                        if (fact.AssemblyPath.Length > 0)
                        {
                            var asm = Assembly.Load(fact.AssemblyPath);
                            if (asm == null)
                            {
                                // fail
                                throw (new InvalidOperationException("failed to create type " + fact.Type));
                            }
                            type = asm.GetType(fact.Type, true, false);
                        }
                        else
                        {
                            // must be in path
                            type = Type.GetType(fact.Type);
                        }

                        facts.Add(Activator.CreateInstance(type, objectArgs));
                        break;
                    }

                    case "DocumentFact":
                    {
                        var fact = currentFact as DocumentFact;
                        var xd1  = new XmlDocument();
                        xd1.Load(fact.InstanceDocument);
                        var txd = new TypedXmlDocument(fact.SchemaType, xd1);
                        facts.Add(txd);
                        break;
                    }

                    case "DataConnectionFact":
                    {
                        var fact = currentFact as DataConnectionFact;
                        var conn = new SqlConnection(fact.ConnectionString);
                        conn.Open();
                        var dc = new DataConnection(fact.Dataset, fact.TableName, conn);
                        facts.Add(dc);
                        break;
                    }

                    case "dataTable":
                    case "dataRow":
                    {
                        var fact = currentFact as DataTableFact;

                        var conn = new SqlConnection(fact.ConnectionString);
                        conn.Open();
                        var myCommand = new SqlCommand(fact.Command, conn)
                        {
                            CommandType = CommandType.Text
                        };
                        var dAdapt = new SqlDataAdapter();
                        dAdapt.TableMappings.Add("Table", fact.TableName);
                        dAdapt.SelectCommand = myCommand;
                        var ds = new DataSet(fact.Dataset);
                        dAdapt.Fill(ds);
                        var tdt = new TypedDataTable(ds.Tables[fact.TableName]);
                        if (fact.Type == "dataRow")
                        {
                            var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt);
                            facts.Add(tdr);
                        }
                        else
                        {
                            facts.Add(tdt);
                        }
                        break;
                    }
                    }
                }

                // Create an instance of the DebugTrackingInterceptor
                using (var dti = new DebugTrackingInterceptor(DebugTracking))
                {
                    // Execute Policy Tester
                    try
                    {
                        policyTester.Execute(facts.ToArray(), dti);
                    }
                    catch (Exception e)
                    {
                        context.LogException(e);
                        throw;
                    }
                }
            }

            // write out all document instances passed in
            foreach (var fact in facts)
            {
                switch (fact.GetType().Name)
                {
                case "TypedXmlDocument":
                {
                    var txd = (TypedXmlDocument)fact;

                    context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml);
                    using (var data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml))
                    {
                        if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS")
                        {
                            SubSteps.Aggregate(data, (current, subStep) => subStep.Execute(current, context));
                        }
                    }

                    break;
                }

                case "DataConnection":
                {
                    var dc = (DataConnection)fact;
                    dc.Update();     // persist any changes
                    break;
                }

                case "TypedDataTable":
                {
                    var tdt = (TypedDataTable)fact;
                    tdt.DataTable.AcceptChanges();
                    break;
                }

                case "TypedDataRow":
                {
                    var tdr = (TypedDataRow)fact;
                    tdr.DataRow.AcceptChanges();
                    break;
                }
                }
            }
        }
Пример #19
0
 public void RemoveSubStep(Step step)
 {
     SubSteps.Remove(step);
 }