[AX]AX2012 启动时运行命令

先来讲讲在打开AX客户端时,自动运行一些命令。客户端程序ax32.exe在启动时按先后顺序调用以下方法:

appl.startup() // The SysStartupCmd class is instantiated here.
sysStartupCmd.applInit()
super(sysStartupCmd)
appl.startupPost()
sysStartupCmd.applRun()

info.startup() // The SysStartupCmd class is instantiated here.
sysStartupCmd.infoInit() 
super(sysStartupCmd) 
info.startupPost() 
sysStartupCmd.infoRun()

以前我们可能在info.startupPost()中直接调用要执行的方法,但是可以使用上面的SysStartupCmd类,系统根据传入的startupcmd参数在appl.startup()和info.startup()两处构建一个SysStartupCmd类的实例,并分别调用applInit()和infoInit()初始化实例,随后分别调用applRun()和infoRun()来执行相应的操作。传入的参数可以通过命令行来指定:

ax32.exe -startupcmd= MyCommand

还可以把“MyCommand”命令字符串直接填到客户端配置工具的“Command to run at application startup”一节。

SysStartupCmd实例的构建是在SysStartupCmd::construct(),在这里使用switch...case判断传入的命令参数,构建相应的SysStartupCmd子类的实例,比如命令“batch”,会初始化一个SysStartupCmdBatchRun的实例来运行。如果我们要实现自己的命令,可以从SysStartupCmd构建一个子类,再放到SysStartupCmd::construct(),通过判断传入的命令参数来初始化我们的这个命令实例。

在这里我们注意到一个处理“autorun”命令的子类SysStartupCmdAutoRun,它处理类似“AutoRun_c:\folder\filename.XML”这样的启动命令行,“_”后是该命令的参数,由它标识一个XML的配置文件,下面是一个XML配置文件的例子:

<?xml version=”1.0” ?>
<AxaptaAutoRun  
    exitWhenDone="false"  
    version="4.0"  
    logFile="D:\Axapta\AxaptaAutorun.log"> 
 <CompileApplication crossReference="false" />  
 <LicenseInformation file="d:\axapta\license.txt" />  
 <Configuration> 
    <ConfigurationKey name="SysUserLog" enabled="true" /> 
    <ConfigurationKey name="PBA_AdvancedProductBuilder"  
        enabled="false" /> 
 </Configuration> 
 <AdjustGlobalTypes> 
    <AccountNum length="24" adjustRight="false" /> 
    <AmountMst displayLength="12" decimals="10" /> 
 </AdjustGlobalTypes> 
 <Synchronize />  
 <UpdateCrossReference />  
 <UserGroups> 
    <UserGroup id="sales" name="Sales force" /> 
 </UserGroups> 
 <Users> 
  <User id="MaryN" 
      name="Mary North" 
      email="someone@example.com" 
      language="en-us" 
      companyId="ex" 
      osAccount="MaryN"/> 
 </Users>  
 <CompanyAccounts> 
     <Company id="NWT" name="Northwind Traders" overwrite="true" /> 
 </CompanyAccounts>  
 <XpoImport  
     file="d:\axapta\setup\XPO\Logger\Enum_TestLogEntryType.xpo" />  
 <DataImport companyId="BVT" file="d:\axapta\basedata.dat" />  
 <Run type="class" name="RunMyTests" method="main" />  
 <Run type="displayMenuItem" name="MyTestMenuItem"/>
 <PreventCheckList />  
</AxaptaAutoRun>

可以在配置文件中指定用户信息、License等,还有就是<run>指定的自动运行命令,比如上面的例子中运行一个Class的main方法,以及运行一个菜单项。

实际上在SysStartupCmdAutoRun内部,它使用 SysAutoRun::construct(xmlFile)构建一个SysAutoRun的实例,由它来具体解析和运行在xml文件中的命令和配置。

除了客户端配置工具的“Command to run at application startup”,客户端和服务器配置工具都有一个“Configuration Command to run at kernel startup”,前者通过命令行参数“-startupCmd”交由上面的SysStartupCmd机制处理,后者则是内核直接处理的配置命令,包括连接服务器端口、启用X++调试等,可用的命令列表在这里可以找到:http://technet.microsoft.com/en-us/library/aa569637.aspx。这些命令可以放置在命令行参数中,多个命令参数用空格隔开:

Ax32.exe -command=value -command2=value
Ax32Serve.exe -command=value -command2=value

也可以把命令行“-command=value -command2=value”直接填入配置工具的“Configuration Command to run at kernel startup”内,效果和命令行参数是一样的。

顺便指出“ax32.exe -development ”可以直接打开开发workspace,这里的“-development”命令参数不属于kenerl命令参数。

原文地址:https://www.cnblogs.com/duanshuiliu/p/2695205.html