initial
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
Aaron Greenlee
|
||||
http://aarongreenlee.com/
|
||||
|
||||
This work is licensed under a Creative Commons Attribution-Share-Alike 3.0
|
||||
Unported License.
|
||||
|
||||
// Original Info -----------------------------------------------------------
|
||||
Author : Aaron Greenlee
|
||||
Created : 10/01/2010
|
||||
|
||||
Core configuration object for Hoth. This object provides all the
|
||||
functionality for a Hoth Config Object. Individual implementations should
|
||||
extend this object and provide their own values within the property
|
||||
declaration.
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
Modified : 12/13/2010 10:04:06 AM by Aaron Greenlee.
|
||||
- Added support for global settings.
|
||||
|
||||
*/
|
||||
component
|
||||
accessors='true'
|
||||
{
|
||||
|
||||
/** Construct a configuration object for Hoth. */
|
||||
public function init ()
|
||||
{
|
||||
local.md = getMetadata(this);
|
||||
local.n = arrayLen(local.md.properties);
|
||||
for (local.i=1; local.i <= local.n; local.i++) {
|
||||
local.fn = this['set' & local.md.properties[local.i].name];
|
||||
local.fn(local.md.properties[local.i]['default']);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void function setGlobalDatabasePath(required string path) {
|
||||
variables.GlobalDatabasePath = arguments.path;
|
||||
}
|
||||
public string function getGlobalDatabasePath() {
|
||||
return (structKeyExists(variables, 'GlobalDatabasePath'))
|
||||
? variables.GlobalDatabasePath
|
||||
: '/Hoth/db/';
|
||||
}
|
||||
|
||||
/** Expands a path **/
|
||||
public string function getLogPathExpanded ()
|
||||
{
|
||||
if (!structKeyExists(variables, 'logPathIsRelative')) {
|
||||
variables.logPathIsRelative = false;
|
||||
}
|
||||
return variables.logPathIsRelative ? expandPath( getLogPath() ) : getLogPath();
|
||||
}
|
||||
|
||||
/** Return a path for Hoth. */
|
||||
public string function getPath (name)
|
||||
{
|
||||
switch (arguments.name) {
|
||||
// Sub-Directories
|
||||
case 'incidents' :
|
||||
case 'exceptions' :
|
||||
return getLogPathExpanded() & '/' & lcase(arguments.name);
|
||||
break;
|
||||
|
||||
// Files
|
||||
case 'exceptionIndex' :
|
||||
case 'exceptionReport' :
|
||||
case 'exceptionReportActivity' :
|
||||
return getLogPathExpanded() & '/' & lcase(arguments.name) & '.log';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
Aaron Greenlee
|
||||
http://aarongreenlee.com/
|
||||
|
||||
This work is licensed under a Creative Commons Attribution-Share-Alike 3.0
|
||||
Unported License.
|
||||
|
||||
// Original Info -----------------------------------------------------------
|
||||
Author : Aaron Greenlee
|
||||
Created : 12/13/2010
|
||||
|
||||
Responsible for helping Hoth report for multiple applications.
|
||||
*/
|
||||
component
|
||||
name = 'HothApplicationManager'
|
||||
accessors = true
|
||||
{
|
||||
property name='applications' type='array';
|
||||
|
||||
// The filename that holds application knowledge.
|
||||
VARIABLES.APP_LOCK_KEY = 'HothApplicationDBFileLock';
|
||||
|
||||
/** Constructor.
|
||||
* @HothConfig Requires a HothConfig Object.
|
||||
*/
|
||||
public Hoth.object.HothApplicationManager function init(
|
||||
required HothConfig
|
||||
){
|
||||
|
||||
setApplications( loadApplicationsFromDisk(HothConfig) );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/** To allow for easy reporting, Hoth needs to be able to track new
|
||||
applications (or really, new log paths). When a new instance of
|
||||
HothTracker is created, this method will be called. **/
|
||||
public boolean function learnApplication(
|
||||
required HothConfig
|
||||
){
|
||||
// Prevent any other threads from saving our new application
|
||||
lock
|
||||
name=VARIABLES.APP_LOCK_KEY
|
||||
timeout=arguments.HothConfig.getTimeToLock()
|
||||
type="exclusive"
|
||||
{
|
||||
local.knownApplications =
|
||||
loadApplicationsFromDisk(argumentCollection=arguments);
|
||||
|
||||
for(local.index in local.knownApplications)
|
||||
{
|
||||
// Confirm our keys exist
|
||||
if (structKeyExists(local.index, 'logPath'))
|
||||
{
|
||||
// If we find the same logPath, we know about this
|
||||
// application and need to exit.
|
||||
if (local.index.logPath == arguments.HothConfig.getLogPath())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We did not find out application path within the file.
|
||||
// Create the struct and append it to our array.
|
||||
local.applicationDataToSave =
|
||||
{
|
||||
'applicationName' = arguments.HothConfig.getApplicationName()
|
||||
,'logPath' = arguments.HothConfig.getLogPath()
|
||||
,'created' = now()
|
||||
};
|
||||
arrayAppend(
|
||||
local.knownApplications
|
||||
,local.applicationDataToSave
|
||||
);
|
||||
|
||||
// Save the contents of the entire array, replacing the entire file
|
||||
local.path = arguments.HothConfig.getGlobalDatabasePath();
|
||||
fileWrite(
|
||||
expandPath(arguments.HothConfig.getGlobalDatabasePath() & 'applications.hoth')
|
||||
,serializeJSON(local.knownApplications)
|
||||
,'UTF-8'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Loads applications already observed by Hoth from disk.
|
||||
* This process should be locked by the calling method.
|
||||
* @HothConfig Requires a HothConfig Object. */
|
||||
private array function loadApplicationsFromDisk (
|
||||
required HothConfig
|
||||
){
|
||||
local.path = arguments.HothConfig.getGlobalDatabasePath();
|
||||
local.appfile = expandPath(arguments.HothConfig.getGlobalDatabasePath() & 'applications.hoth');
|
||||
|
||||
// Return an empty array if the appFile does not exist.
|
||||
if (!fileExists( local.appfile ) )
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
local.applicationsFound = fileRead( local.appfile );
|
||||
|
||||
// Delete the database if the file is invalid.
|
||||
if (!isJSON(local.applicationsFound))
|
||||
{
|
||||
fileDelete( local.appfile );
|
||||
return [];
|
||||
}
|
||||
|
||||
// Convert the file to our desired structure
|
||||
local.parsedDB = deserializeJSON(local.applicationsFound);
|
||||
|
||||
return local.parsedDB;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
component
|
||||
{
|
||||
/**
|
||||
* Returns the number of seconds since UTC January 1, 1970, 00:00:00
|
||||
* (Epoch time).
|
||||
*
|
||||
* @param DateTime Date/time object you want converted to
|
||||
* Epoch time.(Required)
|
||||
*
|
||||
* @return Returns a numeric value.
|
||||
* @author Rob Brooks-Bilson (rbils@amkor.com)
|
||||
* @version 1, June 21, 2002
|
||||
*/
|
||||
function GetEpochTimeFromLocal() {
|
||||
local.datetime = 0;
|
||||
|
||||
if ( arrayLen(arguments) == 0)
|
||||
{
|
||||
local.datetime = Now();
|
||||
} else {
|
||||
local.datetime = arguments[1];
|
||||
}
|
||||
|
||||
return
|
||||
DateDiff(
|
||||
"s"
|
||||
,DateConvert("utc2Local", "January 1 1970 00:00")
|
||||
,datetime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
Aaron Greenlee
|
||||
http://aarongreenlee.com/
|
||||
|
||||
This work is licensed under a Creative Commons Attribution-Share-Alike 3.0
|
||||
Unported License.
|
||||
|
||||
// Original Info -----------------------------------------------------------
|
||||
Author : Aaron Greenlee
|
||||
Created : 10/01/2010
|
||||
|
||||
Interface for a Hoth Config Object.
|
||||
|
||||
*/
|
||||
interface {
|
||||
public function init ();
|
||||
public string function getLogPathExpanded();
|
||||
public string function getPath (name);
|
||||
}
|
||||
Reference in New Issue
Block a user