Und damit es richtig Spaß macht, hier noch eine Variante, die die unterschiedlichen ODS Versionen berücksichtigt
/*
* copyright (c) 2019 Ulrich Krause www.eknori.de
*/
#pragma warning(disable:4005)
#include "main.h"
STATUS LNPUBLIC AddInMain (HMODULE hModule, int argc, char *argv[]) {
HANDLE hStatusLine;
HANDLE hStatusLineDesc;
HMODULE hMod;
AddInQueryDefaults (&hMod, &hStatusLine);
AddInDeleteStatusLine (hStatusLine);
hStatusLineDesc = AddInCreateStatusLine(ADDIN_STATUS_LINE);
AddInSetDefaults (hMod, hStatusLineDesc);
AddInSetStatusText("Initialising");
CmdLine *cmdline = new CmdLine();
cmdline->addUsage(" user activity, V1.0.0.0, (c) 2019, Ulrich Krause\n");
cmdline->addUsage("Usage: lo ua [options] [flags]\n");
cmdline->addUsage( "Options:\n" );
cmdline->addUsage( "-d --db\t\tdatabase path" );
cmdline->addUsage( "" );
cmdline->addUsage( "Flags:\n" );
cmdline->addUsage( "-h --help\t\tPrints this help" );
cmdline->setOption( "db", 'd' );
cmdline->setFlag ( "help", 'h' );
cmdline->processCommandArgs( argc, argv );
if( ! cmdline->hasOptions()) {
cmdline->printUsage2();
delete cmdline;
return ERROR;
}
if( cmdline->getFlag( "help" )
|| cmdline->getFlag( 'h' ) ) {
cmdline->printUsage2();
return NOERROR;
}
string file_path;
if( cmdline->getValue( 'd' ) != NULL
|| cmdline->getValue( "db" ) != NULL ){
file_path = cmdline->getValue( 'd' );
}
cNotesDatabase db;
try{
db.open(file_path.c_str());
AddInLogMessageText(
MSG("DbTitle: %s\n"),
NOERROR, db.title().c_str());
// get ODS
NSFDbMajorMinorVersionGet(db.h, &major, &minor);
AddInLogMessageText(MSG("ODS: %d\n"), NOERROR, major);
if(major < 43) {
error = get_user_activity(db.h);
}
else {
error = get_user_activity_extended(db.h);
}
} catch (cNotesErr& err) {
delete cmdline;
db.close();
LAPI_RETURN (ERR(error));
} catch (...) {
delete cmdline;
db.close();
AddInLogMessageText(
"Unexpected Error\n", NOERROR);
LAPI_RETURN (ERR(error));
}
delete cmdline;
db.close();
LAPI_RETURN (ERR(error));
}
STATUS get_user_activity(DHANDLE hDb){
error = NSFDbGetUserActivity (hDb, 0L, &DbSummaryActivity,
&hDbUserActivity, &wUserCount);
if (error)
{
return error;
}
pDbUserActivity = OSLock (DBACTIVITY_ENTRY, hDbUserActivity);
for (i = 0; i < wUserCount; i++)
{
DbUserActivity = pDbUserActivity[i];
error = ConvertTIMEDATEToText (NULL, NULL, &(DbUserActivity.Time),
szTimedate, MAXALPHATIMEDATE, &wLen);
if (error)
{
OSUnlock (hDbUserActivity);
OSMemFree (hDbUserActivity);
return error;
}
szTimedate[wLen] = '\0';
szUserName = NSFDbGetActivityUserNamePtr (pDbUserActivity, i);
if (DbUserActivity.Reads)
AddInLogMessageText(
MSG("%s %s read %d\n"),
NOERROR, szTimedate, szUserName, DbUserActivity.Reads);
if (DbUserActivity.Writes)
AddInLogMessageText(
MSG("%s %s wrote %d\n"),
NOERROR, szTimedate, szUserName,
DbUserActivity.Writes);
}
OSUnlock (hDbUserActivity);
OSMemFree (hDbUserActivity);
AddInLogMessageText(" Uses Reads Writes\n", NOERROR);
AddInLogMessageText(
MSG("Last Day %5d %5d %5d\n"),
NOERROR,
DbSummaryActivity.PrevDayUses,DbSummaryActivity.PrevDayReads,
DbSummaryActivity.PrevDayWrites);
AddInLogMessageText(
MSG("Last Week %5d %5d %5d\n"),
NOERROR,
DbSummaryActivity.PrevWeekUses,DbSummaryActivity.PrevWeekReads,
DbSummaryActivity.PrevWeekWrites);
AddInLogMessageText(
MSG("Last Month %5d %5d %5d\n"),
NOERROR,
DbSummaryActivity.PrevMonthUses,DbSummaryActivity.PrevMonthReads,
DbSummaryActivity.PrevMonthWrites);
lRptPeriod = TimeDateDifference (&(DbSummaryActivity.Last),
&(DbSummaryActivity.First));
if (lRptPeriod % (60*60*24))
lRptPeriod = lRptPeriod / (60*60*24) + 1;
else
lRptPeriod = lRptPeriod / (60*60*24);
AddInLogMessageText(
MSG("Last %lu days %5d %5d %5d\n"),
NOERROR, lRptPeriod,
DbSummaryActivity.Uses,DbSummaryActivity.Reads,
DbSummaryActivity.Writes);
return error;
}
STATUS get_user_activity_extended(DHANDLE hDb){
error = NSFDbGetUserActivityExtended (
hDb, 0L,
&DbSummaryActivityExt,
&hDbUserActivityExt, &wUserCount);
if (error)
{
return error;
}
pDbUserActivityExt = OSLock (DBACTIVITY_ENTRY_EXTENDED, hDbUserActivityExt);
for (i = 0; i < wUserCount; i++)
{
DbUserActivityExt = pDbUserActivityExt[i];
error = ConvertTIMEDATEToText (NULL, NULL, &(DbUserActivityExt.Time),
szTimedate, MAXALPHATIMEDATE, &wLen);
if (error)
{
OSUnlock (hDbUserActivityExt);
OSMemFree (hDbUserActivityExt);
return error;
}
szTimedate[wLen] = '\0';
szUserName = NSFDbGetActivityUserNamePtr (pDbUserActivityExt, i);
if (DbUserActivityExt.AEDetails.DataAdds)
AddInLogMessageText(
MSG("%s %s read %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.DataAdds);
if (DbUserActivityExt.AEDetails.DataDeletes)
AddInLogMessageText(
MSG("%s %s read %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.DataDeletes);
if (DbUserActivityExt.AEDetails.DataReads)
AddInLogMessageText(
MSG("%s %s read %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.DataReads);
if (DbUserActivityExt.AEDetails.DataUpdates)
AddInLogMessageText(
MSG("%s %s wrote %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.DataUpdates);
// NON-DATA
if (DbUserActivityExt.AEDetails.NonDataAdds)
AddInLogMessageText(
MSG("%s %s read %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.NonDataAdds);
if (DbUserActivityExt.AEDetails.NonDataDeletes)
AddInLogMessageText(
MSG("%s %s read %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.NonDataDeletes);
if (DbUserActivityExt.AEDetails.NonDataReads)
AddInLogMessageText(
MSG("%s %s read %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.NonDataReads);
if (DbUserActivityExt.AEDetails.NonDataUpdates)
AddInLogMessageText(
MSG("%s %s wrote %d\n"),
NOERROR, szTimedate,
szUserName, DbUserActivityExt.AEDetails.NonDataUpdates);
}
OSUnlock (hDbUserActivityExt);
OSMemFree (hDbUserActivityExt);
AddInLogMessageText(" Uses Reads Writes Adds\n", NOERROR);
AddInLogMessageText(
MSG("Last Day %5d %5d %5d %5d\n"),
NOERROR,
DbSummaryActivityExt.PrevDayUses,
DbSummaryActivityExt.PrevDayReads,
DbSummaryActivityExt.PrevDayUpdates,
DbSummaryActivityExt.PrevDayAdds);
AddInLogMessageText(
MSG("Last Week %5d %5d %5d %5d\n"),
NOERROR,
DbSummaryActivityExt.PrevWeekUses,
DbSummaryActivityExt.PrevWeekReads,
DbSummaryActivityExt.PrevWeekUpdates,
DbSummaryActivityExt.PrevWeekAdds);
AddInLogMessageText(
MSG("Last Month %5d %5d %5d %5d\n"),
NOERROR,
DbSummaryActivityExt.PrevMonthUses,
DbSummaryActivityExt.PrevMonthReads,
DbSummaryActivityExt.PrevMonthUpdates,
DbSummaryActivityExt.PrevMonthAdds);
lRptPeriod = TimeDateDifference (&(DbSummaryActivityExt.Last),
&(DbSummaryActivityExt.First));
if (lRptPeriod % (60*60*24))
lRptPeriod = lRptPeriod / (60*60*24) + 1;
else
lRptPeriod = lRptPeriod / (60*60*24);
AddInLogMessageText(
MSG("Last %lu days %5d %5d %5d %5d\n"),
NOERROR,
lRptPeriod,
DbSummaryActivityExt.Uses,
DbSummaryActivityExt.Reads,
DbSummaryActivityExt.Writes,
DbSummaryActivityExt.Adds);
return error;
}