Пример #1
0
        private static void AddEventStatesForSources(ISourceParent parent, IEnumerable <string> eventsToCheck,
                                                     IList enabled, IList disabled, IList mixed, bool setFromFirstSource)
        {
            IEnumerator enumerator = parent.Sources.GetEnumerator();

            if (setFromFirstSource)
            {
                // When processing the first source just set our states from its states.

                if (enumerator.MoveNext())
                {
                    var source = (Source)enumerator.Current;
                    ReadOnlyStringList childEnabled = source.EnabledEvents;

                    foreach (string eventName in eventsToCheck)
                    {
                        if (childEnabled.Contains(eventName))
                        {
                            enabled.Add(eventName);
                        }
                        else
                        {
                            disabled.Add(eventName);
                        }
                    }
                }
            }

            while (enumerator.MoveNext())
            {
                // For subsequent children look for states that change our state for an event from enabled or
                // disabled to mixed. Once an event is in "mixed" state that won't change.

                var source = (Source)enumerator.Current;
                ReadOnlyStringList childEnabled = source.EnabledEvents;

                int index = 0;
                while (index < enabled.Count)
                {
                    var eventName = (string)enabled[index];
                    if (!childEnabled.Contains(eventName))
                    {
                        // This event was enabled for all children so far, but not for this one - now it's mixed.

                        enabled.RemoveAt(index);
                        mixed.Add(eventName);
                    }
                    else
                    {
                        index++;
                    }
                }

                index = 0;
                while (index < disabled.Count)
                {
                    var eventName = (string)disabled[index];
                    if (childEnabled.Contains(eventName))
                    {
                        // This event was disabled for all children so far, but not for this one - now it's mixed.

                        disabled.RemoveAt(index);
                        mixed.Add(eventName);
                    }
                    else
                    {
                        index++;
                    }
                }
            }
        }
Пример #2
0
        public static bool AddEventStatesForChildNamespaces(INamespaceParent parent, string[] eventsToCheck,
                                                            IList enabled, IList disabled, IList mixed)
        {
            IEnumerator enumerator = parent.Namespaces.GetEnumerator();

            if (enumerator.MoveNext())
            {
                // When processing the first namespace just set our states from its states.

                var childNs = (Namespace)enumerator.Current;
                ReadOnlyStringList childEnabled = childNs.EnabledEvents;
                ReadOnlyStringList childMixed   = childNs.MixedEvents;

                foreach (string eventName in eventsToCheck)
                {
                    if (childEnabled.Contains(eventName))
                    {
                        enabled.Add(eventName);
                    }
                    else if (childMixed.Contains(eventName))
                    {
                        mixed.Add(eventName);
                    }
                    else
                    {
                        disabled.Add(eventName);
                    }
                }
            }
            else
            {
                return(false);                // No namespaces to process.
            }
            while (enumerator.MoveNext())
            {
                // For subsequent children look for states that change our state for an event from enabled or
                // disabled to mixed. Once an event is in "mixed" state that won't change.

                var childNs = (Namespace)enumerator.Current;
                ReadOnlyStringList childEnabled = childNs.EnabledEvents;
                ReadOnlyStringList childMixed   = childNs.MixedEvents;

                int index = 0;
                while (index < enabled.Count)
                {
                    var eventName = (string)enabled[index];
                    if (!childEnabled.Contains(eventName))
                    {
                        // This event was enabled for all children so far, but not for this one - now it's mixed.

                        enabled.RemoveAt(index);
                        mixed.Add(eventName);
                    }
                    else
                    {
                        index++;
                    }
                }

                index = 0;
                while (index < disabled.Count)
                {
                    var eventName = (string)disabled[index];
                    if (childEnabled.Contains(eventName) || childMixed.Contains(eventName))
                    {
                        // This event was disabled for all children so far, but not for this one - now it's mixed.

                        disabled.RemoveAt(index);
                        mixed.Add(eventName);
                    }
                    else
                    {
                        index++;
                    }
                }
            }

            return(true);
        }