コード例 #1
0
        public XDocument ConvertCheckRunLaunchToCheckRunArtifact(XDocument crl)
        {
            DataValidation.Instance.ValidateCheckRunLaunch(crl);
            XDocument craXDocumentResult = new XDocument();

            // Transform CRL to CRA
            using (XmlWriter xmlWriter = craXDocumentResult.CreateWriter())
            {
                CheckRunTransforms   checkRunTransforms = new CheckRunTransforms();
                XslCompiledTransform xslTransform       = checkRunTransforms.CrlToCraTransform;
                xslTransform.Transform(crl.CreateReader(), xmlWriter);
            }

            // Remove all the extra whitespace text nodes. This works around what seems to be a bug in the XSL implementation
            var          nodeIterator      = from node in craXDocumentResult.Root.DescendantNodes() where (node.NodeType == XmlNodeType.Text) select node;
            List <XNode> textNodesToRemove = new List <XNode>();

            foreach (XNode textNode in nodeIterator)
            {
                textNodesToRemove.Add(textNode);
            }

            foreach (XNode textNode in textNodesToRemove)
            {
                textNode.Remove();
            }

            return(craXDocumentResult);
        }
コード例 #2
0
        /// <summary>
        /// Accepts and validates CheckRunLaunch XDocument
        /// </summary>
        /// <param name="checkRunLaunchXDocument"></param>
        /// <returns></returns>
        public void InitializeCheckRunFromCheckRunLaunch(XDocument checkRunLaunchXDocument, CheckConstants.RunSubCheckDelegate runSubCheckDelegate = null)
        {
            DataValidation.Instance.ValidateCheckRunLaunch(checkRunLaunchXDocument);
            CheckRunTransforms checkRunTransforms = new CheckRunTransforms();
            XDocument          checkRunArtifact   = checkRunTransforms.ConvertCheckRunLaunchToCheckRunArtifact(checkRunLaunchXDocument);

            this.m_CheckRunArtifact = new CheckRunArtifact(checkRunArtifact, runSubCheckDelegate);
        }
コード例 #3
0
        /// <summary>
        /// invokes the sub check
        /// </summary>
        /// <param name="oneBasedIndex">1-based index into the check run object</param>
        /// <param name="currentStep">current step</param>
        public void CallSubCheck(int oneBasedIndex, XElement currentStep)
        {
            int subCheckCount = this.SubCheckCount;

            if (oneBasedIndex > SubCheckCount)
            {
                throw new CheckInfrastructureClientException(string.Format("CallSubCheck invoked with 1-based index='{0}', but the total number of subChecks is '{1}'. This might be due to a mismatch between the XML driving the check and the check method call of a sub-check.", oneBasedIndex, subCheckCount));
            }

            CheckRunTransforms checkRunTransforms   = new CheckRunTransforms();
            XDocument          subCheckCrl          = checkRunTransforms.CreateSubCheckRunLaunch(this.m_BaseElementForSection.Document, this.GetSubCheck(oneBasedIndex), currentStep);
            XDocument          artifactFromSubCheck = null;

            if (this.m_RunSubCheckDelegate != null)
            {
                artifactFromSubCheck = this.m_RunSubCheckDelegate(subCheckCrl);
            }
            else
            {
                throw new CheckInfrastructureClientException("The subcheck delegate is not set, so cannot be invoked for subcheck.");
            }

            XElement rootOfSubsteps = artifactFromSubCheck.Root.Element(DataStringConstants.ElementNames.CompleteCheckStepInfo);

            // remove child steps from current step as needed
            XElement rootStepFromSubCheck = rootOfSubsteps.Elements(DataStringConstants.ElementNames.CheckStepInformation).First <XElement>();

            if (rootStepFromSubCheck != null)
            {
                string   subCheckRootStepName = rootStepFromSubCheck.Attribute(DataStringConstants.AttributeNames.Name).Value;
                XElement tempCurrentStep      = ChildSteps.CleanStepsOnSearchForCorrectChildStep(currentStep, subCheckRootStepName);

                if (tempCurrentStep == null)
                {
                    ChildSteps.AddChildStep(currentStep, rootStepFromSubCheck);
                }
                else
                {
                    ChildSteps.ReplaceChildStep(tempCurrentStep, rootStepFromSubCheck);
                }
            }

            // Copy over the subcheck exception informaiton, and throw if needed
            XElement checkFailDataFromSubCheck = artifactFromSubCheck.Root.Element(DataStringConstants.ElementNames.CheckFailData);

            if (checkFailDataFromSubCheck.HasElements)
            {
                XElement failDataRoot = currentStep.Document.Root.Element(DataStringConstants.ElementNames.CheckFailData);
                XElement subCheckRoot = new XElement(DataStringConstants.ElementNames.DataElement,
                                                     new XAttribute(DataStringConstants.AttributeNames.Name, CheckConstants.AttributeValues.SubCheckExceptions));

                failDataRoot.Add(subCheckRoot);

                // the subcheck failed, so insert the element before CompleteCheckStepInfo = CheckConstants.Strings.CheckStepRootInfo.
                // At this time, this is the only failure info in the current process context
                foreach (XElement el in checkFailDataFromSubCheck.Elements())
                {
                    subCheckRoot.Add(el);
                }

                throw new CheckFailException("The subcheck failed, so rethrowing here to fail the check.");
            }
        }