/// <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) { try { 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.CreateReceivePipeline(pipelineType); if (!string.IsNullOrEmpty(_instanceConfigFile)) { pipelineWrapper.ApplyInstanceConfig(_instanceConfigFile); } if (instanceConfigLoader != null) { XmlReader reader = XmlReader.Create(instanceConfigLoader.Load(context)); pipelineWrapper.ApplyInstanceConfig(reader); } if (null != _docSpecs) { foreach (Type docSpec in _docSpecs) { pipelineWrapper.AddDocSpec(docSpec); } } MessageCollection mc = null; using (Stream stream = new FileStream(_source, 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 (!string.IsNullOrEmpty(_inputContextFile)) { var mi = MessageInfo.Deserialize(_inputContextFile); mi.MergeIntoMessage(inputMessage); } if (inputContextLoader != null) { XmlSerializer messageInfoSerializer = new XmlSerializer(typeof(MessageInfo)); XmlReader reader = XmlReader.Create(inputContextLoader.Load(context)); MessageInfo mi = messageInfoSerializer.Deserialize(reader) as MessageInfo; mi.MergeIntoMessage(inputMessage); } mc = pipelineWrapper.Execute(inputMessage); } for (var count = 0; count < mc.Count; count++) { string destination = null; if (!string.IsNullOrEmpty(_destinationFileFormat)) { destination = string.Format(_destinationFileFormat, count); if (!string.IsNullOrEmpty(_destinationDir)) { destination = Path.Combine(_destinationDir, destination); } PersistMessageHelper.PersistMessage(mc[count], destination); } if (!string.IsNullOrEmpty(_outputContextFileFormat)) { var contextDestination = string.Format(_outputContextFileFormat, count); if (!string.IsNullOrEmpty(_destinationDir)) { contextDestination = Path.Combine(_destinationDir, contextDestination); } var mi = BizTalkMessageInfoFactory.CreateMessageInfo(mc[count], destination); MessageInfo.Serialize(mi, contextDestination); } } } catch (Exception) { throw; } }
/// <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 (instanceConfigLoader != null) { XmlReader reader = XmlReader.Create(instanceConfigLoader.Load(context)); pipelineWrapper.ApplyInstanceConfig(reader); } if (null != _docSpecs) { foreach (Type docSpec in _docSpecs) { pipelineWrapper.AddDocSpec(docSpec); } } var mc = new MessageCollection(); if (inputFileLoader != null) { Stream inputStream = inputFileLoader.Load(context); var inputMessage = MessageHelper.CreateFromStream(inputStream); if (!string.IsNullOrEmpty(_sourceEncoding)) { inputMessage.BodyPart.Charset = _sourceEncoding; } // Load context file, add to message context. if (inputContextFileLoader != null) { Stream inputContextStream = inputContextFileLoader.Load(context); var mi = MessageInfo.Deserialize(inputContextStream); mi.MergeIntoMessage(inputMessage); mc.Add(inputMessage); } } else { 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)) { if (outputMsg != null) { var omi = BizTalkMessageInfoFactory.CreateMessageInfo(outputMsg, _destination); MessageInfo.Serialize(omi, _outputContextFile); } else { using (var fs = new FileStream(_outputContextFile, FileMode.Create)) { var enc = System.Text.Encoding.GetEncoding("UTF-8"); using (var writer = new StreamWriter(fs, enc)) { Stream msgStream = new System.IO.MemoryStream(); using (var reader = new StreamReader(msgStream, enc)) { const int size = 1024; var buf = new char[size]; var charsRead = reader.Read(buf, 0, size); while (charsRead > 0) { writer.Write(buf, 0, charsRead); charsRead = reader.Read(buf, 0, size); } } } } } } }