File: eaf_n_cst_loggingservice.sru
Size: 19455
Date: Tue, 22 Jan 2008 23:39:42 +0100
$PBExportHeader$eaf_n_cst_loggingservice.sru
forward
global type eaf_n_cst_loggingservice from n_cst_loggingservice_base
end type
end forward

global type eaf_n_cst_loggingservice from n_cst_loggingservice_base
end type
global eaf_n_cst_loggingservice eaf_n_cst_loggingservice

type prototypes
protected:

function long GetEnvironmentVariable(ref string variablename, ref string variablevalue, long length ) Library "KERNEL32.DLL" Alias for "GetEnvironmentVariableA;Ansi"

Function ulong RegisterEventSource ( &
   ulong lpUNCServerName, &
   string lpSourceName &
   ) Library "advapi32.dll" Alias For "RegisterEventSourceW"

Function boolean ReportEvent ( &
   ulong hEventLog, &
   uint wType, &
   uint wCategory, &
   ulong dwEventID, &
   ulong lpUserSid, &
   uint wNumStrings, &
   ulong dwDataSize, &
   string lpStrings[], &
   ulong lpRawData &
   ) Library "advapi32.dll" Alias For "ReportEventW"

Function boolean DeregisterEventSource ( &
   ref ulong hEventLog &
   ) Library "advapi32.dll"
   

end prototypes

type variables
Public:
ErrorLogging               iel_obj

Protected:
n_cst_VariableManager            inv_variablemanager
n_cst_LogManager                 inv_logmanager

Constant Uint EVENTLOG_ERROR_TYPE         = 1
Constant Uint EVENTLOG_WARNING_TYPE       = 2
Constant Uint EVENTLOG_INFORMATION_TYPE   = 4

string                        is_username
end variables
forward prototypes
public function long propagatesettings (ref n_cst_component anv_target)
public function long propagatesettings (ref n_transaction anv_target)
public function long populatesettings ()
public function integer setusedatabaselogging (boolean ab_value)
protected subroutine standardlog (string as_methodname, string as_messagetype, string as_messagetext)
public subroutine log (string as_methodname, string as_messagetype, string as_messagetext)
public function long propagatesettings (ref n_datastore anv_target)
public function string getusername ()
public function long setusername (string as_username)
public subroutine setcomponentname (string as_componentname)
public function string getcomponentname ()
end prototypes

public function long propagatesettings (ref n_cst_component anv_target);////////////////////////////////////////////////////////////////
// Description:
//    Propagate component log settings to n_cst_component and descendants
// Note.
//    
// Revisions
//    3.0   - Initial version
// Arguments:
//    None
// 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 = "propagateSettings(REF n_cst_component anv_target) "

//Propagate Database Logging
if ib_usedatabaselogging then
   anv_target.setUseDatabaseLogging( true )
end if

//Propagate Trace setting
if ib_trace then
   anv_target.setTrace( true )
end if

//Propagate Debug Setting
if ib_debug then
   anv_target.setDebug( true )
end if

//Propagate Warning setting
if ib_warning then
   anv_target.setWarning( true )
end if

//Propagate Detailed Debugging
if ib_detailed then
   anv_target.setDetailed( true )
end if

//Propagate settings to dependent objects
return 1


end function

public function long propagatesettings (ref n_transaction anv_target);////////////////////////////////////////////////////////////////
// Description:
//    Propagate component log settings to service classes
// Note.
//    
// Revisions
//    3.0   - Initial version
// Arguments:
//    None
// 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 = "propagateSettings(REF n_cst_baseservice anv_target) "

//Propagate Database Logging
if ib_usedatabaselogging then
   anv_target.setUseDatabaseLogging( true )
end if

//Propagate Trace setting
if ib_trace then
   anv_target.setTrace( true )
end if

//Propagate Debug Setting
if ib_debug then
   anv_target.setDebug( true )
end if

//Propagate Warning setting
if ib_warning then
   anv_target.setWarning( true )
end if

//Propagate Detailed Debugging
if ib_detailed then
   anv_target.setDetailed( true )
end if

//Propagate settings to dependent objects
return anv_target.propagateLogSettings()

end function

public function long populatesettings ();////////////////////////////////////////////////////////////////
// Description:
//    Invoked when the object is created at the base level of the component
//    Queries component properties and the variable manager for values
// Revisions
//    3.0   - Initial Version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////
// 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 = "populateSettings "

// Declare local variables
long                       ll_rc
string                        ls_value
boolean                    lb_value

// Check Component Properties for Debug
inv_variablemanager.GetValue( inv_constants.DEBUG_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setDebug( (ls_value = "YES" or ls_value = "TRUE") )

// Check Component Properties for Trace
inv_variablemanager.GetValue( inv_constants.TRACE_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setTrace( (ls_value = "YES" or ls_value = "TRUE") )

// Check Component Properties for Detailed Debugging
inv_variablemanager.GetValue( inv_constants.DEBUG_DETAILED_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setDetailed( (ls_value = "YES" or ls_value = "TRUE") )

// Check Component Properties for Warning
//Warning is on by default unless specifically disabled
inv_variablemanager.GetValue( inv_constants.WARNING_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
lb_value = (ls_value = "NO" or ls_value = "FALSE")
if lb_value then
   setWarning( false )
end if

// Check Component Properties for Use Database Logging
inv_variablemanager.GetValue( inv_constants.USE_DATABASE_LOGGING_PROPERTY_NAME, ls_value)
ls_value = upper(trim(ls_value))
setUseDatabaseLogging( (ls_value = "YES" or ls_value = "TRUE") )

debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Debug Setting:" + string( ib_debug ) )
debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Trace Setting:" + string( ib_trace ) )
debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Detailed Setting:" + string( ib_detailed ) )
debugLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "UseDatabaseLogging Setting:" + string( ib_usedatabaselogging ) )


return 1

end function

public function integer setusedatabaselogging (boolean ab_value);////////////////////////////////////////////////////////////////
// Description:
//    Sets the use of database logging
//    If true, looks up LogManager component and stores a reference to it
//    
// Revisions
//    3.0   - Initial version
// Arguments:  
//    boolean - On/Off
// 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 = "setUseDatabaseLogging( boolean value ) "
String ls_runtimeerror

ib_usedatabaselogging = ab_value

//instantiate proxy instance to LogManager component
if ( ib_usedatabaselogging ) then
   if ( not isValid( inv_logmanager ) ) then
      
      try
         
         inv_logmanager = create using inv_constants.LOG_MANAGER_COMPONENT_NAME
      
      catch ( RuntimeError re )
      
         ls_runtimeerror = "Runtime Error:" + inv_constants.CRLF + inv_constants.CRLF
         ls_runtimeerror += "Error Code: " + string(re.number) + inv_constants.CRLF
         ls_runtimeerror += "Object: " + re.objectName + inv_constants.CRLF
         ls_runtimeerror += "Class: " + re.class + inv_constants.CRLF
         ls_runtimeerror += "Function/Event: " + re.routineName + inv_constants.CRLF
         ls_runtimeerror += "Line: " + string(re.line) + inv_constants.CRLF
         ls_runtimeerror += "Message: " + re.getMessage() + inv_constants.CRLF
                  
         //lookup for logmanager failed
         //turn off UseDatabaseLogging
         ib_usedatabaselogging = false
         
         //Write error out to standard log file
         standardLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_ERROR, "There was a problem instantiating the LogManager component" )
      
      end try
      
   end if
end if

Return 1

end function

protected subroutine standardlog (string as_methodname, string as_messagetype, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Add an entry to the EAServer log file
//    Does not use the LogManager component
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// 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 = "standardLog( String as_methodName, String as_messageType, String as_messageText ) "

long                    ll_cnt
string                  ls_padding = "                      "
string                  ls_message
string                  ls_username
ULong                   lul_EventSource
Long                    lui_type
String                  ls_msgs[]
Long ll_filenum

// Get Username 
ls_username = GetUserName()

ls_message = "Component: " + is_componentname + inv_constants.CRLF
ls_message += ls_padding + "Object: " + is_objectname + inv_constants.CRLF
ls_message += ls_padding + "Method: " + as_methodname + inv_constants.CRLF
ls_message += ls_padding + "Message Type: " + as_messagetype + inv_constants.CRLF
ls_message += ls_padding + "User: " + ls_userName + inv_constants.CRLF
ls_message += ls_padding + "Message: " + as_messagetext + inv_constants.CRLF

if isValid(iel_obj) Then
   // test for longer than allowed text.
   if len(ls_message) > 990 then // actual limit is 1000
      ll_cnt = 0
      iel_obj.log("Multi Part Entry Follows:")
      DO 
         ll_cnt ++
         ls_message = left(ls_message,990)
         if ls_message <> "" then
            iel_obj.log("Part #" +string(ll_cnt) + " : " + ls_message)
         end if
         ls_message = mid(ls_message,990)
      LOOP until ls_message = ""
   else
      iel_obj.log(ls_message)
   end if
else
   
   // Write to log file
   ll_filenum = FileOpen(is_service + ".txt", LineMode!, Write!, LockWrite!, Append!)
   FileWriteEx(ll_filenum, String(Today()) + " " + String(Now()) + "~t" + ls_message)
   FileClose(ll_FileNum)
   
   // Write to windows event
// lul_EventSource = RegisterEventSource(0, is_service)
// choose case as_messagetype
//    case inv_constants.MESSAGE_TYPE_EAF_ERROR
//       lui_type = EVENTLOG_ERROR_TYPE
//    case inv_constants.MESSAGE_TYPE_EAF_WARNING
//       lui_type = EVENTLOG_WARNING_TYPE
//    case else
//       lui_type = EVENTLOG_INFORMATION_TYPE
// end choose
// If lul_EventSource > 0 Then
//    ls_msgs[1] = ls_message
//    ReportEvent(lul_EventSource, lui_type, &
//          0, 0, 0, UpperBound(ls_msgs), 0, ls_msgs, 0)
//    DeregisterEventSource(lul_EventSource)
// End If
   
end If

end subroutine

public subroutine log (string as_methodname, string as_messagetype, string as_messagetext);////////////////////////////////////////////////////////////////
// Description:
//    Debug logging
// Revisions
//    3.0   - Initial version
// Arguments:  
//    as_methodname  -  The method where the error happened
//    as_messagetype -  Message type from constants object
//    as_messagetext -  Text of the message
// Returns: 
//    None
////////////////////////////////////////////////////////////////
// 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 = "log( String as_methodName, String as_messageType, String as_messageText ) "

boolean           lbl_writetostandardlog

if ib_usedatabaselogging then
   if inv_logmanager.logMessage( is_componentname, is_objectname, as_methodname, as_messagetype, as_messagetext ) = -1 then
      //There was a problem calling the LogManager component
      //Write a message to this effect
      standardLog( METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_ERROR, "There was an error calling logMessage() on " + inv_constants.LOG_MANAGER_COMPONENT_NAME + ". Error message to follow.")
      
      //signal write to the standard log
      lbl_writetostandardlog = true
   end if
else
   lbl_writetostandardlog = true
end if
   
if lbl_writetostandardlog then
   standardLog( as_methodname, as_messagetype, as_messagetext )
end if

end subroutine

public function long propagatesettings (ref n_datastore anv_target);////////////////////////////////////////////////////////////////
// Description:
//    Propagate component log settings to service classes
// Note.
//    
// Revisions
//    3.0   - Initial version
// Arguments:
//    None
// 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 = "propagateSettings(REF n_cst_baseservice anv_target) "

//Propagate Database Logging
if ib_usedatabaselogging then
   anv_target.setUseDatabaseLogging( true )
end if

//Propagate Trace setting
if ib_trace then
   anv_target.setTrace( true )
end if

//Propagate Debug Setting
if ib_debug then
   anv_target.setDebug( true )
end if

//Propagate Warning setting
if ib_warning then
   anv_target.setWarning( true )
end if

//Propagate Detailed Debugging
if ib_detailed then
   anv_target.setDetailed( true )
end if


//Propagate settings to dependent objects
return anv_target.propagateLogSettings()

end function

public function string getusername ();///////////////////////////////////////////////////////////////////////////////////
// Description:
//    Gets the User Name property.  
//    1.0   - Initial version
// Arguments:  
//    None
// Returns:
//     The User Name property
///////////////////////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Applirk
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
/////////////////////////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "getUserName "

If ib_trace Then
   tracelog (METHOD_NAME, "")
End If   

Return is_username
end function

public function long setusername (string as_username);///////////////////////////////////////////////////////////////////////////////////
// Description:
//    Sets the User Name property.  
//    1.0   - Initial version
// Arguments:  
//    al_UserName - The Login User Name
// Returns:
//     1 - Success
//    -1 - Failure
///////////////////////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft, Inc.  All rights reserved.
// Any distribution of thems, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
/////////////////////////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "setUserName "

If ib_trace Then
   traceLog (METHOD_NAME, "(as_UserName)   as_UserName="+string(as_UserName))
End If   

is_UserName = as_UserName

Return 1
end function

public subroutine setcomponentname (string as_componentname);is_componentname = as_componentname
end subroutine

public function string getcomponentname ();return is_componentname
end function

on eaf_n_cst_loggingservice.create
call super::create
end on

on eaf_n_cst_loggingservice.destroy
call super::destroy
end on

event destructor;call super::destructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is destroyed
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////
// 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 = "destructor "

if isValid( inv_variablemanager ) then
   destroy inv_variablemanager
end if

if isValid( inv_logmanager ) then
   destroy inv_logmanager
end if
end event

event constructor;call super::constructor;////////////////////////////////////////////////////////////////
// Description:
//    Occurs when the object is created
// Revisions
//    3.0   - Initial version
// Arguments:  
//    None
// Returns: 
////////////////////////////////////////////////////////////////
// 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 = "constructor "

long                    ll_rc
Long                    ll_length = 255
String                  ls_jaguarpath, ls_name

//Get the location of EAServer for checking the environment of application
ls_name = "JAGUAR"
ls_jaguarpath = Space(ll_length)
GetEnvironmentVariable( ls_name, ls_jaguarpath, ll_length)
if Trim(ls_jaguarpath) <> "" then
   // Get the supported Context Services
   ll_rc = getContextService("ErrorLogging",iel_obj)
end if

inv_variablemanager = create n_cst_VariableManager

inv_logmanager = create n_cst_LogManager

return 1

end event