Class FileSystemRepositoryHelper
- Namespace
- CMS.ContinuousIntegration
- Assembly
- CMS.ContinuousIntegration.dll
Contains methods necessary to define and validate the behavior of file system repository.
public class FileSystemRepositoryHelper : AbstractHelper<FileSystemRepositoryHelper>
- Inheritance
-
objectFileSystemRepositoryHelper
- Inherited Members
- Extension Methods
Constructors
FileSystemRepositoryHelper()
public FileSystemRepositoryHelper()
Fields
HASH_DELIMITER
Delimiter between name and hash.
protected const char HASH_DELIMITER = '@'
Field Value
- char
SHORTENED_FILENAME_PART_DELIMITER
Delimiter between parts of shortened file name.
protected const string SHORTENED_FILENAME_PART_DELIMITER = ".."
Field Value
- string
Methods
DeleteDirectory(string, bool)
Deletes a directory specified by directoryPath.
public static bool DeleteDirectory(string directoryPath, bool recursive = false)
Parameters
directoryPathstringAbsolute path to the directory.
recursiveboolTrue to remove directories, subdirectories, and files in path, otherwise false.
Returns
- bool
False if the delete method throws an System.IO.IOException with System.Exception.HResult 0x80070091 (ERROR_DIR_NOT_EMPTY), otherwise true.
Remarks
If the delete method throws an System.IO.IOException with System.Exception.HResult 0x80070091 (ERROR_DIR_NOT_EMPTY), it is ignored.
DeleteDirectoryInternal(string, bool)
Deletes a directory specified by directoryPath. If the delete method
throws an System.IO.IOException with System.Exception.HResult 0x80070091 (ERROR_DIR_NOT_EMPTY), it is ignored.
protected virtual bool DeleteDirectoryInternal(string directoryPath, bool recursive)
Parameters
directoryPathstringAbsolute path to the directory.
recursiveboolTrue to remove directories, subdirectories, and files in path, otherwise false.
Returns
- bool
False if the delete method throws an System.IO.IOException with System.Exception.HResult 0x80070091 (ERROR_DIR_NOT_EMPTY), otherwise true.
DeleteRepositoryDirectoryIfEmpty(string, string)
Deletes repository directory identified by relativeDirectoryPath. Does nothing when directory is not empty
or relative path is null or empty string (to prevent unintended deletion of repository root).
public static void DeleteRepositoryDirectoryIfEmpty(string relativeDirectoryPath, string repositoryRootPath)
Parameters
relativeDirectoryPathstringPath within repository identifying the directory to be deleted.
repositoryRootPathstringRoot path of the repository.
Exceptions
- ArgumentNullException
Thrown when
repositoryRootPathis null.
DeleteRepositoryDirectoryIfEmptyInternal(string, string)
Deletes repository directory identified by relativeDirectoryPath. Does nothing when directory is not empty
or relative path is null or empty string (to prevent unintended deletion of repository root).
protected virtual void DeleteRepositoryDirectoryIfEmptyInternal(string relativeDirectoryPath, string repositoryRootPath)
Parameters
relativeDirectoryPathstringPath within repository identifying the directory to be deleted.
repositoryRootPathstringRoot path of the repository.
Exceptions
- ArgumentNullException
Thrown when
repositoryRootPathis null.
GetFileSystemName(string, int, int)
Gets file system safe representation of name. The resulting name does not exceed maxNameLength characters in length.
maxNameLength must accommodate hashLength and delimiting character.
public static string GetFileSystemName(string name, int maxNameLength, int hashLength)
Parameters
namestringName to be transformed to file system safe representation.
maxNameLengthintMax length of the resulting name.
hashLengthintNumber of hash characters to be included in the resulting name, if hashing is needed.
Returns
- string
Name in file system safe representation.
Remarks
The name processing is similar to code name processing. Diacritics in Latin characters is removed,
illegal characters are replaced by '' (underscore), multiple '.' (dot) are grouped to single '.',
leading and trailing '.' and '' are trimmed.
Exceptions
- ArgumentException
Thrown when
nameis null or empty.- ArgumentOutOfRangeException
Thrown when
hashLengthis not a positive integer ormaxNameLengthis not greater than (hash length + 1) - the extra character is for hash delimiter.
GetFileSystemName(string, string, int, int)
Gets file system safe representation of name. The resulting name does not exceed maxNameLength characters in length.
maxNameLength must accommodate hashLength and delimiting character.
public static string GetFileSystemName(string name, string fullName, int maxNameLength, int hashLength)
Parameters
namestringName to be transformed to file system safe representation.
fullNamestringFull name for given
name. The full name is used for the purpose of hash computation. Null means the full name is the same asname.maxNameLengthintMax length of the resulting name.
hashLengthintNumber of hash characters to be included in the resulting name, if hashing is needed.
Returns
- string
Name in file system safe representation.
Examples
The following code creates 2 file system names, which differ in their hash only
string articleFileSystemName1 = FileSystemRepositoryHelper.GetFileSystemName("Article", "/Path/To/Some/Document/Named/Article", 50, 10);
string articleFileSystemName2 = FileSystemRepositoryHelper.GetFileSystemName("Article", "/Path/To/Different/Document/Named/Article", 50, 10);
// Produces result similar to:
// article@1234567890
// article@0987654321
The following code shows how to create a human-readable file name from a name, which would otherwise result in hash only (due to special characters processing)
string defaultFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("/", 50, 10);
string customFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", "/", 50, 10);
// Produces result similar to:
// @1234567890
// root@1234567890
The following code demonstrates the difference between providing a name and full name pair for obtaining a human-readable name and why the same can not be achieved with name only. Let's assume we have an object representing a root of a tree (named "/") and we want a human-readable file system name to store such object
string customFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", "/", 50, 10);
string wrongCustomFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", 50, 10); // This is wrong. If another object named "root" would exist, its name would collide with the custom name for "/"
// Produces result similar to:
// root@1234567890 The hash value is computed from "/"
// root
Remarks
The name processing is similar to code name processing. Diacritics in Latin characters is removed,
illegal characters are replaced by '_' (underscore), multiple '.' (dot) are grouped to single '.',
leading and trailing '.' and '_' are trimmed.
Specify the fullName parameter to avoid file system name collisions when name is some shortcut or human-readable form of fullName.
Exceptions
- ArgumentException
Thrown when
nameis null or empty orfullNameis empty.- ArgumentOutOfRangeException
Thrown when
hashLengthis not a positive integer ormaxNameLengthis not greater than (hash length + 1) - the extra character is for hash delimiter.
GetFileSystemNameInternal(string, string, int, int)
Gets file system safe representation of name. The resulting name does not exceed maxNameLength characters in length.
maxNameLength must accommodate hashLength and delimiting character.
protected virtual string GetFileSystemNameInternal(string name, string fullName, int maxNameLength, int hashLength)
Parameters
namestringName to be transformed to file system safe representation.
fullNamestringFull name for given
name. The full name is used for the purpose of hash computation. Null means the full name is the same asname.maxNameLengthintMax length of the resulting name.
hashLengthintNumber of hash characters to be included in the resulting name, if hashing is needed.
Returns
- string
Name in file system safe representation.
Examples
The following code creates 2 file system names, which differ in their hash only
string articleFileSystemName1 = FileSystemRepositoryHelper.GetFileSystemName("Article", "/Path/To/Some/Document/Named/Article", 50, 10);
string articleFileSystemName2 = FileSystemRepositoryHelper.GetFileSystemName("Article", "/Path/To/Different/Document/Named/Article", 50, 10);
// Produces result similar to:
// article@1234567890
// article@0987654321
The following code shows how to create a human-readable file name from a name, which would otherwise result in hash only (due to special characters processing)
string defaultFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("/", 50, 10);
string customFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", "/", 50, 10);
// Produces result similar to:
// @1234567890
// root@1234567890
The following code demonstrates the difference between providing a name and full name pair for obtaining a human-readable name and why the same can not be achieved with name only. Let's assume we have an object representing a root of a tree (named "/") and we want a human-readable file system name to store such object
string customFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", "/", 50, 10);
string wrongCustomFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", 50, 10); // This is wrong. If another object named "root" would exist, its name would collide with the custom name for "/"
// Produces result similar to:
// root@1234567890 The hash value is computed from "/"
// root
Remarks
The name processing is similar to code name processing. Diacritics in Latin characters is removed,
illegal characters are replaced by '_' (underscore), multiple '.' (dot) are grouped to single '.',
leading and trailing '.' and '_' are trimmed.
Specify the fullName parameter to avoid file system name collisions when name is some shortcut or human-readable form of fullName.
Exceptions
- ArgumentException
Thrown when
nameis null or empty orfullNameis empty.- ArgumentOutOfRangeException
Thrown when
hashLengthis not a positive integer ormaxNameLengthis not greater than (hash length + 1) - the extra character is for hash delimiter.
IsCDRepositoryInitialized(string, string)
Checks whether CD repository is initialized, by testing the presence of the configuration file.
public static bool IsCDRepositoryInitialized(string applicationRootPath, string repositoryPath)
Parameters
applicationRootPathstringPath to the root of the application.
repositoryPathstringPath to the CD repository given by the user.
Returns
- bool
True if repository is initialized, otherwise false.
IsCDRepositoryInitializedInternal(string, string)
Checks whether Continuous Delivery repository is initialized, by testing the presence of the configuration file.
protected virtual bool IsCDRepositoryInitializedInternal(string applicationRootPath, string repositoryPath)
Parameters
applicationRootPathstringPath to the root of the application.
repositoryPathstringPath to the repository given by the user.
Returns
- bool
True if repository is initialized, otherwise false.
IsCIRepositoryInitialized(string)
Checks whether CI repository is initialized, by testing the presence of the configuration file.
public static bool IsCIRepositoryInitialized(string applicationRootPath)
Parameters
applicationRootPathstringPath to the root of the application.
Returns
- bool
True if repository is initialized, otherwise false.
IsCIRepositoryInitializedInternal(string)
Checks whether Continuous Integration repository is initialized, by testing the presence of the configuration file.
protected virtual bool IsCIRepositoryInitializedInternal(string applicationRootPath)
Parameters
applicationRootPathstringPath to the root of the application.
Returns
- bool
True if repository is initialized, otherwise false.