Beispiel #1
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);
        }
Beispiel #2
0
            public void ProcessInstance(BizTalkOperations operations,
                                        List <ControlProperty> contextProps,
                                        List <ControlField> xpathProps,
                                        string processName,
                                        AppendResultDescriptionHandler writeLog)
            {
                OrchestrationInstance instance = null;
                StringWriter          log      = new StringWriter();

                log.WriteLine("  Analysing instance of '{0}'", tempInstance.ServiceType);
                if (tempInstance.ServiceType.StartsWith(processName))
                {
                    log.WriteLine("    [OK] Service Type match : {0}", processName);
                    foreach (var rawMessage in tempInstance.Messages)
                    {
                        if (rawMessage.GetType() == typeof(BizTalkMessage))
                        {
                            bool           currentMatch = true;
                            BizTalkMessage btsMsg       = (BizTalkMessage)rawMessage;

                            #region Test context and XPath
                            foreach (ControlProperty prop in contextProps)
                            {
                                string expectedValue = prop.Value;
                                string foundValue    = (string)btsMsg.Context.Read(
                                    prop.Property,
                                    prop.Namespace);

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

                            if (xpathProps.Count > 0 && currentMatch)
                            {
                                string body = string.Empty;
                                using (StreamReader streamReader = new StreamReader(btsMsg.BodyPart.Data))
                                {
                                    body = streamReader.ReadToEnd();
                                }
                                XmlDocument testedMsg = new XmlDocument();
                                testedMsg.LoadXml(body);

                                foreach (ControlField field in xpathProps)
                                {
                                    string  expectedValue  = field.Value;
                                    XmlNode foundValueNode = testedMsg.SelectSingleNode(field.XPath);

                                    if (foundValueNode != null)
                                    {
                                        string foundValue = testedMsg.SelectSingleNode(field.XPath).InnerText;
                                        if (expectedValue != foundValue)
                                        {
                                            log.WriteLine("      [KO] XPath '{0}' : mismatch - Expected {1}, found {2}.",
                                                          field.XPath,
                                                          expectedValue,
                                                          foundValue);
                                            currentMatch = false;
                                            break;
                                        }
                                        else
                                        {
                                            log.WriteLine("      [OK] XPath '{0}' : match - Expected {1}, found {2}.",
                                                          field.XPath,
                                                          expectedValue,
                                                          foundValue);
                                        }
                                    }
                                    else
                                    {
                                        log.WriteLine("      [KO] XPath '{0}' : returned no value.",
                                                      field.XPath);
                                        currentMatch = false;
                                        break;
                                    }
                                }
                            }
                            #endregion

                            if (currentMatch)
                            {
                                instance = tempInstance;
                                log.WriteLine("  Matching service instance found : {0}", instance.ID);
                                this.AddToContext(instance);

                                try
                                {
                                    log.WriteLine("  Waiting for instance to finish...");

                                    bool loop = true;
                                    OrchestrationInstance waitInstance = null;
                                    while (loop)
                                    {
                                        while (instance.InstanceStatus != InstanceStatus.Completed &&
                                               instance.InstanceStatus != InstanceStatus.Dehydrated &&
                                               instance.InstanceStatus != InstanceStatus.Suspended &&
                                               instance.InstanceStatus != InstanceStatus.SuspendedAll &&
                                               instance.InstanceStatus != InstanceStatus.SuspendedNotResumable &&
                                               instance.InstanceStatus != InstanceStatus.Terminated)
                                        {
                                            System.Threading.Thread.Sleep(5000);

                                            waitInstance = (OrchestrationInstance)operations.GetServiceInstance(instance.ID);
                                            instance     = waitInstance;
                                        }

                                        loop = this.ProcessStopped(instance);
                                        if (loop)
                                        {
                                            System.Threading.Thread.Sleep(2000);
                                            waitInstance = (OrchestrationInstance)operations.GetServiceInstance(instance.ID);
                                            instance     = waitInstance;
                                        }
                                    }
                                }
                                catch { }

                                writeLog(0, log.ToString());

                                break;
                            }
                            else
                            {
                                writeLog(0, log.ToString());
                            }
                        }
                    }
                }
            }