Показать сообщение отдельно
Старый 22.01.2021, 16:54   #45  
kair84 is offline
kair84
Участник
 
47 / 58 (2) ++++
Регистрация: 15.04.2010
Адрес: Belarus
Работает только для SysOperation, в Asynchronous и ReliableAsynchronous режимах.
Важно параметризировать parmShowProgressForm(true) в контроллере, и в сервисе получить RunbaseProgress.


Вот код:

Controller
X++:
class Test_SysOperationController extends SysOperationServiceController
{
    protected void loadFromSysLastValue()
    {
        if (!dataContractsInitialized)
        {
            // This is a bug in the SysOperationController class
            // never load from syslastvalue table when executing in batch
            // it is never a valid scenario
            if (!this.isInBatch())
            {
                super();
            }

            dataContractsInitialized = true;
        }
    }

    public void new()
    {
        super();

        // defaulting parameters common to all scenarios

        // If using reliable async mechanism do not wait for the batch to
        // complete. This is better done at the application level since
        // the batch completion state transition is not predictable
        //this.parmRegisterCallbackForReliableAsyncCall(false);

        // default for controllers in these samples is synchronous execution
        // batch execution will be explicity specified. The default for
        // SysOperationServiceController is ReliableAsynchronous execution

        //this.parmExecutionMode(SysOperationExecutionMode::ReliableAsynchronous);
        this.parmExecutionMode(SysOperationExecutionMode::Asynchronous);
        
        //this.parmExecutionMode(SysOperationExecutionMode::Synchronous); // ProgressBar doesn't work.

        this.parmShowProgressForm(true);
        
        this.parmClassName(classStr(Test_SysOperationService));
        this.parmMethodName(methodStr(Test_SysOperationService, runOperation));
        //this.parmMethodName(methodStr(Test_SysOperationService, runOperationResult)); // Doesn't work ???
        
    }

    public ClassDescription caption()
    {
        return 'Test SysOperation !';
    }

    protected boolean canRunInNewSession()
    {
        return true;
    }

    public void asyncCallbackVoid(AsyncTaskResult _asyncResult)
    {
        info("Async Callback Void");
        
        super(_asyncResult);

        /*
        SysOperationDataContractInfo contractInfo = this.getDataContractInfoObjects().lookup("dataContract");        
        Test_SysOperationDataContract dataContract = contractInfo.dataContractObject();
        */

        //Box::info("Async Callback  Void Box");
        //this.sendFile("Async Callback Void");

    }

    public void asyncCallbackReturnValue(AsyncTaskResult _asyncResult, anytype _returnValue)
    {
        // Doesn't work ???
        info("Async Callback Result");

        //super(_asyncResult,_returnValue);
        
        //Box::info("Async Callback  Result Box");

    }

    public void sendFile(str _fileContent)
    {
        Filename filename = "file.csv";
        System.Byte[] byteArray =  System.Text.Encoding::Unicode.GetBytes(_fileContent);
        System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
        stream.Position = 0;

        File::SendFileToUser(stream, fileName);
        info(strFmt("File %1 Sent to user",filename));
    
    }

    public static void main(Args args)
    {
        Test_SysOperationController operation;

        operation = new Test_SysOperationController();
        operation.startOperation();
    }

}
DataContract
X++:
[DataContractAttribute,
SysOperationContractProcessingAttribute(classStr(Test_SysOperationUIBuilder))]
    class Test_SysOperationDataContract extends SysOperationDataContractBase
{
    int duration;

    [DataMemberAttribute,
        SysOperationLabelAttribute('Duration (sec.)'),
        SysOperationHelpTextAttribute('Type some number >= 0'),
        SysOperationDisplayOrderAttribute('1')]
    public int parmDuration(int _duration = duration)
    {
        duration = _duration;

        return duration;
    }

}
UIBuilder
X++:
class Test_SysOperationUIBuilder extends SysOperationAutomaticUIBuilder
{
    DialogField durationField;

    public void postBuild()
    {
        super();

        // get references to dialog controls after creation
        durationField = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(Test_SysOperationDataContract, parmDuration));
        
    }

    public void postRun()
    {
        super();

        // register overrides for form control events
        durationField.registerOverrideMethod(methodstr(FormIntControl, validate), methodstr(Test_SysOperationUIBuilder, durationFieldValidate), this);
    }

    public boolean durationFieldValidate(FormIntControl _control)
    {
        if (_control.value() < 0)
        {
            error('Please type a number >= 0');
            return false;
        }
        return true;
    }

}
Service
X++:
class Test_SysOperationService extends SysOperationServiceBase
{
    public void runOperation(Test_SysOperationDataContract dataContract)
    {
        RunbaseProgress                 progress = this.getProgressController(dataContract);
        int total = dataContract.parmDuration();

        progress.setTotal(total);

        int i;
        for (i = 1; i <= total; i++ )
        {
            progress.incCount();
            progress.setText(strFmt("%1 / %2",i,total));
            progress.update(true);
            sleep(1000);
        }

        info('Done!');

    }

    public container runOperationResult(Test_SysOperationDataContract dataContract)
    {
        this.runOperation(dataContract);

        return [dataContract.parmDuration()];

    }

}


Может кто то подскажет, почему не работает asyncCallbackReturnValue(..) для parmMethodName(methodStr(Test_SysOperationService, runOperationResult)) ?
Выбрасывается ошибка что нет такого метода но вот же он... ???
За это сообщение автора поблагодарили: Logger (5).