Class CultureDataFormatter
Namespace: SuperOffice.WebApi.DataAssembly: SuperOffice.WebApi.dll This is a helper class designed to encode, parse and reformat culturally sensitive data types between an application server without culture knowledge, and a front-end with such knowledge.
Inheritance
object ← CultureDataFormatterInherited Members
object.ToString(), object.Equals(object), object.Equals(object, object), object.ReferenceEquals(object, object), object.GetHashCode(), object.GetType(), object.MemberwiseClone()Remarks
<p></p> The problem: The application server does not know the culture of the current client. At the same time, we need to be able to include culturally sensitive data (such as a date) as part of a tooltip or other server-side generated text. Before displaying this text to the user, culturally sensitive elements need to be parsed and reformatted to the correct culture. <p></p> The methods in this class take care of both sides of this process. The Encode methods, such as <xref href=“SuperOffice.WebApi.Data.CultureDataFormatter.EncodeDate(System.DateTime)” data-throw-if-not-resolved=“false”></xref>, take a native data type as input and return a string that contains both a specification of what it is (a date) and the value formatted in the invariant culture. <p></p> The <xref href=“SuperOffice.WebApi.Data.CultureDataFormatter.LocalizeEncoded(System.String)” data-throw-if-not-resolved=“false”></xref> method will take such a formatted element, and by calling on the proper LocalFormat method (such as <xref href=“SuperOffice.WebApi.Data.CultureDataFormatter.LocalFormatDate(System.DateTime)” data-throw-if-not-resolved=“false”></xref>, return it in its correct form according to the current culture settings for the thread.Fields
BeginTag
Field Value
stringBinaryMarker
Field Value
stringDateMarker
Field Value
stringDateTimeMarker
Field Value
stringDoubleMarker
Field Value
stringEndTag
Field Value
stringIntArrMarker
Field Value
stringIntMarker
Field Value
stringMarkerSeparator
Field Value
charMoneyMarker
Field Value
stringTimeMarker
Field Value
stringTimeSpanMarker
Field Value
stringMethods
AddColon(string)
Add a colon to a string if it was not already there, strip any whitespaceParameters
label string
String to process
Returns
string Original string, now guaranteed to end in exactly one colonAddTerminator(string, string)
Add a terminator to a string. The string is first stripped, then the terminator is added at the end with no whitespace.Parameters
label string
String to process
terminator string
Terminator to add
Returns
string String, now ending with terminator and no white spaceCompareEncoded(string, string)
Compare two encoded strings, by parsing them into their underlying data datatype and comparing thoseParameters
x string
Formatted string
y string
Formatted string
Returns
int -1, 0 or 1 depending on the ordering relation between x and yEncode(object)
Encode a object based on type. Types supported: DateTime, Double, Integer, String and BooleanParameters
value object
Object to be encoded
Returns
string Encoded objectEncodeBinary(Stream)
Encode a block of binary data, such as an imageParameters
data Stream
DateTime whose date component is to be encoded
Returns
string Encoded dateEncodeBinary(Stream, bool)
Encode a block of binary data, such as an imageParameters
data Stream
Stream be encoded
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded dateEncodeBinaryNoTags(Stream)
Parameters
data Stream
Returns
stringEncodeDate(DateTime)
Encode a date, without a time partParameters
dateTime DateTime
DateTime whose date component is to be encoded
Returns
string Encoded dateEncodeDate(DateTime, bool)
Encode a date, without a time part. Optionally skip encoding and return an empty string instead.Parameters
dateTime DateTime
DateTime whose date component is to be encoded
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded dateEncodeDateTime(DateTime)
Encode a date, with a time part.Parameters
dateTime DateTime
DateTime whose date and time components are to be encoded
Returns
string Encoded date/timeEncodeDateTime(DateTime, bool)
Encode a date, with a time part. Optionally skip encoding and return an empty string instead.Parameters
dateTime DateTime
DateTime whose date and time components are to be encoded
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded date/timeEncodeDouble(double, int)
Encode a double (decimal value), with the given number of decimals. Note that the full precision is included here, but rounded to the given number of decimals on (re)localization. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies, saying $ when it’s actually € or NOK is silly).Parameters
val double
Value to be encoded
decimals int
Final desired number of decimals
Returns
string Encoded valueEncodeDouble(double, int, bool)
Encode a double (decimal value), with the given number of decimals. Note that the full precision is included here, but rounded to the given number of decimals on (re)localization. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies, saying $ when it’s actually € or NOK is silly). Optionally skip encoding and return an empty string instead.Parameters
val double
Value to be encoded
decimals int
Final desired number of decimals
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded valueEncodeDouble(double)
Encode a double (decimal value). On localization, the default number of decimal digits will be used. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies).Parameters
val double
Value to be encoded
Returns
string Encoded valueEncodeDouble(double, bool)
Encode a double (decimal value). On localization, the default number of decimal digits will be used. Also note that currency amounts should use the EncodeMoney method, if the cultural settings for money are to be taken into account (though the currency symbol is NOT used in localization, because we may be displaying non-native currencies). Optionally skip encoding and return an empty string instead.Parameters
val double
Value to be encoded
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded valueEncodeInt(int)
Encode an integer. Integers are usually not culturally sensitive… but who knows.Parameters
val int
Value to encode
Returns
string Encoded valueEncodeInt(int, bool)
Encode an integer. Integers are usually not culturally sensitive… but who knows. Optionally skip encoding and return an empty string instead.Parameters
val int
Value to encode
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded valueEncodeIntArr(params int[])
Parameters
intArr int[]
Returns
stringEncodeMoney(double)
Encode a double, for displaying it as money. The local user settings for currency, EXCEPT the currency symbol, will be used for display. No currency symbol will be display regardless of settings.Parameters
val double
Value to encode
Returns
string Encoded valueEncodeMoney(double, bool)
Encode a double, for displaying it as money. The local user settings for currency, EXCEPT the currency symbol, will be used for display. No currency symbol will be display regardless of settings. Optionally skip encoding and return an empty string instead.Parameters
val double
Value to encode
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded valueEncodeTime(DateTime)
Encode a time, without a date partParameters
dateTime DateTime
DateTime whose time component is to be encoded
Returns
string Encoded timeEncodeTime(DateTime, bool)
Encode a time, without a date part. Optionally skip encoding and return an empty string instead.Parameters
dateTime DateTime
DateTime whose time component is to be encoded
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded timeEncodeTimeSpan(TimeSpan, bool)
Encode a timespan, encodes total number of seconds Optionally skip encoding and return an empty string instead.Parameters
timeSpan TimeSpan
TimeSpan to be encoded.
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded timeEncodeTimeSpan(int, bool)
Encode a timespan Optionally skip encoding and return an empty string instead.Parameters
seconds int
Seconds to be encoded.
performEncode bool
If true, the input parameter is encoded to string. If false, an empty string is returned instead.
This parameter is implemented to streamline coding of optimized field population in the archive providers, where a mode
switch may eliminate the need for string-encoded display values.
Returns
string Encoded timeGetCultureDisplayName(CultureInfo)
Parameters
cultureInfo CultureInfo
Returns
stringGetReadableTimeSpan(int, bool, string, string, string, string, string)
Convert the time/duration/timespan to a “readable” text - either seconds, or day/hour/minute/secondParameters
seconds int
Total seconds to convert
mostSignificant bool
If true, then only show the most-significant unit; otherwise show d/h/m/s
daySignifier string
The string to use for the day component suffix
hourSignifier string
The string to use for the hour component suffix
minuteSignifier string
The string to use for the minute component suffix
secondSignifier string
The string to use for the second component suffix
zeroSignifier string
The suffix string to use when 0 seconds were passed. Empty string might be returned if this parameter was missing
Returns
string Formatted stringGetStringType(string, out string, out int)
Parameters
encodedSomething string
val string
decimals int
Returns
stringGetSuperOfficeLanguages()
Get all current supported superoffice languages, by superoffice language code (win legacy)Returns
IEnumerable<string>LocalFormatDate(DateTime)
Format a date (without time) according to current settingsParameters
dateTime DateTime
DateTime to be formatted
Returns
string Formatted dateLocalFormatDateTime(DateTime)
Format a date with time according to current settingsParameters
dateTime DateTime
Datetime to be formatted
Returns
string Formatted date and timeLocalFormatDouble(double, int)
Format a double, with the given number of decimal digits; otherwise the current settings will be followedParameters
val double
Double to be formatted
decimals int
Desired number of decimals
Returns
string Formatted numberLocalFormatInt(int)
Format an integer according to current settingsParameters
val int
int to be formatted
Returns
string Formatted integerLocalFormatLongDate(DateTime)
Format a long date (without time) according to current settingsParameters
dateTime DateTime
DateTime to be formatted
Returns
string Formatted long dateLocalFormatLongDateTime(DateTime)
Format a long date with a short time according to current settingsParameters
dateTime DateTime
Datetime to be formatted
Returns
string Formatted long date and short timeLocalFormatMoney(double)
Format a double as a currency value, though without a currency symbol. Other local settings for currencies will be followed.Parameters
val double
Double to be formatted
Returns
string Formatted amountLocalFormatTime(DateTime)
Format a time without date according to current settingsParameters
dateTime DateTime
DateTime to be formatted
Returns
string Formatted time, without dateLocalizeEncoded(string)
Take an encoded value of any type, parse it, and reformat it to its localized (current culture) string formParameters
encodedSomething string
Output from one of the Encode methods
Returns
string Equivalent, localized valueMapCsLanguageToSuperOfficeLanguage(string)
Convert a language code from cs to SuperOffice language code.Parameters
csLang string
Returns
string SuperOffice languagecode or string.empty if none foundMapCultureToSuperOfficeLanguage(string)
Converts .net Culture name (“sv-SE”) to SuperOffice language code (“SW”).Parameters
cultureName string
Either a culture name or a SuperOffice language code.
Returns
string A SuperOffice language code. (US, NO, SW, DA, FI, FR, GE, IT, NL, SP, PL, RU, CN, CZ, JP, UK, KO, VI, BR, CH)Remarks
Converting to a SuperOffice language code twice is harmless. <p></p> If unable to determine a mapping, the default is US (English). <p></p> See also <a href=“http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx”>MSDN on culture codes</a>.See Also
CultureDataFormatter.MapSuperOfficeLanguageToCulture(string)MapLCIDToSuperOfficeLanguage(int)
Converts a .net culture LCID to SuperOffice Language CodeParameters
lcid int
The LCID to convert
Returns
string The SuperOffice language code if defined - the two letter iso name if undefinedMapLanguageToCsLanguage(string)
Convert a language code to the language code expected by CS.Parameters
languageCode string
Returns
stringMapSuperOfficeLanguageToCulture(string)
Converts a SuperOffice language code (“SW”) to a neutral .net culture name (“sv”)Parameters
superOfficeLanguageCode string
SuperOffice language code. (US, NO, SW, DA, FI, FR, GE, IT, NL, SP, PL, RU, CN, CZ, JP, UK, KO, VI, BR, CH)
Returns
string .net neutral Culture name, or empty string (invariant culture) if no mapping foundRemarks
If unable to determine a mapping, the default is US (English). <p></p> See also <a href=“http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx”>MSDN on culture codes</a>.See Also
CultureDataFormatter.MapCultureToSuperOfficeLanguage(string)ParseEncoded(string)
Inspect the marker and parse the content, returning a strongly typed object (double, int, byte[], DateTime etc)Parameters
encodedSomething string
Returns
objectParseEncodedBinary(string)
Parse/decode an encoded binary data block - either with a marker, or just a Base64 encoded stringParameters
encodedBinary string
Returns
byte[]ParseEncodedDate(string)
Parameters
encodedDate string
Returns
DateTimeParseEncodedDecimal(string)
Parse “123.4” and “[F:123.4]” into 123.4Parameters
encodedDecimal string
“123.4” or “[F:123.4]“
Returns
decimal The value or an exception if not a decimalParseEncodedDouble(string)
Parse “123.4” and “[F:123.4]” into 123.4Parameters
encodedDouble string
“123.4” or “[F:123.4]“
Returns
double The value or an exception if not an doubleParseEncodedInt(string)
Parse “123” and “[I:123]” into 123. Parse “abc” into 0. Does not throw, but returns 0.Parameters
encodedInt string
“123” or “[I:123]“
Returns
int The value as int, or 0 if not an integerParseEncodedInt(string, bool)
Parse “123” and “[I:123]” into 123.Parameters
encodedInt string
“123” or “[I:123]”
strictly bool
If true, then throws instead of returning 0 for non-numbers
Returns
int The value or an exception if not an integerParseEncodedIntArr(string)
Parameters
encodedIntArr string
Returns
int[]ParseEncodedTimeSpan(string, bool)
Parameters
encodedTimeSpan string
strictly bool
Returns
intParseInlineElements(string, string)
Parses a resource string with inline culture-sensitive data in the text, for instance dates… provided they have been encoded using the SuperOffice.CRM.Globalization.CultureDataFormatter in the first place. Multi-language elements are also handled, before any culture-sensitive elements.Parameters
resourceString string
The string to parse
cultureName string
The cultureName, typically en-US, nb-NO, but also US, NO is accepted
Returns
string Parsed resource string.ParseInlineMultiLanguageString(string, string, int)
Parses the string for multilang strings and uses <xref href=“SuperOffice.WebApi.Data.CultureDataFormatter.ParseMultiLanguageString(System.String%2cSystem.String)” data-throw-if-not-resolved=“false”></xref> to translate the fragment to a culture specific string partParameters
multilangString string
The multilanguage string to parse: <pre><code class=“lang-csharp”>US:“Location and size”;GE:“Position und Größe”;NO:“Posisjon og størrelse”</code></pre>
cultureName string
The cultureName, typically en-US, nb-NO, but also US, NO is accepted
startingIndex int
The starting index for the parsing
Returns
string All culture specific string parts translated, or original string if there is a problemParseMultiLanguageString(string, string)
Returns the string part of the specified culture from the multi language string These strings are typically used in SuperOffice list and description data <example> String example from PrefDesc table: US:“Location and size”;GE:“Position und Größe”;NO:“Posisjon og størrelse” </example>Parameters
multilangString string
The multilanguage string to parse: <pre><code class=“lang-csharp”>US:“Location and size”;GE:“Position und Größe”;NO:“Posisjon og størrelse”</code></pre>
cultureName string
The cultureName, typically en-US, nb-NO, but also US, NO is accepted
Returns
string Culture specific string part, or original string if there is a problemRemarks
This version will also accept strings that have non-multilanguage text before and after the multilanguage block, and even multiple multilanguage blocks (provided there is at least one non-conforming character between them), isolating them and parsing each one separately. Non-conforming text is kept in place in the output.StripColon(string)
Strip a terminating colon from a string, and any whitespaceParameters
label string
String to process
Returns
string String, without colon and without leading/trailing whitespaceStripCountrySpecificsFromLanguageName(string)
Converts “English (Zimbabwe)” into plain “English” by removing anything in parenthesis and stripping spaces.Parameters
languageName string
Human readable language name: “Norsk (Bokmål)” or “Francaise”
Returns
string Simplified language name with initial capital: “Norsk” or “Francaise”StripTerminator(string, string)
Strip a terminator from a string. Whitespace is first trimmed from both sides of the string, the terminator is removed if present, and any whitespace now at the end of the string is also removedParameters
label string
String to process
terminator string
Terminator to remove
Returns
string Original string minus terminatorTryParse(string, out int)
Try to parse a string as an encoded or bare InvariantCulture Integer32Parameters
encoded string
String, either marked with [I: ] or just an integer
result int
Int value, if return value is true; otherwise 0
Returns
bool true if parsing succeededTryParse(string, out int[])
Parameters
encodedIntArr string
result int[]
Returns
boolTryParse(string, out double)
Try to parse a string as an encoded or bare InvariantCulture DoubleParameters
encoded string
String, either marked with [F: ] or just a date
result double
Double value, if return value is true; otherwise 0
Returns
bool true if parsing succeededTryParse(string, out DateTime)
Try to parse a string as an encoded or bare InvariantCulture DateTimeParameters
encoded string
String, either marked with [DT: ] or just a datetime
result DateTime
DateTime value, if return value is true; otherwise <xref href=“System.DateTime.MinValue” data-throw-if-not-resolved=“false”></xref>