Exemplo n.º 1
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)
        {
            if (_docSpecsRawList.Count > 0)
            {
                var ds = new List <Type>(_docSpecsRawList.Count);
                foreach (var docSpec in _docSpecsRawList)
                {
                    var ass = AssemblyHelper.LoadAssembly((string)docSpec.AssemblyPath);
                    context.LogInfo("Loading DocumentSpec {0} from location {1}.", docSpec.TypeName, ass.Location);
                    var type = ass.GetType(docSpec.TypeName);

                    ds.Add(type);
                }
                _docSpecs = ds.ToArray();
            }

            context.LogInfo("Loading pipeline {0} from location {1}.", _pipelineTypeName, _pipelineAssemblyPath);
            var pipelineType = ObjectCreator.GetType(_pipelineTypeName, _pipelineAssemblyPath);

            var pipelineWrapper = PipelineFactory.CreateSendPipeline(pipelineType);

            if (!string.IsNullOrEmpty(_instanceConfigFile))
            {
                pipelineWrapper.ApplyInstanceConfig(_instanceConfigFile);
            }

            if (null != _docSpecs)
            {
                foreach (Type docSpec in _docSpecs)
                {
                    pipelineWrapper.AddDocSpec(docSpec);
                }
            }

            var mc = new MessageCollection();

            FileInfo[] contexts = null;
            if (!string.IsNullOrEmpty(_inputContextDir) && !string.IsNullOrEmpty(_inputContextSearchPattern))
            {
                var cdi = new DirectoryInfo(_inputContextDir);
                contexts = cdi.GetFiles(_inputContextSearchPattern);
            }

            var di    = new DirectoryInfo(_sourceDir);
            int index = 0;

            foreach (FileInfo fi in di.GetFiles(_searchPattern))
            {
                Stream stream       = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
                var    inputMessage = MessageHelper.CreateFromStream(stream);
                if (!string.IsNullOrEmpty(_sourceEncoding))
                {
                    inputMessage.BodyPart.Charset = _sourceEncoding;
                }

                // Load context file, add to message context.
                if ((null != contexts) && (contexts.Length > index))
                {
                    string cf = contexts[index].FullName;
                    if (System.IO.File.Exists(cf))
                    {
                        MessageInfo mi = MessageInfo.Deserialize(cf);
                        mi.MergeIntoMessage(inputMessage);
                    }
                }

                mc.Add(inputMessage);
                index++;
            }

            var outputMsg = pipelineWrapper.Execute(mc);

            PersistMessageHelper.PersistMessage(outputMsg, _destination);

            if (!string.IsNullOrEmpty(_outputContextFile))
            {
                var omi = BizTalkMessageInfoFactory.CreateMessageInfo(outputMsg, _destination);
                MessageInfo.Serialize(omi, _outputContextFile);
            }
        }