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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 13.06.2023, 03:49   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Complete pack/unpack pack for RunBaseBatch adventure
Источник: http://alexvoy.blogspot.com/2023/06/...-pack-for.html
==============

Usage

We can use pack-unpack methods in RunBaseBatch classes and all its descendants to save and/or store the state of an object, and then later re-instantiate the same object.

We need it, for example, to use the user's input for any batch job: some parameters can be used when a batch job is executed on the server.

Documentation

Microsoft doc article is here.

Quote: "A reinstantiated object is not the same object as the one that was saved. It is just an object of the same class whose members contain the same information."

You need to teleport your objects without a fly or other bugs.

Case examples

Basics

Basic example of such a class is Tutorial_RunbaseBatch.



TransDate transDate; CustAccount custAccount; #define.CurrentVersion(1) #localmacro.CurrentList transDate, custAccount #endmacro public container pack() { return [#CurrentVersion,#CurrentList]; } public boolean unpack(container packedClass) { Version version = RunBase::getVersion(packedClass); ; switch (version) { case #CurrentVersion: [version,#CurrentList] = packedClass; break; default: return false; } return true; }


Containers

Basically you can add a container directly to pack() or convert a container to a string and save the latter. Opposite conversion required for restoring.

container siteIds;str siteIdsStr;#define.CurrentVersion(1)#define.Version1(1)#localmacro.CurrentList siteIdsStr#endmacropublic boolean getFromDialog(){ ... // convert it to string for pack/unpack siteIdsStr = con2Str(siteIds); return super();}public void dialogPostRun(DialogRunbase _dialog){ FormRun formRun; super(dialog); formRun = _dialog.dialogForm().formRun(); if (formRun) { // if we restored from last values if(siteIdsStr) { //then we convert the string to container siteIds = str2con(siteIdsStr); } }}
See the following article for the complete usage https://alexvoy.blogspot.com/2014/11...le-choice.html

Tables

Save an unique key value, say, RecId to find a target buffer after unpack()

Collection types

Maps, lists, and sets are equipped with method pack, which you can use directly for packing.

// collections List list; Map map; Set set; // saved states container packedCont; packedCont = list.pack(); list = List::create(packedCont); packedCont = map.pack(); map = Map::create(packedCont); packedCont = set.pack(); set = Set::create(packedCont);
Queries

How to pack/unpack a query among other parameters, you can find in IntrastatTransfer class.



QueryRun queryRunIntrastatTransfer; container pack() { return [#CurrentVersion,#CurrentList,queryRunIntrastatTransfer.pack()]; } boolean unpack(container packedClass) { Integer version = conPeek(packedClass,1); container packedQuery; switch (version) { case #CurrentVersion: [version,#CurrentList,packedQuery] = packedClass; if (packedQuery) { queryRunIntrastatTransfer = new QueryRun(packedQuery); } break; default: return false; } return true; }


Subclasses

How to pack/unpack additional parameters in a subclass.

class myVendCreateGlobalPaymJournal extends CustVendCreatePaymJournal_Vend NoYes myParm; #define.CurrentVersion(1) #localmacro.CurrentList myParm #endmacro /// /// Pack the new parameters /// /// standard list of parameters with the new ones public container pack() { return [#CurrentVersion,#CurrentList] + [super()]; } /// /// Unpacks saved parameters /// /// Parameters container /// True if OK public boolean unpack(container _packedClass) { Integer version = conPeek(_packedClass,1); container packedBase; switch (version) { case #CurrentVersion: [version, #CurrentList, packedBase] = _packedClass; return super(packedBase); } return super(_packedClass); }
Extensions

How to pack/unpack additional parameters in an augmented class (extension).

/// /// We are going to use a new additional parameter/// [ExtensionOf(classStr())]public final class My_Extension{ private boolean myNewParm; #define.CurrentVersion(1) #localmacro.CurrentList myNewParm #endmacro /// /// myNewParm access /// /// boolean /// boolean public boolean parmMyNewParm(boolean _parm = myNewParm) { myNewParm= _parm; return myNewParm; } /// /// Extends Pack /// /// container public container pack() { container packedClass = next pack(); return SysPackExtensions::appendExtension(packedClass, classStr(My_Extension), this.myPack()); } /// /// Extends Unpack /// /// container /// boolean private boolean myUnpack(container packedClass) { Integer version = RunBase::getVersion(packedClass); switch (version) { case #CurrentVersion: [version, #currentList] = packedClass; break; default: return false; } return true; } /// /// Packs my locals /// /// container private container myPack() { return [#CurrentVersion, #CurrentList]; } /// /// Extends unpack /// /// container /// boolean public boolean unpack(container _packedClass) { boolean result = next unpack(_packedClass); if (result) { container myState = SysPackExtensions::findExtension(_packedClass, classStr(My_Extension)); //Also unpack the extension if (!this.myUnpack(myState)) { result = false; } } return result; }}
Originally from https://alexvoy.blogspot.com/2022/02...basebatch.html

Please, ping me if I missed anything.



Источник: http://alexvoy.blogspot.com/2023/06/...-pack-for.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
pack/unpack syl DAX: Программирование 2 11.06.2015 19:00
Malaysia: Pack and Unpack Blog bot DAX Blogs 0 01.11.2012 11:11
ax-erp: Pack-Unpack Design Pattern [AX 2012] Blog bot DAX Blogs 0 20.06.2012 22:11
Platform updates overview - 3.70.B - NAV2009 R2 Blog bot Dynamics CRM: Blogs 0 07.02.2011 22:06
Ошибка в методах unpack pack Arahnid DAX: Программирование 13 25.02.2009 00:50

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

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

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