Beispiel #1
0
        /// <summary>
        /// Wrapper Method To Return the Output message in case of schema Validation Error
        /// </summary>
        /// <param name="pContext"></param>
        /// <param name="pInMsg"></param>
        /// <param name="processStatus"></param>
        /// <returns></returns>
        private static IBaseMessage CreateOutputMessageWrapper(IPipelineContext pContext, IBaseMessage pInMsg, object processStatus, string fileName)
        {
            VirtualStream errorStream = PipelineHelper.SerializeMessageToXml <object>(processStatus, Constants.AIBPValidationErrorNameSpace);

            IBaseMessage pOutMsg = PipelineHelper.CreateOutPutMessage(pContext, pInMsg, errorStream, fileName);

            return(pOutMsg);
        }
Beispiel #2
0
        /// <summary>
        /// Execute the Custom Logic To Do the Schema Validation
        /// </summary>
        /// <param name="pContext">Pipeline context</param>
        /// <param name="pInMsg">Input message to the pipeline</param>
        /// <returns>Output message</returns>
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            _logger.Debug("PipelineComponent::XmlValidator: Executing validation pipeline component.");

            int maxErrorCount = 20;

            //Parse the maxErrorCount property value to int
            Int32.TryParse(_maxErrorCount, out maxErrorCount);

            string messageType = Convert.ToString(pInMsg.Context.Read(Constants.MessageTypePropName, Constants.SystemPropertiesNamespace));
            string messageId   = Convert.ToString(pInMsg.MessageID);
            string fileName    = Convert.ToString(pInMsg.Context.Read(Constants.ReceivedFileNamePropName, Constants.FileAdapterPropertiesNameSpace));

            fileName = PipelineHelper.GetFileNameWithoutExtension(fileName);

            XmlValidatorHelper helper = new XmlValidatorHelper(); // (maxErrorCount, fileName);

            helper.Logger = _logger;

            if (pContext == null)
            {
                throw new ArgumentNullException("Pipeline Context is null");
            }

            if (pInMsg == null)
            {
                throw new ArgumentNullException("Incoming Message in null");
            }

            //Create OutMessage

            //Invoke the XMLValidator Validate Method

            var    originalStream = pInMsg.BodyPart.GetOriginalDataStream();
            Stream seekableStream;

            if (!originalStream.CanSeek)
            {
                seekableStream       = new ReadOnlySeekableStream(originalStream);
                pInMsg.BodyPart.Data = seekableStream;
            }
            else
            {
                seekableStream = originalStream;
            }

            IDocumentSpec docSpec = null;

            try
            {
                docSpec = pContext.GetDocumentSpecByType(messageType);


                //Use a temperory Disposable Virtual Stream
                using (VirtualStream virtusalStream = new VirtualStream())
                {
                    seekableStream.CopyTo(virtusalStream);
                    virtusalStream.Position = 0;
                    helper.ValidationWrapper(docSpec, maxErrorCount, virtusalStream, messageType, messageId);
                }


                //var errorProcessStatus = null; // helper.ProcessStatus;
                ////Check if validation Helper has caught any errors
                //if (errorProcessStatus.Errors != null && errorProcessStatus.Errors.Count() > 0)
                //{

                //    return CreateOutputMessageWrapper(pContext, pInMsg, errorProcessStatus, fileName);

                //}
                //else
                //{
                //    //Need to move the wrapped seekable stream to beginning and assign to the BodyPart as incoming message is not seekable
                //    seekableStream.Seek(0, SeekOrigin.Begin);
                //    // Track the stream so that it can be disposed when the message is finially finished with
                //    pContext.ResourceTracker.AddResource(pInMsg.BodyPart.Data);
                return(pInMsg);
                //}
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("RequestId: {0} ErrorMessage: {1}", fileName, ex.Message);
                _logger.Error(errorMessage);
                return(pInMsg);
            }
        }