locked
Convert user input into ToString() method inside FlowDocument RRS feed

  • Question

  • I have a Workflow 4.0 app that generates emails. In a dialog for creating the email body the user needs to be able to input some string value representing an existing wf instance variable to be inserted as a string at runtime.

    So they input something like: Email body text including <ExistingEmail>.

    (say ExistingVariable is an int or something like that)

    Any helpful hints for how to convert this text with a ToString() at runtime?


    Those who beat their swords into plowshares will eventually plow the fields of those who didn't.
    Tuesday, June 8, 2010 5:18 PM

Answers

  • Perhaps you could use .NET reflection to stringify runtime variables.

     

     

    Tuesday, June 15, 2010 6:26 PM

All replies

  • First a question - Do you really want to also give them the ability to access every workflow variable you might have in your workflow, such as message timeout etc?

    There are difficulties in that workflow gurus didn't provide API to access arbitrary workflow variables from just any activity. Activities can only access either whatever is passed in as an InArgument, or the variables/arguments of their parent IF they are an implementation child. VB expressions seem to cheat that somehow. Dynamically generating VB expressions (to use their cheating powers) doesn't work either.

    With that in mind I have no good solution but you could pass in a single InArgument to your custom activity called e.g. 'MailParameters'. And MailParameters itself should be a class or dictionary which holds every possible parameter someone might want to use.

    Tim

    Tuesday, June 8, 2010 9:40 PM
  • It's a solid point I agree. However, this is one of those "I was told to do it this way" situations. I tried twice to allow for myself to define the variables being input and it was politely shot down. Thanks for the feedback though. =)
    Those who beat their swords into plowshares will eventually plow the fields of those who didn't.
    Wednesday, June 9, 2010 5:45 AM
  • Hi, Jonathan

    Besides using InArgument, we can also use bookmark activities to pass objects into workflow from the outside(host).
    For example, create a generic bookmark activity: InputActivity<T>:

        public sealed class InputActivity<T> : NativeActivity {
            public InArgument<string> bookmarkName { get; set; }
            public OutArgument<T> result { get; set; }
            protected override void Execute(NativeActivityContext context) {     
                context.CreateBookmark(bookmarkName.Get(context),new BookmarkCallback(OnResumeBookmark));
            }
            public void OnResumeBookmark(NativeActivityContext context,
                                         Bookmark              bookmark,
                                         object                obj) {
                result.Set(context, (T)obj);
            }
            protected override bool CanInduceIdle {
                get { return true; }
            }
        }

    A workflow:
                 WriteLine Activity
                             |
                 InputActivity<EMail>
                             |
                 WriteLine Activity
    Host:
        Email email=new Email();
        //Assign values to email object
        WorkflowApplication wfApp=new WorkflowApplication(workflowInstance);
        wfApp.Run();
        wfApp.ResumeBookmark("bookmarkName",email);// by this statement, we pass the email object into the workflow

    Hope this helps
    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
    Monday, June 14, 2010 6:33 AM
  • Perhaps you could use .NET reflection to stringify runtime variables.

     

     

    Tuesday, June 15, 2010 6:26 PM
  • This was indeed the correct path. I was able to set a PropertyDescriptorCollection equal to the DataContext properties and extract the values from that. Thanks, cheers!
    Those who beat their swords into plowshares will eventually plow the fields of those who didn't.
    Thursday, June 17, 2010 3:57 AM