internal IEnumerable <ModelItem> GetItemsOnDesigner(bool preOrder, bool excludeRoot, bool excludeErrorActivity, bool excludeExpression, bool includeOtherObjects)
        {
            WorkflowViewService viewService = this.WorkflowViewService;
            IList <ModelItem>   items       =
                ModelTreeManager.DepthFirstSearch(modelService.Root,
                                                  delegate(Type type)
            {
                // Only find items on the designer surface.
                return(includeOtherObjects || (typeof(WorkflowViewElement).IsAssignableFrom(viewService.GetDesignerType(type))));
            },
                                                  delegate(ModelItem modelItem)
            {
                return(!(excludeExpression && modelItem != null && typeof(ITextExpression).IsAssignableFrom(modelItem.ItemType)));
            },
                                                  preOrder);

            // ModelItemKeyValuePair is associated with CaseDesigner.
            // So ModelItemKeyValuePair will be returned even if they are not really Cases.
            // Those ModelItemKeyValuePairs need to be excluded.
            IEnumerable <ModelItem> itemsToSearch = null;

            if (!excludeErrorActivity)
            {
                itemsToSearch = items.Where <ModelItem>(item => !ModelUtilities.IsModelItemKeyValuePair(item.ItemType) ||
                                                        ModelUtilities.IsSwitchCase(item));
            }
            else
            {
                itemsToSearch = items.Where <ModelItem>(item =>
                                                        (!ModelUtilities.IsModelItemKeyValuePair(item.ItemType) || ModelUtilities.IsSwitchCase(item)) &&
                                                        !IsErrorActivity(item));
            }
            if (excludeRoot)
            {
                itemsToSearch = itemsToSearch.Except <ModelItem>(new ModelItem[] { modelService.Root });
            }
            return(itemsToSearch);
        }