コード例 #1
0
        public ExecutableRcvPipeline(ReceivePipeline source)
        {
            XmlDocument conf = new XmlDocument();

            conf.LoadXml(source.XmlContent);

            foreach (XmlNode stageConf in conf.SelectNodes("/*[local-name()='Document']/*[local-name()='Stages']/*[local-name()='Stage']"))
            {
                XmlNode       fileStageConf = stageConf.SelectSingleNode("*[local-name()='PolicyFileStage']");
                ExecutionMode mode          = ExecutionMode.allRecognized;
                switch (fileStageConf.Attributes["execMethod"].Value.ToLower())
                {
                case "all":
                    mode = ExecutionMode.all;
                    break;

                case "firstmatch":
                    mode = ExecutionMode.firstRecognized;
                    break;

                default:
                    mode = ExecutionMode.allRecognized;
                    break;
                }


                CustomStage tempStage = new CustomStage
                {
                    StageID    = Guid.Parse(fileStageConf.Attributes["stageId"].Value),
                    StageLevel = Int32.Parse(fileStageConf.Attributes["_locID"].Value),
                    Mode       = mode
                };
                this.Stages.Add(tempStage);


                foreach (XmlNode componentConf in stageConf.SelectNodes("*[local-name()='Components']/*[local-name()='Component']"))
                {
                    IBaseComponent realComponent = (IBaseComponent)Activator.CreateInstance(Type.GetType(componentConf.SelectSingleNode("*[local-name()='Name']").InnerText));
                    MethodInfo     initNewInfo   = realComponent.GetType().GetMethod("InitNew");
                    if (initNewInfo != null)
                    {
                        initNewInfo.Invoke(realComponent, new object[] { });
                    }

                    IPropertyBag componentProps = new CustomPropertyBag();

                    List <string> hiddenProps = new List <string>();
                    XmlNode       hiddenNode  = componentConf.SelectSingleNode("*[local-name()='Properties']/*[local-name()='Property' and @Name='HiddenProperties']");
                    if (hiddenNode != null)
                    {
                        hiddenProps.AddRange(hiddenNode.InnerText.Split(','));
                    }
                    hiddenProps.Add("HiddenProperties");

                    foreach (XmlNode propConf in componentConf.SelectNodes("*[local-name()='Properties']/*[local-name()='Property']"))
                    {
                        if (!String.IsNullOrEmpty(propConf.SelectSingleNode("*[local-name()='Value']").InnerText) && !hiddenProps.Contains(propConf.Attributes["Name"].Value))
                        {
                            componentProps.Write(
                                propConf.Attributes["Name"].Value,
                                this.TryConvertToSchemaList(propConf.SelectSingleNode("*[local-name()='Value']").InnerText,
                                                            propConf.SelectSingleNode("*[local-name()='Value']").Attributes["xsi:type"].Value));
                            //switch (propConf.Attributes["Name"].Value)
                            //{
                            //    case "Microsoft.BizTalk.Component.Utilities.SchemaList":
                            //        componentProps.Write(
                            //                            propConf.Attributes["Name"].Value,
                            //                            this.ConvertToSchemaList(propConf.SelectSingleNode("*[local-name()='Value']").InnerText));
                            //        break;
                            //    default:
                            //        componentProps.Write(
                            //                            propConf.Attributes["Name"].Value,
                            //                            Convert.ChangeType(propConf.SelectSingleNode("*[local-name()='Value']").InnerText, propertyInfo.PropertyType));
                            //        break;
                            //}
                        }
                    }

                    if (realComponent.GetType().GetInterfaces().Contains(typeof(IPersistPropertyBag)))
                    {
                        MethodInfo loadInfo = realComponent.GetType().GetMethod("Load");
                        if (loadInfo != null)
                        {
                            loadInfo.Invoke(realComponent, new object[] { componentProps, null });
                        }
                    }

                    tempStage.Components.Add(realComponent);
                }
            }
        }
コード例 #2
0
        private void executeComponent(CustomStage stage, IBaseComponent component, IPipelineContext context, IBaseMessage msgIn)
        {
            msgIn.BodyPart.Data.Position = 0;

            MethodInfo probeInfo = null;

            switch (stage.StageLevel)
            {
            case 1:
                probeInfo = component.GetType().GetMethod("Execute");
                IBaseMessage stage1Msg = (IBaseMessage)probeInfo.Invoke(component, new object[] { context, msgIn });

                msgIn = stage1Msg;
                break;

            case 2:
                probeInfo = component.GetType().GetMethod("Disassemble");
                probeInfo.Invoke(component, new object[] { context, msgIn });
                //msgIn.BodyPart.Data.Position = 0;

                MethodInfo   nextInfo        = component.GetType().GetMethod("GetNext");
                object[]     compArgs        = new object[] { context };
                IBaseMessage disassembledMsg = (IBaseMessage)nextInfo.Invoke(component, compArgs);

                //this.OutputMsgs.Add(disassembledMsg);
                Guid lastID = Guid.Empty;
                while (disassembledMsg != null && disassembledMsg.MessageID != lastID)
                {
                    MemoryStream tempStream = new MemoryStream();
                    disassembledMsg.BodyPart.Data.CopyTo(tempStream);
                    //BizWTF.Core.Entities.MultipartMessage msg = BizWTF.Core.Entities.Mocking.MultipartMessageManager.GenerateFromMessage(disassembledMsg);
                    tempStream.Position           = 0;
                    disassembledMsg.BodyPart.Data = tempStream;

                    this.OutputMsgs.Add(disassembledMsg);
                    lastID = disassembledMsg.MessageID;

                    disassembledMsg = (IBaseMessage)nextInfo.Invoke(component, compArgs);
                }
                break;

            case 3:
                probeInfo = component.GetType().GetMethod("Execute");

                List <IBaseMessage> stage3Msgs = new List <IBaseMessage>();
                foreach (IBaseMessage previousStageMsg in this.OutputMsgs)
                {
                    stage3Msgs.Add((IBaseMessage)probeInfo.Invoke(component, new object[] { context, previousStageMsg }));
                }
                this.OutputMsgs = stage3Msgs;

                break;

            case 4:
                probeInfo = component.GetType().GetMethod("Execute");

                List <IBaseMessage> stage4Msgs = new List <IBaseMessage>();
                foreach (IBaseMessage previousStageMsg in this.OutputMsgs)
                {
                    stage4Msgs.Add((IBaseMessage)probeInfo.Invoke(component, new object[] { context, previousStageMsg }));
                }
                this.OutputMsgs = stage4Msgs;

                break;

            default:
                break;
            }
        }