Skip to main content

AX2012 CompileCIL and Refresh Services using X++


static void CILRefreshServices(Args _args)
{
    #AviFiles
    #File

    #define.fileName('AxTime.txt')

    TextIo                  file;
    FileIoPermission        permission;
    SysOperationProgress    progress;
    container               fileContainer;

    int                     i;

    Dialog                  dialog;

    DialogField             dlgCompile;
    DialogField             dlgCIL;
    DialogField             dlgIncCIL;
    DialogField             dlgRefreshService;

    int                     timeStarted[2];
    int                     timeAverage[4]; //1:FUllCompileTime,2:FULLCILCompileTime,3:IncrementalCILTime,4:RefreshServicesTime
    int                     timeExpected;

    Filename                filename
    ;

    void getAverageTime()
    {
        filename = WinAPI::getCurrentDirectory() + '\\' + fileName;

        permission = new FileIoPermission(filename, #io_read+#io_write);
        permission.assert();

        if(WinAPI::fileExists(filename))
        {
            file        = new TextIo(filename, #io_read);
            fileContainer   = file.read();
            timeAverage[1]  = str2int(conPeek(fileContainer,1));
            timeAverage[2]  = str2int(conPeek(fileContainer,2));
            timeAverage[3]  = str2int(conPeek(fileContainer,3));
            timeAverage[4]  = str2int(conPeek(fileContainer,4));
            file = null;
        }

        CodeAccessPermission::revertAssert();
    }

    void setAverageTime()
    {
        permission = new FileIoPermission(filename, #io_write);
        permission.assert();

        fileContainer = conNull();
        fileContainer = conIns(fileContainer,1,int2str(timeAverage[1]));
        fileContainer = conIns(fileContainer,2,int2str(timeAverage[2]));
        fileContainer = conIns(fileContainer,3,int2str(timeAverage[3]));
        fileContainer = conIns(fileContainer,4,int2str(timeAverage[4]));

        file = new TextIo(filename, #io_write);
        file.write(fileContainer);
        file.finalize();

        file = null;

        CodeAccessPermission::revertAssert();
        permission = null;
    }

    dialog  = new Dialog("Compile/CIl/Refresh");

    dialog.addInfoImage();
    dialog.addText("Please select actions needed and please be aware that all are time consuming processes");

    dialog.addGroup("Compile application");
    dlgCompile  = dialog.addFieldValue(extendedTypeStr(NoYesId),NoYes::No,"AOT Compile");

    dialog.addGroup("Compile CIL");
    dlgCIL      = dialog.addFieldValue(extendedTypeStr(NoYesId), NoYes::No, "FULL");
    dlgIncCIL   = dialog.addFieldValue(extendedTypeStr(NoYesId), NoYes::No, "Incemental");

    dialog.addGroup("Other");
    dlgRefreshService   = dialog.addFieldValue(extendedTypeStr(NoYesId),NoYes::No,"Refresh Services");

    if (!dialog.run())
        throw error("Operation aborted");

    filename        = #fileName;

    timeAverage[1]  = 3600; // 60:00 min
    timeAverage[2]  = 1800; // 30:00 min
    timeAverage[3]  = 900;  // 15:00 min
    timeAverage[4]  = 300;  // 5:00 min

    getAverageTime();

    timeExpected += dlgCompile.value()          ? timeAverage[1] : 0;
    timeExpected += dlgCIL.value()              ? timeAverage[2] : 0;
    timeExpected += dlgIncCIL.value()           ? timeAverage[3] : 0;
    timeExpected += dlgRefreshService.value()   ? timeAverage[4] : 0;

    progress = new SysOperationProgress();
    progress.updateInterval(0);
    progress.setAnimation(#AviStopwatch);

    progress.setTotal(1 + dlgCompile.value() + (dlgCIL.value() || dlgIncCIL.value()) + dlgRefreshService.value());

    timeStarted[1] = timeNow();

    info(strFmt("Process stared by %1",curUserId()));

    //Compile the application
    startLengthyOperation();
    sleep(3);

    //AOT Compile
    if (dlgCompile.value())
    {
        progress.incCount();
        progress.setText(strfmt("AOT Compile compiling | Start time : %1 ETA : %2",time2str(timeNow(),1,1),time2str(timeAverage[1] + timeNow(),1,1)));

        //Do function
        timeStarted[2] = timeNow();

        SysCompileAll::flushClient();
        SysCompileAll::compile();

        SysCheckList::finished(classnum(SysCheckListItem_Compile));
        SysCheckList::finished(classnum(SysCheckListItem_CompileUpgrade));
        SysCheckList::finished(className2Id(classStr(SysCheckListItem_CompileServ)));
        SysCheckList::finished(classnum(SysCheckListItem_SysUpdateCodeCompilInit));

        timeAverage[1] = ((timeNow()-timeStarted[2]) + timeAverage[1])/2;
        info(strFmt("AOT Compile toke : %1*",time2str(timeAverage[1],1,1)));
    }

    //Incremntal CIL
    if (dlgIncCIL.value())
    {
        progress.incCount();
        progress.setText(strfmt("Incremental CIL Compiling | Start time : %1 ETA : %2",time2str(timeNow(),1,1),time2str(timeAverage[3] + timeNow(),1,1)));

        //Do function
        timeStarted[2] = timeNow();
        SysCompileIL::generateIncrementalIL();

        timeAverage[3] = ((timeNow()-timeStarted[2]) + timeAverage[3])/2;
        info(strFmt("Increment CIL toke : %1*",time2str(timeAverage[3],1,1)));
    }
    //Full CIL
    else if (dlgCIL.value())
    {
        progress.incCount();
        progress.setText(strfmt("FULL CIL Compiling | Start time : %1 ETA : %2",time2str(timeNow(),1,1),time2str(timeAverage[2] + timeNow(),1,1)));

        //Do function
        timeStarted[2] = timeNow();
        SysCompileIL::generateIL();
        timeAverage[2] = ((timeNow()-timeStarted[2]) + timeAverage[2])/2;
        info(strFmt("FULL CIL toke : %1*",time2str(timeAverage[2],1,1)));
    }

    // Refresh services
    if (dlgRefreshService.value())
    {
        progress.setText(strfmt("Refresh Services | Start time : %1 ETA : %2",time2str(timeNow(),1,1),time2str(timeAverage[4] + timeNow(),1,1)));
        progress.incCount();

        timeStarted[2] = timeNow();

        AifServiceGenerationManager::registerServices();

        timeAverage[4] = ((timeNow()-timeStarted[2]) + timeAverage[4])/2;
        info(strFmt("Refresh Services toke : %1*",time2str(timeAverage[4],1,1)));
    }

    setAverageTime();

    endLengthyOperation();

    //Flush all
    sysFlushAOD::main(_args);
    sysFlushData::main(_args);
    sysFlushDictionary::main(_args);
    info(strFmt("*Averagetime"));
    info(strFmt("Total time spendt : %1",time2str(timeNow()-timeStarted[1],1,1)));
}

Comments

Popular posts from this blog

Customization Tips for D365 for Finance and Operations How to configure Excel Add in D365 Finance and Operations August 1, 2021 by alirazazaidi I recorded how to configure Excel Addin for D365 finance and operations. How to configure Power BI out of the box dashboard on local VM Dynamics 365 for Finance and Operations July 17, 2021 by alirazazaidi Hi friends, here is video, which I recording during configuring Dynamics 365 Finance and operations out of the box dashboard on local VM. My session is held on Urdu Hindi User group on 1 August. For this I need to configure it. During development we need to configure these dashboards and some times we need to extend these dashboard. Hope this video will helpful to you. How hide SSRS Parameter RDP Menu Name Dynamics 365 Finance and Operations

  Again documentation class XYZUIBuilder extends SrsReportDataContractUIBuilder { public void build() { RecId hcmWorkerRecId; str name, menuItemName; FormBuildGroupControl grp; //Dialog dialogLocal = this.dialog(); XYZDC rdpContract = this.dataContractObject(); DialogField workerfieldDiff; DialogField _FromDate,_Todate; // Add the pay cycle field. menuItemName = this.controller().parmArgs().menuItemName(); workerfieldDiff = this.addDialogField(methodStr(XYZDC ,parmworkerrecid),rdpContract); // hcmWorkerRecId = HcmWorker::userId2Worker(curUserId()); if (menuItemName =="ESSReport") { workerfieldDiff.visible(false); workerfieldDiff.value(0); } _FromDate= this.addDialogField(methodStr(BEKenyaP9DC,parmFromDate),rdpContract); _Todate = this.addDialogField(methodStr(BEKenyaP9DC,parmToDate),rdpContract); } }

D365 : SEND EMAIL

 class SRSendEmail_D365 {            public static void main(Args _args)     {           SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();         Email   toEmail;         Email   fromEmail;                   try         {             FromEmail = "fromemail@xyzcompany.com";             toEmail   = "oemail@xyzcompany.com";             messageBuilder.setBody("Hello from D365", false);             messageBuilder.setSubject("Email Test from D365");             messageBuilder.addTo(toEmail);             // Note: not calling setFrom() defaults to the current user for SMTP client, whereas ...

CODE TO PDF IN AX 2012

static void Job1(Args _args) {         PurchPackingSlipController      ssrsController = new SrsReportRunController();         TradeDocumentReportContract     purchPackingSlipContract = new TradeDocumentReportContract();         SRSPrintDestinationSettings     printerSettings;         VendPackingSlipJour             VendPackingSlipJour;         Args                            args;         //select the latest record based on create date         while select VendPackingSlipJour             order by VendPackingSlipJour.createdDateTime DESC             where VendPackingSlipJour.PackingSlipId == 'LJ-01'         ...