File: eaf_n_cst_contentproviderservice.sru
Size: 22184
Date: Tue, 22 Jan 2008 23:40:19 +0100
$PBExportHeader$eaf_n_cst_contentproviderservice.sru
forward
global type eaf_n_cst_contentproviderservice from n_cst_baseservice
end type
end forward

global type eaf_n_cst_contentproviderservice from n_cst_baseservice
string is_logservice = "n_cst_loggingservice"
end type
global eaf_n_cst_contentproviderservice eaf_n_cst_contentproviderservice

type prototypes
function boolean GetUniqueFileName (ref string  lptempdir, ref string lpprefix, integer seed, ref string tempfile) Library "KERNEL32.DLL" Alias for "GetTempFileNameA;Ansi"
function ulong GetTempPath(ulong nBufferLength, ref string lpBuffer) Library "kernel32" Alias for "GetTempPathA;Ansi"
end prototypes

type variables

end variables

forward prototypes
public function long prepareretrievestart (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long prepareretrievemain (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long prepareretrieveend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
protected function long prepareretrieve (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long createcontent (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long createcontentend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long createcontentmain (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long createcontentstart (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset)
public function long readfile (string as_filename, ref blob abl_filecontents, boolean ab_delete)
public function long generatetempfilename (ref string as_directory, ref string as_filename)
public function long preparecontent (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset)
public function long preparecontentend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset)
public function long preparecontentmain (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset)
public function long preparecontentstart (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset)
public function long readfile (string as_filename, ref string as_filecontents, boolean ab_delete)
end prototypes

public function long prepareretrievestart (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Beginning method in prepareRetrieve process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareRetrieveStart (REF n_cst_datasetattrib, REF s_mimedataset)"

inv_log.traceLog (METHOD_NAME, "")


Return 1

end function

public function long prepareretrievemain (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Main method in prepareRetrieve process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareRetrieveMain (REF n_cst_datasetattrib, REF s_mimedataset)"

inv_log.traceLog (METHOD_NAME, "")


Return -1

end function

public function long prepareretrieveend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    End method in prepareRetrieve process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareRetrieveEnd (REF n_cst_datasetattrib, REF s_mimedataset)"

inv_log.traceLog (METHOD_NAME, "")


Return 1

end function

protected function long prepareretrieve (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Controller method for the prepareRetrieve process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareRetrieve (REF n_cst_datasetattrib, REF s_mimedataset)"

inv_log.traceLog (METHOD_NAME, "")

long           ll_start_rc
long           ll_end_rc
long           ll_rc


// Invoke the Start processing method
ll_start_rc = this.prepareRetrieveStart(anv_datasetattrib, astr_mimedataset)
If ll_start_rc < 0 Then
   addError (METHOD_NAME,  "Operation prepareRetrieveStart()failed with RC="+string(ll_start_rc))
   Return -1   
ElseIf ll_start_rc = 0 Then
   inv_log.warningLog(METHOD_NAME,  "Call to prepareRetrieveStart() has cancelled the createContent operation RC="+string(ll_start_rc))
   Return -1
End If


// Invoke the Main processing (skipped if ll_start_rc =2 )
If ll_start_rc = 1 Then
   ll_rc = this.prepareRetrieveMain(anv_datasetattrib, astr_mimedataset)
   If ll_rc < 0 Then
      Return -1   
   End If   
End If


// Invoke the End processing method
ll_end_rc = this.prepareRetrieveEnd(anv_datasetattrib, astr_mimedataset)
If ll_end_rc <=0 Then
   addError (METHOD_NAME,  "Call to prepareRetrieveEnd() returned with error condition")
   Return -1
End If


Return 1

end function

public function long createcontent (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Controller method for the createContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "createContent (REF n_cst_datasetattrib, REF s_mimedataset)"

inv_log.traceLog (METHOD_NAME, "")

long           ll_start_rc
long           ll_end_rc
long           ll_rc

// Invoke the Start processing method
ll_start_rc = this.createContentStart(anv_datasetattrib, astr_mimedataset)
If ll_start_rc < 0 Then
   addError (METHOD_NAME,  "Operation createContentStart()failed with RC="+string(ll_start_rc))
   Return -1   
ElseIf ll_start_rc = 0 Then
   inv_log.warningLog(METHOD_NAME,  "Call to createContentStart() has cancelled the createContent operation RC="+string(ll_start_rc))
   Return -1
End If

// Invoke the Main processing (skipped if ll_start_rc =2 )
If ll_start_rc = 1 Then
   ll_rc = this.createContentMain(anv_datasetattrib, astr_mimedataset)
   If ll_rc < 0 Then
      Return -1   
   End If   
End If

// Invoke the End processing method
ll_end_rc = this.createContentEnd(anv_datasetattrib, astr_mimedataset)
If ll_end_rc <=0 Then
   addError (METHOD_NAME,  "Call to createContentEnd() returned with error condition")
   Return -1
End If


Return 1

end function

public function long createcontentend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    End method for the createContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "createContentEnd (REF n_cst_datasetattrib, REF s_mimedataset)"


return 1

end function

public function long createcontentmain (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Main method for the createContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "createContentMain (REF n_cst_datasetattrib, REF s_mimedataset)"


return -1

end function

public function long createcontentstart (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Start method for the createContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
// Returns: 
//     1 - Success
//     0 - Cancel
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "createContentStart (REF n_cst_datasetattrib, REF s_mimedataset)"


return 1

end function

public function long readfile (string as_filename, ref blob abl_filecontents, boolean ab_delete);////////////////////////////////////////////////////////////////
// Description:
//    Read a file into the reference array
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_filename - File name of the file to be read
//    abl_filecontents - (REF) Blob variable to store the file contents
//    ab_delete - Flag to indicate if the file should be deleted
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string    METHOD_NAME = "readFile( string, REF blob, boolean )"

n_cst_helperservice                 lnvo_helper

try
   
   lnvo_helper = create n_cst_helperservice
   lnvo_helper.readfile(as_filename, abl_filecontents)   
      
   inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Length of file '" + as_filename + "': " + string( len( abl_filecontents ) ) )

finally
   
   if ab_delete then
      //Delete the file
      fileDelete( as_filename )
   end if
   
   if IsValid(lnvo_helper) then
      destroy lnvo_helper
   end if
end try

return 1

end function

public function long generatetempfilename (ref string as_directory, ref string as_filename);////////////////////////////////////////////////////////////////
// Description:
//    Creates a random file name
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_directory   -  REF   
//    as_filename    -  REF
// Returns: 
//     1 - Success
//    -1 - Failure
//
// Notes:
//
// Special thanks to Bob Francis of Steel Dynamics for the tip on GetTempFileNameA
//
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "generateTempFileName (REF string)"

inv_log.traceLog (METHOD_NAME, "")

string                              ls_value
string                              ls_prefix            = "eaftemp"
string                              ls_tempfile          = space(248)

long ll_bufferlength                                     = 256

try
      
   //Can't access window temp directory when Webform and Webservice deployment
   #if defined PBWEBFORM then
      as_filename = "eaftemp.tmp"
      return 1
   #end if
   #if defined PBWEBSERVICE then
      as_filename = "eaftemp.tmp"
      return 1
   #end if

   as_directory = space(ll_bufferLength)
   
   if GetTempPath(ll_bufferLength, as_directory) = 0 THEN
      addError( METHOD_NAME, "Temporary filename generation failed.  Unable to locate the temporary directory using GetTempPathA()." )
      return -1
   end if
   
   //Amyuni only runs on windows so the \ is appropriate
   if right( trim( as_directory ), 1 ) <> "\" then
      as_directory += "\"
   end if

   //Get temporary file name
   GetUniqueFileName (as_directory, ls_prefix, 0, ls_tempfile)

   ls_tempfile = trim( ls_tempfile )
   
   as_filename = right( ls_tempfile, Len( ls_tempfile ) - len( as_directory ) )

   inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Generated temporary filename: '" + ls_tempfile + "'" )
   
finally

end try

return 1

end function

public function long preparecontent (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset);////////////////////////////////////////////////////////////////
// Description:
//    Controller method for the prepareContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
//    anv_dataset          -  REF
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareContent (REF n_cst_datasetattrib, REF s_mimedataset, REF n_cst_dataset)"

inv_log.traceLog (METHOD_NAME, "")

long           ll_start_rc
long           ll_end_rc
long           ll_rc

// Invoke the Start processing method
ll_start_rc = this.prepareContentStart(anv_datasetattrib, astr_mimedataset, anv_dataset)
If ll_start_rc < 0 Then
   addError (METHOD_NAME,  "Operation prepareContentStart()failed with RC="+string(ll_start_rc))
   Return -1   
ElseIf ll_start_rc = 0 Then
   inv_log.warningLog(METHOD_NAME,  "Call to prepareContentStart() has cancelled the prepareContent operation RC="+string(ll_start_rc))
   Return -1
End If

// Invoke the Main processing (skipped if ll_start_rc =2 )
If ll_start_rc = 1 Then
   ll_rc = this.prepareContentMain(anv_datasetattrib, astr_mimedataset, anv_dataset)
   If ll_rc < 0 Then
      Return -1   
   End If   
End If

// Invoke the End processing method
ll_end_rc = this.prepareContentEnd(anv_datasetattrib, astr_mimedataset, anv_dataset)
If ll_end_rc <=0 Then
   addError (METHOD_NAME,  "Call to prepareRetrieveEnd() returned with error condition")
   Return -1
End If

Return 1

end function

public function long preparecontentend (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset);////////////////////////////////////////////////////////////////
// Description:
//    End method in prepareContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
//    anv_dataset          -  REF
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareContentEnd (REF n_cst_datasetattrib, REF s_mimedataset, REF n_cst_dataset)"

inv_log.traceLog (METHOD_NAME, "")


Return 1

end function

public function long preparecontentmain (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset);////////////////////////////////////////////////////////////////
// Description:
//    Main method in prepareContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF
//    anv_dataset          -  REF
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareContentMain (REF n_cst_datasetattrib, REF s_mimedataset, REF n_cst_dataset)"

inv_log.traceLog (METHOD_NAME, "")


Return 1

end function

public function long preparecontentstart (ref n_cst_datasetattrib anv_datasetattrib, ref s_mimedataset astr_mimedataset, ref n_cst_dataset anv_dataset);////////////////////////////////////////////////////////////////
// Description:
//    Beginning method in prepareContent process
// Revisions
//    3.0   - Initial version
// Arguments:  
//    n_cst_datasetattrib  -  REF
//    s_mimerequest        -  REF   
//    anv_dataset          -  REF
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of th//   Arguments: Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "prepareContentStart (REF n_cst_datasetattrib, REF s_mimedataset, REF n_cst_dataset)"

inv_log.traceLog (METHOD_NAME, "")


Return 1

end function

public function long readfile (string as_filename, ref string as_filecontents, boolean ab_delete);////////////////////////////////////////////////////////////////
// Description:
//    Read a file into the reference array
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_filename - File name of the file to be read
//    as_filecontents - (REF) Blob variable to store the file contents
//    ab_delete - Flag to indicate if the file should be deleted
// Returns: 
//     1 - Success
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string    METHOD_NAME = "readFile( string, REF string, boolean )"

n_cst_helperservice                 lnvo_helper

try
   
   lnvo_helper = create n_cst_helperservice
   lnvo_helper.readfile(as_filename, as_filecontents) 
      
   inv_log.debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Length of file '" + as_filename + "': " + string( len( as_filecontents ) ) )

finally
   
   if ab_delete then
      //Delete the file
      fileDelete( as_filename )
   end if
   
   if IsValid(lnvo_helper) then
      destroy lnvo_helper
   end if
end try

return 1

end function

on eaf_n_cst_contentproviderservice.create
call super::create
end on

on eaf_n_cst_contentproviderservice.destroy
call super::destroy
end on