Skip to main content

AX2012 Actiavte/Deactivate Ports using X++


create enum 1. AIFPortActivorDeactive  with Acivate,Decativate as enumvalues.
                    2. AIF portType with inbound and Outbound as enumvalues.

class krishhAIFPortsUtil extends RunBaseBatch
{
    Map serviceStatusMap;
    Map portWsdlUrlMap;
    AIFPortActivorDeactive portActiveorDeactive;
    AIFPortType aifPortType;


    DialogField     dlgActiveorDeactive;
    DialogField     dlgaifPortType;

    #define.CurrentVersion(1)
    #define.Version1(1)
    #localmacro.CurrentList
        portActiveorDeactive,
        aifPortType
    #endmacro
}

private void deployInboundPort(AifInboundPort port)
{
        startLengthyOperation();
        AifPortManager::deployPort(port.Name);
        this.updateServiceHostStatus();
        endLengthyOperation();
}

private void deployOutboundPort(AifOutboundPort port)
{
    startLengthyOperation();
    AifPortManager::deployPort(port.Name);
    endLengthyOperation();
}


public Object dialog()
{
    DialogRunbase       dialog = super();
    #resAppl
;

    dlgActiveorDeactive=dialog.addField(enumStr(AIFPortActivorDeactive), "Activate/Deactivate");
    dlgaifPortType=dialog.addField(enumStr(AIFPortType), "PortType");
    return dialog;
}

public boolean getFromDialog()
{
;
    portActiveorDeactive=dlgActiveorDeactive.value();
    aifPortType=dlgaifPortType.value();
    return super();
}

str getPortRuntimeError(AifInboundPort port)
{
    str serviceTypeName, status;
    boolean isPortStarted = false;
#Aif

    if (port.Deployed)
    {
        serviceTypeName = strFmt('%1.%2', #DotNetServiceNamespace, port.Name);

        if (!serviceStatusMap)
        {
            // If the map is null, then the IL appDomain does not exist and services are not available
            status = strFmt("@SYS345108");
        }
        else if (serviceStatusMap.exists(serviceTypeName))
        {
            status = serviceStatusMap.lookup(serviceTypeName);
            isPortStarted = strStartsWith(status, #WcfCommunicationState_Opened);
        }
    }

    return isPortStarted?"":status;
}

// BP deviation documented
str getPortWsdlUrl(AifInboundPort port)
{
    str wsdlUrl = '';
    AifPortName portName;
    AifWcfAdapter wcfAdapter;

    if (port.Deployed)
    {
        portName = port.Name;

        if (portWsdlUrlMap.exists(portName))
        {
            wsdlUrl = portWsdlUrlMap.lookup(portName);
        }
        else
        {
            wcfAdapter = AifWcfAdapter::getWcfAdapterForPort(port);

            if (wcfAdapter != null)
            {
                wsdlUrl = wcfAdapter.getWsdlUrl(port.ChannelId, port.Name);
            }

            portWsdlUrlMap.insert(portName, wsdlUrl);
        }
    }

    return wsdlUrl;
}

// BP deviation documented
boolean isPortRunning(AifInboundPort port)
{
    str serviceTypeName, status;
    boolean isPortStarted = false;
#Aif

    if (port.Deployed)
    {
        serviceTypeName = strFmt('%1.%2', #DotNetServiceNamespace, port.Name);

        // If the map is null, then the IL appDomain does not exist and services are not available
        if (serviceStatusMap && serviceStatusMap.exists(serviceTypeName))
        {
            status = serviceStatusMap.lookup(serviceTypeName);
            isPortStarted = strStartsWith(status, #WcfCommunicationState_Opened);
        }
    }

    return isPortStarted;
}

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;
}

public AIFPortType parmAifPortType(AIFPortType _aifPortType = aifPortType)
{
    aifPortType = _aifPortType;

    return aifPortType;
}

public AIFPortActivorDeactive parmPortActiveorDeactive(AIFPortActivorDeactive _portActiveorDeactive = portActiveorDeactive)
{
    portActiveorDeactive = _portActiveorDeactive;

    return portActiveorDeactive;
}

public void portinit()
{
    AifSetup::initialize();
    // Register out of the box adapters
    AifSetup::registerOutOfTheBoxAdapters();

    portWsdlUrlMap = new Map(Types::String, Types::String);
}

/// <summary>
///    Contains the code that does the actual job of the class.
/// </summary>
public void run()
{
    #OCCRetryCount
    AifInboundPort AifInboundPort;

    AifOutboundPort AifOutboundPort;

    try
    {
        this.updateServiceHostStatus();
        switch (aifPortType)
        {
            case AIFPortType::Inbound:
                if(AIFPortActivorDeactive::Activate==portActiveorDeactive)
                {
                    while select AifInboundPort //where AifInboundPort.PortCategory==AifPortCategory::Enhanced
                    {

                          if(this.isPortRunning(AifInboundPort))
                          {
                              this.portinit();
                              this.deployInboundPort(AifInboundPort);
                              if(this.getPortRuntimeError(AifInboundPort)!="")
                              {
                                  info(strFmt("@krishh1896",AifInboundPort.Name,this.getPortRuntimeError(AifInboundPort)));
                              }
                          }
                    }
                }
                else
                {
                    while select AifInboundPort where AifInboundPort.PortCategory==AifPortCategory::Enhanced
                    {
                          this.portinit();
                          this.undeployInboundPort(AifInboundPort);
                    }
                }
             break;
            case AIFPortType::OutBound:
                if(IFPortActivorDeactive::Activate==portActiveorDeactive)
                {
                    while select AifOutboundPort
                    {
                              this.portinit();
                              this.deployOutboundPort(AifOutboundPort);

                    }
                }
                else
                {
                    while select AifOutboundPort
                    {
                          this.portinit();
                          this.unDeployOutboundPort(AifOutboundPort);
                    }
                }
            break;
            default:
            throw error(strfmt("@SYS12580",aifPortType));



        }
    }
    catch (Exception::Deadlock)
    {
        retry;
    }
    catch (Exception::UpdateConflict)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::UpdateConflictNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw Exception::UpdateConflict;
        }
    }

}

private void undeployInboundPort(AifInboundPort port)
{
        startLengthyOperation();
        AifPortManager::undeployPort(port.Name);
        this.updateServiceHostStatus();
        //this.clearPortWsdlUrl(port);
        endLengthyOperation();
}

private void unDeployOutboundPort(AifOutboundPort port)
{
    startLengthyOperation();
    AifPortManager::undeployPort(port.Name);
    endLengthyOperation();
}
public void updateServiceHostStatus()
{
    // If the map is null, then the IL appDomain does not exist and services are not available
    serviceStatusMap = appl.getServiceHostStatus();
}

static krishhAIFPortsUtil construct()
{
    return new krishhAIFPortsUtil();
}
public static void main(Args _args)
{
    krishhAIFPortsUtil  krishhAIFPortsUtil ;
;
    krishhAIFPortsUtil = krishhAIFPortsUtil  ::construct();

    if (krishhAIFPortsUtil .prompt())
        krishhAIFPortsUtil .run();
}

public static void mainAutoRun(str _args)
{
    krishhAIFPortsUtil aifPortsUtil;
    ;
    aifPortsUtil = krishhAIFPortsUtil ::construct();

    if (!_args)
        return;

    switch(_args)
    {
        case('activate') :
            {
                aifPortsUtil.parmPortActiveorDeactive(AIFPortActivorDeactive::Activate);
            }

        case('deactivate') :
            {
                aifPortsUtil.parmPortActiveorDeactive(AIFPortActivorDeactive::Deactivate);
            }
    }

    aifPortsUtil.run();
}

Comments

Popular posts from this blog

D365 : ENABLE AND DISABLE IN LIST PAGE

 here i have added 4 button in salesQuotationlistpage. now i need to enable/disable button according status. so i have Extensionof  of class SalesQuotationListPageInteraction and modify setButtonEnabled method by Chain of Command //list page button enable and diable in listpage interation class [ExtensionOf(classStr(SalesQuotationListPageInteraction))] final class SQTableinimathod_Extension {     protected void setButtonEnabled()     {                SalesQuotationTable SalesQuotationTable;         CustQuotationJour   CustQuotationJour;         CustQuotationConfirmJour  CustQuotationConfirmJour;               next setButtonEnabled();         SalesQuotationTable SalesQuotationTable1 = this.listPage().activeRecord(queryDataSourceStr(SalesQuotationListPage, SalesQuotationTable));         selec...

An error occurred during report data sets execution D365 For finance and operations

  Hi all, small tip. I faced this issue, when I extend the custom report in D365 for finance and operations. During development on onebox     Solution was simple, restart IIS services Restart Reporting Services. Happy Daxing.

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'         ...