[r5]: / Tags / The -Abstract Factory- Pattern / Abstract Factory3.project  Maximize  Restore  History

Download this file

287 lines (203 with data), 150.8 kB

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR

-------------------------------------------------------------------------------
FB_Logger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_Logger

VAR
    ipLogger: ILogger;
END_VAR

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    refLoggerFactory: REFERENCE TO FB_AbstractLoggerFactory;
END_VAR
IF (__ISVALIDREF(refLoggerFactory)) THEN
	ipLogger := refLoggerFactory.GetLogger();
ELSE
	ipLogger := 0;
END_IF

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    message: string;
END_VAR
Write := 'Error';
IF (ipLogger <> 0) THEN
	Write := ipLogger.Write(message);
END_IF	

-------------------------------------------------------------------------------
FB_DatabaseLoggerFactory
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_DatabaseLoggerFactory EXTENDS FB_AbstractLoggerFactory

VAR
    pSQLServerLogger: pointer;
    ipLogger: ILogger;
END_VAR

-------------------------------------------------------------------------------
FB_exit
-------------------------------------------------------------------------------


METHOD FB_exit: BOOL

VAR_INPUT
    bInCopyCode: BOOL;
END_VAR
IF (pSQLServerLogger <> 0) THEN
	__DELETE(pSQLServerLogger);
	pSQLServerLogger := 0;
END_IF

-------------------------------------------------------------------------------
GetLogger
-------------------------------------------------------------------------------


METHOD GetLogger: ILogger
GetLogger := ipLogger;
-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    sDataSource: string;
    sPassword: string;
    sUser: string;
END_VAR
pSQLServerLogger := __NEW(FB_SQLServerLogger);
ipLogger := pSQLServerLogger^;


-------------------------------------------------------------------------------
FB_FileLoggerFactory
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_FileLoggerFactory EXTENDS FB_AbstractLoggerFactory

VAR
    pTxtLogger: pointer;
    pCsvLogger: pointer;
    pXmlLogger: pointer;
    ipLogger: ILogger;
END_VAR

-------------------------------------------------------------------------------
GetLogger
-------------------------------------------------------------------------------


METHOD GetLogger: ILogger
GetLogger := ipLogger;

-------------------------------------------------------------------------------
FB_init
-------------------------------------------------------------------------------


METHOD FB_init: BOOL

VAR_INPUT
    bInitRetains: BOOL;
    bInCopyCode: BOOL;
    sFilename: string;
END_VAR

VAR
    sFilenameExtension: string;
END_VAR
sFilenameExtension := RIGHT(sFilename, 3);
IF (sFilenameExtension = 'txt') THEN
    pTxtLogger := __NEW(FB_TxtLogger);
    ipLogger := pTxtLogger^;
ELSIF (sFilenameExtension = 'csv') THEN
    pCsvLogger := __NEW(FB_CsvLogger);
    ipLogger := pCsvLogger^;
ELSIF (sFilenameExtension = 'xml') THEN
    pXmlLogger := __NEW(FB_XmlLogger);
    ipLogger := pXmlLogger^;
ELSE
    ipLogger := 0;
END_IF

-------------------------------------------------------------------------------
FB_exit
-------------------------------------------------------------------------------


METHOD FB_exit: BOOL

VAR_INPUT
    bInCopyCode: BOOL;
END_VAR
IF (pTxtLogger <> 0) THEN
	__DELETE(pTxtLogger);
	pTxtLogger := 0;
END_IF

IF (pCsvLogger <> 0) THEN
	__DELETE(pCsvLogger);
	pCsvLogger := 0;
END_IF

IF (pXmlLogger <> 0) THEN
	__DELETE(pXmlLogger);
	pXmlLogger := 0;
END_IF

-------------------------------------------------------------------------------
FB_CsvLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_CsvLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('CsvLogger: ', sMsg);
-------------------------------------------------------------------------------
FB_SQLServerLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_SQLServerLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('DatabaseLogger: ', sMsg);
-------------------------------------------------------------------------------
FB_AbstractLoggerFactory
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_AbstractLoggerFactory

-------------------------------------------------------------------------------
GetLogger
-------------------------------------------------------------------------------


METHOD GetLogger: ILogger
;
-------------------------------------------------------------------------------
FB_TxtLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_TxtLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('TxtLogger: ', sMsg);

-------------------------------------------------------------------------------
FB_XmlLogger
-------------------------------------------------------------------------------


FUNCTION_BLOCK FB_XmlLogger

-------------------------------------------------------------------------------
Write
-------------------------------------------------------------------------------


METHOD Write: string

VAR_INPUT
    sMsg: string;
END_VAR
Write := CONCAT('XmlLogger: ', sMsg);
-------------------------------------------------------------------------------
MAIN
-------------------------------------------------------------------------------


PROGRAM MAIN

VAR
    fbDatabaseLoggerFactory: FB_DatabaseLoggerFactory;
    refDatabaseLoggerFactory: REFERENCE TO FB_DatabaseLoggerFactory;
    fbLogger: FB_Logger;
    sRetMsg: string;
END_VAR
sRetMsg := fbLogger.Write('Hello');