Пример #1
0
        /// <summary>
        /// Add item to the container.
        /// The additional shall be verified against existing items (no duplication),
        /// as well as the "confirmation" delegates, if any are assigned.
        /// </summary>
        public bool Add(ItemType item)
        {
            if (ItemAddDelegate != null)
            {
                if (ItemAddDelegate(this, item) == false)
                {// Confirmative owner delegate denied item addition.
                    return(false);
                }
            }

            lock (this)
            {
                if (_items.Add(item) == false)
                {// Item add failed.
                    return(false);
                }

                if (_itemIsOperational)
                {
                    ((IOperational)item).OperationalStateChangedEvent += new OperationalStateChangedDelegate(GenericKeeper_OperationalStatusChangedEvent);
                }
            }


            if (ItemAddedEvent != null)
            {
                ItemAddedEvent(this, item);
            }

            return(true);
        }
Пример #2
0
 /// <summary>
 /// Add a tracer item sink to tracer.
 /// </summary>
 /// <param name="sink"></param>
 /// <returns></returns>
 public bool Add(ITracerItemSink sink)
 {
     lock (this)
     {
         return(_itemSinks.Add(sink));
     }
 }
Пример #3
0
        /// <summary>
        /// Helper method allows to retrieve initial assembly and it referenced (static and runtime) assemblies.
        /// </summary>
        static public ListUnique <Assembly> GetReferencedAndInitialAssembly(Assembly initialAssembly)
        {
            ListUnique <Assembly> assemblies = GetReferencedAssemblies(initialAssembly);

            assemblies.Add(initialAssembly);
            return(assemblies);
        }
Пример #4
0
 /// <summary>
 /// Add a new tracer filter to tracer.
 /// Make sure this is correct, since once filter in place, items will not be passed to sinks at all.
 /// </summary>
 public bool Add(TracerFilter filter)
 {
     filter.Initialize(this);
     lock (this)
     {
         return(_filters.Add(filter));
     }
 }
Пример #5
0
        /// <summary>
        /// Add sink specific filter.
        /// It is up to the sinks implementation to how the filter will be used.
        /// </summary>
        public bool AddFilter(TracerFilter filter)
        {
            lock (this)
            {
                if (_filters.Add(filter))
                {
                    filter.FilterUpdatedEvent += new TracerFilter.FilterUpdatedDelegate(filter_FilterUpdatedEvent);
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public EnumItemTracerFilter()
        {
            // Find all candidate enum types and assemblies they reside in.
            List <Type> possibleEnumTypes = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(Enum), ReflectionHelper.GetApplicationEntryAssemblyAndReferencedAssemblies());

            for (int i = possibleEnumTypes.Count - 1; i >= 0; i--)
            {
                object[] attributes = possibleEnumTypes[i].GetCustomAttributes(typeof(TracerEnumAttribute), true);
                if (attributes == null || attributes.Length == 0)
                {
                    possibleEnumTypes.RemoveAt(i);
                }
                else
                {
                    _assemblies.Add(possibleEnumTypes[i].Assembly);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Helper method allows to retrieve initial assembly referenced (static and runtime) assemblies.
        /// </summary>
        static public ListUnique <Assembly> GetReferencedAssemblies(Assembly initialAssembly)
        {
            ListUnique <Assembly> result = new ListUnique <Assembly>();

            AssemblyName[] names = initialAssembly.GetReferencedAssemblies();
            for (int i = 0; i < names.Length; i++)
            {
                result.Add(Assembly.Load(names[i]));
            }

            lock (_dynamicReferencedAssemblies)
            {
                if (_dynamicReferencedAssemblies.ContainsKey(initialAssembly))
                {
                    result.AddRange(_dynamicReferencedAssemblies[initialAssembly]);
                }
            }

            return(result);
        }
Пример #8
0
        /// <summary>
        /// Will create a control using reflection, corresponding to the object passed it. In order for the control to be recognized
        /// it must take as a constructor paramterer the type passed in.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="allowComponentBaseTypes">This indicates whether the search for corresponding control should also cover parent types of the given type</param>
        /// <returns></returns>
        static public CommonBaseControl CreateCorrespondingControl(object component, bool allowComponentBaseTypes)
        {
            Type componentType = component.GetType();
            ListUnique <Assembly> assemblies = ReflectionHelper.GetReferencedAndInitialAssembly(Assembly.GetEntryAssembly());

            assemblies.Add(Assembly.GetAssembly(componentType));
            List <Type> types = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(CommonBaseControl), true, false, assemblies, new Type[] { componentType });

            if (types.Count == 0 && allowComponentBaseTypes)
            {
                while (componentType != typeof(object) && types.Count == 0)
                {
                    componentType = componentType.BaseType;
                    types         = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(CommonBaseControl), true, false, assemblies, new Type[] { componentType });
                }
            }

            if (types.Count == 0)
            {// Type not found.
                return(null);
            }

            string typesNames = string.Empty;

            if (types.Count > 1)
            {
                foreach (Type type in types)
                {
                    typesNames += type.Name + "();";
                }

                SystemMonitor.CheckWarning(types.Count == 1, "More than 1 control found for this type [" + component.GetType().Name + "][" + typesNames + "] of component, creating the first one.");
            }

            // Return the first proper object.
            CommonBaseControl control = (CommonBaseControl)types[0].GetConstructor(new Type[] { componentType }).Invoke(new object[] { component });

            control.Tag = component;
            return(control);
        }
Пример #9
0
 public virtual bool AddSlaveControl(ITimeControl control)
 {
     lock (_slaveControls) { return(_slaveControls.Add(control)); }
 }