Enter the key words to find the related topics

Showing posts with label SysOperation Framework Export to CSV. Show all posts
Showing posts with label SysOperation Framework Export to CSV. Show all posts

SYSOperation framework : Export to CSV

 


DATA CONTRACT


[DataContractAttribute]
 
class SalesTableDataContract implements SysOperationValidatable
{
    Filepath                          filepath;


    [DataMemberAttribute(
'FilePath'), SysOperationLabelAttribute(literalStr("Designation path")) ]


    
public FilePath parmFilePath(FilePath _filePath = filePath)
   {
        filePath = _filePath;
        return filePath;
    }
 
    public boolean validate()
    {
        boolean isValid = true;
        if(!filepath)
        {
            isValid = checkFailed("File fill the path");
        }
        return isValid;
    }
}
 
DATA Controller
 
class SalesTableDataController extends SysOperationServiceController
{
   public ClassDescription caption()

   {

        return "Sales order Export"; 
    
 }
    public ClassDescription defaultCaption()

    {

         return "Sales order Export";
    }
 

    public static void main(Args args)

    {

        SalesTableDataController   controller;

 

        SalesTableDataContract  contract;

        controller = new SalesTableDataController(classStr(SalesTableService),

                                                    methodStr(SalesTableService, processOperation),

                                                    SysOperationExecutionMode::Asynchronous);

 

        contract = controller.getDataContractObject();



        if (controller)

         {

            controller.startOperation();

         }

    }
 


   

    public boolean canGoBatch()

    {

        boolean ret;
        ret = super();
        return ret;
    }

}

 

Service


class SalesTableService extends SysOperationServiceBase

{

    public void processOperation(SalesTableDataContract _contract)
    {
        
CommaIo                             commaIOTmp;

        FileName                            fileName;
        
FileName                            fileNameTmp;

        FilePath                            fileNameDestination;
        
Set                                 permissionSet;

        SalesTable                      SalesTable;
        
NumberOfRecords                     currentRecordIndex;

 
        fileNameDestination = _contract.parmfilePath();


        
if (!strFind(fileNameDestination, '\\', strLen(fileNameDestination), 1))

        {
            fileNameDestination += 
'\\';

        }



        fileName             = this.getFileName();
        fileNameDestination  = fileNameDestination + fileName;


        fileNameTmp          = WinAPIServer::getTempPath();



        if (!strFind(fileNameTmp, '\\', strLen(fileNameTmp), 1))
        {


            fileNameTmp += '\\';
        }



        fileNameTmp += fileName;



        permissionSet =  new Set(Types::Class);
       


        permissionSet.add(new FileIoPermission(fileNametmp,'rw'));
        permissionSet.add(
new InteropPermission(InteropKind::ClrInterop));

        CodeAccessPermission::assertMultiple(permissionSet);
 


        commaIOTmp = new CommaIO(fileNametmp,'W');

        commaIOTmp.writeExp(['ServiceTags']);



        while select SalesTable where SalesTable.Processed == NoYes::No
        {


            commaIOTmp.writeExp([SalesTable.ServiceTag]);


            
ttsbegin;

            SalesTable.selectForUpdate(true);
            SalesTable.Processed = 
NoYes::Yes;

            SalesTable.update();
            
ttscommit;



            currentRecordIndex++;
        }


        
if(currentRecordIndex>0)

        {
            commaIOTmp.finalize();


            commaIOTmp = null;

            CodeAccessPermission::revertAssert();
 


            permissionSet =  new Set(Types::Class);
 


            permissionSet.add(new FileIoPermission(fileNameDestination,'rw'));
            
CodeAccessPermission::assertMultiple(permissionSet);
            System.IO.
File::Move(filenametmp, fileNameDestination);
            
CodeAccessPermission::revertAssert();

        }
    }


    
private FileName getFileName()

    {
        
str                     datestr,timestr;


        timestr = strAlpha(time2Str(timeNow(),


                                            TimeSeparator::Auto,
                                            
TimeFormat::Hour24)); //Time format : HHMMSS

        datestr = date2str(today(),
                                   
321,

                                   DateDay::Digits2,
                                   
DateSeparator::None,

                                   DateMonth::Digits2,
                                   
DateSeparator::None,

                                   DateYear::Digits4); //Date format : YYYYMMDD
 


        return 'DSPST_'+ strUpr(curExt())+'_'+datestr+'_'+timestr+'.csv';
 


    }

 

 /*

    private str getTempPath()
    {


        InteropPermission interopPerm;
        str tempPath;


   
        // get dll interop permission


        interopPerm = new InteropPermission(InteropKind::ClrInterop);
        interopPerm.assert();

        tempPath = System.IO.Path::GetTempPath();


        return tempPath;

    }

 */

}