/// <summary>
        /// This method will ensure that the identifiers of the activities to be added to the parent activity
        /// are unique within the scope of the parent activity.
        /// </summary>
        /// <param name="parentActivity">THis activity is the parent activity which the child activities are being added</param>
        /// <param name="childActivities"></param>
        void IIdentifierCreationService.EnsureUniqueIdentifiers(CompositeActivity parentActivity, ICollection childActivities)
        {
            if (parentActivity == null)
            {
                throw new ArgumentNullException("parentActivity");
            }
            if (childActivities == null)
            {
                throw new ArgumentNullException("childActivities");
            }

            ArrayList allActivities = new ArrayList();

            Queue activities = new Queue(childActivities);

            while (activities.Count > 0)
            {
                Activity activity = (Activity)activities.Dequeue();
                if (activity is CompositeActivity)
                {
                    foreach (Activity child in ((CompositeActivity)activity).Activities)
                    {
                        activities.Enqueue(child);
                    }
                }

                //If we are moving activities, we need not regenerate their identifiers
                if (((IComponent)activity).Site != null)
                {
                    continue;
                }

                //If the activity is built-in, we won't generate a new ID.
                if (IsPreBuiltActivity(activity))
                {
                    continue;
                }

                allActivities.Add(activity);
            }

            // get the root activity
            CompositeActivity rootActivity = Helpers.GetRootActivity(parentActivity) as CompositeActivity;
            StringDictionary  identifiers  = new StringDictionary(); // all the identifiers in the workflow

            Type customActivityType = GetRootActivityType(this.serviceProvider);

            if (rootActivity != null)
            {
                foreach (string identifier in Helpers.GetIdentifiersInCompositeActivity(rootActivity))
                {
                    identifiers[identifier] = identifier;
                }
            }

            if (customActivityType != null)
            {
                foreach (MemberInfo member in customActivityType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
                {
                    Type memberType = null;
                    if (member is FieldInfo)
                    {
                        memberType = ((FieldInfo)member).FieldType;
                    }

                    if (memberType == null || !typeof(Activity).IsAssignableFrom(memberType))
                    {
                        identifiers[member.Name] = member.Name;
                    }
                }
            }

            // now loop until we find a identifier that hasn't been used
            foreach (Activity activity in allActivities)
            {
                int    index           = 0;
                string baseIdentifier  = Helpers.GetBaseIdentifier(activity);
                string finalIdentifier = null;

                if (string.IsNullOrEmpty(activity.Name) || string.Equals(activity.Name, activity.GetType().Name, StringComparison.Ordinal))
                {
                    finalIdentifier = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[] { baseIdentifier, ++index });
                }
                else
                {
                    finalIdentifier = activity.Name;
                }

                while (identifiers.ContainsKey(finalIdentifier))
                {
                    finalIdentifier = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[] { baseIdentifier, ++index });
                    if (this.Provider != null)
                    {
                        finalIdentifier = this.Provider.CreateValidIdentifier(finalIdentifier);
                    }
                }

                // add new identifier to collection
                identifiers[finalIdentifier] = finalIdentifier;
                activity.Name = finalIdentifier;
            }
        }
        void IIdentifierCreationService.EnsureUniqueIdentifiers(CompositeActivity parentActivity, ICollection childActivities)
        {
            if (parentActivity == null)
            {
                throw new ArgumentNullException("parentActivity");
            }
            if (childActivities == null)
            {
                throw new ArgumentNullException("childActivities");
            }
            ArrayList list  = new ArrayList();
            Queue     queue = new Queue(childActivities);

            while (queue.Count > 0)
            {
                Activity activity = (Activity)queue.Dequeue();
                if (activity is CompositeActivity)
                {
                    foreach (Activity activity2 in ((CompositeActivity)activity).Activities)
                    {
                        queue.Enqueue(activity2);
                    }
                }
                if ((activity.Site == null) && !IsPreBuiltActivity(activity))
                {
                    list.Add(activity);
                }
            }
            CompositeActivity rootActivity = Helpers.GetRootActivity(parentActivity) as CompositeActivity;
            StringDictionary  dictionary   = new StringDictionary();
            Type rootActivityType          = this.GetRootActivityType(this.serviceProvider);

            if (rootActivity != null)
            {
                foreach (string str in Helpers.GetIdentifiersInCompositeActivity(rootActivity))
                {
                    dictionary[str] = str;
                }
            }
            if (rootActivityType != null)
            {
                foreach (MemberInfo info in rootActivityType.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
                {
                    Type c = null;
                    if (info is FieldInfo)
                    {
                        c = ((FieldInfo)info).FieldType;
                    }
                    if ((c == null) || !typeof(Activity).IsAssignableFrom(c))
                    {
                        dictionary[info.Name] = info.Name;
                    }
                }
            }
            foreach (Activity activity4 in list)
            {
                int    num            = 0;
                string baseIdentifier = Helpers.GetBaseIdentifier(activity4);
                string key            = null;
                if (string.IsNullOrEmpty(activity4.Name) || string.Equals(activity4.Name, activity4.GetType().Name, StringComparison.Ordinal))
                {
                    key = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[] { baseIdentifier, ++num });
                }
                else
                {
                    key = activity4.Name;
                }
                while (dictionary.ContainsKey(key))
                {
                    key = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[] { baseIdentifier, ++num });
                    if (this.Provider != null)
                    {
                        key = this.Provider.CreateValidIdentifier(key);
                    }
                }
                dictionary[key] = key;
                activity4.Name  = key;
            }
        }