locked
Questions about Activities, scenario in WF RRS feed

  • Question

  • My project is a DMS, in which I used the following tools for buliding it: WF, WCF service to access the DB I've rehosted the workflow designer. I'm buliding the activities and hosting them to make the user able to use drag and drop, making a workflow in the rehosted workflow designer.

     

    The scenario that I want has 3 activites: 

    1- Choose_Draft_Document

    2- Waiting_The_Approve

    3- The_Document_Published

     

    My problems are:

    1- The second activity is as follows:

     

        Service1Client SC = new Service1Client();

        protected override void Execute(NativeActivityContext context)

        {

            context.CreateBookmark("samename", new BookmarkCallback(OnBookmarkCallback));

        }

     

        protected override bool CanInduceIdle

        {

            get

            {

                return true;

            }

        }

     

        void OnBookmarkCallback(NativeActivityContext context, Bookmark bookmark, object val)

        {

            Guid g_id = MainPage.wa.Id;

            string WF_ID = MainPage.wa.Id.ToString();

     

            bool approve=SC.Get_The_Approval("Rizk",55, "4");

            If (approve == true)

                            SC.change_The_state(WF_ID);                        

    ///////////

     

    In the Run Button inside The main page:

     

                    var writer = new StringWriter();

                    var workflow = ActivityXamlServices.Load(_fileName);                    

                    wa = new WorkflowApplication(workflow);                    

                    Service1Client ser = new Service1Client();

                    wa.Extensions.Add(writer);

                    wa.Completed = WorkflowCompleted;

                    wa.OnUnhandledException = WorkflowUnhandledException;

                    //for bookmark

                    AutoResetEvent syncEvent = new AutoResetEvent(false);

                    wa.Completed = delegate(WorkflowApplicationCompletedEventArgs r)

                    {

                        syncEvent.Set();

                    };

                    Guid g_id;

                    g_id = wa.Id;

                    string WF_ID = wa.Id.ToString();

                    ser.Fill_WF_ID(WF_ID);

                    wa.Run();

     

                    wa.ResumeBookmark("samename", 3);                   

                    syncEvent.WaitOne();                    

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.Message);

                }

    ////// 1-a: I wrote wa.ResumeBookmark("samename", 3); in Main for all the bookmarks, because how can I know the the bookmark name and the specific value for an activity, since now the end user can make hundreds of workflows(XAML files)?

     

    1-b: The idea is: I want the waiting for approval to become true, then I can move the document to another activity and change its state = "published" So, How can I make the bookmark which is stopping the workflow till the approval value changes to True?, or if I want it just waiting for a specific length of time, how should it be done? I tried alot, but context.CreateBookmark("samename", new BookmarkCallback(OnBookmarkCallback),BookmarkOptions.MultipleResume); then I put in the OnBookmarkCallback method

     

            if (approve == true)

            {

                context.RemoveBookmark("samename");

            }

    but it needed another resume which I don't know where I've to put it!

     

    2- When I debugged the program for many times, I found the Resume method had called before the CreatBookmark, It does not make sense! then syncEvent.WaitOne(); and the last one BookmarkCallback()

     

    3- When I want to pass the arguments between these activities in a actvity.xaml, I need to make variables and insert thier values in the designer mode, but the end user can't do this! so I replaced the idea with reading all data from table in DB by WF_ID. but still not that comfortable, is there another way ?

     

    Thank you, and I really need help!

    Sunday, August 28, 2011 9:42 AM

Answers

  • Hi,

     

    Dont write

    wa.ResumeBookmark("samename", 3);          

    in your main function .  Just run your worklow . when your custom actvity will create bookmark. the workflow will be persisted.

    when your are creating bookmark , save your workflowGuid and unique bookmark name in DB or any place you want to.

    Now to resume your workflow you can launch another thread from your main function . or write a separate prgrom . which will continuously ping tha DB to check if value of your particuler property is true or not . if yes . pick name of the bookmark from the table you have saved while creatiing the bookmark.

    now resume the bookmark with the correct name.

     

    Hope this will help.

     

    Thanks,

    Madhur


    MB
    • Proposed as answer by MadhurBhardwaj Thursday, September 1, 2011 11:11 AM
    • Marked as answer by Andrew_Zhu Monday, September 5, 2011 1:13 AM
    Thursday, September 1, 2011 11:11 AM

All replies

  • Hi,

    1-a: You can define an InArgument in your second activity to receive bookmark name.

    1-b: Can you resume the bookmark when approval becomes to true or after waiting for a specific length of time in main page?

    2: You can run "wa.GetBookmarks()", if the bookmark has been created then resume the bookmark.

    3.Is there any reason you can't define the variables beforehand?

    Bookmarks

    http://msdn.microsoft.com/en-us/library/dd489442.aspx#Y518

    hope this helps.

    Thursday, September 1, 2011 9:29 AM
  • Hi,

     

    Dont write

    wa.ResumeBookmark("samename", 3);          

    in your main function .  Just run your worklow . when your custom actvity will create bookmark. the workflow will be persisted.

    when your are creating bookmark , save your workflowGuid and unique bookmark name in DB or any place you want to.

    Now to resume your workflow you can launch another thread from your main function . or write a separate prgrom . which will continuously ping tha DB to check if value of your particuler property is true or not . if yes . pick name of the bookmark from the table you have saved while creatiing the bookmark.

    now resume the bookmark with the correct name.

     

    Hope this will help.

     

    Thanks,

    Madhur


    MB
    • Proposed as answer by MadhurBhardwaj Thursday, September 1, 2011 11:11 AM
    • Marked as answer by Andrew_Zhu Monday, September 5, 2011 1:13 AM
    Thursday, September 1, 2011 11:11 AM