Ejemplo n.º 1
0
        protected void ApplyProperties(Namespace ns, Namespace newNamespace)
        {
            // Copy properties and commit the changes.

            ns.CopyProperties(newNamespace);
            ns.Commit();
        }
Ejemplo n.º 2
0
        private static void CopyElement(INamespaceParent parent, Namespace ns, bool iterate)
        {
            bool mergeEventStates = false;

            // Check whether the namespace already exists.

            Namespace thisNamespace = parent.Namespaces[ns.Name];

            if (thisNamespace == null)
            {
                // Doesn't exist so create new clone.

                thisNamespace = ns.CloneProperties(parent, ns.Name);
                parent.Namespaces.Add(thisNamespace);
            }
            else
            {
                if (thisNamespace.IsEnsured)
                {
                    // Already exists, so copy details if "ensured".
                    thisNamespace.CopyProperties(ns);
                }
                else
                {
                    // If "ns" has any children then the event states on "thisNamespace" need to be merged from
                    // "ns", since we may be adding sources.

                    mergeEventStates = (ns.Sources.Count > 0 || ns.Namespaces.Count > 0);
                }
            }

            string[] eventsToUpdate = null;
            if (mergeEventStates)
            {
                // The status of all events that are enabled or mixed on either target or source needs to be
                // merged. To do this first push the "enabled" status right down to the source level then,
                // after the children of the source namespace are added to this (target) namespace update
                // the event states on the namespace from the states of the children.

                eventsToUpdate = Util.AddRangeUnique(
                    Util.AddRangeUnique(thisNamespace.EnabledEventsInternal, thisNamespace.MixedEventsInternal),
                    Util.AddRangeUnique(ns.EnabledEventsInternal, ns.MixedEventsInternal));

                if (eventsToUpdate != null && eventsToUpdate.Length != 0)
                {
                    thisNamespace.PushAllEnabledEventsToChildren();
                    ns.PushAllEnabledEventsToChildren();
                }
            }

            // Iterate.

            if (iterate)
            {
                foreach (Source source in ns.Sources)
                {
                    CopyElement(thisNamespace, source);
                }
                foreach (Namespace childNamespace in ns.Namespaces)
                {
                    CopyElement(thisNamespace, childNamespace, true);
                }
            }

            if (mergeEventStates && eventsToUpdate != null && eventsToUpdate.Length > 0)
            {
                // Don't go up to the parent at all in this case - we're traversing from bottom up already.

                thisNamespace.UpdateEventStates(eventsToUpdate);
            }
        }