PreEmptive Analytics .NET API  1.3
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Static Public Member Functions | List of all members
PreEmptive.Analytics.Common.Utilities.Utils Class Reference

Class containing extension methods to make our lives easier. More...

Static Public Member Functions

static string ToISOFormat (this DateTime dateTime)
 Converts a DateTime object to a string in ISO format. More...
 
static string Sanitize (this string s)
 Trims whitespace off of the beginning and end of a string if it is not null or empty. More...
 
static IList< TagByName (this IList< Tag > tags, string name)
 Retrieves an IList of Tags with the given name. More...
 
static string GetInstanceId (this IPlatform platform, Configuration config, ILogger logger)
 Retrieves the instance ID. More...
 
static string GetGeneratedUserName (this IPlatform platform, Configuration config, ILogger logger)
 Retrieves the instance ID. More...
 
static bool WithTimeout (Action task, int duration)
 Executes a task on the threadpool with a timeout More...
 
static void ExecuteAsync (this IAsyncProvider platform, Action action, bool highPriority=false)
 Executes a method asynchronously. If the provider throws an error, will fall back to the threadpool More...
 
static void ExecuteAsync< T > (this IAsyncProvider platform, Func< T > action, Action< T > completed=null, bool highPriority=false)
 Executes a method asynchronously. If the provider throws an error, will fall back to the threadpool. More...
 
static void ExecuteSync< T > (Func< T > action, Action< T > completed=null)
 Executes a method synchronously and catches any error that occurs. More...
 
static MessageBatch[] Split (this MessageBatch batch)
 This will split the batch in half. If there is only one message in the batch, then it will return a list with only the single batch More...
 
static void LogException (this ILogger logger, Exception e, string prefix="An unexpected exception occured")
 Will log an exception as an error More...
 
static void LogExceptionWarning (this ILogger logger, Exception e, string prefix="An unexpected non-critical exception occured")
 Will log an exception as a warning More...
 
static void Attempt (Action action, ILogger logger=null)
 Attempt the action and swallow any exceptions it throws More...
 
static T Attempt< T > (Func< T > action, ILogger logger=null)
 Attempt the action and swallow any exceptions it throws More...
 
static void MergeStopDefaults (this IPlatform platform, Configuration config)
 Will merge the defaults of the platform with an existing configuration. Any nulls will be replaced by platform defaults More...
 

Detailed Description

Class containing extension methods to make our lives easier.

Member Function Documentation

static void PreEmptive.Analytics.Common.Utilities.Utils.Attempt ( Action  action,
ILogger  logger = null 
)
static

Attempt the action and swallow any exceptions it throws

Parameters
actionthe action to execute
loggerA logger for debug log messages to be sent to
static T PreEmptive.Analytics.Common.Utilities.Utils.Attempt< T > ( Func< T >  action,
ILogger  logger = null 
)
static

Attempt the action and swallow any exceptions it throws

Parameters
actionthe action to execute
loggerA logger for debug log messages to be sent to
static IList<Tag> PreEmptive.Analytics.Common.Utilities.Utils.ByName ( this IList< Tag tags,
string  name 
)
static

Retrieves an IList of Tags with the given name.

Parameters
tagsThe IList of Tags to look through.
nameThe tag name to look for.
Returns
The found list of tags.
static void PreEmptive.Analytics.Common.Utilities.Utils.ExecuteAsync ( this IAsyncProvider  platform,
Action  action,
bool  highPriority = false 
)
static

Executes a method asynchronously. If the provider throws an error, will fall back to the threadpool

Parameters
platformthe provider of the asynchronous mechanism
actionthe code to execute
highPriorityIs a high priority
static void PreEmptive.Analytics.Common.Utilities.Utils.ExecuteAsync< T > ( this IAsyncProvider  platform,
Func< T >  action,
Action< T >  completed = null,
bool  highPriority = false 
)
static

Executes a method asynchronously. If the provider throws an error, will fall back to the threadpool.

Template Parameters
TThe return type of the action.
Parameters
platformThe provider of the asynchronous mechanism.
actionThe code to execute.
completedThe code to execute when action is completed.
highPriorityIs the action a high priority.
static void PreEmptive.Analytics.Common.Utilities.Utils.ExecuteSync< T > ( Func< T >  action,
Action< T >  completed = null 
)
static

Executes a method synchronously and catches any error that occurs.

Template Parameters
TThe return type of the action.
Parameters
actionThe code to execute.
completedThe code to execute when action is completed.
static string PreEmptive.Analytics.Common.Utilities.Utils.GetGeneratedUserName ( this IPlatform  platform,
Configuration  config,
ILogger  logger 
)
static

Retrieves the instance ID.

Parameters
platformThe current platform.
configThe current configuration.
loggerILogger instance that determines how logging is done.
Returns
The instance ID.
static string PreEmptive.Analytics.Common.Utilities.Utils.GetInstanceId ( this IPlatform  platform,
Configuration  config,
ILogger  logger 
)
static

Retrieves the instance ID.

Parameters
platformThe current platform.
configThe current configuration.
logger
Returns
The instance ID.
static void PreEmptive.Analytics.Common.Utilities.Utils.LogException ( this ILogger  logger,
Exception  e,
string  prefix = "An unexpected exception occured" 
)
static

Will log an exception as an error

Parameters
loggerThe logger to log to
eThe exception
prefixThe prefix message to include in the log message
static void PreEmptive.Analytics.Common.Utilities.Utils.LogExceptionWarning ( this ILogger  logger,
Exception  e,
string  prefix = "An unexpected non-critical exception occured" 
)
static

Will log an exception as a warning

Parameters
loggerThe logger to log to
eThe exception
prefixThe prefix message to include in the log message
static void PreEmptive.Analytics.Common.Utilities.Utils.MergeStopDefaults ( this IPlatform  platform,
Configuration  config 
)
static

Will merge the defaults of the platform with an existing configuration. Any nulls will be replaced by platform defaults

Parameters
platformThe platform to merge from
configThe configurate instance to modify
static string PreEmptive.Analytics.Common.Utilities.Utils.Sanitize ( this string  s)
static

Trims whitespace off of the beginning and end of a string if it is not null or empty.

Parameters
sThe string to trim.
Returns
The trimmed string.
static MessageBatch [] PreEmptive.Analytics.Common.Utilities.Utils.Split ( this MessageBatch  batch)
static

This will split the batch in half. If there is only one message in the batch, then it will return a list with only the single batch

Parameters
batch
Returns
static string PreEmptive.Analytics.Common.Utilities.Utils.ToISOFormat ( this DateTime  dateTime)
static

Converts a DateTime object to a string in ISO format.

Parameters
dateTimeA DateTime object.
Returns
An ISO formatted string.
static bool PreEmptive.Analytics.Common.Utilities.Utils.WithTimeout ( Action  task,
int  duration 
)
static

Executes a task on the threadpool with a timeout

Parameters
tasktask to execute
durationduration of timeout in milliseconds
Returns
true if succeeded, false if timed out

The documentation for this class was generated from the following file: