locked
Custom Workflow Activity Designer Serialization Issues RRS feed

  • Question

  • I have an activity which has collection properties as below

     

        [Designer(typeof(TaskDesigner))]
        public sealed class TaskActivity : NativeActivity
        {
            public TaskActivity()
            {
                TaskParameters = new ObservableCollection<PMTaskParameter>();
                TaskExceptions = new ObservableCollection<Guid>();
            }
     
            public InArgument<Guid> WorkItemId { getset; }
            public OutArgument<ObservableCollection<PMTaskParameter>> ParameterValues { getset; }
            public OutArgument<PMTaskException> ExceptionValue { getset; }
            public OutArgument<bool> IsFaulted { getset; }
     
            public InArgument<Guid> DummyChangeReplicator { getset; }
     
            protected override bool CanInduceIdle { get { return true; } }
            protected override void Execute(NativeActivityContext context)
            {
                var Task = new PMTask();
                var server = new PMServer(ConfigurationManager.ConnectionStrings["upm4_db"].ConnectionString);
                Task.TaskID = Guid.NewGuid();
                Task.WorkItemID = WorkItemId.Get(context);
                Task.TaskExceptions = TaskExceptions.ToList();
                foreach (var parm in TaskParameters)
                {
                    parm.ParameterID = Guid.NewGuid();
                    parm.TaskID = Task.TaskID;
                    Task.Parameters.Add(parm);
                }
                server.Tasks.Attach(Task);
                server.SubmitChanges();
     
                //suspend workflow
                context.CreateBookmark(Task.TaskID.ToString(), new BookmarkCallback(OnResumeBookmark), BookmarkOptions.None);
            }
     
            private void OnResumeBookmark(NativeActivityContext context, Bookmark bookmark, object obj)
            {
                if (obj is ObservableCollection<PMTaskParameter>)
                {
                    IsFaulted.Set(context, false);
                    ParameterValues.Set(context, obj);
                }
                else if (obj is PMTaskException)
                {
                    IsFaulted.Set(context, true);
                    ExceptionValue.Set(context, obj);
                }
            }
     
            public ObservableCollection<PMTaskParameter> TaskParameters { getset; }
            public ObservableCollection<Guid> TaskExceptions { getset; }
    

     

    I have a custom activity designer that enables the user to add, remove and modify values using wpf controls. The problem is, after saving the xaml text from the designer the first time, subsequent saves after modifying the collections does not seem to serialize the custom activity, instead it returns the old text value.

    If I modify the ExpressionTextBox bound to the WorkItemId property, then the activity serializes including changes to the collections.

    How can I force the designer to serialize the custom activity whenever I save?

    Wednesday, April 6, 2011 6:23 PM

Answers

  • Hi Tolu,
    You are binding your WPF presentation to the ObservableCollections directly, and not going through a ModelItemCollection, is that right?
    Tim
    • Marked as answer by Tolu Thursday, April 7, 2011 11:06 AM
    Wednesday, April 6, 2011 7:20 PM

All replies

  • Hi Tolu,
    You are binding your WPF presentation to the ObservableCollections directly, and not going through a ModelItemCollection, is that right?
    Tim
    • Marked as answer by Tolu Thursday, April 7, 2011 11:06 AM
    Wednesday, April 6, 2011 7:20 PM
  • Hi Tim, yes that's right i'm binding directly using a viewmodel.


    Regards, Tolu Ogunremi Lagos, Nigeria
    Thursday, April 7, 2011 6:46 AM
  • Thanks Tim, i tried using the modelitem collection and it worked.

    Although, i think i ought to mention that the api is rather queer. But thanks a lot for responding.


    Regards, Tolu Ogunremi Lagos, Nigeria
    Thursday, April 7, 2011 11:05 AM
  • You probably figured this out now but what you're seeing is that the workflow designer detects changes to the underlying model and update the 'dirty' flag on the document - but only as long as you go through model tree.

    Another advantage of going through the model tree is that Undo and Redo works. :)

    Tim
    Thursday, April 7, 2011 4:20 PM