Показать сообщение отдельно
Старый 06.01.2017, 11:12   #1  
Blog bot is offline
Blog bot
24,154 / 809 (75) +++++++
Регистрация: 28.10.2006
palleagermark: Authoring Best Practice checks that use XML based input
Источник: http://www.agermark.com/2017/01/auth...-that-use.html

In AX7 you can pretty easily write and deploy your own Best Practice checks. The process of doing so, is described in this article on the wiki.

Some of the standard Best Practice checks use XML files as input. These XML files are found under your local packages folder, in ..\PackagesLocalDirectory\Bin\BPExtensions\RuleXml

The following is an example of how you can write your own Best Practice check that uses an XML file as input. The check itself is used to check the naming of table extensions. We want to check that a certain prefix is part of the name, and that it is put in the correct place in the overall name. The prefix to look for is specified in the XML file.

The XML file looks like this:

The file is stored in ..\PackagesLocalDirectory\Bin\BPExtensions\RuleXml and the name is MVPProductPrefix.xml. The name is important, as a reference is made to it from the code.

Your Best Practice class needs to extend either DetectorWithXMLDataFile or MetadataDetectorWithXMLDataFile depending on the type of your check. In this case we extend MetadataDetectorWithXMLDataFile since we will be looking at table extension names.

Included in your solution your need to add a data contract class for the XML file. This class must extend from RulePatternsBase.
The framework and the base classes will then do the rest of the work with loading the XML file, de-serialize it and caching it.

Here is the code:

And here is the code for the diagnostic item:

I'd like to thank Joris de Gruyter for helpful hints on how to solve this. And .NET Reflector has been a great tool to look into the standard Best Practice dll's to figure out how they work (Microsoft MVPs get a free license for .NET Reflector from Redgate).

Источник: http://www.agermark.com/2017/01/auth...-that-use.html
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.