Esempio n. 1
0
        void IAssemblerComponent.AddDocument(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            if (this.GetFault(pInMsg) != null)
            {
                qOutputMsgs.Enqueue(pInMsg);
            }
            else
            {
                MultipartMessageDefinition tempMessage = MultipartMessageManager.GenerateFromMessage(pInMsg);

                StringWriter  sw  = new StringWriter();
                XmlSerializer ser = new XmlSerializer(typeof(MultipartMessageDefinition), Constants.SUBMISSION_NAMESPACE);
                ser.Serialize(sw, tempMessage);
                byte[]       arrByte    = System.Text.Encoding.UTF8.GetBytes(sw.ToString().Replace("utf-16", "utf-8")); //GetBytes(sw.ToString().Replace("utf-16", "utf-8")); //GetBytes(sw.ToString());
                MemoryStream tempStream = new MemoryStream(arrByte);
                tempStream.Seek(0, SeekOrigin.Begin);

                IBaseMessage     outMsg  = pContext.GetMessageFactory().CreateMessage();
                IBaseMessagePart outPart = pContext.GetMessageFactory().CreateMessagePart();
                outPart.Data    = tempStream;
                outPart.Charset = "utf-8";
                outMsg.AddPart("ConstructedPart", outPart, true);
                //outMsg.BodyPart.Data = tempStream;

                outMsg.Context = pInMsg.Context;
                outMsg.Context.Promote(BTSProperties.messageType.Name.Name, BTSProperties.messageType.Name.Namespace, "http://BizWTF.Mocking.Schemas.Submission#MultipartMessage");


                qOutputMsgs.Enqueue(outMsg);
                pContext.ResourceTracker.AddResource(tempStream);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if this resolution setting applies to the given message.
        /// </summary>
        /// <param name="request">Message to probe</param>
        /// <returns>True if there is a match</returns>
        public bool Probe(MultipartMessageDefinition request)
        {
            foreach (ControlProperty prop in this.ContextProps)
            {
                if (!request.PropertyBag.ToList <ContextProperty>().Exists(cp => cp.Namespace == prop.Namespace && cp.Name == prop.Property && cp.Value == prop.Value))
                {
                    return(false);
                }
            }

            foreach (PartSetting ps in this.PartSettings)
            {
                string partName;

                if (request.Parts == null)
                {
                    return(false);
                }

                if (String.IsNullOrEmpty(ps.PartName))
                {
                    partName = request.Parts[0].PartName;
                }
                else
                {
                    partName = ps.PartName;
                }

                if (request.Parts.ToList().Exists(p => p.PartName == partName))
                {
                    Part messagePart = request.Parts.ToList().SingleOrDefault <Part>(p => p.PartName == partName);
                    if (messagePart.Data != null)
                    {
                        foreach (ControlField field in ps.XPathProps)
                        {
                            XPathDocument  doc = new XPathDocument(new StringReader(messagePart.Data.OuterXml));
                            XPathNavigator nav = doc.CreateNavigator();
                            nav.Select(field.XPath);

                            XmlDocument partXml = new XmlDocument();
                            partXml.LoadXml(messagePart.Data.OuterXml);
                            XmlNodeList nodeList = partXml.SelectNodes(field.XPath);
                            foreach (XmlNode node in nodeList)
                            {
                                if (node.InnerText != field.Value && node.Value != field.Value)
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
 internal static void RaiseMessageResolved(string serviceURI, MultipartMessageDefinition inputMessage)
 {
     if (OnMessageResolved != null)
     {
         OnMessageResolved(serviceURI, inputMessage);
     }
 }
Esempio n. 4
0
        public void SubmitMessage(MultipartMessageDefinition MultipartMessage)
        {
            Debug.WriteLine(String.Format("Mock Service : {0}", OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri));
            Debug.WriteLine(String.Format("Received message : {0}", String.IsNullOrEmpty(MultipartMessage.Description)?"<No description provided>":MultipartMessage.Description));
            Debug.WriteLine(String.Format("Nb Parts : {0}", MultipartMessage.Parts.Length));

            this.LocalReceivedMessages.Add(MultipartMessage);
            MockServiceEventHub.RaiseMessageReceived(OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri, MultipartMessage);
        }
Esempio n. 5
0
        public void TOOLS_DeserializeMultipartMessage()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(@"C:\Projets\BizWTF\BizWTF.Testing.Sample\Messages\OK_SystemARequest.xml"); //doc.Load(@"C:\Temp\GeneratedMultipartMessage.xml");

            MultipartMessageDefinition msg = BizWTF.Core.Entities.Mocking.MultipartMessageSerializer.Deserialize(doc.DocumentElement);

            Assert.IsNotNull(msg.Parts);
        }
        //public override object GetData()
        //{
        //    // Not implemented
        //    return null;
        //}

        public override bool ExecuteStep()
        {
            this.AppendResultDescription(0, "Executing step [{0}] ({1}):", this.StepName, this.StepType);
            this.AppendResultDescription(1, "Context Properties :");
            foreach (ControlProperty prop in this.ContextProps)
            {
                this.AppendResultDescription(2, "{0}/{1} : {2}", prop.Namespace, prop.Property, prop.Value);
                if (!String.IsNullOrEmpty(prop.TargetContextProperty))
                {
                    this.AppendResultDescription(3, "(overrided by context prop '{0}')", prop.TargetContextProperty);
                }
            }
            this.AppendResultDescription(1, "XPath Values :");
            foreach (ControlField field in this.XPathProps)
            {
                this.AppendResultDescription(2, "{0} : {1}", field.XPath, field.Value);
            }


            using (BizTalkDTADbEntities btsDTA = new BizTalkDTADbEntities(System.Configuration.ConfigurationManager.ConnectionStrings["BizTalkDTADbEntities"].ConnectionString))
            {
                TrackingDatabase dta = new TrackingDatabase(BTSTestContext.BizTalkDbServer,
                                                            BTSTestContext.BizTalkDTADb);
                BizTalkOperations       operations = new BizTalkOperations(BTSTestContext.BizTalkDbServer, BTSTestContext.BizTalkMgmtDb);
                List <MatchingPartInfo> partList   = MatchingPartInfo.GetMatchingPartInfo(btsDTA, dta, operations, this.ContextProps, this.XPathProps, this.ProcessName, null);

                if (partList.Count > 0)
                {
                    List <MultipartMessageDefinition> msgs = new List <MultipartMessageDefinition>();
                    foreach (MatchingPartInfo part in partList)
                    {
                        this.AppendResultDescription(1, "[OK] Matching service instance found, messageID={0}", part.MessageInstanceId);
                        IBaseMessage trackedMsg = operations.GetTrackedMessage(part.MessageInstanceId, dta);

                        MultipartMessageDefinition tempMsg = MultipartMessageManager.GenerateFromMessage(trackedMsg);
                        tempMsg.Description = String.Format("Service : {0} - Message instance: {1}", part.ServiceName, part.MessageInstanceId);
                        msgs.Add(tempMsg);
                    }

                    BTSTestContext.AddParam(this.TargetContextProperty, msgs);
                    this.Result = StepResult.OK;
                }
                else
                {
                    this.AppendResultDescription(1, "[KO] No matching service instance found", EventLogEntryType.Error);
                    this.Result = StepResult.Error;
                }
            }

            return(this.Result == StepResult.OK);
        }
        public static XmlDocument Serialize(MultipartMessageDefinition source)
        {
            StringWriter sw = new StringWriter();

            XmlSerializer ser = new XmlSerializer(typeof(MultipartMessageDefinition));

            ser.Serialize(sw, source);

            XmlDocument target = new XmlDocument();

            target.PreserveWhitespace = true;
            target.LoadXml(sw.ToString());
            return(target);
        }
Esempio n. 8
0
        private MultipartMessageDefinition GetMessage(IBaseMessage inMsg)
        {
            XmlDocument doc = new XmlDocument();
            MultipartMessageDefinition netmsg = null;

            try
            {
                inMsg.BodyPart.Data.Position = 0;
                doc.Load(inMsg.BodyPart.Data);
                netmsg = DeserializeXMLMessage(doc);
            }
            catch
            {
                throw new ArgumentNullException("inMsg");
            }
            return(netmsg);
        }
Esempio n. 9
0
        public void SubmitMessage(ref MultipartMessageDefinition MultipartMessage)
        {
            Debug.WriteLine(String.Format("Mock Service : {0}", OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri));
            Debug.WriteLine(String.Format("Received message : {0}", String.IsNullOrEmpty(MultipartMessage.Description)?"<No description provided>":MultipartMessage.Description));
            Debug.WriteLine(String.Format("Nb Parts : {0}", MultipartMessage.Parts.Length));

            this.LocalReceivedMessages.Add(MultipartMessage);
            MockServiceEventHub.RaiseMessageReceived(OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri, MultipartMessage);

            foreach (Settings.MessageResolutionSetting setting in this.LocalResolutionSettings)
            {
                if (setting.Probe(MultipartMessage))
                {
                    MockServiceEventHub.RaiseMessageResolved(OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri, setting.TargetMessage);
                    MultipartMessage = setting.TargetMessage;
                    return;
                }
            }

            throw new FaultException("Unable to resolve message");
        }
Esempio n. 10
0
        public void TOOLS_SerializeMultipartMessage()
        {
            MultipartMessageDefinition msg = new MultipartMessageDefinition();

            msg.Description = "Test description";

            msg.PropertyBag = new List <ContextProperty> {
                new ContextProperty {
                    Name = "Prop1", Namespace = "http://blabla", Promoted = true, Value = "TestPropValue1"
                },
                new ContextProperty {
                    Name = "Prop2", Namespace = "http://blabla", Promoted = true, Value = "TestPropValue2"
                },
                new ContextProperty {
                    Name = "Prop3", Namespace = "http://blabla", Promoted = true, Value = "TestPropValue3"
                }
            }.ToArray();

            XmlDocument part = new XmlDocument();

            part.LoadXml("<ns0:Request xmlns:ns0=\"http://BizWTF.Sample.Processes.Schemas.SysASchemas\"><Field1>1</Field1><Field2>Top</Field2></ns0:Request>");

            msg.Parts = new List <Part> {
                new Part {
                    IsBodyPart = true, PartName = "body", PartNumber = 1, RawData = "Some raw data"
                }                                                                                                  //RawData="Some raw data" //Data=part.DocumentElement
                , new Part {
                    IsBodyPart = true, PartName = "body", PartNumber = 1, Data = part.DocumentElement
                }
            }.ToArray();

            XmlDocument doc = BizWTF.Core.Entities.Mocking.MultipartMessageSerializer.Serialize(msg);

            doc.Save(@"C:\Temp\GeneratedMultipartMessage.xml");

            msg = BizWTF.Core.Entities.Mocking.MultipartMessageSerializer.Deserialize(doc.DocumentElement);

            Assert.IsNotNull(msg.Parts);
        }
Esempio n. 11
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            //string targetDirectory = new FileInfo(this._project.FullName).DirectoryName;

            BizTalkOperations operations = new BizTalkOperations(this.txtDTAServerName.Text, this.txtMgmtDBName.Text);
            TrackingDatabase  dta        = new TrackingDatabase(this.txtDTAServerName.Text,
                                                                this.txtDTADBName.Text);

            if (this.dgMessages.SelectedRows.Count > 0)
            {
                foreach (DataGridViewRow row in this.dgMessages.SelectedRows)
                {
                    IBaseMessage btsMessage            = operations.GetTrackedMessage((Guid)row.Cells["InstanceID"].Value, dta);
                    MultipartMessageDefinition tempMsg = MultipartMessageManager.GenerateFromMessage(btsMessage);

                    string destPath = System.IO.Path.Combine(this._targetFolder,
                                                             String.Format("{0}-{1}-{2}.xml",
                                                                           row.Cells["EventType"].Value,
                                                                           row.Cells["PortName"].Value,
                                                                           row.Cells["InstanceID"].Value));
                    MultipartMessageSerializer.Serialize(tempMsg).Save(destPath);

                    if (this._project != null)
                    {
                        EnvDTE.ProjectItem item = this._project.ProjectItems.AddFromFile(destPath);

                        EnvDTE.Property prop = item.Properties.Item("BuildAction");
                        prop.Value = 2;
                    }
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Please select one or more messages to generate.", "No message selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 12
0
        public override bool ExecuteStep()
        {
            MultipartMessageDefinition tempMsg = null;
            XmlTextReader xmlBodyReader        = null;

            this.AppendResultDescription(0, "Executing step {0} ({1}):", this.StepName, this.StepType);

            if (!File.Exists(this.SourceFile) && String.IsNullOrEmpty(this.SourceResource))
            {
                this.AppendResultDescription(1, "File {0} does not exist.", this.SourceFile);
                this.Result = StepResult.Error;
            }
            else if (File.Exists(this.SourceFile))
            {
                //xmlBodyReader = new XmlTextReader(this.SourceFile);
                tempMsg = MultipartMessageSerializer.RetrieveDocument(this.SourceFile);
            }
            else
            {
                Assembly asmb = Assembly.Load(this.SourceResourceAssembly);
                //xmlBodyReader = new XmlTextReader(asmb.GetManifestResourceStream(this.SourceResource));
                tempMsg = MultipartMessageSerializer.RetrieveDocument(this.SourceResource, asmb);
            }

            if (this.Result != StepResult.Error)
            {
                if (!string.IsNullOrEmpty(this.TestID))
                {
                    List <ContextProperty> props = tempMsg.PropertyBag.ToList <ContextProperty>();
                    props.Add(new ContextProperty
                    {
                        Name      = BTSProperties.testID.Name.Name,
                        Namespace = BTSProperties.testID.Name.Namespace,
                        Promoted  = false,
                        Value     = this.TestID
                    });
                    tempMsg.PropertyBag = props.ToArray();
                }
                XmlDocument doc = MultipartMessageSerializer.Serialize(tempMsg);
                xmlBodyReader = new XmlTextReader(new StringReader(doc.OuterXml));

                BizTalk2WayReference.TwoWayAsyncClient client = new BizTalk2WayReference.TwoWayAsyncClient();
                try
                {
                    client.Endpoint.Address = new System.ServiceModel.EndpointAddress(this.DestURI);
                    client.Open();

                    Message request = Message.CreateMessage(MessageVersion.Soap11, "Get2WayMultipartMessage", xmlBodyReader);

                    Message response = client.BizTalkSubmit(request);
                    this.AppendResultDescription(1, "[OK] Send file {0}, received response from {1}", this.SourceFile, DestURI);



                    HttpResponseMessageProperty httpResponse = (HttpResponseMessageProperty)response.Properties["httpResponse"];
                    if (httpResponse.StatusCode != System.Net.HttpStatusCode.InternalServerError)
                    {
                        MemoryStream ms = new MemoryStream();
                        XmlWriter    xw = XmlWriter.Create(ms, new XmlWriterSettings {
                            Indent = true, IndentChars = "  ", OmitXmlDeclaration = true
                        });
                        XmlDictionaryReader bodyReader = response.GetReaderAtBodyContents();

                        while (bodyReader.NodeType != XmlNodeType.EndElement && bodyReader.LocalName != "Body" && bodyReader.NamespaceURI != "http://schemas.xmlsoap.org/soap/envelope/")
                        {
                            if (bodyReader.NodeType != XmlNodeType.Whitespace)
                            {
                                xw.WriteNode(bodyReader, true);
                            }
                            else
                            {
                                bodyReader.Read(); // ignore whitespace; maintain if you want
                            }
                        }
                        xw.Flush();

                        XmlSerializer serializer = new XmlSerializer(typeof(MultipartMessageDefinition));
                        ms.Seek(0, SeekOrigin.Begin);
                        BTSTestContext.AddParam(this.TargetContextProperty, serializer.Deserialize(ms));
                    }
                    else
                    {
                        MessageFault fault       = MessageFault.CreateFault(response, 10000000);
                        string       faultString = fault.Reason.ToString();

                        //XmlDocument faultDoc = new XmlDocument();
                        //faultDoc.Load(bodyReader);

                        this.AppendResultDescription(1, "[KO] Error when sending file {0} to {1} : {2}", this.SourceFile, DestURI, faultString);
                        this.Result = StepResult.Error;
                    }
                }
                catch (Exception exc)
                {
                    this.AppendResultDescription(1, "[KO] Error when sending file {0} to {1} : {2}", this.SourceFile, DestURI, exc.Message);
                    this.Result = StepResult.Error;
                }
                finally
                {
                    if (client != null)
                    {
                        if (client.State == System.ServiceModel.CommunicationState.Opened)
                        {
                            client.Close();
                        }
                    }
                }
            }
            if (this.Result == StepResult.Working)
            {
                this.Result = StepResult.OK;
            }

            return(this.Result != StepResult.Error);
        }
Esempio n. 13
0
        public static MultipartMessageDefinition GenerateFromMessage(IBaseMessage pInMsg)
        {
            MultipartMessageDefinition tempMessage = new MultipartMessageDefinition();
            List <ContextProperty>     propList    = new List <ContextProperty>();

            List <Part> partList = new List <Part>();

            for (int i = 0; i < pInMsg.PartCount; i++)
            {
                string           partName = String.Empty;
                IBaseMessagePart msgPart  = pInMsg.GetPartByIndex(i, out partName);

                Part mockPart = new Part();
                mockPart.ContentType = msgPart.ContentType;
                mockPart.PartName    = partName;
                mockPart.PartNumber  = i;
                mockPart.IsBodyPart  = (pInMsg.BodyPart.PartID == msgPart.PartID);
                mockPart.Data        = null;

                try
                {
                    XmlDocument tempXML = new XmlDocument();
                    tempXML.Load(msgPart.Data);
                    mockPart.Data = tempXML.DocumentElement;

                    //ContextProperty performXMLdsm = new ContextProperty();
                    //performXMLdsm.Name = BTSProperties.emulateXMLDisassembler.Name.Name;
                    //performXMLdsm.Namespace = BTSProperties.emulateXMLDisassembler.Name.Namespace;
                    //performXMLdsm.Value = "true";
                    //propList.Add(performXMLdsm);
                }
                catch
                {
                    XmlTextReader rawStreamReader = new XmlTextReader(msgPart.Data);
                    mockPart.RawData = rawStreamReader.ReadContentAsString(); // String.Format("<![CDATA[{0}]]>", rawStreamReader.ReadContentAsString());
                }
                //msgPart.Data.Seek(0, System.IO.SeekOrigin.Begin);
                //msgPart.Data.Position = 0;

                partList.Add(mockPart);
            }
            tempMessage.Parts = partList.ToArray();

            for (uint iProp = 0; iProp < pInMsg.Context.CountProperties; iProp++)
            {
                string propName;
                string propNamespace;
                object value = pInMsg.Context.ReadAt((int)iProp, out propName, out propNamespace);

                ContextProperty prop = new ContextProperty();
                prop.Name      = propName;
                prop.Namespace = propNamespace;
                prop.Value     = value.ToString();
                prop.Promoted  = pInMsg.Context.IsPromoted(propName, propNamespace);

                propList.Add(prop);
            }
            tempMessage.PropertyBag = propList.ToArray();

            return(tempMessage);
        }
Esempio n. 14
0
        void IDisassemblerComponent.Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            if (pContext == null)
            {
                throw new ArgumentNullException("context");
            }
            if (pInMsg == null)
            {
                throw new ArgumentNullException("inMsg");
            }

            bool isFault = false;

            object objFault = pInMsg.Context.Read("IsFault", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties");

            if (objFault != null)
            {
                isFault = (bool)objFault;
            }

            if (!isFault)
            {
                try
                {
                    this._inputmessage = pInMsg;
                    MultipartMessageDefinition netmsg = GetMessage(this._inputmessage);
                    List <Part> partList = new List <Part>(netmsg.Parts);

                    #region Obsolete
                    /// Find body part
                    //Part bodyPart = partList.Find(p => p.IsBodyPart == true);
                    //if (bodyPart == null)
                    //{
                    //    partList[0].IsBodyPart = true;
                    //    bodyPart = partList[0];
                    //}
                    #endregion

                    //ContextProperty executePipeline = netmsg.PropertyBag.FirstOrDefault(prop =>
                    //                                                                        prop.Namespace == BTSProperties.executePipeline.Name.Namespace
                    //                                                                        && prop.Name == BTSProperties.executePipeline.Name.Name);

                    IBaseMessage sourceMessage = this.BuildBTSMessage(pContext, pInMsg.Context, partList);
                    if (sourceMessage.BodyPart == null)
                    {
                        throw new Exception("No part was extracted from the mock message!");
                    }

                    if (this.ExecutePipeline)
                    {
                        object tempInstance = Activator.CreateInstance(Type.GetType(this.PipelineToExecute));
                        Microsoft.BizTalk.PipelineOM.ReceivePipeline rcvPipeline = (Microsoft.BizTalk.PipelineOM.ReceivePipeline)tempInstance;

                        IBasePropertyBag      propBag  = pContext.GetMessageFactory().CreatePropertyBag();
                        ExecutableRcvPipeline pipeline = new ExecutableRcvPipeline(rcvPipeline);
                        pipeline.Run(pContext, sourceMessage);

                        foreach (IBaseMessage outputMsg in pipeline.OutputMsgs)
                        {
                            this.attachPropetyBag(outputMsg, netmsg.PropertyBag);
                            qOutputMsgs.Enqueue(outputMsg);
                        }
                    }
                    else
                    {
                        this.attachPropetyBag(sourceMessage, netmsg.PropertyBag);
                        qOutputMsgs.Enqueue(sourceMessage);
                    }


                    #region Obsolete
                    //if (bodyPart.Data != null)
                    //{
                    //    string bodyType = bodyPart.Data.NamespaceURI + "#" + bodyPart.Data.LocalName;
                    //    XmlDocument xDoc = new System.Xml.XmlDocument();
                    //    xDoc.LoadXml(bodyPart.Data.OuterXml);
                    //    System.IO.MemoryStream memStream = new MemoryStream();
                    //    xDoc.PreserveWhitespace = true;
                    //    xDoc.Save(memStream);
                    //    memStream.Position = 0;
                    //    memStream.Seek(0, System.IO.SeekOrigin.Begin);


                    //    /// If Body part is an enveloppe, we have to split it
                    //    IDocumentSpec docSpec = pContext.GetDocumentSpecByType(bodyType);
                    //    XPathDocument xp = new XPathDocument(memStream);

                    //    if (!String.IsNullOrEmpty(docSpec.GetBodyPath()))
                    //    {
                    //        XPathNodeIterator xNI = xp.CreateNavigator().Select(docSpec.GetBodyPath());

                    //        while (xNI.MoveNext())
                    //        {
                    //            string nodeName = "";
                    //            string nodeNamespace = "";

                    //            if (xNI.Current.MoveToFirstChild())
                    //            {
                    //                XmlDocument tempNode = new XmlDocument();
                    //                tempNode.LoadXml(xNI.Current.OuterXml);
                    //                nodeName = tempNode.DocumentElement.LocalName;
                    //                nodeNamespace = tempNode.DocumentElement.NamespaceURI;

                    //                this.CreateMsg(pContext, pInMsg.Context, tempNode.OuterXml, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true));
                    //            }

                    //            while (xNI.Current.MoveToNext(nodeName, nodeNamespace))
                    //            {
                    //                XmlDocument tempNode = new XmlDocument();
                    //                tempNode.LoadXml(xNI.Current.OuterXml);
                    //                this.CreateMsg(pContext, pInMsg.Context, tempNode.OuterXml, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true));
                    //            }
                    //        }
                    //    }
                    //    else
                    //    {
                    //        this.CreateMsg(pContext, pInMsg.Context, bodyPart.Data.OuterXml, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true));
                    //    }
                    //}
                    //else
                    //{
                    //    this.CreateMsg(pContext, pInMsg.Context, bodyPart.RawData, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true));
                    //}
                    #endregion
                }
                catch (Exception e)
                {
                    if (this.GetFault(pInMsg) != null)
                    {
                        qOutputMsgs.Enqueue(pInMsg);
                        string faultText = this.GetFault(pInMsg).SelectSingleNode("/*[local-name()='Fault']/*[local-name()='faultstring']").InnerText;
                        throw new Exception(faultText);
                    }
                    else
                    {
                        System.Diagnostics.EventLog.WriteEntry(Constants.EVENT_SOURCE, "IDisassemblerComponent.Disassemble : \n" + e.Message + "\n" + e.StackTrace, System.Diagnostics.EventLogEntryType.Error, 8000, 1);
                        throw e;
                    }
                }
            }
            else
            {
                qOutputMsgs.Enqueue(pInMsg);
            }
        }
Esempio n. 15
0
 private void messageReceived(string uri, MultipartMessageDefinition message)
 {
     Assert.IsTrue(message.Parts.Length > 0);
 }
Esempio n. 16
0
        //public override object GetData()
        //{
        //    // Not implemented
        //    return null;
        //}

        public override bool ExecuteStep()
        {
            this.AppendResultDescription(0, "Executing step [{0}] ({1}):", this.StepName, this.StepType);
            this.AppendResultDescription(1, "Context Properties :");
            foreach (ControlProperty prop in this.ContextProps)
            {
                this.AppendResultDescription(2, "{0}/{1} : {2}", prop.Namespace, prop.Property, prop.Value);
                if (!String.IsNullOrEmpty(prop.TargetContextProperty))
                {
                    this.AppendResultDescription(3, "(overrided by context prop '{0}')", prop.TargetContextProperty);
                }
            }
            this.AppendResultDescription(1, "XPath Values :");
            foreach (ControlField field in this.XPathProps)
            {
                this.AppendResultDescription(2, "{0} : {1}", field.XPath, field.Value);
            }

            TrackingDatabase dta = new TrackingDatabase(BTSTestContext.BizTalkDbServer,
                                                        BTSTestContext.BizTalkDTADb);
            BizTalkOperations operations   = new BizTalkOperations(BTSTestContext.BizTalkDbServer, BTSTestContext.BizTalkMgmtDb);
            IEnumerable       services     = operations.GetServiceInstances();
            IEnumerator       servicesEnum = services.GetEnumerator();

            while (servicesEnum.MoveNext())
            {
                if (servicesEnum.Current.GetType() == typeof(Microsoft.BizTalk.Operations.OrchestrationInstance))
                {
                    OrchestrationInstance tempInstance = (OrchestrationInstance)servicesEnum.Current;
                    this.AppendResultDescription(1, "Analysing instance of '{0}'", tempInstance.ServiceType);
                    this.AppendResultDescription(1, "Service status : {0}", tempInstance.InstanceStatus);

                    if (tempInstance.ServiceType.StartsWith(this.ProcessName))
                    {
                        this.AppendResultDescription(2, "[OK] Service Type match : {0}", this.ProcessName);
                        foreach (var rawMessage in tempInstance.Messages)
                        {
                            if (rawMessage.GetType() == typeof(BizTalkMessage))
                            {
                                bool           currentMatch = true;
                                BizTalkMessage btsMsg       = (BizTalkMessage)rawMessage;

                                string body = string.Empty;
                                using (StreamReader streamReader = new StreamReader(btsMsg.BodyPart.Data))
                                {
                                    body = streamReader.ReadToEnd();
                                }

                                foreach (ControlProperty prop in this.ContextProps)
                                {
                                    string expectedValue = prop.Value;
                                    string foundValue    = (string)btsMsg.Context.Read(
                                        prop.Property,
                                        prop.Namespace);

                                    if (expectedValue != foundValue)
                                    {
                                        this.AppendResultDescription(3, "[KO] Prop '{0}/{1}' : mismatch - Expected {2}, found {3}.",
                                                                     prop.Namespace,
                                                                     prop.Property,
                                                                     expectedValue,
                                                                     foundValue);
                                        currentMatch = false;
                                        break;
                                    }
                                    else
                                    {
                                        this.AppendResultDescription(3, "[OK] Prop '{0}/{1}' : match - Expected {2}, found {3}.",
                                                                     prop.Namespace,
                                                                     prop.Property,
                                                                     expectedValue,
                                                                     foundValue);
                                    }
                                }

                                if (this.XPathProps.Count > 0 && currentMatch)
                                {
                                    XmlDocument testedMsg = new XmlDocument();
                                    testedMsg.LoadXml(body);

                                    foreach (ControlField field in this.XPathProps)
                                    {
                                        string expectedValue = field.Value;
                                        string foundValue    = testedMsg.SelectSingleNode(field.XPath).InnerText;

                                        if (expectedValue != foundValue)
                                        {
                                            this.AppendResultDescription(3, "[KO] XPath '{0}' : mismatch - Expected {1}, found {2}.",
                                                                         field.XPath,
                                                                         expectedValue,
                                                                         foundValue);
                                            currentMatch = false;
                                            break;
                                        }
                                        else
                                        {
                                            this.AppendResultDescription(3, "[OK] XPath '{0}' : match - Expected {1}, found {2}.",
                                                                         field.XPath,
                                                                         expectedValue,
                                                                         foundValue);
                                        }
                                    }
                                }

                                if (currentMatch)
                                {
                                    // Implement copy here
                                    this.AppendResultDescription(2, "Matching message found : instance {0}, message {1}", tempInstance.ID, btsMsg.MessageID);


                                    foreach (IBaseMessage processMessage in tempInstance.Messages)
                                    {
                                        MultipartMessageDefinition tempMessage = MultipartMessageManager.GenerateFromMessage(processMessage);
                                        tempMessage.Description = "Message from instance:" + tempInstance.ID.ToString();
                                        this.FoundMessages.Add(tempMessage);
                                    }
                                    this.Result = StepResult.OK;
                                }
                            }
                        }
                    }
                }
            }

            if (this.FoundMessages.Count == 0)
            {
                this.AppendResultDescription(1, "No matching instance found!");
                this.Result = StepResult.Error;
            }

            return(this.Result == StepResult.OK);
        }
        public void ReadXml(System.Xml.XmlReader reader)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(reader);
            this.MPMessage = new MultipartMessageDefinition();

            //again this is a simple contrived example
            this.MPMessage.Description = doc.DocumentElement.SelectSingleNode("*[local-name()='Description']") == null ? String.Empty : doc.DocumentElement.SelectSingleNode("*[local-name()='Description']").InnerText;

            List <ContextProperty> propList = new List <ContextProperty>();

            foreach (XmlElement xmlProp in doc.DocumentElement.SelectNodes("*[local-name()='PropertyBag']/*[local-name()='ContextProperty']"))
            {
                ContextProperty tempProp = new ContextProperty();
                tempProp.Name      = xmlProp.SelectSingleNode("*[local-name()='Name']").InnerText;
                tempProp.Namespace = xmlProp.SelectSingleNode("*[local-name()='Namespace']").InnerText;
                tempProp.Value     = xmlProp.SelectSingleNode("*[local-name()='Value']").InnerText;
                tempProp.Promoted  = Boolean.Parse(xmlProp.SelectSingleNode("*[local-name()='Promoted']").InnerText);

                propList.Add(tempProp);
            }
            this.MPMessage.PropertyBag = propList.ToArray();

            List <Part> partList = new List <Part>();

            foreach (XmlElement xmlPart in doc.DocumentElement.SelectNodes("*[local-name()='Parts']/*[local-name()='Part']"))
            {
                Part tempPart = new Part();
                tempPart.PartName = xmlPart.SelectSingleNode("*[local-name()='PartName']").InnerText;
                if (xmlPart.SelectSingleNode("*[local-name()='PartNumber']") != null)
                {
                    tempPart.PartNumber = Int32.Parse(xmlPart.SelectSingleNode("*[local-name()='PartNumber']").InnerText);
                }
                if (xmlPart.SelectSingleNode("*[local-name()='IsBodyPart']") != null)
                {
                    tempPart.IsBodyPart = Boolean.Parse(xmlPart.SelectSingleNode("*[local-name()='IsBodyPart']").InnerText);
                }
                if (xmlPart.SelectSingleNode("*[local-name()='ContentType']") != null)
                {
                    tempPart.ContentType = xmlPart.SelectSingleNode("*[local-name()='ContentType']").InnerText;
                }


                if (xmlPart.SelectSingleNode("*[local-name()='Data']") != null)
                {
                    XmlDocument tempData = new XmlDocument();

                    string dataXmlString = xmlPart.SelectSingleNode("*[local-name()='Data']").OuterXml;
                    dataXmlString = dataXmlString.Substring(dataXmlString.IndexOf('>') + 1);
                    dataXmlString = dataXmlString.Substring(0, dataXmlString.LastIndexOf("</Data>"));
                    tempData.LoadXml(dataXmlString);
                    tempPart.Data = tempData.DocumentElement;
                    //tempPart.Data = xmlPart.SelectSingleNode("*[local-name()='Data']") as XmlElement;
                }
                if (xmlPart.SelectSingleNode("*[local-name()='RawData']") != null)
                {
                    tempPart.RawData = xmlPart.SelectSingleNode("*[local-name()='RawData']").InnerText;
                }

                partList.Add(tempPart);
            }
            this.MPMessage.Parts = partList.ToArray();
        }
        public override bool ExecuteStep()
        {
            MultipartMessageDefinition tempMsg = null;
            XmlTextReader xmlBodyReader        = null;

            this.AppendResultDescription(0, "Executing step {0} ({1}):", this.StepName, this.StepType);

            if (!File.Exists(this.SourceFile) && String.IsNullOrEmpty(this.SourceResource))
            {
                this.AppendResultDescription(1, "File {0} does not exist.", this.SourceFile);
                this.Result = StepResult.Error;
            }
            else if (File.Exists(this.SourceFile))
            {
                //xmlBodyReader = new XmlTextReader(this.SourceFile);
                tempMsg = MultipartMessageSerializer.RetrieveDocument(this.SourceFile);
            }
            else
            {
                Assembly asmb = Assembly.Load(this.SourceResourceAssembly);
                //xmlBodyReader = new XmlTextReader(asmb.GetManifestResourceStream(this.SourceResource));
                tempMsg = MultipartMessageSerializer.RetrieveDocument(this.SourceResource, asmb);
            }

            if (this.Result != StepResult.Error)
            {
                if (!string.IsNullOrEmpty(this.TestID))
                {
                    List <ContextProperty> props = tempMsg.PropertyBag.ToList <ContextProperty>();
                    props.Add(new ContextProperty
                    {
                        Name      = BTSProperties.testID.Name.Name,
                        Namespace = BTSProperties.testID.Name.Namespace,
                        Promoted  = false,
                        Value     = this.TestID
                    });
                    tempMsg.PropertyBag = props.ToArray();
                }
                XmlDocument doc = MultipartMessageSerializer.Serialize(tempMsg);
                xmlBodyReader = new XmlTextReader(new StringReader(doc.OuterXml));
                xmlBodyReader.WhitespaceHandling = WhitespaceHandling.All;

                //xmlBodyReader.i

                BizTalk1WayReference.TwoWayAsyncVoidClient client = new BizTalk1WayReference.TwoWayAsyncVoidClient();
                try
                {
                    client.Endpoint.Address = new System.ServiceModel.EndpointAddress(this.DestURI);
                    client.Open();

                    Message request = Message.CreateMessage(MessageVersion.Soap11, "Get1WayMultipartMessage", xmlBodyReader);
                    client.BizTalkSubmit(request);
                }
                catch (Exception exc)
                {
                    this.AppendResultDescription(1, "[KO] Error when sending file {0} to {1} : {2}", this.SourceFile, DestURI, exc.Message);
                    this.Result = StepResult.Error;
                }
                finally
                {
                    if (client != null)
                    {
                        if (client.State == System.ServiceModel.CommunicationState.Opened)
                        {
                            client.Close();
                        }
                    }
                }

                this.AppendResultDescription(1, "[OK] Sent file {0} to {1}", this.SourceFile, DestURI);
            }

            if (this.Result == StepResult.Working)
            {
                this.Result = StepResult.OK;
            }

            return(this.Result == StepResult.OK);
        }