Exemplo n.º 1
0
        private static Activity CloneRootActivity(Activity originalRootActivity)
        {
            // create new definition root
            string           xomlText           = originalRootActivity.GetValue(Activity.WorkflowXamlMarkupProperty) as string;
            string           rulesText          = null;
            Activity         clonedRootActivity = null;
            IServiceProvider serviceProvider    = originalRootActivity.GetValue(Activity.WorkflowRuntimeProperty) as IServiceProvider;

            Debug.Assert(serviceProvider != null);
            if (!string.IsNullOrEmpty(xomlText))
            {
                rulesText          = originalRootActivity.GetValue(Activity.WorkflowRulesMarkupProperty) as string;
                clonedRootActivity = Activity.OnResolveActivityDefinition(null, xomlText, rulesText, true, false, serviceProvider);
            }
            else
            {
                clonedRootActivity = Activity.OnResolveActivityDefinition(originalRootActivity.GetType(), null, null, true, false, serviceProvider);
            }

            if (clonedRootActivity == null)
            {
                throw new NullReferenceException(SR.GetString(SR.Error_InvalidRootForWorkflowChanges));
            }

            // deserialize change history and apply it to new definition tree
            ArrayList workflowChanges = (ArrayList)((Activity)originalRootActivity).GetValue(WorkflowChanges.WorkflowChangeActionsProperty);

            if (workflowChanges != null)
            {
                workflowChanges = CloneWorkflowChangeActions(workflowChanges, originalRootActivity);
                if (workflowChanges != null)
                {
                    // apply changes to the shared schedule Defn to get the instance specific copy
                    foreach (WorkflowChangeAction action in workflowChanges)
                    {
                        bool result = action.ApplyTo((Activity)clonedRootActivity);
                        Debug.Assert(result, "ApplyTo Failed");
                    }
                    ((Activity)clonedRootActivity).SetValue(WorkflowChanges.WorkflowChangeActionsProperty, workflowChanges);
                }
            }
            return(clonedRootActivity);
        }
Exemplo n.º 2
0
        private static Activity CloneRootActivity(Activity originalRootActivity)
        {
            string           str             = originalRootActivity.GetValue(Activity.WorkflowXamlMarkupProperty) as string;
            string           rulesMarkup     = null;
            Activity         rootActivity    = null;
            IServiceProvider serviceProvider = originalRootActivity.GetValue(Activity.WorkflowRuntimeProperty) as IServiceProvider;

            if (!string.IsNullOrEmpty(str))
            {
                rulesMarkup  = originalRootActivity.GetValue(Activity.WorkflowRulesMarkupProperty) as string;
                rootActivity = Activity.OnResolveActivityDefinition(null, str, rulesMarkup, true, false, serviceProvider);
            }
            else
            {
                rootActivity = Activity.OnResolveActivityDefinition(originalRootActivity.GetType(), null, null, true, false, serviceProvider);
            }
            if (rootActivity == null)
            {
                throw new NullReferenceException(SR.GetString("Error_InvalidRootForWorkflowChanges"));
            }
            ArrayList workflowChanges = (ArrayList)originalRootActivity.GetValue(WorkflowChangeActionsProperty);

            if (workflowChanges != null)
            {
                workflowChanges = CloneWorkflowChangeActions(workflowChanges, originalRootActivity);
                if (workflowChanges == null)
                {
                    return(rootActivity);
                }
                foreach (WorkflowChangeAction action in workflowChanges)
                {
                    action.ApplyTo(rootActivity);
                }
                rootActivity.SetValue(WorkflowChangeActionsProperty, workflowChanges);
            }
            return(rootActivity);
        }