Click or drag to resize

NeonHelper Class

Provides global common utilities and state.
Inheritance Hierarchy
SystemObject
  Neon.CommonNeonHelper

Namespace:  Neon.Common
Assembly:  Neon.Common (in Neon.Common.dll) Version: 2.2.0
Syntax
public static class NeonHelper

The NeonHelper type exposes the following members.

Properties
  NameDescription
Public propertyStatic memberDockerCli
Returns the name of the Docker CLI execuable for the current platform. This will be docker.exe on Windows and just docker on Linux and OS/x.
Public propertyStatic memberDockerComposeCli
Returns the name of the Docker Compose CLI execuable for the current platform. This will be docker-compose.exe on Windows and just docker-compose on Linux and OS/x.
Public propertyStatic memberFileWildcards
Returns the characters used as wildcards for the current file system.
Public propertyStatic memberFramework
Identifies the .NET framework hosting the current process.
Public propertyStatic memberFrameworkDescription
Returns the .NET runtime description.
Public propertyStatic memberIs32BitBuild
Returns true if the client was built as 32-bit.
Public propertyStatic memberIs64Bit
Returns true if the application was built as 64-bit.
Public propertyStatic memberIsDevWorkstation
Indicates whether the current application is running on a developer workstation. This is determined by the presence of the DEV_WORKSTATION environment variable.
Public propertyStatic memberIsLinux
Returns true if the application is running on a Linux variant operating system.
Public propertyStatic memberIsOSX
Returns true if the application is running on Max OSX.
Public propertyStatic memberIsWindows
Returns true if the application is running on a Windows variant operating system.
Public propertyStatic memberJsonConverters

Returns the list of JsonConverter instances that will be automatically recognized by the JSON deserializers. This is initialized with converters for some common types like DateTime, TimeSpan, and Version.

Note Note
IMPORTANT: You may customize this list but for that to have any impact, you must make the modifications very early in your application startup sequence, before any JSON serialization operations have been performed. Any changes made after this will be ignored.
Public propertyStatic memberOpenEditorHandler
Used for implementing unit tests against the OpenEditor(String) method. OpenEditor(String) will call this action when it's non-null passing the file path, rather than actually opening the file in an editor. The handler can then simulate editing the file.
Public propertyStatic memberOsDescription
Returns the operation system description.
Public propertyStatic memberServiceContainer
The root dependency injection service container used by Neon class libraries. and applications.
Top
Methods
  NameDescription
Public methodStatic memberArrayEquals
Determines whether two byte arrays contain the same values in the same order.
Public methodStatic memberBase64UrlDecode
Decodes a base64url encoded string. This is a URL and filename safe base-64 based encoding scheme: RFC6448.
Public methodStatic memberBase64UrlEncode
Encodes a byte array using Base64Url encoding as specifed here: RFC 4648
Public methodStatic memberCopyFolder
Recursively copies the files within one directory to another, creating target folders as required.
Public methodStatic memberCreateSecureRandom
Creates a Random pseudo random number generated with a cryptographically random seed.
Public methodStatic memberDeflateBytes
Uses deflate to commpress a byte array.
Public methodStatic memberDeflateString
Uses deflate to commpress a string.
Public methodStatic memberDeleteFolder
Recursively deletes a file system folder, ignoring any errors.
Public methodStatic memberDeleteFolderContents
Recursively deletes the contents of a file folder, ignoring any errors.
Public methodStatic memberDoesNotThrow(Action)
Verfies that an action does not throw an exception.
Public methodStatic memberDoesNotThrowTException(Action)
Verfies that an action does not throw a TException.
Public methodStatic memberEnumToString(Type, Object)
Type-safe enum serializer that also honors any EnumMemberAttribute decorating the enumeration values.
Public methodStatic memberEnumToStringTEnum(TEnum)
Type-safe enum serializer that also honors any EnumMemberAttribute decorating the enumeration values.
Public methodStatic memberEscapeCsv
Escapes a string passed so that is suitable for writing to a CSV file as a field.
Public methodStatic memberExceptionError
Returns a string representation of an exception suitable for logging.
Public methodStatic memberExecute(String, Object, NullableTimeSpan, Process)
Starts a process with an array of arguments to run an executable file and then waits for the process to terminate.
Public methodStatic memberExecute(String, String, NullableTimeSpan, Process)
Starts a process to run an executable file and then waits for the process to terminate.
Public methodStatic memberExecuteAsync(String, Object, NullableTimeSpan, Process)
Asynchronously starts a process to run an executable file with an array of arguments and then and waits for the process to terminate.
Public methodStatic memberExecuteAsync(String, String, NullableTimeSpan, Process)
Asynchronously starts a process to run an executable file and then waits for the process to terminate.
Public methodStatic memberExecuteCapture(String, Object, NullableTimeSpan, Process, ActionString, ActionString)
Starts a process to run an executable file and then waits for the process to terminate while capturing any output written to the standard output and error streams.
Public methodStatic memberExecuteCapture(String, String, NullableTimeSpan, Process, ActionString, ActionString)
Starts a process to run an executable file and then waits for the process to terminate while capturing any output written to the standard output and error streams.
Public methodStatic memberExecuteCaptureAsync(String, Object, NullableTimeSpan, Process)
Asynchronously starts a process to run an executable file and then waits for the process to terminate while capturing any output written to the standard output and error streams.
Public methodStatic memberExecuteCaptureAsync(String, String, NullableTimeSpan, Process)
Asynchronously starts a process to run an executable file and then waits for the process to terminate while capturing any output written to the standard output and error streams.
Public methodStatic memberExecuteShell
Executes a command using the local shell, CMD.EXE for Windows and Bash for OSX and Linux.
Public methodStatic memberExpandTabs
Expands any embedded TAB (\t) characters in the string passed into spaces such that the tab stops will be formatted correctly.
Public methodStatic memberFork
Forks a child process that will run in parallel with the current process.
Public methodStatic memberFromHex
Parses the hex string passed and converts it a byte array.
Public methodStatic memberGetAssemblyFolder
Returns the fully qualified path to the folder holding the assembly passed (includes the terminating "\").
Public methodStatic memberGetAssemblyPath
Returns the fully qualified path to the assembly file.
Public methodStatic memberGetConstructor
Uses reflection to locate a specific public or non-public constructor for a type.
Public methodStatic memberGetCryptoRandomBytes
Generates a byte array filled with a cryptographically strong sequence of random values.
Public methodStatic memberGetCryptoRandomPassword
Generates a cryptographically random password.
Public methodStatic memberGetEnhancedJsonConverters
Returns instances of the types that implement IEnhancedJsonConverter from the Neon.Common assembly.
Public methodStatic memberGetEntryAssemblyPath
Returns the fully qualified path the entry assembly for the current process.
Public methodStatic memberGetMethod
Uses reflection to locate a specific public, non-public, instance or static method on a type.
Public methodStatic memberGetProcessById
Returns the Process associated with an ID or null if no process with this ID exists.
Public methodStatic memberGetTaskResultAsObjectAsync
Used to await a generic TaskTResult and return its result as an Object. This is handy for situations where the task result type is unknown at compile time.
Public methodStatic memberGunzipBytes
Uses GZIP to decompress a byte array from compressed bytes.
Public methodStatic memberGunzipString
Uses GZIP to decompress a string from compressed bytes.
Public methodStatic memberGzipBytes
Uses GZIP to commpress a byte array.
Public methodStatic memberGzipString
Uses GZIP to commpress a string.
Public methodStatic memberHexDump(Byte, Int32, HexDumpOption)
Returns a byte array as a formatted hex dump.
Public methodStatic memberHexDump(Byte, Int32, Int32, Int32, HexDumpOption)
Returns a byte array as a formatted hex dump.
Public methodStatic memberHexValue
Returns the decimal value of the hex digit passed.
Public methodStatic memberInflateBytes
Uses deflate to decompress a byte array from compressed bytes.
Public methodStatic memberInflateString
Uses deflate to decompress a string from compressed bytes.
Public methodStatic memberIsGzipped(Stream)
Examines a Stream to determine whether it has been compressed via GZIP. This assumes that the current position points to the GZIP header if there is one. The stream position will be restored before returning.
Public methodStatic memberIsGzipped(String)
Examines a file to determine whether it has been compressed via GZIP.
Public methodStatic memberIsHex
Returns true if the character passed is a hex digit.
Public methodStatic memberIsOdd
Determines whether an integer is odd.
Public methodStatic memberJsonCloneT
Creates a deep clone of an object by first serializing to JSON and then deserializing it.
Public methodStatic memberJsonDeserialize(Type, Byte, Boolean)
Non-generic method that deserializes UTF-8 encoded JSON bytes, optionally requiring strict mapping of input properties to the target type.
Public methodStatic memberJsonDeserialize(Type, String, Boolean)
Non-generic method that deserializes JSON text, optionally requiring strict mapping of input properties to the target type.
Public methodStatic memberJsonDeserializeT(Byte, Boolean)
Deserializes UITF-8 encoded JSON bytes, optionally requiring strict mapping of input properties to the target type.
Public methodStatic memberJsonDeserializeT(String, JsonSerializerSettings)
Deserializes JSON text using custom settings.
Public methodStatic memberJsonDeserializeT(String, Boolean)
Deserializes JSON text, optionally requiring strict mapping of input properties to the target type.
Public methodStatic memberJsonEquals
Compares two object instances for equality by serializing them JSON and comparing the output.
Public methodStatic memberJsonOrYamlDeserializeT
Deserializes JSON or YAML text using, optionally requiring strict mapping of input properties to the target type.
Public methodStatic memberJsonSerialize(Object, Formatting)
Serializes an object to JSON text.
Public methodStatic memberJsonSerialize(Object, JsonSerializerSettings, Formatting)
Serializes an object to JSON text using custom settings.
Public methodStatic memberJsonSerializeToBytes(Object, Formatting)
Serializes an object to UTF-8 encoded JSON bytes.
Public methodStatic memberJsonSerializeToBytes(Object, JsonSerializerSettings, Formatting)
Serializes an object to UTF-8 encoded JSON bytes using custom settings.
Public methodStatic memberJsonToYaml
Converts a JSON text to YAML.
Public methodStatic memberJTokenEquals
Compares the two Newtonsoft JSON.NET JToken instances along with their decendants for equality. This is an alternative to EqualityComparer which seems to have some problems, as outlined in the remarks.
Public methodStatic memberNoAwait
Do nothing method that is used when you explicitly don't want to await a task and you don't want to see warning CS4014.
Public methodStatic memberNormalizeExecArgs
Normalizes an array of argument objects into a form that can be passed to an invoked process by adding a quotes and escape characters as necessary.
Public methodStatic memberNullableEqualsT
Determines whether two nullable values are equal.
Public methodStatic memberOpenBrowser
Launches the default browser to display the specified URI.
Public methodStatic memberOpenEditor
Launches the platform text editor to create or edit a file.
Public methodStatic memberOpenStandardInput
Opens the current process standard inout stream.
Public methodStatic memberPackageReferenceToNeonCommonIsRequired

This method may be called to ensure that the Neon.Common assembly is required at compile in a project that doesn't reference Neon.Common. The method does nothing.

Note Note
A call to this is currently included by Neon.ModelGen to ensure that the enclosing project references Neon.Common.
Public methodStatic memberParseBool
Parses common boolean literals.
Public methodStatic memberParseCsv
Parses a CSV encoded string into its component fields.
Public methodStatic memberParseEnumTEnum
Type-safe enum parser that also honors any EnumMemberAttribute decorating the enumeration values. This is case insensitive.
Public methodStatic memberParseNullableBool
Parses a nullable Boolean.
Public methodStatic memberPseudoRandomDouble
Returns a double pseudo random number between 0.0 and +1.0
Public methodStatic memberPseudoRandomDouble(Double)
Returns a double pseudo random number between 0.0 and the specified limit.
Public methodStatic memberPseudoRandomIndex
Returns a random index into a sequence whose length is specified.
Public methodStatic memberPseudoRandomInt
Returns an integer pseudo random number.
Public methodStatic memberPseudoRandomInt(Int32)
Returns a pseudo random number in the range of 0..limit-1.
Public methodStatic memberPseudoRandomTimespan(TimeSpan)
Returns a random TimeSpan between zero and a specified maximum.
Public methodStatic memberPseudoRandomTimespan(TimeSpan, Double)
Returns a TimeSpan between the specified base interval plus a random period of the specified fraction of the value.
Public methodStatic memberPseudoRandomTimespan(TimeSpan, TimeSpan)
Returns a random TimeSpan value between the min/max values specified.
Public methodStatic memberReadConsolePassword
Reads a password from the Console terminated by Enter without echoing the typed characters.
Public methodStatic memberReadStandardInputBytes
Reads the standard input file to the end and returns the result as bytes.
Public methodStatic memberReadStandardInputText
Reads the standard input file to the end and returns the result as a string.
Public methodStatic memberRegisterMisspelledUtf8Provider
Ensures that a special UTF-8 text encoding provider misnamed as utf8 (without the dash) is registered. This is required sometimes because certain REST APIs may return incorrect charset values.
Public methodStatic memberSequenceEqualT(IEnumerableT, IEnumerableT)
Compares two null or non-null enumerable sequences for equality.
Public methodStatic memberSequenceEqualT(IListT, IListT)
Compares two null or non-null lists for equality.
Public methodStatic memberStartProcess
Starts a process for an Assembly by calling the assembly's main() entry point method.
Public methodStatic memberStripAnsibleWarnings
HACK: This method attempts to trim warnings generated by Ansible because it writes these warnings to STDOUT instead of STDERR. This is super fragile.
Public methodStatic memberStripFileScheme
Removes a file:// scheme from the path URI if this is scheme is present. The result will be a valid file system path.
Public methodStatic memberThreadRun
Starts a new Thread to perform an action.
Public methodStatic memberToBoolString
Renders a bool value as either true or false (lower case).
Public methodStatic memberToHex(Byte, Boolean)
Converts a single byte into its hexidecimal equivalent.
Public methodStatic memberToHex(Byte, Boolean)
Converts the byte buffer passed into a hex encoded string.
Public methodStatic memberToLinuxLineEndings
Converts Windows line endings (CR-LF) to Linux/Unix line endings (LF).
Public methodStatic memberTryParseTEnum
Type-safe enum parser that also honors any EnumMemberAttribute decorating the enumeration values. This is case insensitive.
Public methodStatic memberTryParseBool
Attempts to parse a boolean from common literals.
Public methodStatic memberTryParseEnum
enum parser that also honors any EnumMemberAttribute decorating the enumeration values. This is case insensitive.
Public methodStatic memberTryParseHex(String, Byte)
Attempts to parse a hex string into a byte array.
Public methodStatic memberTryParseHex(String, Int32)
Attempts to parse a hex encoded string into an integer.
Public methodStatic memberTryParseNullableBool
Attempts to parse a nullable Boolean. null, empty or input == "null" will return null. Otherwise we'll expect either "true" or "false" or one of the other literals supported by ParseBool(String).
Public methodStatic memberUrlTokenDecode
Public methodStatic memberUrlTokenEncode
Encodes a byte array into a form suitable for using as a URI path segment or query parameter.
Public methodStatic memberWaitAllAsync(IEnumerableTask)
Asynchronously waits for all of the Tasks passed to complete.
Public methodStatic memberWaitAllAsync(Task)
Asynchronously waits for all of the Tasks passed to complete.
Public methodStatic memberWaitAllAsync(IEnumerableTask, NullableTimeSpan, CancellationToken)
Asynchronously waits for all of the Tasks passed to complete.
Public methodStatic memberWaitFor
Waits for a boolean function to return true.
Public methodStatic memberWaitForAsync
Asynchronously waits for a boolean function to return true.
Public methodStatic memberYamlDeserializeT

Deserializes YAML text to an object, optionally requiring strict mapping of input properties to the target type.

Note Note
Property names are expected to be lowercase.
Public methodStatic memberYamlSerialize

Serializes an object to YAML.

Note Note
Property names are always converted to lowercase when serializing to YAML.
Top
Fields
  NameDescription
Public fieldStatic memberCR
Ordinal value of an ASCII carriage return.
Public fieldStatic memberCRLF
A string consisting of a CRLF sequence.
Public fieldStatic memberDateFormat100NsTZ
Returns the date format string used for serialize dates with 100 nanosecond precision to strings like: 2018-06-05T14:30:13.000000Z
Public fieldStatic memberDateFormat100NsTZOffset
Returns the date format string used for serialize dates with 100 nanosecond precision to strings like: 2018-06-05T14:30:13.000000+00:00
Public fieldStatic memberDateFormatMicroTZ
Returns the date format string used for serialize dates with microsecond precision to strings like: 2018-06-05T14:30:13.000000Z
Public fieldStatic memberDateFormatMicroTZOffset
Returns the date format string used for serialize dates with microsecond precision to strings like: 2018-06-05T14:30:13.000000+00:00
Public fieldStatic memberDateFormatTZ
Returns the date format string used for serialize dates with millisecond precision to strings like: 2018-06-05T14:30:13.000Z
Public fieldStatic memberDateFormatTZOffset
Returns the date format string used for serialize dates with millisecond precision to strings like: 2018-06-05T14:30:13.000+00:00
Public fieldStatic memberESC
Ordinal value of an ASCII escape character.
Public fieldStatic memberHT
Ordinal value of an ASCII horizontal TAB.
Public fieldStatic memberJsonRelaxedSerializerSettings
The global relaxed JSON serializer settings. These settings do not require that all source JSON properties match those defined by the type being deserialized.
Public fieldStatic memberJsonStrictSerializerSettings
The global strict JSON serializer settings. These settings do require that all source JSON properties match those defined by the type being deserialized.
Public fieldStatic memberLF
Ordinal value of an ASCII linefeed.
Public fieldStatic memberLineEnding
Returns the native text line ending for the current environment.
Public fieldStatic memberTAB
Ordinal value of an ASCII TAB character.
Public fieldStatic memberTestModeFolderVar
The environment variable used for unit testing that indicates that Neon.Service.NeonService and Neon.Kube.HubeHelper should run in test mode and locate user test files in in the folder specified by this variable when set.
Public fieldStatic memberUnixEpoch
Returns the Unix epoch time: 01-01-1970 (UTC).
Top
See Also