public void RemoveComponent(IBaseComponent child_)
        {
            Type type = child_.GetType();

            if (_children.ContainsKey(type) && _children[type].Contains(child_))
            {
                Debug.Log(GetType().Name + " -> removeChild :: " + child_.GetType().Name);
                _children[type].Remove(child_);
                child_.Release();
                child_ = null;
            }
        }
示例#2
0
        public void AddComponent(IBaseComponent component)
        {
            var componentType = component.GetType();

            if (!this.ComponentsByType.TryAdd(componentType, component))
            {
                Logger.Write(typeof(ComponentRegistry), LogLevel.Warn, "Cannot register component type \"{0}\", it was already registered.", componentType.FullName);
            }
            foreach (var componentInterface in componentType.GetInterfaces())
            {
                if (!this.ComponentsByInterface.GetOrAdd(componentInterface, () => new HashSet <IBaseComponent>()).Add(component))
                {
                    Logger.Write(typeof(ComponentRegistry), LogLevel.Warn, "Cannot register component type \"{0}\" by interface \"{1}\", it was already registered.", componentType.FullName, componentInterface.FullName);
                }
            }
            var attribute = componentType.GetCustomAttribute <ComponentAttribute>();

            if (attribute == null || string.IsNullOrEmpty(attribute.Slot) || string.Equals(attribute.Slot, ComponentSlots.None, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (!this.ComponentsBySlot.GetOrAdd(attribute.Slot, () => new HashSet <IBaseComponent>()).Add(component))
            {
                Logger.Write(typeof(ComponentRegistry), LogLevel.Warn, "Cannot register component type \"{0}\" by slot \"{1}\", it was already registered.", componentType.FullName, attribute.Slot);
            }
        }
示例#3
0
            public Task WriteAsync(IBaseComponent component, LogLevel level, string message, params object[] args)
            {
#if DEBUG
                global::System.Diagnostics.Debug.WriteLine(this.FormatMessage(component.GetType(), level, message, args));
#endif
#if NET40
                return(TaskEx.FromResult(false));
#else
                return(Task.CompletedTask);
#endif
            }
示例#4
0
            /// <summary>
            /// Gets information about <paramref name="target"/>, first checks if its type is compatible with <see cref="_TargetType"/>
            /// </summary>
            /// <param name="target"></param>
            /// <returns></returns>
            public ISignalInformation Get(IBaseComponent target)
            {
                // If target object's type doesn't match target type, throw an exception
                if (target.GetType() != _TargetType)
                {
                    throw new ArgumentException(nameof(target) + " is of type that is not a target type for this instance " +
                                                "(" + nameof(target) + " is of type " + target.GetType().FullName +
                                                ", target type is " + _TargetType.FullName + ")");
                }

                // Call the abstract method
                return(GetSignalInformation(target));
            }
        public void AddComponent(IBaseComponent child_)
        {
            Type type = child_.GetType();

            if (!_children.ContainsKey(type))
            {
                _children.Add(type, new List <IBaseComponent>());
            }
            else
            if (child_.IsOneChildOfAKind && _children[type].Count > 0)
            {
                Debug.Log(GetType().Name + " couldn't attach more than one child of type: " + type.Name);
                return;
            }
            _children[type].Add(child_);
            child_.Parent = this;
            child_.Init();
        }
示例#6
0
        public bool IsDefault(IBaseComponent component)
        {
            var type = component.GetType();

            {
                var attribute = type.GetCustomAttribute <ComponentAttribute>();
                if (attribute != null && attribute.Default)
                {
                    return(true);
                }
            }
            {
                var attribute = type.GetCustomAttribute <ComponentReleaseAttribute>();
                if (attribute != null)
                {
                    var releaseType = StandardComponents.Instance.Configuration.ReleaseType;
                    if (attribute.ReleaseType == releaseType)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#7
0
        public void RemoveComponent(IBaseComponent component)
        {
            var components    = default(ISet <IBaseComponent>);
            var componentType = component.GetType();

            this.ComponentsByType.Remove(componentType);
            foreach (var componentInterface in componentType.GetInterfaces())
            {
                if (this.ComponentsByInterface.TryGetValue(componentInterface, out components))
                {
                    components.Remove(component);
                }
            }
            var attribute = componentType.GetCustomAttribute <ComponentAttribute>();

            if (attribute == null || string.IsNullOrEmpty(attribute.Slot) || string.Equals(attribute.Slot, ComponentSlots.None, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (this.ComponentsBySlot.TryGetValue(attribute.Slot, out components))
            {
                components.Remove(component);
            }
        }
        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);
                }
            }
        }
        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;
            }
        }
示例#10
0
 public bool IsErrorEnabled(IBaseComponent component)
 {
     return(this.IsErrorEnabled(component.GetType()));
 }
示例#11
0
 public Task WriteAsync(IBaseComponent component, LogLevel level, string message, params object[] args)
 {
     return(this.WriteAsync(component.GetType(), level, message, args));
 }
示例#12
0
 public void Write(IBaseComponent component, LogLevel level, string message, params object[] args)
 {
     this.Write(component.GetType(), level, message, args);
 }
示例#13
0
            public void Write(IBaseComponent component, LogLevel level, string message, params object[] args)
            {
#if DEBUG
                global::System.Diagnostics.Debug.WriteLine(this.FormatMessage(component.GetType(), level, message, args));
#endif
            }