AcUtils
A high performance abstraction layer for AccuRev
Static Public Member Functions | Properties | Static Private Member Functions | List of all members
AcUtils.AcDebug Class Reference

Use to log and display error and general purpose text messages, and to save the XML param data sent by AccuRev to a trigger for development, debugging, and troubleshooting purposes. For OS environment problems, log the system network activity generated by the program by modifying <prog_name>.exe.config similar to this version. More...

Static Public Member Functions

static bool paramFileCopy (string xmlFile, ParamFileCopy pfcopy, string trigger, string prncpl, string command)
 Used by a trigger to save the content of the XML param file passed to it by AccuRev to %LOCALAPPDATA%\AcTools\Param\<trigger-command-principal-timestamp>.xml. More...
 
static bool paramFileCopy (ParamFileCopy pfcopy, string xml, string trigger, string prncpl)
 Used by the server_auth_trig to save the content of the XML param data passed to it by AccuRev to %LOCALAPPDATA%\AcTools\Param\server_auth_trig-principal-timestamp.xml. More...
 
static void Log (string message, bool formatting=true)
 Write the message text to STDOUT, to weekly log files located in %LOCALAPPDATA%\AcTools\Logs, and to trigger.log in the AccuRev server's ..storage\site_slice\logs folder in the case of triggers. More...
 
static void Log (string message, string xmlParamFile, bool formatting=true)
 Used by triggers, this method overload includes all functionality of Log(string, bool) and adds overwriting the trigger's xmlParamFile with the message text so it is displayed in the console or error dialog given to the user on trigger failure. More...
 
static bool initAcLogging ()
 Initialize application logging support, for general purpose or error messages, in conjunction with a client application's <prog_name>.exe.config file and Log(string, bool). More...
 
static string getLogFile ()
 Get the log file's full path name. More...
 
static void unhandledException (object sender, UnhandledExceptionEventArgs args)
 Ensure that an unhandled exception gets logged to %LOCALAPPDATA%\AcTools\Logs\<prog_name>-YYYY-MM-DD.log before the system default handler terminates the application. More...
 
static void errorDataHandler (object sendingProcess, DataReceivedEventArgs errLine)
 Centralized error handler. More...
 

Properties

static string TrigTargetEnv [get]
 Returns "AccuRevTriggers", the name of the environment variable on the AccuRev server that points to the network share where TriggersTarget.xml and other application support files are located. More...
 

Static Private Member Functions

static void createParamFile (string fileName, string content)
 Helper function that creates the XML param data copy. More...
 
static string getStamp ()
 Helper function for creating a unique filename for our copy of the XML param data. More...
 
static bool entryInTrigTargetsFile (string trigger, string prncpl)
 Determine if an entry exists for this user and trigger combo in TriggersTarget.xml. More...
 

Detailed Description

Use to log and display error and general purpose text messages, and to save the XML param data sent by AccuRev to a trigger for development, debugging, and troubleshooting purposes. For OS environment problems, log the system network activity generated by the program by modifying <prog_name>.exe.config similar to this version.

Definition at line 100 of file AcDebug.cs.

Member Function Documentation

static void AcUtils.AcDebug.createParamFile ( string  fileName,
string  content 
)
inlinestaticprivate

Helper function that creates the XML param data copy.

Parameters
fileNameName of file to create.
contentString containing the XML param data.
Exceptions
Exceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\<trig_name>-YYYY-MM-DD.log on failure to handle a range of exceptions.

Definition at line 248 of file AcDebug.cs.

Referenced by AcUtils.AcDebug.paramFileCopy().

static bool AcUtils.AcDebug.entryInTrigTargetsFile ( string  trigger,
string  prncpl 
)
inlinestaticprivate

Determine if an entry exists for this user and trigger combo in TriggersTarget.xml.

Use the CopyParmFileTrigTarget enum directive in the appSettings section of a <trigger>.exe.config file (located in the same folder as the trigger's executable) to have the trigger's XML param data copied to %LOCALAPPDATA%\AcTools\Param\<trigger-command-principal-timestamp>.xml for specific users and triggers. Only param data for matching entries in TriggersTarget.xml located on the AccuRevTriggers network share are copied.

Parameters
triggerThe name of the trigger sent by AccuRev.
prncplName of the principal sent by AccuRev.
Returns
true if entry exists, false otherwise.
Exceptions
XPathExceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\<trig_name>-YYYY-MM-DD.log on xpath failure.
Exceptioncaught and logged in same on failure to handle a range of exceptions.
In <trigger>.exe.config:
<appSettings>
...
<add key="ParamFileCopy" value="CopyParmFileTrigTarget" />
</appSettings>
Example TriggersTarget.xml:
<Triggers>
<Trigger Name="server-post-promote">
<Principal Name="barnyrd"></Principal>
</Trigger>
<Trigger Name="server_admin_trig">
<Principal Name="robert"></Principal>
<Principal Name="barnyrd"></Principal>
</Trigger>
<Trigger Name="server_preop_trig">
<Principal Name="thomas"></Principal>
</Trigger>
<Trigger Name="server_auth_trig">
<Principal Name="madhuri"></Principal>
<Principal Name="thomas"></Principal>
</Trigger>
</Triggers>

Definition at line 332 of file AcDebug.cs.

Referenced by AcUtils.AcDebug.paramFileCopy().

static void AcUtils.AcDebug.errorDataHandler ( object  sendingProcess,
DataReceivedEventArgs  errLine 
)
inlinestatic

Centralized error handler.

Parameters
sendingProcessThe spawned process.
errLineThe error message sent to this method by the spawned process.

Definition at line 554 of file AcDebug.cs.

Referenced by AcUtils.AcGroups.isMember().

static string AcUtils.AcDebug.getLogFile ( )
inlinestatic

Get the log file's full path name.

Log files are created on initial write. If logging support was previously initialized and the log file does not yet exist (nothing written), calling this method will create a zero-byte log file.

Returns
Full path to the log file if logging support was previously initialized, otherwise null.

Definition at line 525 of file AcDebug.cs.

static string AcUtils.AcDebug.getStamp ( )
inlinestaticprivate

Helper function for creating a unique filename for our copy of the XML param data.

Returns
String to ensure the copied file is unique and doesn't get subsequently overwritten.

Definition at line 281 of file AcDebug.cs.

Referenced by AcUtils.AcDebug.paramFileCopy().

static bool AcUtils.AcDebug.initAcLogging ( )
inlinestatic

Initialize application logging support, for general purpose or error messages, in conjunction with a client application's <prog_name>.exe.config file and Log(string, bool).

Creates weekly log files in %LOCALAPPDATA%\AcTools\Logs in the format <prog_name>-YYYY-MM-DD.log with the first day of the current week in the file name. The AcTools\Logs folder is created if not already there. Log files can grow to a maximum of 80MB in size. At least 2.3GB free space must exist for logging to continue. Additional log files are created with an iteration part (blue circle) should a write conflict occur:

Returns
true if logging support successfully initialized, false on error.
Exceptions
Exceptioncaught on failure to handle a range of exceptions with error sent to STDOUT.
Example usage:
// Init our logging support so we can log errors.
string error;
if (!AcDebug.initAcLogging())
{
MessageBox.Show(error, "PromoHist", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
XML that must exist in <prog_name>.exe.config. Change source name attribute to <prog_name>.
<system.diagnostics>
<assert assertuienabled="false"/>
<sources>
<source name="PromoHist"> <!-- name attribute value must be program executable's root name -->
<listeners>
<remove name="Default" />
<add name="AcLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</listeners>
</source>
</sources>
</system.diagnostics>

Definition at line 471 of file AcDebug.cs.

static void AcUtils.AcDebug.Log ( string  message,
bool  formatting = true 
)
inlinestatic

Write the message text to STDOUT, to weekly log files located in %LOCALAPPDATA%\AcTools\Logs, and to trigger.log in the AccuRev server's ..storage\site_slice\logs folder in the case of triggers.

Parameters
messageThe text to be logged.
formattingtrue to include the date, time and newline formatting in the log file. false for no formatting.
See also
Log(string, string, bool)

Definition at line 378 of file AcDebug.cs.

Referenced by AcUtils.AcCommand.AcCommand(), AcUtils.AcDateTime.AcDate2DateTime(), AcUtils.AcDebug.createParamFile(), AcUtils.AcDebug.entryInTrigTargetsFile(), AcUtils.AcDebug.errorDataHandler(), AcUtils.AcQuery.getAccuRevVersionAsync(), AcUtils.AcQuery.getAcGUIpath(), AcUtils.AcPreferences.getAcHomeFolderAsync(), AcUtils.AcQuery.getCatFileAsync(), AcUtils.AcQuery.getElementNameAsync(), AcUtils.AcDepot.getHierarchyAsync(), AcUtils.AcQuery.getPrincipalAsync(), AcUtils.AcWorkspaces.getReferenceTreesXMLAsync(), AcUtils.AcQuery.getServerFromAcClientCnf(), AcUtils.AcPreferences.getUseIgnoreElemsOptimizationAsync(), AcUtils.AcWorkspaces.getWorkspacesXMLAsync(), AcUtils.Stat.init(), AcUtils.AcGroups.initAsync(), AcUtils.AcDepot.initAsync(), AcUtils.AcSessions.initAsync(), AcUtils.AcProperties.initAsync(), AcUtils.AcRules.initAsync(), AcUtils.AcLocks.initAsync(), AcUtils.AcPermissions.initAsync(), AcUtils.AcStreams.initAsync(), AcUtils.AcUsers.initAsync(), AcUtils.AcDepots.initAsync(), AcUtils.AcUser.initFromADAsync(), AcUtils.AcUser.initGroupsListAsync(), AcUtils.AcLocks.initList(), AcUtils.AcGroups.initMembersListAsync(), AcUtils.AcUsers.initUserPropsAsync(), AcUtils.AcGroups.isMember(), AcUtils.AcDepot.listFile(), AcUtils.AcLocks.lockAsync(), AcUtils.AcDebug.Log(), AcUtils.AcDebug.paramFileCopy(), AcUtils.AcCommand.run(), AcUtils.AcCommand.runAsync(), AcUtils.AcWorkspaces.storeWSpaces(), AcUtils.AcDebug.unhandledException(), and AcUtils.AcLocks.unlockAsync().

static void AcUtils.AcDebug.Log ( string  message,
string  xmlParamFile,
bool  formatting = true 
)
inlinestatic

Used by triggers, this method overload includes all functionality of Log(string, bool) and adds overwriting the trigger's xmlParamFile with the message text so it is displayed in the console or error dialog given to the user on trigger failure.

Results from AccuRev commands issued on the command line are sent to STDOUT for both success and failure. For the AccuRev GUI, results are discarded if the program return value is zero (0) (Success). For triggers that return a non-zero program return value (Failure), the message text will display in the console or error dialog provided the xmlParamFile sent by AccuRev was overwritten with it. Otherwise, the raw XML param data will display which is not user-friendly.

Parameters
messageThe text to be logged and displayed to the user on trigger failure.
xmlParamFileThe XML trigger param file sent by AccuRev to the trigger.
formattingtrue to include the date, time and newline formatting in the log file. false for no formatting.
Exceptions
Exceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\<trig_name>-YYYY-MM-DD.log on failure to overwrite the XML param file.
See also
AcUtils.ParamFileCopy

Definition at line 413 of file AcDebug.cs.

static bool AcUtils.AcDebug.paramFileCopy ( string  xmlFile,
ParamFileCopy  pfcopy,
string  trigger,
string  prncpl,
string  command 
)
inlinestatic

Used by a trigger to save the content of the XML param file passed to it by AccuRev to %LOCALAPPDATA%\AcTools\Param\<trigger-command-principal-timestamp>.xml.

Parameters
xmlFileXML param file sent to the trigger by AccuRev.
pfcopyParamFileCopy enum to indicate in what manner to handle the XML param file passed by AccuRev.
triggerName of this trigger.
prncplPrincipal name of the user who issued the command.
commandAccuRev command issued.
Returns
true if operation ran successfully, false on error.
Exceptions
Exceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\<trig_name>-YYYY-MM-DD.log on failure to handle a range of exceptions.
See also
paramFileCopy(ParamFileCopy, string, string, string)

Definition at line 131 of file AcDebug.cs.

static bool AcUtils.AcDebug.paramFileCopy ( ParamFileCopy  pfcopy,
string  xml,
string  trigger,
string  prncpl 
)
inlinestatic

Used by the server_auth_trig to save the content of the XML param data passed to it by AccuRev to %LOCALAPPDATA%\AcTools\Param\server_auth_trig-principal-timestamp.xml.

Overloaded version used by the server_auth_trig since the XML param data is sent, for security reasons, via STDIN and not in a file.

Parameters
pfcopyParamFileCopy enum to indicate in what manner to handle the XML param data passed by AccuRev.
xmlString containing the XML param data.
triggerName of the trigger (server_auth_trig until something changes).
prncplPrincipal name of the user who issued the command.
Returns
true if operation ran successfully, false on error.
Exceptions
Exceptioncaught and logged in %LOCALAPPDATA%\AcTools\Logs\server_auth_trig-YYYY-MM-DD.log on failure to handle a range of exceptions.
See also
paramFileCopy(string, ParamFileCopy, string, string, string)

Definition at line 200 of file AcDebug.cs.

static void AcUtils.AcDebug.unhandledException ( object  sender,
UnhandledExceptionEventArgs  args 
)
inlinestatic

Ensure that an unhandled exception gets logged to %LOCALAPPDATA%\AcTools\Logs\<prog_name>-YYYY-MM-DD.log before the system default handler terminates the application.

// save an unhandled exception in log file before program terminates
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AcDebug.unhandledException);
See also
AppDomain.UnhandledException Event

Definition at line 543 of file AcDebug.cs.

Property Documentation

string AcUtils.AcDebug.TrigTargetEnv
staticget

Returns "AccuRevTriggers", the name of the environment variable on the AccuRev server that points to the network share where TriggersTarget.xml and other application support files are located.

Definition at line 109 of file AcDebug.cs.