Class Utilities
Common utility class contains shared methods to enhance the generic works
Inheritance
Namespace: AxaFrance.WebEngine
Assembly: AxaFrance.WebEngine.dll
Syntax
public static class Utilities
Methods
| Improve this Doc View SourceExtractDateFromText(String)
Turn the string "JJ/MM/AAAA" into a date
Declaration
public static DateTime ExtractDateFromText(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The string to convert |
Returns
Type | Description |
---|---|
System.DateTime | The date represented by the String. If no date is contained in the string or wrong format, the current date is returned |
GenerateEmail(String, String, Boolean, String)
Return an email based on first and last name. No transformation is done on last name and first names. The email is considered unique as the date is injected in the construction.
Declaration
public static string GenerateEmail(string lastname, string firstname, bool isUnique = true, string domain = "test.com")
Parameters
Type | Name | Description |
---|---|---|
System.String | lastname | The last name. |
System.String | firstname | The first name. |
System.Boolean | isUnique | Indicates if the generated email must be unique or not. Default: true |
System.String | domain | The domain of the generated mail. Default: gmail.com |
Returns
Type | Description |
---|---|
System.String | An email. |
GeneratePhoneNumber(String)
Return a phone number composed by a fixed base and the 4 last digits randomly generated.
Declaration
public static string GeneratePhoneNumber(string numberBase = "01000")
Parameters
Type | Name | Description |
---|---|---|
System.String | numberBase | The first part of the phone number. Default: 010000 (french format) |
Returns
Type | Description |
---|---|
System.String | A phone number |
GetRandomItemFromEnvironmentVariable(String, Char)
Picks up a random value from an environment variable containing a list of values.
Declaration
public static string GetRandomItemFromEnvironmentVariable(string variable, char separator = ';')
Parameters
Type | Name | Description |
---|---|---|
System.String | variable | The name of the environment variable |
System.Char | separator | The list separator used to define the environment variable. Default: ';' |
Returns
Type | Description |
---|---|
System.String | String |
GetRandomLetter()
Return a random letter (uppercase).
Declaration
public static string GetRandomLetter()
Returns
Type | Description |
---|---|
System.String | String |
GetRandomNumber(Int32)
Generate a random number between 0 and the value.
Declaration
public static int GetRandomNumber(int val)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | val | The max value. |
Returns
Type | Description |
---|---|
System.Int32 | Integer |
GetRandomStringFromList(Object[])
Randomly select an item from a list. If the field has single or double quotes, quotes are removed.
Declaration
public static object GetRandomStringFromList(object[] items)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | items | List of items |
Returns
Type | Description |
---|---|
System.Object | Picked-up item |
LoremIpsum(Int32, Int32, Int32, Int32, Int32)
Generates a Lorem Ipsum text.
Declaration
public static string LoremIpsum(int minWords, int maxWords, int minSentences, int maxSentences, int numParagraphs)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | minWords | The min number of words in the generated text. |
System.Int32 | maxWords | The max number of words in the generated text. |
System.Int32 | minSentences | The min number of sentences in the generated text. |
System.Int32 | maxSentences | The max number of sentences in the generated text. |
System.Int32 | numParagraphs | The number of paragraphs in the generated text. |
Returns
Type | Description |
---|---|
System.String | A Lorem Ipsum string of the defined size. |
SaveFile(String, String)
Saves the content into a file
Declaration
public static void SaveFile(string filename, string content)
Parameters
Type | Name | Description |
---|---|---|
System.String | filename | The file name to be saved. |
System.String | content | The content to save. |
ShiftDateByDuration<T>(String, T)
Returns a new date calculated from a given date and a duration.
The duration is positive or negative with a unity.
The unity is (D or J), M or (Y or A) representing respectively : a duration expressed in days, month or year.
The sign indicates that the calculated date must be in the past (negative) or in the future (positive).
The start date is optional. If omitted, the current date is considered.
If passed as argument, the start date must be either a string with the following format "DD/MM/YYYY" or a DateTime or even a "differential" date like the duration itself.
In this last case, the startDate is recalculated from the current date.
Example:
MoveDateByDuration("7D"): returns Today+7 days.
MoveDateByDuration("-6M", DateTime(2017, 6, 25)): should return 25th of december 2016
MoveDateByDuration("-6M", "25/06/2017"): should return 25th of december 2016.
MoveDateByDuration("2D", "1D"): the day in 3 days (2 days from tomorrow).
Declaration
public static DateTime ShiftDateByDuration<T>(string duration, T startDate)
Parameters
Type | Name | Description |
---|---|---|
System.String | duration | |
T | startDate |
Returns
Type | Description |
---|---|
System.DateTime | The calcuated Date of type System.DateTime |
Type Parameters
Name | Description |
---|---|
T |