public void ActivityTrackingSanityCheck()
        {
            var interchangeID = Activity.NewActivityId();
            var message       = new BizMockMessage(@"Messages\btf2_services_header.xml");

            message.Promote(BtsProperties.InterchangeID, interchangeID);

            Submit.Request(message).To(_xmlReceiveLocation);
            Expect.One.Request.At(_xmlSendPort).Verify(new XmlMessageVerifier <btf2_services_header>());

            var process = TrackingDatabase.SingleProcess(p => p.InterchangeID == interchangeID && p.Name == DefaultProcesses.Unidentified);

            Assert.That(process.MessagingSteps.Count, Is.EqualTo(2));

            var inboundMessagingStep = process.MessagingSteps.Single(ms => ms.Status == TrackingStatus.Received);

            Assert.That(inboundMessagingStep.Name, Is.EqualTo(_xmlReceiveLocation.Name));
            Assert.That(
                inboundMessagingStep.Context.Properties.Any(
                    p => p.Name == TrackingProperties.MessagingStepActivityId.Name &&
                    p.Namespace == TrackingProperties.MessagingStepActivityId.Namespace &&
                    p.Value == inboundMessagingStep.ActivityID));
            Assert.That(inboundMessagingStep.Message.Body, Is.EqualTo(message.ReadBodyAsString()));

            var outboundMessagingStep = process.MessagingSteps.Single(ms => ms.Status == TrackingStatus.Sent);

            Assert.That(outboundMessagingStep.Name, Is.EqualTo(_xmlSendPort.Name));
            Assert.That(
                outboundMessagingStep.Context.Properties.Any(
                    p => p.Name == TrackingProperties.MessagingStepActivityId.Name &&
                    p.Namespace == TrackingProperties.MessagingStepActivityId.Namespace &&
                    p.Value == outboundMessagingStep.ActivityID));
            Assert.That(outboundMessagingStep.Message.Body, Is.EqualTo(message.ReadBodyAsString()));
        }
示例#2
0
        public void AddParts()
        {
            const string filePath = @"Messages\btf2_services_header.xml";

            for (var i = 0; i < 2; i++)
            {
                var interchangeID = Activity.NewActivityId();
                var message       = new BizMockMessage(filePath);
                message.Promote(BizTalkFactoryProperties.EnvelopeSpecName, Schema <soap_envelope_1__1.Envelope> .AssemblyQualifiedName);
                message.Promote(BtsProperties.InterchangeID, interchangeID);

                Submit.Request(message).To(_xmlReceiveLocation);

                var process = TrackingDatabase.SingleProcess(p => p.InterchangeID == interchangeID && p.Name == Factory.Processes.Batching.Aggregator);
                Assert.That(process.MessagingSteps.Count, Is.EqualTo(2));

                var inboundMessagingStep = process.MessagingSteps.Single(ms => ms.Status == TrackingStatus.Received);
                Assert.That(inboundMessagingStep.Name, Is.EqualTo(_xmlReceiveLocation.Name));

                var outboundMessagingStep = process.MessagingSteps.Single(ms => ms.Status == TrackingStatus.Sent);
                Assert.That(outboundMessagingStep.Name, Is.EqualTo("BizTalk.Factory.SP1.Batching.AddPart.WCF-SQL"));

                // TODO find the right way: following line should not be there
                BizMockery.Reset(true);
            }
        }
        public void ProcessSingleMessage()
        {
            const string filePath = @"Messages\btf2_services_header.xml";

            var interchangeID = Activity.NewActivityId();
            var message       = new BizMockMessage(filePath);

            message.Promote(BtsProperties.InterchangeID, interchangeID);

            Submit.Request(message).To(_xmlReceiveLocation);
            Expect.One.Request.At(_xmlSendPort).Verify(new XmlMessageVerifier <btf2_services_header>());

            var process = TrackingDatabase.SingleProcess(p => p.InterchangeID == interchangeID && p.Name == DefaultProcesses.Unidentified);

            Assert.That(process.MessagingSteps.Count, Is.EqualTo(2));

            var inboundMessagingStep = process.MessagingSteps.Single(ms => ms.Status == TrackingStatus.Received);

            Assert.That(inboundMessagingStep.Name, Is.EqualTo(_xmlReceiveLocation.Name));
            Assert.That(inboundMessagingStep.MessageSize, Is.EqualTo(new FileInfo(filePath).Length));
            Assert.That(inboundMessagingStep.MessageType, Is.EqualTo(Schema <btf2_services_header> .MessageType));

            var outboundMessagingStep = process.MessagingSteps.Single(ms => ms.Status == TrackingStatus.Sent);

            Assert.That(outboundMessagingStep.Name, Is.EqualTo(_xmlSendPort.Name));
            Assert.That(outboundMessagingStep.MessageSize, Is.EqualTo(new FileInfo(filePath).Length));
            Assert.That(outboundMessagingStep.MessageType, Is.EqualTo(Schema <btf2_services_header> .MessageType));
        }
        //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);
        }
示例#5
0
        public void ReleaseBatch()
        {
            const string filePath = @"Messages\ReleaseBatchContent.xml";

            var interchangeID = Activity.NewActivityId();
            var message       = new BizMockMessage(filePath);

            message.Promote(BtsProperties.InterchangeID, interchangeID);

            Submit.Request(message).To(_xmlReceiveLocation);

            var process = TrackingDatabase.SingleProcess(p => p.InterchangeID == interchangeID && p.Name == Factory.Processes.Batching.Releaser);

            Assert.That(process.MessagingSteps.Count, Is.GreaterThan(2));

            var inboundMessagingStep = process.MessagingSteps.Single(ms => ms.Status == TrackingStatus.Received);

            Assert.That(inboundMessagingStep.Name, Is.EqualTo(_xmlReceiveLocation.Name));

            Assert.That(process.MessagingSteps.All(ms => ms.Status == TrackingStatus.Sent && ms.Name == "BizTalk.Factory.SP2.Batching.ReleaseBatch.WCF-SQL"));
        }
        public void MessageFailureUponReceiving()
        {
            var interchangeID = Activity.NewActivityId();
            var message       = new BizMockMessage(@"Messages\unknown.xml");

            message.Promote(BtsProperties.InterchangeID, interchangeID);

            Submit.Request(message).To(_xmlReceiveLocation);
            Expect.One.Request.At(_failSendPort);

            var messagingStep = TrackingDatabase.SingleMessagingStep(ms => ms.InterchangeID == interchangeID);

            Assert.That(messagingStep.ErrorCode, Is.Not.Empty);
            Assert.That(messagingStep.ErrorDescription, Is.Not.Empty);
            Assert.That(messagingStep.Name, Is.EqualTo(_xmlReceiveLocation.Name));
            Assert.That(messagingStep.Processes.Count, Is.EqualTo(0));
            Assert.That(messagingStep.Status, Is.EqualTo(TrackingStatus.FailedMessage));

            Assert.That(messagingStep.Message.Body, Is.EqualTo(File.ReadAllText(@"Messages\unknown.xml")));
            Assert.That(messagingStep.Context.GetProperty(BtsProperties.SendPortName).Value, Is.EqualTo(_failSendPort.Name));
        }
示例#7
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);
            }
        }
示例#8
0
        public static List <MatchingPartInfo> GetMatchingPartInfo(BizTalkDTADbEntities btsDTA, TrackingDatabase dta, BizTalkOperations operations, List <ControlProperty> contextProps, List <ControlField> xpathProps, string processName, string sourceContextProperty)
        {
            DateTime startDate           = DateTime.Now.Subtract(new TimeSpan(BTSTestContext.MaxHistory, 0, 0, 0));
            List <MatchingPartInfo> info = new List <MatchingPartInfo>();

            if (!String.IsNullOrEmpty(sourceContextProperty))
            {
                Logger.CurrentLogger.Write(1, "Getting service instance info according to cached property '{0}'", System.Diagnostics.EventLogEntryType.Information, sourceContextProperty);
                //Guid serviceInstanceID = (Guid)BTSTestContext.Params[sourceContextProperty];
                //List<Guid> serviceInstanceIDs = (List<Guid>)BTSTestContext.Params[sourceContextProperty];
                List <OrchestrationInstance> serviceInstanceIDs = (List <OrchestrationInstance>)BTSTestContext.Params[sourceContextProperty];


                foreach (OrchestrationInstance serviceInstance in serviceInstanceIDs)
                {
                    Logger.CurrentLogger.Write(2, "(Value = '{0}')", System.Diagnostics.EventLogEntryType.Information, serviceInstanceIDs[0]);

                    /// Query the DTA Db to retrieve all messages related to
                    /// the type of process we are looking for.
                    var msgIds = from s in btsDTA.dta_Services
                                 join si in btsDTA.dta_ServiceInstances on s.uidServiceId equals si.uidServiceId
                                 //join ss in btsDTA.dta_ServiceState on si.nServiceStateId equals ss.nServiceStateId
                                 join me in btsDTA.dta_MessageInOutEvents on si.uidServiceInstanceId equals me.uidServiceInstanceId
                                 where s.strServiceName == processName &&
                                 si.uidServiceInstanceId == serviceInstance.ID
                                 orderby me.dtInsertionTimeStamp descending
                                 select new MatchingPartInfo
                    {
                        ServiceId         = s.uidServiceId,
                        txtSymbol         = s.txtSymbol,
                        ServiceInstanceId = si.uidServiceInstanceId,
                        MessageInstanceId = me.uidMessageInstanceId,
                        Status            = (ServiceStatus)si.nServiceStateId
                    };

                    if (msgIds.Count() == 0)
                    {
                        info = GetMatchingPartInfo(btsDTA, dta, operations, contextProps, xpathProps, processName, null);
                    }
                    else
                    {
                        info.AddRange(msgIds.ToList <MatchingPartInfo>());
                    }
                }
            }
            else
            {
                Logger.CurrentLogger.Write(1, "Looking for service instance into DTA Db", System.Diagnostics.EventLogEntryType.Information);

                /// Query the DTA Db to retrieve all messages related to
                /// the type of process we are looking for.
                var msgIds = from s in btsDTA.dta_Services
                             join si in btsDTA.dta_ServiceInstances on s.uidServiceId equals si.uidServiceId
                             join me in btsDTA.dta_MessageInOutEvents on si.uidServiceInstanceId equals me.uidServiceInstanceId
                             where s.strServiceName == processName &&
                             si.dtStartTime > startDate
                             orderby me.dtInsertionTimeStamp descending
                             select new MatchingPartInfo
                {
                    ServiceId         = s.uidServiceId,
                    ServiceName       = s.strServiceName,
                    txtSymbol         = s.txtSymbol,
                    ServiceInstanceId = si.uidServiceInstanceId,
                    MessageInstanceId = me.uidMessageInstanceId,
                    Status            = (ServiceStatus)si.nServiceStateId
                };

                /// Looping through all the messages in order to identify the one we are looking for
                Logger.CurrentLogger.Write(2, "Retrieved {0} messages", System.Diagnostics.EventLogEntryType.Information, msgIds.Count());
                foreach (MatchingPartInfo part in msgIds)
                {
                    bool match = PerformMessageLookup(part.MessageInstanceId, contextProps, xpathProps, dta, operations);

                    if (match)
                    {
                        Logger.CurrentLogger.Write(2, "[OK] Message match", System.Diagnostics.EventLogEntryType.Information);
                        info.Add(part);
                        //break;
                    }
                }
            }

            return(info);
        }
示例#9
0
        public static bool PerformMessageLookup(Guid messageInstanceID, List <ControlProperty> contextProps, List <ControlField> xpathProps, TrackingDatabase dta, BizTalkOperations operations)
        {
            bool result = true;

            try
            {
                /// NOTE :
                /// Following instruction will throw an exception if the corresponding message was not found in the DTA Db
                IBaseMessage message = operations.GetTrackedMessage(messageInstanceID, dta);
                Logger.CurrentLogger.Write(2, "Testing message {0}", System.Diagnostics.EventLogEntryType.Information, messageInstanceID);
                //BizTalkMessage btsMsg = (BizTalkMessage)rawMessage;

                foreach (ControlProperty prop in contextProps)
                {
                    string expectedValue = prop.Value;
                    string foundValue    = (string)message.Context.Read(
                        prop.Property,
                        prop.Namespace);

                    if (expectedValue != foundValue)
                    {
                        Logger.CurrentLogger.Write(3, "[KO] Prop '{0}/{1}' : mismatch - Expected {2}, found {3}.", System.Diagnostics.EventLogEntryType.Information,
                                                   prop.Namespace,
                                                   prop.Property,
                                                   expectedValue,
                                                   foundValue);
                        result = false;
                    }
                    else
                    {
                        Logger.CurrentLogger.Write(3, "[OK] Prop '{0}/{1}' : match - Expected {2}, found {3}.", System.Diagnostics.EventLogEntryType.Information,
                                                   prop.Namespace,
                                                   prop.Property,
                                                   expectedValue,
                                                   foundValue);
                    }
                }

                if (xpathProps.Count > 0)
                {
                    List <ControlField> tmpXpathProps = xpathProps.ToList <ControlField>();
                    for (int i = 0; i < message.PartCount; i++)
                    {
                        string body     = string.Empty;
                        string partName = string.Empty;
                        using (StreamReader streamReader = new StreamReader(message.GetPartByIndex(i, out partName).Data))
                        {
                            Logger.CurrentLogger.Write(3, "Testing part {0}", System.Diagnostics.EventLogEntryType.Information, partName);

                            Logger.CurrentLogger.Write(3, "Retrieving body...", System.Diagnostics.EventLogEntryType.Information);
                            body = streamReader.ReadToEnd();
                            Logger.CurrentLogger.Write(3, "Body retrieved successfully : Length={0}", System.Diagnostics.EventLogEntryType.Information, body.Length);
                            XmlDocument testedMsg = new XmlDocument();
                            testedMsg.LoadXml(body);

                            foreach (ControlField field in xpathProps)
                            {
                                string  expectedValue = field.Value;
                                XmlNode tmpNode       = testedMsg.SelectSingleNode(field.XPath);
                                if (tmpNode != null)
                                {
                                    string foundValue = tmpNode.InnerText;

                                    if (expectedValue != foundValue)
                                    {
                                        Logger.CurrentLogger.Write(3, "[KO] XPath '{0}' : mismatch - Expected {1}, found {2}.", System.Diagnostics.EventLogEntryType.Information,
                                                                   field.XPath,
                                                                   expectedValue,
                                                                   foundValue);
                                    }
                                    else
                                    {
                                        Logger.CurrentLogger.Write(3, "[OK] XPath '{0}' : match - Expected {1}, found {2}.", System.Diagnostics.EventLogEntryType.Information,
                                                                   field.XPath,
                                                                   expectedValue,
                                                                   foundValue);
                                        tmpXpathProps.Remove(tmpXpathProps.Find(tmpField => tmpField.XPath == field.XPath && tmpField.Value == field.Value));
                                    }
                                }
                            }

                            if (tmpXpathProps.Count == 0)
                            {
                                break;
                            }
                        }
                    }

                    if (tmpXpathProps.Count == 0)
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                Logger.CurrentLogger.Write(2, "Error when retrieving message {0} from DTA Db : {1}", System.Diagnostics.EventLogEntryType.Error, messageInstanceID, ex.Message);
                return(false);
            }
        }
示例#10
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.dgMessages.Rows.Clear();

            List <ControlProperty> contextProps = new List <ControlProperty>();
            List <string>          serviceNames = new List <string>();

            foreach (DataGridViewRow dr in this.dgProps.Rows)
            {
                if (dr.Cells[0].Value != null)
                {
                    //ControlProperty cp = new ControlProperty();
                    //cp.Namespace = (string)dr.Cells[1].Value;
                    //cp.Property = (string)dr.Cells[0].Value;
                    //cp.Value = (string)dr.Cells[2].Value;

                    //contextProps.Add(cp);
                    serviceNames.Add((string)dr.Cells[0].Value);
                }
            }

            string entityConnectionStr = String.Empty;

            this.testConnection(out entityConnectionStr, false);

            using (BizTalkDTADbEntities btsDTA = new BizTalkDTADbEntities(entityConnectionStr))
            {
                TrackingDatabase dta = new TrackingDatabase(this.txtDTAServerName.Text,
                                                            this.txtDTADBName.Text);
                BizTalkOperations operations = new BizTalkOperations(this.txtDTAServerName.Text, this.txtMgmtDBName.Text);

                var msgIds = from mioe in btsDTA.dta_MessageInOutEvents
                             join si in btsDTA.dta_ServiceInstances on mioe.uidServiceInstanceId equals si.uidServiceInstanceId
                             join s in btsDTA.dta_Services on si.uidServiceId equals s.uidServiceId
                             join pn in btsDTA.dta_PortName on mioe.nPortId equals pn.nPortId
                             join sn in btsDTA.dta_SchemaName on mioe.nSchemaId equals sn.nSchemaId
                             where mioe.dtTimestamp > this.dtFrom.Value &&
                             mioe.dtTimestamp < this.dtTo.Value &&
                             serviceNames.Contains(s.strServiceName)
                             orderby mioe.dtInsertionTimeStamp descending
                             select new tempMsgInfo
                {
                    strServiceName         = s.strServiceName
                    , uidMessageInstanceId = mioe.uidMessageInstanceId
                    , strPortName          = pn.strPortName
                    , dtTimestamp          = mioe.dtTimestamp
                    , nStatus       = mioe.nStatus
                    , strSchemaName = sn.strSchemaName
                };

                ControlProperty tempCP = contextProps.Find(cp =>
                                                           cp.Namespace == BizWTF.Core.Entities.BTSProperties.messageType.Name.Namespace
                                                           &&
                                                           cp.Property == BizWTF.Core.Entities.BTSProperties.messageType.Name.Name);
                if (tempCP != null)
                {
                    msgIds = msgIds.Where(rec => rec.strSchemaName == tempCP.Value);
                }

                /// Looping through all the messages in order to identify the one we are looking for
                foreach (var msg in msgIds.Take(Int32.Parse(this.txtMaxRecord.Text)))
                {
                    bool match = MatchingPartInfo.PerformMessageLookup(msg.uidMessageInstanceId, contextProps, new List <ControlField>(), dta, operations);

                    if (match)
                    {
                        string status = String.Empty;
                        switch (msg.nStatus)
                        {
                        case 0:
                            status = "Receive";
                            break;

                        case 1:
                            status = "Send";
                            break;

                        case 5:
                            status = "Transmission Failure";
                            break;

                        default:
                            status = "?";
                            break;
                        }
                        this.dgMessages.Rows.Add(status, msg.strServiceName, msg.strPortName, msg.strSchemaName, msg.dtTimestamp, msg.uidMessageInstanceId);
                    }
                }
            }
        }
 public Extractor(Settings settings)
 {
     this._settings         = settings;
     this._btsOps           = new BizTalkOperations(settings.BizTalkMgmtHost, settings.BizTalkMgmtDb);
     this._trackingDatabase = new TrackingDatabase(settings.BizTalkDTAHost, settings.BizTalkDTADb);
 }
示例#12
0
 public BizTalkObject(string serverName)
 {
     this._BizTalkOperations = new BizTalkOperations(mgmtDbServer: serverName, mgmtDbName: MANAGEMENTDBNAME);
     this._TrackingDatabase  = new TrackingDatabase(dbServer: serverName, dbName: TRACKINGDBNAME);
 }
        //public override List<OrchestrationInstanceInfo> GetData<List<OrchestrationInstanceInfo>>()
        //{
        //    return this.InstanceList;
        //}

        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(2, "(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,
                                                                                          this.SourceContextProperty
                                                                                          ).Distinct <MatchingPartInfo>(new MatchingPartServiceIDComparer()).ToList();

                if (partList.Count > 0)
                {
                    this.AppendResultDescription(1, "[OK] Matching service {0} instances found ", partList.Count);
                    foreach (MatchingPartInfo part in partList)
                    {
                        this.AppendResultDescription(2, "Matching service instance : {0}", part.ServiceInstanceId);

                        OrchestrationInstanceInfo currentInstance = new OrchestrationInstanceInfo(part.txtSymbol);
                        currentInstance.FlowDefinition.ProcessName = this.ProcessName;

                        var filteredMsgIds = from me in btsDTA.dta_MessageInOutEvents
                                             where me.uidServiceInstanceId == part.ServiceInstanceId
                                             orderby me.dtInsertionTimeStamp descending
                                             select new
                        {
                            me.uidMessageInstanceId
                        };
                        foreach (var msg in filteredMsgIds)
                        {
                            currentInstance.Messages.Add(operations.GetTrackedMessage(msg.uidMessageInstanceId, dta));
                        }
                        this.AppendResultDescription(3, "Found {0} attached messages", filteredMsgIds.Count());

                        this.AppendResultDescription(3, "Pre-processing DebugShapes", filteredMsgIds.Count());
                        var debugTraces = from dt in btsDTA.dta_DebugTrace
                                          where dt.uidServiceInstanceId == part.ServiceInstanceId
                                          orderby dt.dtInsertionTimeStamp ascending
                                          select new DebugShape
                        {
                            ShapeID    = dt.vtInstructionId,
                            StartTime  = dt.dtBeginTimeStamp,
                            FinishTime = dt.dtEndTimeStamp
                        };
                        foreach (DebugShape trace in debugTraces)
                        {
                            string    shapePath = String.Empty;
                            ShapeInfo shape     = currentInstance.FlowDefinition.GetShape(trace.ShapeID, ref shapePath);
                            trace.shapeText = shape.shapeText;
                            trace.shapeType = shape.shapeType;
                            trace.ShapePath = shapePath;

                            currentInstance.Trace.TraceDetails.Add(trace);
                            this.AppendResultDescription(4, "Processed shape '{0}' ({1})", trace.shapeText, trace.ShapePath);
                        }
                        this.InstanceList.Add(currentInstance);
                    }

                    this.Result = StepResult.OK;
                }
                else
                {
                    this.AppendResultDescription(1, "No matching service instance found", EventLogEntryType.Error);
                    this.Result = StepResult.Error;
                }
            }

            BTSTestContext.AddParam(this.TargetContextProperty, this.InstanceList);

            return(this.Result == StepResult.OK);
        }
示例#14
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);
        }
示例#15
0
        //public override object GetData()
        //{ return null; }

        public override bool ExecuteStep()
        {
            BTSTestContext.AddParam(this.TargetContextProperty, new List <OrchestrationInstance>());

            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, "(overridden 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);
            }
            this.AppendResultDescription(1, "PollingInterval : {0}", this.PollingInterval);
            this.AppendResultDescription(1, "PollingCount : {0}", this.PollingCount);

            TrackingDatabase dta = new TrackingDatabase(BTSTestContext.BizTalkDbServer,
                                                        BTSTestContext.BizTalkDTADb);
            BizTalkOperations operations = new BizTalkOperations(BTSTestContext.BizTalkDbServer, BTSTestContext.BizTalkMgmtDb);
            //bool result = true;



            int loopIterator = 0;

            while (((IList)BTSTestContext.GetParam(this.TargetContextProperty)).Count == 0 && loopIterator < this.PollingCount)
            {
                loopIterator++;

                //IEnumerable services = operations.GetServiceInstances();
                IEnumerator servicesEnum = operations.GetServiceInstances().GetEnumerator();

                while (servicesEnum.MoveNext())
                {
                    if (servicesEnum.Current.GetType() == typeof(Microsoft.BizTalk.Operations.OrchestrationInstance))
                    {
                        OrchestrationInstance tempInstance = (OrchestrationInstance)servicesEnum.Current;

                        Analyzer analyser = new Analyzer(tempInstance);
                        this.onProcess         += analyser.ProcessInstance;
                        analyser.ProcessStopped = this.ProcessStopped;
                        analyser.AddToContext   = this.addInstanceInContext;
                    }
                }
                if (this.onProcess != null)
                {
                    this.onProcess(operations, this.ContextProps, this.XPathProps, this.ProcessName, this.AppendResultDescription);
                }



                if (((IList)BTSTestContext.GetParam(this.TargetContextProperty)).Count == 0)
                {
                    this.AppendResultDescription(1, "[{0}] No matching service instance found, retrying in {1} milliseconds.", EventLogEntryType.Warning, this.PollingInterval);
                    System.Threading.Thread.Sleep(this.PollingInterval);
                }
                else
                {
                    this.Result = StepResult.OK;
                }
            }


            if (this.Result != StepResult.OK)
            {
                this.AppendResultDescription(1, "[{0}] No matching service instance found!!", EventLogEntryType.Error);
                this.Result = StepResult.Error;
            }

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