Util Class

Collection of handy static utility like methods.

Definition

Namespace: DHI.Mike1D.Generic
Assembly: DHI.Mike1D.Generic (in DHI.Mike1D.Generic.dll) Version: 24.0.0.0 (11.1.1.1111)
C#
public static class Util
Inheritance
Object    Util

Properties

AutoFileCaseUpdate Flag indicating if the FileExists method will try to automatically fix the path for case differences. Default is false on Windows (because it will have no effect), and true on Linux.
HyperThreadingEnabled Flag specifying that Hyper Threading is enabled on this machine

This is false by default, and hence can be false, even though Hyper Threading is enabled.

ProcessorCount Returns the number of processing units in the current system.

If HyperThreadingEnabled is set, it returns half of Environment.ProcessorCount, otherwise it just returns Environment.ProcessorCount.

UnitProvider If not null, then this unit provider is use to convert values into user units

Methods

AllMessages Get a message that describes the current exception and all inner exceptions.
AsString Return value as a string, in proper unit
BaseUnit Get base unit (SI)
CandoUnitConversion Returns true if unit conversions can be performed between the two units, i.e. they are different and none of them are undefined.
ChainageEquals(Double, Double) Returns true if the chainage equals, withing LOCATION_EQUAL_TOLERANCE
ChainageEquals(Double, Double, Double) Returns true if the chainage equals, withing tolerance
ChainageIsLargerThan(Double, Double) Returns true if the referenceChainage is larger than chainage, and more than LOCATION_EQUAL_TOLERANCE after

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsLargerThan(Double, Double, Double) Returns true if the chainage is before referenceChainage, and more than tolerance after

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsLargerThanOrEquals Returns true if the referenceChainage is larger than chainage, and more than LOCATION_EQUAL_TOLERANCE after

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsSmallerThan(Double, Double) Returns true if the referenceChainage is smaller than chainage, and more than LOCATION_EQUAL_TOLERANCE before

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsSmallerThan(Double, Double, Double) Returns true if the referenceChainage is smaller than chainage, and more than tolerance before

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsSmallerThanOrEquals Returns true if the referenceChainage is smaller than or equals chainage, and more than LOCATION_EQUAL_TOLERANCE before

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

CheckDirectoryForFile Check a directory for the file, if the directory or the parent directory exists.
CreateDirectoryForFileIfNotExists Creates a directory for the file, if the directory does not already exist.

It only creates one level of directory. If the directory already exists, nothing is done.

The method returns false if it was not possible to create directory, becase the parent directory did not exists either. Otherwise it returns true.

CreateDirectoryIfNotExists Creates a directory, if the directory does not already exist.

It many levels of directory. If the directory already exists, nothing is done.

The method returns false if it was not possible to create directory, becase the parent directory did not exists either. Otherwise it returns true.

CreateStackTraceString From a stack trace object, return a stack trace string. Call like: CreateStackTraceString(System.Diagnostics.StackTrace(true), false)
EasterSunday Calculation of Easter Sunday for a given year
FileExists(FilePath) Check if file exists. If AutoFileCaseUpdate is set, allowing case differences (Linux).

If a file is found with same name but different case, the filePath is updated to match the case.

FileExists(String) Check if file exists. If AutoFileCaseUpdate is set, allowing case differences (Linux).

If a file is found with same name but different case, the path is updated to match the case.

FileExists(FilePath, Boolean) Check if file exists. If AutoFileCaseUpdate is set, allowing case differences (Linux).

If a file is found with same name but different case, the filePath is updated to match the case.

FileExists(String, String, Boolean) Check if file exists. If AutoFileCaseUpdate is set, allowing case differences (Linux).

If a file is found with same name but different case, the path is updated to match the case.

FileExistsCase Check if file exists with case (path is not checked, only file part of file path).
FullPath Get full path of path and basePath
GetParameters Get parameters of unit
GetUnitConversionFactor(eumQuantity, eumQuantity) Get a unit conversion factor from target unit to source unit. Undefined units are treated as SI unit, and does not contribute to the factor. Units need not be equivalent.

See also UnitConversionFactors(eumUnit, eumUnit, Double, Double, Boolean) for details.

GetUnitConversionFactor(eumUnit, eumUnit) Get a unit conversion factor from target unit to source unit. Undefined units are treated as SI unit, and does not contribute to the factor. Units need not be equivalent.

See also UnitConversionFactors(eumUnit, eumUnit, Double, Double, Boolean) for details.

GetUnitConversionFactor(IUnitProvider, eumItem, eumUnit) Get a unit conversion factor for EUM quantity
GetUnitConversionFactor(IUnitProvider, eumItem, eumUnit, eumUnit) Get a unit conversion factor for EUM quantity
GetUserUnitOrDefault Get a unit conversion factor for EUM quantity
IsDefined Check if this double "is defined", i.e. does not equal the UndefinedDouble
IsIntegrating Returns true if the derivedType is applying time integrating
IsSimple Returns true if this is a "simple" type
IsTime Returns true if the derivedType is a time quantity
LimitTimeStepToCheckPoint Make sure timestep hits exactly checkPoint.

The lookAhead parameter defines how many time steps before checkPoint to modify in order to hit the checkPoint. If lookAhead is 1, only the last time step before checkPoint will be modified. If 2, then two time steps before checkPoint will be modified etc.

Assuming checkPoint is after currentTime (suggestedTimeStep is returned).

MakeValidFileName Makes a file name valid by replacing invalid file name characters by an underscore.

The input string must be the file name only, and can not contain any path characters.

Max Maximum of span 1 and span 2
Min Minimum of span 1 and span 2
NextTimeAfter Returns the next time after currentTime, being an integer multiplum of dt after startTime
PathUpdateCase(FilePath) Update the Path of filepath with the case present on the disk.

The path can be relative. If it is relative, and no BaseFilePath is present, then the current working directory is used.

PathUpdateCase(String, String) Update path with the case present on the disk.

The path can be relative. If it is relative, the base path can be provided as basePath, and if that is not provided (null), then the current working directory is used.

PathUpdateCase(String, String) Update path with the case present on the disk.

The path can be relative. If it is relative, the base path can be provided as basePath, and if that is not provided (null), then the current working directory is used.

ReadAssemblyBuildDateTime Returns the DateTime that the assembly was build.

The PE header of the assembly file includes a time stamp (in UTC time) of when it was build. this procedures opens the assembly file, reads the header and returns the build time.

ReadSelectionFile Read a MU .MUS file into a list of strings
Round(TimeSpan, Int64) Round timespan to nearest roundToTicks, use as span.Round(TimeSpan.TicksPerSecond);
Round(TimeSpan, TimeSpan) Round timespan to nearest roundTo, use as span.Round(TimeSpan.FromSeconds(10));
RoundDown Rounding up time to nearest dt, where dt is typicalle on the form dt = TimeSpan.FromHours(1)
RoundUp Rounding up time to nearest dt, where dt is typicalle on the form dt = TimeSpan.FromHours(1)
SetupEnvironmentPath Setup environment path to this DHI install root.
SetupInstallRoot Sets up a run environment that does not utilize the GAC. This is only necessary in a develoment environment and should not be used by others.
SetupInstallRoot(String) Sets up a run environment that does not utilize the GAC. This is only necessary in a develoment environment and should not be used by others.
SwapT Swapping two elements.
TimeIntegratedItem(eumItem) Get the item that comes from time integration of item
TimeIntegratedItem(eumItem, String, String) Get the item that comes from time integration of item. Also return additional id and description, to be used if creating new Quantity's.
TimeIntegratedUnit Get the item that comes from time integration of item
TrimString Trim the string c from back and front of string str.
Truncate Truncate string to the maximum length specified.
UnitConversionFactors(eumUnit, eumUnit, Double, Double, Boolean) Calculate scale factor and offset for converting between eum units.

In case of success, the factor and offset contains the conversion values, that will convert from source to target using target = source*factor + offset

The method will fail if one of the units are undefined, or if the units are not equivalent and unitsMustBeEquivalent is set. On failure, default values are used (scale is 1 and offset is 0). and false is returned

It can handle units that are not equivalent, i.e. if the target is kg/m3 and the source is g/s, and there is some processing (in proper units) between the target and the source, the conversion will take care of the factor 1000 here.

UnitConversionFactors(eumQuantity, eumQuantity, Double, Double, Boolean, Boolean) Calculate scale factor and offset for converting between eum units.

In case of success, the factor and offset contains the conversion values, that will convert from source to target using target = source*factor + offset

The method will fail 1) if one of the units are undefined and undefinedAsSI is not set, or 2) if the units are not equivalent and unitsMustBeEquivalent is set. On failure, default values are used (scale is 1 and offset is 0). and false is returned

It can handle units that are not equivalent, i.e. if the target is kg/m3 and the source is g/s, and there is some processing (in proper units) between the target and the source, the conversion will take care of the factor 1000 here.

UnitConversionFactors(eumUnit, eumUnit, Double, Double, Boolean, Boolean) Calculate scale factor and offset for converting between eum units.

In case of success, the factor and offset contains the conversion values, that will convert from source to target using target = source*factor + offset

The method will fail 1) if one of the units are undefined and undefinedAsSI is not set, or 2) if the units are not equivalent and unitsMustBeEquivalent is set. On failure, default values are used (scale is 1 and offset is 0). and false is returned

It can handle units that are not equivalent, i.e. if the target is kg/m3 and the source is g/s, and there is some processing (in proper units) between the target and the source, the conversion will take care of the factor 1000 here.

UpdateQuantityUserUnit Update quantity with user unit, if user unit is available
UserUnitToString(eumItem) Return a unit as a string

Uses global (static) unit system (UnitProvider) to convert to user units. To use local user units, use the version with the IUnitProvider argument.

UserUnitToString(IUnitProvider, eumItem) Return a unit as a string
ValueInUserUnit(eumItem, Double) Convert a value to user unit and return as a string

Uses global (static) unit system (UnitProvider) to convert to user units. To use local user units, use the version with the IUnitProvider argument.

ValueInUserUnit(eumQuantity, Double) Convert a value to user unit and return as a string

Uses global (static) unit system (UnitProvider) to convert to user units. To use local user units, use the version with the IUnitProvider argument.

ValueInUserUnit(IUnitProvider, eumItem, Double) Convert a value to user unit and return as a string
ValueInUserUnit(IUnitProvider, eumQuantity, Double) Convert a value to user unit and return as a string
ValueInUserUnitToString(eumItem, Double) Convert a value to user unit and return as a string

Uses global (static) unit system (UnitProvider) to convert to user units. To use local user units, use the version with the IUnitProvider argument.

ValueInUserUnitToString(eumQuantity, Double) Convert a value to user unit and return as a string

Uses global (static) unit system (UnitProvider) to convert to user units. To use local user units, use the version with the IUnitProvider argument.

ValueInUserUnitToString(IUnitProvider, eumItem, Double) Convert a value to user unit and return as a string
ValueInUserUnitToString(IUnitProvider, eumQuantity, Double) Convert a value to user unit and return as a string
ValueInUserUnitToStringWithUnit(eumItem, Double) Convert a value to user unit and return as a string

Uses global (static) unit system (UnitProvider) to convert to user units. To use local user units, use the version with the IUnitProvider argument.

ValueInUserUnitToStringWithUnit(eumQuantity, Double) Convert a value to user unit and return as a string

Uses global (static) unit system (UnitProvider) to convert to user units. To use local user units, use the version with the IUnitProvider argument.

ValueInUserUnitToStringWithUnit(IUnitProvider, eumItem, Double) Convert a value to user unit and return as a string
ValueInUserUnitToStringWithUnit(IUnitProvider, eumQuantity, Double) Convert a value to user unit and return as a string
ValueToString Convert a value to string, with appropriate number of digits

Fields

See Also