AP&C API Reference
Static Public Member Functions | Static Public Attributes | List of all members
Apac.Core Class Reference

This class is a container for utilities that are used throughout the system: constants, conversions, messaging, time-related features and similar functions. More...

Static Public Member Functions

static bool CanStop (SupervisableState state)
 Determines whether it is safe to call Stop on the ISupervisable or ISupervisor in the specified state. More...
 
static DbConnection GetConnection (string name)
 Gets the connection with the given name. More...
 
static string TranslatePredicateSet (PredicateSet set, IDbCommand cmd, string tableAlias)
 Converts the given PredicateSet into a T-SQL query predicate (without the 'WHERE'). This can be used to compose filtered queries against the targeted table of the data store. In the course of translation, the variables indicated in the set will be converted into query parameters and added to the provided list object. More...
 
static string TranslatePredicateOperator (PredicateOperators op)
 Translates predicate operators into DB (T-SQL) operators. More...
 
static IDbDataParameter AddParameter (IDbCommand cmd, string name, object value, System.Data.DbType type)
 Adds the parameter to the provided IDbCommand as and input parameter. More...
 
static IDbDataParameter AddParameter (IDbCommand cmd, string name, object value, System.Data.DbType type, System.Data.ParameterDirection direction)
 Adds a new parameter to the provided IDbCommand. More...
 
static void SendEmail (Message message, MessagingAddress sender, System.Collections.Generic.IEnumerable< MessagingAddress > recipients)
 This verion uses our internal messages to get the job done. More...
 
static decimal ConvertBtuToKilowatts (decimal btu)
 
static decimal ConvertKilowattsToBtu (decimal kW)
 
static decimal ConvertSquareFeetToSquareMeters (decimal squareFeet)
 
static decimal ConvertSquareMetersToSquareFeet (decimal squareMeters)
 
static void SendEmail (System.Net.Mail.MailMessage msg)
 Sends an email. More...
 
static string GetResourceValue (Type resourceType, string resourceKey)
 Gets the resource value from the given type. More...
 
static AttributeType GetPluginAttribute< AttributeType > (Type t)
 Gets the plugin attribute from the provided type. More...
 
static bool IsMeaningfulString (string str)
 Checks a string for empty, null, or only white-space. More...
 
static int GetNumberOfMonths (DateTime start, TimeSpan span)
 Determines the number of months included in the given timespan, starting at the given date. More...
 
static int GetNumberOfMonths (DateTime start, DateTime end)
 Determines the number of months included between two given dates. Note that this includes partial months so a 45-day span will return 2. More...
 
static int GetNumberOfDays (DateTime start, TimeSpan span)
 Determines the number of days included in the given time span. Note that this is not mathematically the number of hours divided by 24 but the number of days that include part of the time range, so a 36-hour range or 5 minute range that crossed midnight will both return 2, More...
 
static int GetNumberOfDays (DateTime start, DateTime end)
 
static bool SameDay (DateTime lhs, DateTime rhs)
 
static string GetMonthText (int month)
 
static int GetNumberOfYears (DateTime start, TimeSpan span)
 Determines the number of years included in the given time span. Note that this is not mathematically the number of days divided by 365 but the number of years that include part of the time range, so a 13 month time span will reutrn 2. More...
 
static int GetNumberOfYears (DateTime start, DateTime end)
 
static int GetWeekOfYear (DateTime date)
 Gets the week of the year according to the current culture's calendar week rule and first week of the year. More...
 
static int GetMonthOfYear (int year, int week, int dayOfWeek)
 Gets the month of year. More...
 
static DateTime GetFirstDayOfWeek (DateTime date)
 
static DateTime GetLastDayOfWeek (DateTime date)
 
static int GetTotalMinutes (TimeSpan span)
 
static int GetNumberOfBuckets (TimeSpan span)
 
static int GetTotalSeconds (TimeSpan span)
 
static int GetBucket (int hour, int minute)
 
static int GetBucket (DateTime timestamp)
 
static DateTime GetBucketStart (DateTime timestamp)
 Given a time it determines the time when the bucket started in which the given time falls. More...
 
static TimeSpan GetTimeStamp (int bucket, int offset)
 Given a bucket and offset it determines the time when the bucket started. More...
 
static bool BucketEndsHour (int bucket)
 Indicates that the bucket is the last of the hour. More...
 
static bool BucketEndsDay (int bucket)
 Indicates that the bucket is the last of the day. More...
 
static bool DayEndsMonth (int year, int month, int day)
 Indicates that the given day is the last day in the given month for the given year. More...
 
static int GetOffsetIntoBucket (DateTime timestamp)
 Determines the offset of a timestamp (in seconds) into the bucket. This function assumes the given timestamp is actually within the bucket and only utilized those portions of the timestamp needed to determine the offset. More...
 
static uint GetNumberOfSamples (TimeSpan interval, string measurementType, uint subintervalModulus)
 Determines the number of samples that should result from the given time interval for the given type of measurements and subinterval modulus. More...
 
static System.Drawing.Color ConvertToColor (string color)
 Will convert the given color name or HEX value to a Color object. If the conversion cannot be done, it will return Color.Black. More...
 
static System.Drawing.Color ConvertToColor (int argb)
 
static ZedGraph.SymbolType ConvertShape (string plotStyle)
 Converts a configured plot style to an enumerated SymbolType. More...
 
static Data.ValueRange ParseSensorRange (string range)
 Parses a string range of values (eg. 0-20) into a ValueRange instance. More...
 

Static Public Attributes

const string Setting_EmailSsl = "apac.messaging.email.usetls"
 
const string AlertQueue = "Alerts"
 The name of the messaging queue used for sending alert notifications. More...
 
const string DefaultQueue = "System"
 
const string MarkType_Now = "Now"
 
const string MarkType_LastBucket = "LastBucket"
 
const string MarkType_PreviousBucket = "PreviousBucket"
 
const string MarkType_EvenSamples = "EvenSamples"
 
const string MeasurementType_Measurement = "Measurement"
 
const string MeasurementType_FiveMinAvg = "FiveMinAvg"
 
const string MeasurementType_HourlyAvg = "HourlyAvg"
 
const string MeasurementType_DailyAvg = "DailyAvg"
 
const string MeasurementType_MonthlyAvg = "MonthlyAvg"
 
const string Alerts = "Alerts"
 
const decimal OneTwelfth = .08333M
 
const uint DefaultID = 0
 
static readonly object Abort = new object()
 
static readonly Regex ValidUserNameRegEx = new Regex(@"^(?=.{3,15}$)([A-Za-z0-9][._-]?)*$", RegexOptions.Compiled)
 The regex for validating user names. More...
 
static readonly Regex ValidEmailRegEx = new Regex(@"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z")
 The regex for validating email addresses. More...
 

Detailed Description

This class is a container for utilities that are used throughout the system: constants, conversions, messaging, time-related features and similar functions.

Member Function Documentation

◆ AddParameter() [1/2]

static IDbDataParameter Apac.Core.AddParameter ( IDbCommand  cmd,
string  name,
object  value,
System.Data.DbType  type 
)
inlinestatic

Adds the parameter to the provided IDbCommand as and input parameter.

Parameters
cmdThe command.
nameThe name.
valueThe value.
typeThe type.
Returns
Returns the newly created IDbDataParameter.

◆ AddParameter() [2/2]

static IDbDataParameter Apac.Core.AddParameter ( IDbCommand  cmd,
string  name,
object  value,
System.Data.DbType  type,
System.Data.ParameterDirection  direction 
)
inlinestatic

Adds a new parameter to the provided IDbCommand.

Parameters
cmdThe IDbCommand.
nameThe name.
valueThe value.
typeThe type.
directionThe direction.
Returns
Returns the newly created IDbDataParameter.

◆ BucketEndsDay()

static bool Apac.Core.BucketEndsDay ( int  bucket)
inlinestatic

Indicates that the bucket is the last of the day.

Parameters
bucketThe bucket number to analyze.
Returns
true if the bucket is the last for the day, false otherwise.

◆ BucketEndsHour()

static bool Apac.Core.BucketEndsHour ( int  bucket)
inlinestatic

Indicates that the bucket is the last of the hour.

Parameters
bucketThe bucket number to analyze.
Returns
true if the bucket is the last for the hour, false otherwise.

◆ CanStop()

static bool Apac.Core.CanStop ( SupervisableState  state)
inlinestatic

Determines whether it is safe to call Stop on the ISupervisable or ISupervisor in the specified state.

Parameters
stateThe state.
Returns
Returns true if Stop makes sense, false if it doesn't.

◆ ConvertShape()

static ZedGraph.SymbolType Apac.Core.ConvertShape ( string  plotStyle)
inlinestatic

Converts a configured plot style to an enumerated SymbolType.

Parameters
plotStyleThe name of the plot style to be converted.
Returns
The appropriate SymbolType value for the given plot style. If a match cannot be made then SymbolType.Circle is returned.

◆ ConvertToColor()

static System.Drawing.Color Apac.Core.ConvertToColor ( string  color)
inlinestatic

Will convert the given color name or HEX value to a Color object. If the conversion cannot be done, it will return Color.Black.

Parameters
colorA string color as well-known name or HEX value.
Returns
A System.Drawing.Color instance.

◆ DayEndsMonth()

static bool Apac.Core.DayEndsMonth ( int  year,
int  month,
int  day 
)
inlinestatic

Indicates that the given day is the last day in the given month for the given year.

Parameters
yearThe year to analyze.
monthThe month to analyze.
dayThe day to analyze.
Returns
true if the day is the last for the month, false otherwise.

◆ GetBucketStart()

static DateTime Apac.Core.GetBucketStart ( DateTime  timestamp)
inlinestatic

Given a time it determines the time when the bucket started in which the given time falls.

Parameters
timestampThe time used for evaluation.
Returns
The time of the beginning of the bucket.

◆ GetConnection()

static DbConnection Apac.Core.GetConnection ( string  name)
inlinestatic

Gets the connection with the given name.

Parameters
nameThe name.
Returns
Exceptions
System.Configuration.ConfigurationErrorsException

◆ GetMonthOfYear()

static int Apac.Core.GetMonthOfYear ( int  year,
int  week,
int  dayOfWeek 
)
inlinestatic

Gets the month of year.

Parameters
yearThe year.
weekThe week.
dayOfWeekThe day of week.
Returns
Return the number of the month.

◆ GetNumberOfDays()

static int Apac.Core.GetNumberOfDays ( DateTime  start,
TimeSpan  span 
)
inlinestatic

Determines the number of days included in the given time span. Note that this is not mathematically the number of hours divided by 24 but the number of days that include part of the time range, so a 36-hour range or 5 minute range that crossed midnight will both return 2,

Parameters
start
span
Returns

◆ GetNumberOfMonths() [1/2]

static int Apac.Core.GetNumberOfMonths ( DateTime  start,
DateTime  end 
)
inlinestatic

Determines the number of months included between two given dates. Note that this includes partial months so a 45-day span will return 2.

Parameters
startThe starting date to be evaluated.
endThe ending date to be evaluated.
Returns
The number of months that are included in the time span.

◆ GetNumberOfMonths() [2/2]

static int Apac.Core.GetNumberOfMonths ( DateTime  start,
TimeSpan  span 
)
inlinestatic

Determines the number of months included in the given timespan, starting at the given date.

Parameters
startThe starting date to be evaluated.
spanThe length of time to evaluate.
Returns
The number of months that are included in the time span.

◆ GetNumberOfSamples()

static uint Apac.Core.GetNumberOfSamples ( TimeSpan  interval,
string  measurementType,
uint  subintervalModulus 
)
inlinestatic

Determines the number of samples that should result from the given time interval for the given type of measurements and subinterval modulus.

Parameters
intervalThe time interval being evaluated.
measurementTypeThe type of measurement being evaluated.
subintervalModulusThe size of the subinterval to be evaluated.
Returns
The number of samples that would result from the given values.

◆ GetNumberOfYears()

static int Apac.Core.GetNumberOfYears ( DateTime  start,
TimeSpan  span 
)
inlinestatic

Determines the number of years included in the given time span. Note that this is not mathematically the number of days divided by 365 but the number of years that include part of the time range, so a 13 month time span will reutrn 2.

Parameters
start
span
Returns

◆ GetOffsetIntoBucket()

static int Apac.Core.GetOffsetIntoBucket ( DateTime  timestamp)
inlinestatic

Determines the offset of a timestamp (in seconds) into the bucket. This function assumes the given timestamp is actually within the bucket and only utilized those portions of the timestamp needed to determine the offset.

Parameters
timestampThe timestamp to be evaluated.
bucketThe bucket used as the basis for the evaluation.
Returns

Determines the offset of a timestamp (in seconds) into the bucket.

Parameters
timestamp
bucket
Returns

◆ GetPluginAttribute< AttributeType >()

static AttributeType Apac.Core.GetPluginAttribute< AttributeType > ( Type  t)
inlinestatic

Gets the plugin attribute from the provided type.

Template Parameters
AttributeTypeThe type of the Attribute class being sought. This will be PluginAttribute or a subclass thereof.
Parameters
tThe type being searched for the attribute.
Returns
Returns the attribute as a AttributeType , or null if an attribute of that type cannot be found.
Type Constraints
AttributeType :PluginAttribute 

◆ GetResourceValue()

static string Apac.Core.GetResourceValue ( Type  resourceType,
string  resourceKey 
)
inlinestatic

Gets the resource value from the given type.

Parameters
resourceTypeType of the resource.
resourceKeyName of the resource key to retrieve.
Returns

◆ GetTimeStamp()

static TimeSpan Apac.Core.GetTimeStamp ( int  bucket,
int  offset 
)
inlinestatic

Given a bucket and offset it determines the time when the bucket started.

Parameters
bucketThe bucket to be conveted.
offsetThe offset into the bucket to be converted (seconds). Offset values less than 0 are ignored and have no effect on the conversion.
Returns
A TimeSpan with the converted bucket and offset.

◆ GetWeekOfYear()

static int Apac.Core.GetWeekOfYear ( DateTime  date)
inlinestatic

Gets the week of the year according to the current culture's calendar week rule and first week of the year.

Parameters
dateThe date for which the the week is needed.
Returns
A number from 1-53 representing the week of the year.

◆ IsMeaningfulString()

static bool Apac.Core.IsMeaningfulString ( string  str)
inlinestatic

Checks a string for empty, null, or only white-space.

Parameters
strThe string to check.
Returns
Returns true if the string is not null, empty, or only white-space, false otherwise.

◆ ParseSensorRange()

static Data.ValueRange Apac.Core.ParseSensorRange ( string  range)
inlinestatic

Parses a string range of values (eg. 0-20) into a ValueRange instance.

Parameters
range
Returns

◆ SendEmail() [1/2]

static void Apac.Core.SendEmail ( Message  message,
MessagingAddress  sender,
System.Collections.Generic.IEnumerable< MessagingAddress recipients 
)
inlinestatic

This verion uses our internal messages to get the job done.

Parameters
message
sender
recipients

◆ SendEmail() [2/2]

static void Apac.Core.SendEmail ( System.Net.Mail.MailMessage  msg)
inlinestatic

Sends an email.

Parameters
msg

◆ TranslatePredicateOperator()

static string Apac.Core.TranslatePredicateOperator ( PredicateOperators  op)
inlinestatic

Translates predicate operators into DB (T-SQL) operators.

Parameters
opThe PredicateOperators to be translated.
Returns
The string representing op in T-SQL.

◆ TranslatePredicateSet()

static string Apac.Core.TranslatePredicateSet ( PredicateSet  set,
IDbCommand  cmd,
string  tableAlias 
)
inlinestatic

Converts the given PredicateSet into a T-SQL query predicate (without the 'WHERE'). This can be used to compose filtered queries against the targeted table of the data store. In the course of translation, the variables indicated in the set will be converted into query parameters and added to the provided list object.

Parameters
setThe PredicateSet to be translated.
cmdThe DbCommand to which all parameters will be added. This value can be null, but query parameters will not be used in that case and it is not recommended.
tableAliasThe alias given to the table for the given variables in the predicate set.
Returns
Returns a string containing the domain-specific rendering of the predicate.

Member Data Documentation

◆ AlertQueue

const string Apac.Core.AlertQueue = "Alerts"
static

The name of the messaging queue used for sending alert notifications.

◆ ValidEmailRegEx

readonly Regex Apac.Core.ValidEmailRegEx = new Regex(@"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z")
static

The regex for validating email addresses.

◆ ValidUserNameRegEx

readonly Regex Apac.Core.ValidUserNameRegEx = new Regex(@"^(?=.{3,15}$)([A-Za-z0-9][._-]?)*$", RegexOptions.Compiled)
static

The regex for validating user names.


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