⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nsflog.cpp

📁 IBM Lotus C++ API 7.0a for IBM Lotus Notes/Domino Directory Release --------- ------------------
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//===========================================================================
//
// Module:		NSFLOG.CPP
//
// Description:	Implementation of the NSFlog class.
//
//===========================================================================

#ifndef NSFLOG_HPP
#include "nsflog.hpp"
#endif

//---------------------------------------------------------------------------
//
// Name:
//		Default Constructor
//
//---------------------------------------------------------------------------
NSFLog::NSFLog()
{ 
	LogSession		= 0; 
	isLogOpen		= FALSE;
}

//---------------------------------------------------------------------------
//
// Name:
//		Destructor
//
//---------------------------------------------------------------------------
NSFLog::~NSFLog( )
{
}

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::Open
//
// Description:
//		Opens the Log file for NSF Dump.  Also makes sure that the
//		Notes Session Object has been properly initialized and then
//		passes the pointer into this object for later use during the
//		Logging operations. 
//
// Inputs:
//		session		A pointer to an initialized Notes Session object
//		path:		Log file pathname
//
// Outputs:
//		If successful, The Log file is opened and ready for log entrys.
//		and the NSFLog object is now properly initialized for use.
//
// Returns:
//		Throws exception if there is an error.
//
//---------------------------------------------------------------------------
void NSFLog::Open( LNNotesSession *session, const LNString &path )
{
	// Open the log file
//	LogFile.open( (const char *)path, ios::out | ios::app );

//  LogFile.open( (const char *)path, ios::out, filebuf::sh_read );

    LogFile.open( (const char *)path, ios::out );

	if (!LogFile)
		throw "Cannot open log file";

	if (! LNIsNotesInitialized() )
		throw LNERR_SESSION_NOT_INITIALIZED;

	if (!session)
		throw LNERR_NULL_POINTER_PARAMETER;

	LogSession = session;

	isLogOpen = TRUE;

} // END NSFLog::Open

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::Close
//
// Description:
//		Closes the NFS Logfile for NSF Dump.
//
//---------------------------------------------------------------------------
LNSTATUS NSFLog::Close()
{
	if (! isLogOpen )
		return LNWARN_NOT_OPEN;

	// Close The Logfile.
	
	LogFile.close();
	isLogOpen = FALSE;

	return LNNOERROR;

} // END NSFLog::Close

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::CreateLogEntry
//
// Description:
//		All of the top level information about the 
//		.nsf file being dumped is added to the header area
//		of the Log file.
//
// Inputs:
//		The File Name of the .nsf file being dumped
//		The Title of the database that is being dumped.
//		The total number of documents contained in the .NSF file.
//
// Outputs:
//		The output Log file is updated.
//
//---------------------------------------------------------------------------
void NSFLog::CreateLogEntry( const LNString &NSFName, 
							 const LNString &DBTitle,
							 const LNNUMBER &TotalNotes )
{
	LNDatetime	Dt;
	LNString	TimeString;

	if (! isLogOpen )
		throw "Log file is not open!";

	// Get a Snapshot of the Current Date/Time 
	Dt = LogSession->GetCurrentDatetime();

	Dt.GetText(&TimeString);

	LogFile << "***************************************************************" << endl
			<< "***************************************************************" << endl
			<< "****************  Beginning Dump of NSF file  *****************" << endl
			<< "***************************************************************" << endl
			<< "***************************************************************" << endl
			<< endl
			<< "Current Date/Time                       " << TimeString 
			<< endl
			<< "Database Name:                          " << NSFName 
			<< endl
			<< "Database Title                          " << DBTitle 
			<< endl
			<< "Total Number of Notes                   " << TotalNotes 
			<< endl
			<< endl
			<< endl;

} // END NSFLog::CreateLogEntry

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::AddNewNoteHeader
//
// Description:
//		Creates A new Header in the Log File, for each Note found 
//		in the .nsf file being Dumped.
//
// Inputs:
//		Note        - The Current LNNote being dumped.
//		CurrentNote - A number that represents the current note's index
//					  position in the total number of notes in the 
//					  Database.
//		NumItems    - The total number of items contained in the note.
//
// Outputs:
//		A New Note header is added to the Log file.  It contains All
//		of the top level info about the new note being dumped.
//
// Remarks:
//		Of the Three NOTE FLAGS available in the NOTE Header you can
//		currently only get the state of one of them using the C++API.
//		this is NOTE_FLAG_ABSTRACTED and is retrieved using the 
//		LNDocument method: IsAbstracted() which returns an LNBOOL.
//		To get the others you must use the CAPI call:
//		NSFNoteGetInfo(hEditNOTE, _NOTE_FLAGS, &NoteFlags) See the
//		CAPI documentation under NOTE_FLAG_xxx for more info.
//---------------------------------------------------------------------------
void NSFLog::AddNewNoteHeader( LNNote &Note,
							   LNINT CurrentNote,
							   LNINT NumItems    )
{
	LNNOTETYPE	NoteType;
	LNString	TempString;

	// Append a new note Heading in the Log.
	LogMainHeading( "Beginning Dump Of The Next Note in the Database" );

	// Append the Note Number label to the Log.
	LogLabel( "Note Number          ", CurrentNote, 10 );

	// Append the number of fields to the Log.
	LogLabel( "Number of Fields     ", NumItems, 10 );

	// Get the Note's type or (Note Class).
	NoteType = Note.GetNoteType();

	// Append the next Label into the Log.
	LogLabel( "Current Note Type    ", GetNoteTypeString(NoteType) );

	// Append Notes's Originator ID data to the Log.
	LogOID(Note);
	
	//Append the Author Name to the log.
	LogLabel( "Note Author          ", Note.GetAuthor() );

	// Get the Created Date as an LNDatetime and convert to LNString.
	(Note.GetCreated()).GetText(&TempString);

	// Append the Note's creation time to the log.
	LogLabel( "Creation Date        ", TempString );

	// Get the Last Accessed time as an LNDatetime and convert to LNString.
	(Note.GetLastAccessed()).GetText(&TempString);

	// Append the Notes's Last Accessed time to the log.
	LogLabel( "Last Accessed time   ", TempString );

	// Get the Last Modified time as an LNDatetime and convert to LNString.
	(Note.GetLastModified()).GetText(&TempString);

	// Append the Note's Last Modified time to the log.
	LogLabel( "Last Modified time   ", TempString );

	// Append the Note's Note ID to the log.
	LogLabel( "Note ID              ", (LNINT)Note.GetNoteID(), 10 );

	// Append the Note size to the log.
	LogLabel( "Note size            ", (LNINT)Note.GetSize(), 10 );

} // END NSFLog::AddNewNoteHeader

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::LogMainHeading
//
// Description:
//		Appends a new peice of text to the Log. And formats it as
//		a Main Heading.
//
//---------------------------------------------------------------------------
void NSFLog::LogMainHeading( const LNString &Heading )
{
	LogFile << endl
            << "***************************************************************"
			<< endl
            << "***************************************************************"
			<< endl
			<< Heading
			<< endl
            << "***************************************************************"
			<< endl
			<< "***************************************************************"
			<< endl
			<< endl;

} // END NSFLog::LogMainHeading

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::LogNumberData
//
// Description:
//		Appends a new number value to the log file. 
//		The value is a number that gets converted to an ascii
//		string corresponding to the input base parameter (10 or hex)
//---------------------------------------------------------------------------
void NSFLog::LogNumberData( const LNINT Number, const LNINT base )
{	 
	// Append the Current Note Number value between the brackets.
	if (base == 10)
		LogFile	<< "[" << Number << "]";
	else 
	{
		LogFile.setf(ios::hex);
		LogFile	<< "[0x" << Number << "]";
		LogFile.unsetf(ios::hex);
	}

} // END NSFLog::LogNumberData

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::LogLabel
//
// Description:
//		Appends a new item label and it's value to the log. 
//		The value is a number that gets converted to an ascii
//		string corresponding to the input base parameter (10 or hex)
//---------------------------------------------------------------------------
void NSFLog::LogLabel( const LNString &Label,
					   const LNINT Number,
					   const LNINT base       )
{
	// Append the Current Note Number value between the brackets.
	if (base == 10)
		LogFile	<< Label << "[" << Number << "]" << endl; 
	else
	{
		LogFile.setf(ios::hex);
		LogFile	<< Label << "[0x" << Number << "]" << endl;
		LogFile.unsetf(ios::hex);
	}

} // END NSFLog::LogLabel

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::LogLabel
//
// Description:
//		Appends a new item label and it's value to the log. 
//		The value is also a string.
//---------------------------------------------------------------------------
void NSFLog::LogLabel( const LNString &Label, const LNString &StrValue)
{
	// Append the Current Note Number value between the brackets.

	LogFile	<< Label << "[" << StrValue << "]" << endl;

} // END NSFLog::LogLabel

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::LogLabelWithHexTimeDate
//
// Description:
//		Appends The Hex value of a TIMEDATE to the Log using a ostrstream 
//		object to convert it to text. The data is formatted as plain text.
//
//---------------------------------------------------------------------------
void NSFLog::LogLabelWithHexTimeDate( const char *pString, const TIMEDATE &Td )
{	 
	char	Buf[128];

	// Make up the timedate Hex string.
	sprintf(Buf, "%s[0x%X] - [0x%X]", pString, (int)Td.Innards[1], (int)Td.Innards[0] );

	// Append the Hex value for the Time Date to the Log.
	LogFile	<< Buf << endl;

} // END NSFLog::LogLabelWithHexTimeDate

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::LogOID
//
// Description:
//		Gets the Note's OID and appends it's timedate 
//		data to the Log File.
//
//---------------------------------------------------------------------------
void NSFLog::LogOID( LNNote &Note )
{	 
	OID		* poidNote;

	// Append the Note's OID Heading to the Log.

	LogFile	<< endl << "Note Origionator ID:" << endl;

	// Get the Note's OID. 
	if ( (poidNote = Note.GetOriginatorID()) == (OID*)NULL )
	{
		// Add a Note in the Log indicating the Note OID is not available.
		LogLabel( "   OID.File           ", "UNAVAILABLE" );

		return;
	}

	// Append the Hex value for the OID File member to the Log.
	LogLabelWithHexTimeDate( "   OID.File          ", poidNote->File );

	// Append the Hex value for the OID Note member to the Log.
	LogLabelWithHexTimeDate( "   OID.Note          ", poidNote->Note );

	// Append the Hex value for the OID Sequence member to the Log.
	LogLabel( "   OID.Sequence      ", poidNote->Sequence, 10 );

	// Append the Hex value for the OID SequenceTime member to the Log.
	LogLabelWithHexTimeDate( "   OID.SequenceTime  ", poidNote->SequenceTime );

	LogFile	<< endl;

} // END NSFLog::LogOID

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::AddNewItem
//
// Description:
//		Information about the current item in the current note being 
//		dumped is appended to the log file.
//
//		All of the top level info about the current item being dumped is
//		added first and then the ProcessItemType() method is called to do
//		field specific processing and logging as needed.
//
// Inputs:
//		Item		The current note item being processed.
//		CurrentItem	The current item's index position in it's
//					notes item array.
// Outputs:
//		All available information about the current field is logged.
//
//---------------------------------------------------------------------------
void NSFLog::AddNewItem( LNItem &Item, LNINT CurrentItem )
{
	LNString	LogEntryString;
	LNITEMTYPE	ItemType;
	WORD		ItemClass;

	// Append a heading to indicate this is a new item being dumped.
	LogFile << endl
			<< "*************************" << endl
			<< "Note Item: [" << CurrentItem << "]" << endl
			<< "*************************" << endl
			<< endl;

	// Append item's Name to the log.
	LogLabel( "Item Name        ", Item.GetName() );

	ItemType = Item.GetType();

	// Append the Item Type to the log.
	LogLabel( "Item Type        ", GetItemTypeString(ItemType) );

	ItemClass = ( (WORD)ItemType & CLASS_MASK );

	// Append the Item's Class to the log.
	LogLabel( "Item Class       ", GetItemClassString(ItemClass) );

	// Append the Item's Size to the log.
	LogLabel( "Field Size       ", Item.GetValueSize(), 10 );

	// Append the Field Flags Info to the Log.
	LogItemFlags( Item.GetFlags() );

	// This next method call Will do the rest of the processing
	// on the current Item and implements what is done under the 
	// switch (wDataType) statement in the DumpOneItem() function 
	// in NSF_DUMP.
	ProcessItemType(Item, ItemType);

} // END NSFLog::AddNewItem

//---------------------------------------------------------------------------
//
// Name:
//		NSFLog::ProcessItemType
//
// Description:
//		This method Logs the Non Header Information on the current Item 
//		and implements what is done in the switch (wDataType) statement 
//		in the DumpOneItem() function of the CAPI Sample app NSF_DUMP.
//
// Inputs:
//		ItemType
//
// Outputs:
//		All non header information about the current field is logged.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -