private HitTestInfo GetUpdatedLocation(HitTestInfo location)
        {
            int lockedActivityOffset = 0;
            foreach (DesignerView secondaryView in Views)
            {
                if (secondaryView.AssociatedDesigner != null &&
                    this != secondaryView.AssociatedDesigner &&
                    Helpers.IsActivityLocked(secondaryView.AssociatedDesigner.Activity))
                {
                    lockedActivityOffset++;
                }
            }

            return new ConnectorHitTestInfo(this, location.HitLocation, lockedActivityOffset + location.MapToIndex());
        }
        /// <summary>
        /// Inserts activity at specified location within designer
        /// </summary>
        /// <param name="insertLocation">Location at which to insert activities</param>
        /// <param name="activitiesToInsert">Array of activities to insert</param>
        public virtual void InsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert)
        {
            if (insertLocation == null)
                throw new ArgumentNullException("insertLocation");

            if (activitiesToInsert == null)
                throw new ArgumentNullException("activitiesToInsert");

            CompositeActivity compositeActivity = Activity as CompositeActivity;
            if (compositeActivity == null)
                throw new Exception(SR.GetString(SR.Error_DragDropInvalid));

            int index = insertLocation.MapToIndex();

            IIdentifierCreationService identifierCreationService = GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService;
            if (identifierCreationService != null)
                identifierCreationService.EnsureUniqueIdentifiers(compositeActivity, activitiesToInsert);
            else
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName));

            foreach (Activity activity in activitiesToInsert)
            {
                if (activity == null)
                    throw new ArgumentException("activitiesToInsert", SR.GetString(SR.Error_CollectionHasNullEntry));

                if (activity.Parent == null)
                {
                    compositeActivity.Activities.Insert(index++, activity);
                    WorkflowDesignerLoader.AddActivityToDesigner(Activity.Site, activity);
                }
            }

            // filter out unsupported Dependency properties
            foreach (Activity activity in activitiesToInsert)
            {
                Walker walker = new Walker();
                walker.FoundActivity += delegate(Walker w, WalkerEventArgs walkerEventArgs)
                {
                    ExtenderHelpers.FilterDependencyProperties(this.Activity.Site, walkerEventArgs.CurrentActivity);
                };
                walker.Walk(activity);
            }

        }
        /// <summary>
        /// Moves activities from one designer to other
        /// </summary>
        /// <param name="moveLocation">Location at which to move the activities</param>
        /// <param name="activitiesToMove">Array of activities to move</param>
        public virtual void MoveActivities(HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove)
        {
            if (moveLocation == null)
                throw new ArgumentNullException("moveLocation");

            if (activitiesToMove == null)
                throw new ArgumentNullException("activitiesToMove");

            //Make sure that we get the composite activity
            CompositeActivity compositeActivity = Activity as CompositeActivity;
            if (compositeActivity == null)
                throw new Exception(SR.GetString(SR.Error_DragDropInvalid));

            IIdentifierCreationService identifierCreationService = GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService;
            if (identifierCreationService == null)
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName));

            IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
            if (designerHost == null)
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName));

            int index = moveLocation.MapToIndex();
            foreach (Activity activity in activitiesToMove)
            {
                ActivityDesigner designer = ActivityDesigner.GetDesigner(activity);
                if (designer != null)
                {
                    CompositeActivityDesigner parentDesigner = designer.ParentDesigner;
                    if (parentDesigner == this)
                    {
                        int originalIndex = compositeActivity.Activities.IndexOf(activity);
                        if (index > originalIndex)
                            index--;
                    }
                }

                //In some cases we might get activities which are added newly, in such cases we check if the activity
                //is existing activity or new one based on this decision we add it to the designer host.
                Debug.Assert(activity.Parent != null);
                CompositeActivity parentActivity = activity.Parent;
                int positionInParent = parentActivity.Activities.IndexOf(activity);
                activity.Parent.Activities.Remove(activity);

                //We need to make sure that the activity is going to have unique identifier
                //This might just cause problems
                identifierCreationService.EnsureUniqueIdentifiers(compositeActivity, new Activity[] { activity });

                //We do not need to read the activity in the designer host as this is move operation
                //assign unique temporary name to avoid conflicts 
                DesignerHelpers.UpdateSiteName(activity, "_activityonthemove_");
                CompositeActivity compositeActivityMoved = activity as CompositeActivity;
                if (compositeActivityMoved != null)
                {
                    int i = 1;
                    foreach (Activity nestedActivity in Helpers.GetNestedActivities(compositeActivityMoved))
                    {
                        DesignerHelpers.UpdateSiteName(nestedActivity, "_activityonthemove_" + i.ToString(CultureInfo.InvariantCulture));
                        i += 1;
                    }
                }

                try
                {
                    compositeActivity.Activities.Insert(index++, activity);
                }
                catch (Exception ex)
                {
                    // reconnect the activity
                    parentActivity.Activities.Insert(positionInParent, activity);

                    //

                    throw ex;
                }

                DesignerHelpers.UpdateSiteName(activity, activity.Name);
                if (compositeActivityMoved != null)
                {
                    foreach (Activity nestedActivity in Helpers.GetNestedActivities(compositeActivityMoved))
                        DesignerHelpers.UpdateSiteName(nestedActivity, nestedActivity.Name);
                }
            }

            // filter out unsupported Dependency properties and refresh propertyDescriptors
            foreach (Activity activity in activitiesToMove)
            {
                Walker walker = new Walker();
                walker.FoundActivity += delegate(Walker w, WalkerEventArgs walkerEventArgs)
                {
                    ExtenderHelpers.FilterDependencyProperties(this.Activity.Site, walkerEventArgs.CurrentActivity);
                    TypeDescriptor.Refresh(walkerEventArgs.CurrentActivity);
                };
                walker.Walk(activity);
            }
        }
Exemple #4
0
        private HitTestInfo GetUpdatedLocation(HitTestInfo location)
        {
            int lockedActivityOffset = 0;

            foreach (DesignerView secondaryView in Views)
            {
                if (secondaryView.AssociatedDesigner != null &&
                    this != secondaryView.AssociatedDesigner &&
                    Helpers.IsActivityLocked(secondaryView.AssociatedDesigner.Activity))
                {
                    lockedActivityOffset++;
                }
            }

            return(new ConnectorHitTestInfo(this, location.HitLocation, lockedActivityOffset + location.MapToIndex()));
        }