1

Microsoft provides a Validate component as shown below, in the BizTalk Pipeline interface.

Here's what I tried, and didn't seem to work at all:

    public System.Collections.IEnumerator Validate(object projectSystem)
    {
        System.Collections.ArrayList errorStringArrayList = new System.Collections.ArrayList();
        if (this.Substring1ColumnStart >= this.Substring1ColumnEnd)
        {
            errorStringArrayList.Add("Substring1ColumnEnd must be > SubstringColumn1Start");
        }
        return (System.Collections.IEnumerator) errorStringArrayList; 
    }

This doc https://msdn.microsoft.com/en-us/library/microsoft.biztalk.component.interop.icomponentui.validate.aspx?f=255&MSPPError=-2147217396

says

"These error messages appear as compiler error messages. To report successful property validation, the method should return an empty enumerator. "

.

But I'm not getting any compiler messages when I put in invalid values. Also, wouldn't it also do the validation when in BTS-Admin, which would not have "compiler messages"???

Further, why does the Validate receive a generic object as a parm instead of a strongly typed parm? And when is validate called? Each time an propertyBag value is changed?

Update 5/11/2017 at 11:55 AM CT

I tried several more things, two hard to list them all here. I finally got an error, but not a very useful one in the VS compile errors, see screen shot below. It's definitely not the error I returned. Maybe this has an issue on VS2015.

enter image description here

I also got into an issue where I fixed my data, and was still getting the error. Since the Pipeline Componenet is GAC'ed, I was closing and re-opening Visual Studio each time to make sure it got the new copy.

I was thinking maybe that returning anything other than null was the issue. In summary, I have found this practically useless if it doesn't work in BTS-ADMIN. So I will just do run-time errors. Perhaps that's why there is such little documentation and few articles/blogs on this subject.

public System.Collections.IEnumerator Validate(object projectSystem)
{

    System.Collections.ArrayList errorStringArrayList = new System.Collections.ArrayList();
    if (this.Substring1ColumnStart >= this.Substring1ColumnEnd)
    {
        errorStringArrayList.Add("Substring1ColumnEnd must be > SubstringColumn1Start");
    }

    if (errorStringArrayList.Count > 0)
    {
        return (System.Collections.IEnumerator)errorStringArrayList;
    }
    else
    {
        return null; 
    }
}
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
NealWalters
  • 17,197
  • 42
  • 141
  • 251
  • I already answered this question at MSDN: https://social.msdn.microsoft.com/Forums/en-US/05cdf0ec-6e66-41c1-9faf-8f4ef6bb67f6/how-to-validate-value-in-the-propertybag-from-a-pipeline-component?forum=biztalkgeneral – Johns-305 May 11 '17 at 14:28

2 Answers2

2

This validate method is only called in pipeline design mode. It will not be called in BTS Admin. And if you set some invalid value in your "code". this method is also not called.

Zee
  • 830
  • 1
  • 9
  • 22
  • Thanks, so is there anyway to validate in BTSAdmin? Some other method, or just not possible? – NealWalters May 10 '17 at 18:47
  • And why don't I get the compile errors then in Visual Studio when I put a columnEnd that is < columnStart? – NealWalters May 10 '17 at 18:49
  • Not sure how your code implemented, but this is a sample of how Validate method works: In your project, if you create a sendpipeline, drag a XML assembler to its Assemble stage. Then let's say in its "Add PI text" property field, you input some invalid text such as "<>". When you try to compile, you will get error like this: error BTP0007: Component 'XML assembler' properties validation failed. The processing instructions text property must be compliant to the XML standard. – Zee May 10 '17 at 22:46
  • That's not happening, my code is above; that's why I posted this question here. But if it doesn't work in BTS-Admin, then I don't think it's worth spending any more time on. I'll just sadly do run time errors. – NealWalters May 11 '17 at 15:13
0

Same Answer from MSDN

[From memory, but I'm 93% sure this is how it works...]

Validate is called by Visual Studio at build time and perhaps after every Property assignment.

The project will not build if a non 0 collection is returned and the component on the design surface will have a red outline.

IIRC, you just validate the property values directly however you need to.  IPropertyBag.Write has already been called and you code there should have set the Properties.

Basically, if(MyComponent.MySpecialValue != "B") { ErrorStringArray.Add("Oh no!"); }

Johns-305
  • 10,908
  • 12
  • 21
  • As I reported on MSDN, it didn't work. Above is the actual code I tried, so this response really did help. – NealWalters May 11 '17 at 15:12
  • @NealWalters I don't understand the reason for the downvote. I just tested and my Answer is 100% correct with the contents of the ArrayList counting as Build Errors. So, I won't bother you any more on this. Apologies. – Johns-305 May 11 '17 at 15:33
  • Maybe if you post your entire validate routine; like I said, it didn't work for me. I originall posted the full routine with the exact code I tested. However, bottom line, if this validation doesn't work in BTS-ADMIN, which Zee reported below, I think it's not worth pursuing. I don't really care if it works in Visual Studio, but not BTS-Admin. – NealWalters May 11 '17 at 16:33
  • @NealWalters Sorry I tried to help you. I promise to not interfere in the future. – Johns-305 May 11 '17 at 17:09
  • Johns-305 - please don't be so sensitive.Help is always appreciated. – NealWalters May 15 '17 at 17:06