none
How to force to get IValidationErrorService updated? RRS feed

  • Question

  • How to force it to update? It seems that it does not get automatically updated when loading a file. My case is something like this

     

               _designer = new WorkflowDesigner();

                //set up validation service
                _validationService = new ValidationErrorService();
                _designer.Context.Services.Publish<IValidationErrorService>(_validationService);

                _designer.Load(_file);
                bool b = _validationService.IsValid;

    the variable b is false (eventhough the loaded workflow is valid). Only a while after that IsValid gets changed to true (I don't know what triggers it). How can I get the validationService validated instantaneously?

     


    Wednesday, July 27, 2011 3:50 AM

All replies

  • Any suggestion?
    Thursday, July 28, 2011 12:45 AM
  • If it is not possible, how do I know if that value is ready (as opposed to the original false)?
    Friday, July 29, 2011 2:28 AM
  • Hi, Louis

    Is this IsValid property defined by yourself? this article could be helpful to you:
    http://msmvps.com/blogs/theproblemsolver/archive/2009/12/23/rehosting-the-workflow-designer-in-wf4.aspx

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Tuesday, August 2, 2011 3:01 AM
    Moderator
  • Hi Louis,

    The IValidationErrorService is called to output the error when a validation completes and errors are found. Usually every model change could trigger a validation. To manually trigger a validation, you could get the ValidationService from Context.Services and call validationService.ValidateWorkflow().

    Thanks,

    Tony

    Tuesday, August 2, 2011 9:05 AM
  • @Andrew: Yes, I defined my own Validation service. It works like this

    public void ShowValidationErrors(IList<ValidationErrorInfo> errors)
            {
                if (errors.Count > 0) IsValid = false;
                else IsValid = true;
            }

    That's how IsValid gets updated.

    I tried doing what Tony proposed, calling validationService.ValidateWorkflow() before checking IsValid, but it seems that ShowValidationError still did not get called, so IsValid is still false. Did I do something wrong? How to make it work?

     


    Thursday, August 4, 2011 2:35 AM
  • Hi, Louis

    ->I tried doing what Tony proposed, calling validationService.ValidateWorkflow() before checking IsValid, but it seems that ShowValidationError still did not get called"
    It is no need to call ShowValiadationError method manually, if Workflow Designer detects any error, then this method will be invoked.
    Please note that you need to add the follow code below that code that load/create new workflows

              //this must be used after the workflow file is created or loaded. 
                ValidationErrorService validationService = new ValidationErrorService(errorList);
                this.wd.Context.Services.Publish<IValidationErrorService>(validationService);

    Regards

     

     


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Thursday, August 4, 2011 3:00 AM
    Moderator
  • _designer = new WorkflowDesigner();
    _designer.Load(_file);
     //set up validation service
    _validationService = new ValidationErrorService();
    _designer.Context.Services.Publish<IValidationErrorService>(_validationService);
     _designer.Context.Services.GetService<ValidationService>().ValidateWorkflow();
    bool b = _validationService.IsValid;
    

    The above code still doesn't work. THe ShowValidationError still did not get called before the last line (where I check for error)
    Thursday, August 4, 2011 6:26 AM
  • Hi, Louis

    ->"The above code still doesn't work. THe ShowValidationError still did not get called before the last line (where I check for error)"
    You'd not check error like this. for example, you create a ValidationErrorService

        public class ValidationErrorService : IValidationErrorService {
            private IList errorList; 
            public ValidationErrorService(IList errorList) { 
                this.errorList = errorList; 
            }   
     
            public void ShowValidationErrors(IList<ValidationErrorInfo> errors) { 
                errorList.Clear(); 
                foreach (var error in errors) {         
                    errorList.Add(error.Message);
                    Console.WriteLine("error:" + error.Message);
                } 
            }
        }

    Using it by calling the code we mentioned above:

                ValidationErrorService validationService = new ValidationErrorService(errorList);
                this.wd.Context.Services.Publish<IValidationErrorService>(validationService);

    Now, when there are any errors in the workflow designer. errorList will recode the errors. you can check error by:

                if (errorList.Count > 0) {
                    //...
                }

    Hope this helps
    Regards

     

     

     


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Thursday, August 4, 2011 7:02 AM
    Moderator
  • Ok, I changed it to this

     

    _designer = new WorkflowDesigner();
    _designer.Load(_file);
    
    IList error = new List<object>();
    _validationService = new ValidationErrorService(error);
    _designer.Context.Services.Publish<IValidationErrorService>(_validationService);
    _designer.Context.Services.GetService<ValidationService>().ValidateWorkflow();
    bool b = (error.Count == 0);
    

     

    Using your implementation of ShowValidationErrors

    The same problem exist,

    bool b = (error.Count == 0);
    

    gets called before ShowValidationErrors gets called. So my check will still return true (error.Count==0) when I load an error-containing workflow

    Thursday, August 4, 2011 7:15 AM
  • Hi,

    You can define IList error in the class scope so that all methods in this class can access to error list.
    When workflow designer detects errors, list will be updated in the ShwoValidationErrors method. so that you can get the error.Count and check error in other events.

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Thursday, August 4, 2011 8:13 AM
    Moderator
  • Yes. that's true. But in my case, I want to start getting the valid status as soon as possible after it is initialised.
    Thursday, August 4, 2011 10:26 AM
  • Hi, Louis

    ->" I want to start getting the valid status as soon as possible after it is initialised."
    When Workflow is loaded up, ShowValidationErrors will be called too. how about write code inside the ShowValidationErrors, for example, show up a Dailog to tell user the error info.

            public void ShowValidationErrors(IList<ValidationErrorInfo> errors) { 
                errorList.Clear(); 
                foreach (var error in errors) {         
                    errorList.Add(error.Message);
                    
                    //Write code here
                }
            }

    Regards


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Friday, August 5, 2011 2:52 AM
    Moderator
  • Indeed, it will be called, and indeed if I write a message box there, it will show the error to the user.

    But what I want is to programmatically know that after initialization.

    _designer = new WorkflowDesigner();
    _designer.Load(_file);
    
    IList error = new List<object>();
    _validationService = new ValidationErrorService(error);
    _designer.Context.Services.Publish<IValidationErrorService>(_validationService);
    _designer.Context.Services.GetService<ValidationService>().ValidateWorkflow();
    bool b = (error.Count == 0);
    
    //I want to do some stuff here 
    //based on whether b is true (workflow is valid) or false


     


    Friday, August 5, 2011 7:03 AM
  • Hi Louis,

    The validation logic will be run when Application is idle, so you can't assume the valiation is completed and IValidationErrorService is called just after designer is loaded. I suggest you put your logic inside your IValidationErrorService.ShowValidationErrors() method.

    Thanks,

    Tony

    • Proposed as answer by Tony Tang Thursday, August 11, 2011 7:00 AM
    Monday, August 8, 2011 2:06 AM