示例#1
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);
            }
        }
示例#2
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);
        }
        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);
        }