AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
CRM
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.05.2014, 10:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
littleax: Part2. Dynamics ax 2012. Split construct method by models.
Источник: http://littleax.blogspot.com/2014/05...method_26.html
==============

Split construct method by models. Part2.

Last time we try to resolve problem with separate construct method by model in one layer using new future in ax delegate and event handler.
At this article try to resolve this problem using another way.
This way was got from Unit testing (source Classes\SysTestCase\testMethods + Classes\SysTest\invoke - try to find methods from object for specific mask), and now in AX 2012 we can find very similar way using name conversational in financial dimension (\Classes\DimensionEnabledType\getSystemDefinedDimensionsServer - try to find Views by name consist of specific mask). Lets try use this way.
From previous topic we have next conditions
  • TestBaseClass - in model A01
  • TestBaseClass01_Model01 in model A01
  • TestBaseClass02_Model02 in model A02
We need write construct method, and this method must work when we try transfer model A01 to another application.

in TestBaseClass (model A01) we create new static method constructFromCode()
X++:
public static TestBaseClass constructFromCode(SalesTable _salesTable)
{
       #define.codeConstructor('codeConstructor')

       TestBaseClass       ret;

       SysDictClass        sysDictClass = new SysDictClass(classNum(TestBaseClass));
       DictMethod          method = null;
       Set                 methods;
       SetEnumerator       se;
       Set                 orderedSet = new Set(Types::String);
       ExecutePermission   executePermission;
       ;
       // source Classes\SysTestCase\testMethods
       methods = sysDictClass.methods(false, true, false);
       se = methods.getEnumerator();
       while (se.moveNext())
       {
              method = se.current();
              if (method
               && method.accessSpecifier()    == AccessSpecifier::public
               && method.returnType()         != Types::void
               && method.parameterCnt()       == 1)
              {
                     if (strStartsWith(method.name(), #codeConstructor))
                     {
                            orderedSet.add(method.name());
                     }
              }         // if methods
       } // while

       // part 2 - split init call
       // source \Classes\SysTest\invoke
       executePermission = new ExecutePermission();
       executePermission.assert();

       se = orderedSet.getEnumerator();
       while (se.moveNext())
       {
              // part 2.1 call methods
              ret = sysDictClass.callStatic(se.current(), _salesTable);
              if (ret)
                     break;
     }
       CodeAccessPermission::revertAssert();
       // init default value
       if (!ret)
       {
              ret = new TestBaseClass();
       }
       ret.parmSalesTable(_salesTable);
       return ret;
}
next we need create 2 additional methods in TestBaseClass
codeConstructorClass01_M01 in A01 model
X++:
public static TestBaseClass codeConstructorClass01_M01(SalesTable _salesTable)
{
       TestBaseClass01_Model01 testBaseClass01_Model01 = TestBaseClass01_Model01::construct();
       if (testBaseClass01_Model01.findDetermination(_salesTable))
           return testBaseClass01_Model01;
       return null;
}
and codeConstructorClass02_M02 in A02 model
X++:
public static TestBaseClass codeConstructorClass02_M03(SalesTable _salesTable)
{
       TestBaseClass02_Model02 testBaseClass02_Model02 = TestBaseClass02_Model02::construct();
       if (testBaseClass02_Model02.findDetermination(_salesTable))
           return testBaseClass02_Model02;
       return null;
}
let's create and run a job to check our implementation
X++:
[COLOR=blue]static void TestBaseClass2(Args _args)
{
        SalesTable                      salesTable;         // cursor
        TestBaseClass                   baseClass;

        setPrefix("SalesInfo2");
        while select salesTable
        {
                baseClass = TestBaseClass::constructFromCode(salesTable);
                baseClass.showInfo();
        }
        info("done");
}
and results of working


Results


Summary: we can use various way to create construct method without depends from models and layers.



Источник: http://littleax.blogspot.com/2014/05...method_26.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Последний раз редактировалось mazzy; 28.05.2014 в 13:21.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 16 Blog bot Dynamics CRM: Blogs 0 23.01.2014 03:15
DAX: A Shift to Effective Demand Forecasting With Microsoft Dynamics AX 2012 R3 Blog bot DAX Blogs 0 16.11.2013 02:13
ax-erp: Debug::assert() method calls in SYS layer triggering Dynamics AX 2012 debugger Blog bot DAX Blogs 0 10.12.2012 21:11
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 10 Blog bot Dynamics CRM: Blogs 0 17.08.2012 03:27
dynamics-ax: Modeling the world, with Microsoft Dynamics AX 2012 Blog bot DAX Blogs 0 25.01.2011 09:11

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 22:46.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.