//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);
        }
        internal static List <OrchestrationInfo> GetDeployedOrchestrations(string entityDTAConnStr)
        {
            List <OrchestrationInfo> orchs = new List <OrchestrationInfo>();

            using (BizTalkDTADbEntities btsDTA = new BizTalkDTADbEntities(entityDTAConnStr))
            {
                var rawOrchs = from s in btsDTA.dta_Services
                               where s.strServiceType == "Orchestration"
                               select new OrchestrationInfo
                {
                    ServiceName  = s.strServiceName,
                    AssemblyName = s.strAssemblyName,
                    TxtSymbols   = s.txtSymbol
                };

                orchs = rawOrchs.ToList <OrchestrationInfo>();
            }
            return(orchs);
        }
Beispiel #3
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);
        }
        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 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);
        }