Coree.NETStandard
  • API
Show / Hide Table of Contents
  • Coree.NETStandard.Abstractions.DependencySingleton
    • DependencySingleton<T>
    • IDependencySingleton
  • Coree.NETStandard.Abstractions.FluentBase
    • FluentBase
    • IFluentBase
  • Coree.NETStandard.Abstractions.InitializationService
    • InitializationDependentServices
    • InitializationService
  • Coree.NETStandard.Abstractions.ServiceFactory
    • ServiceFactory<T>
  • Coree.NETStandard.Abstractions.ServiceFactoryEx
    • ServiceFactoryEx<T>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z>
    • ServiceFactoryEx<T, K>
    • ServiceFactoryEx<T, K, R>
    • ServiceFactoryEx<T, K, R, S>
    • ServiceFactoryEx<T, K, R, S, U>
    • ServiceFactoryEx<T, K, R, S, U, V>
    • ServiceFactoryEx<T, K, R, S, U, V, W>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y>
  • Coree.NETStandard.Classes.AsyncEventCollection
    • AsyncEventCollection<T>
    • AsyncEventCollection<T>.CustomEventDelegate
  • Coree.NETStandard.Classes.CommonDistinguishedNameBuilder
    • CommonDistinguishedNameBuilder
    • DistinguishedName
  • Coree.NETStandard.Classes.Criteria
    • CriteriaComparisonMethod
    • CriteriaEnumerableExtensions
    • CriteriaExpressionBuilder
    • CriteriaItem<TValue>
    • CriteriaItems
    • CriteriaOperator
    • CriteriaQueryableExtensions
  • Coree.NETStandard.Classes.HttpRequestService
    • ContentComposer
    • HttpRequestHeadersExtensions
    • HttpRequestService
    • HttpRequestServiceHandler
    • HttpRequestServiceUriExtensions
    • ServiceCollectionExtensions
    • TransactionRecord
  • Coree.NETStandard.Classes.Scheduler
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
  • Coree.NETStandard.Classes.ThreadSafeCollection
    • ThreadSafeCollection<T>
  • Coree.NETStandard.Classes.ThreadSafeValue
    • ThreadSafeValue<T>
  • Coree.NETStandard.Classes.TimeOfDay
    • TimeOfDay
  • Coree.NETStandard.Extensions.Collections.Enumerable
    • CollectionsEnumerableExtensions
  • Coree.NETStandard.Extensions.Collections.List
    • CollectionsListExtensions
  • Coree.NETStandard.Extensions.Conversions.ByteArray
    • ConversionsByteArrayExtensions
  • Coree.NETStandard.Extensions.Conversions.HostApplicationBuilder
    • ConversionsHostApplicationBuilderExtensions
  • Coree.NETStandard.Extensions.Conversions.String
    • ConversionsStringExtensions
    • Encodings
  • Coree.NETStandard.Extensions.Conversions.Stringbuilder
    • ConversionsStringbuilderExtension
  • Coree.NETStandard.Extensions.Enums
    • EnumExtensions
  • Coree.NETStandard.Extensions.Http.HttpHeader
    • HttpHeadersExtensions
  • Coree.NETStandard.Extensions.Primitives.Bool
    • PrimitivesBoolExtensions
  • Coree.NETStandard.Extensions.Reflection.ServiceProvider
    • ReflectionServiceProviderExtensions
  • Coree.NETStandard.Extensions.ServiceCollection
    • ServiceCollectionExtensions
  • Coree.NETStandard.Extensions.Threading.CancellationToken
    • ThreadingCancellationTokenExtensions
  • Coree.NETStandard.Extensions.Utilities
    • DateTimeExtensions
  • Coree.NETStandard.Extensions.Validations.String
    • ValidationsStringExtensions
  • Coree.NETStandard.HostedServicesCollection
    • HostedServicesCollectionConfig<T>
    • IHostedServicesCollectionConfig<T>
    • ServiceCollectionExtensions
    • ServiceProviderExtensions
  • Coree.NETStandard.Serilog
    • ConditionalLevelSink
    • CustomTheme
    • LoggerSinkConfigurationExtensions
    • OutputTemplates
    • ServiceCollectionExtensions
    • SourceContextShortEnricher
  • Coree.NETStandard.Services.DebugManagement
    • DebugService
    • IDebugService
  • Coree.NETStandard.Services.DirectoryOperationsManagement
    • DirectoryOperationsService
    • IDirectoryOperationsService
  • Coree.NETStandard.Services.FileManagement
    • FileService
    • IFileService
  • Coree.NETStandard.Services.FileOperationsManagement
    • FileOperationsService
    • FileOperationsService.FileSystemEntry
    • FileOperationsService.FileSystemInformation
    • FileOperationsService.VerifiedCopyStatus
    • IFileOperationsService
  • Coree.NETStandard.Services.HashManagement
    • HashService
    • IHashService
  • Coree.NETStandard.Services.NetworkManagement
    • INetworkService
    • NetworkService
    • NetworkService.IpAdressInformation
    • NetworkService.NetworkInterfaceDetail
  • Coree.NETStandard.Services.ProcessManagement
    • IProcessService
    • ProcessRunExitCodeState
    • ProcessRunResult
    • ProcessService
  • Coree.NETStandard.Services.RuntimeInsightsManagement
    • IRuntimeInsightsService
    • RuntimeInsightsService
  • Coree.NETStandard.SpectreConsole
    • CommandAppExtensions
    • HostBuilderExtensions
    • ServiceCollectionExtensions
    • SpectreConsoleHostedService
    • SpectreConsoleHostedService.ExitCode
    • SpectreConsoleTypeRegistrar
    • SpectreConsoleTypeResolver
  • Coree.NETStandard.UnderConstruction
    • DbContextExtensions
    • HttpClientStatic
    • HttpClientStatic.HttpClientResponse
    • HttpClientStatic.XRate
    • HttpClientStatic.XRateGroup
    • HttpClientStatic.XRateItem
    • IScheduleProvider
    • IntervalScheduleProvider
    • LimitedHistory<T>
    • ScheduleCombiner
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
    • Scheduler2
    • Scheduler2.TickerEventArgs
    • Scheduler2.TickerEventDelegate
    • Scheduler3
    • Scheduler3.TickerEventArgs
    • Scheduler3.TickerEventDelegate
    • SqlliteMemoryContext
    • SqlliteMemoryContext.UserDataDto
    • TimedEntry<T>
    • Timing
    • Timing.Ticker
    • Timing.Ticker.TickerEventArgs
    • Timing.TickerSync
    • WeekDayAtScheduleProvider
  • Coree.NETStandard.Utilities
    • EventSubscription
    • MainContext

Interface IFileOperationsService

Defines a service for file system operations.

Namespace: Coree.NETStandard.Services.FileOperationsManagement
Assembly: Coree.NETStandard.dll
Syntax
public interface IFileOperationsService

Methods

| Edit this page View Source

CopyFileAttributes(string, string, bool)

Copies the file attributes and UTC timestamps from a source file to a destination file. This method provides an option to control exception handling based on the failure conditions encountered during the operation.

Declaration
bool CopyFileAttributes(string source, string destination, bool throwOnError = false)
Parameters
Type Name Description
string source

The source file path. This must point to an existing file, or the method will handle the error based on the throwOnError parameter.

string destination

The destination file path. This must point to an existing file, or the method will handle the error based on the throwOnError parameter.

bool throwOnError

Indicates whether to throw an exception when the operation fails due to the non-existence of the source or destination, or due to other errors during the copying process. If set to false, the method logs a warning and returns false instead of throwing.

Returns
Type Description
bool

True if the file metadata was successfully copied; otherwise, false. If false is returned, check logs for the specific failure reason.

| Edit this page View Source

CreateJsonPathInventoryAsync(string?, string, CancellationToken)

Declaration
Task CreateJsonPathInventoryAsync(string? path, string inventoryFilename = "", CancellationToken cancellationToken = default)
Parameters
Type Name Description
string path
string inventoryFilename
CancellationToken cancellationToken
Returns
Type Description
Task
| Edit this page View Source

DeleteFile(string, bool)

Attempts to delete a file at a specified location. It logs the operation and can optionally throw an exception on error.

Declaration
bool DeleteFile(string filePath, bool throwOnError = false)
Parameters
Type Name Description
string filePath

The path of the file to be deleted.

bool throwOnError

Specifies whether to throw an exception if the deletion fails due to an error.

Returns
Type Description
bool

True if the file was deleted successfully or did not exist; false if an error occurred during deletion.

| Edit this page View Source

FileCopyAsync(string, string, CancellationToken)

Asynchronously copies a file from a source path to a destination path, overwriting the destination file if it already exists.

Declaration
Task<bool> FileCopyAsync(string source, string destination, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string source

The file path of the source file to be copied.

string destination

The file path of the destination where the file will be copied.

CancellationToken cancellationToken

A cancellation token that can be used to cancel the file copy operation.

Returns
Type Description
Task<bool>

Returns true if the file is copied successfully. If the file is not copied, the method throws an exception.

Remarks

This method wraps the RetryVerifyAndResumeFileCopyAsync(string, string, CancellationToken, int, int) method to include asynchronous execution with cancellation support and retry logic. It logs the attempt, success, or failure of the file copying process. Use the provided cancellationToken to cancel the operation if needed.

| Edit this page View Source

InventoryCopyAsync(string, string)

Declaration
Task InventoryCopyAsync(string inventoryFilename, string target)
Parameters
Type Name Description
string inventoryFilename
string target
Returns
Type Description
Task
| Edit this page View Source

RetryVerifyAndResumeFileCopyAsync(string, string, CancellationToken, int, int)

Attempts to verify and resume a file copy operation multiple times in case of failures during the copy process.

Declaration
Task<FileOperationsService.VerifiedCopyStatus> RetryVerifyAndResumeFileCopyAsync(string source, string destination, CancellationToken cancellationToken = default, int maxRetryCount = 3, int retryDelayMilliseconds = 1000)
Parameters
Type Name Description
string source

The source file path from which to copy.

string destination

The destination file path to which the file should be copied.

CancellationToken cancellationToken

Token to monitor for cancellation requests.

int maxRetryCount

The maximum number of retry attempts for the copy operation.

int retryDelayMilliseconds

The delay in milliseconds between retry attempts.

Returns
Type Description
Task<FileOperationsService.VerifiedCopyStatus>

A task that represents the asynchronous operation, with a value indicating the result of the copy operation after retries.

Remarks

This method encapsulates a retry logic for the VerifyAndResumeFileCopyAsync method. It retries the file copy operation up to a specified number of times if the error is related to the copy process itself. Each retry is logged and, if necessary, followed by a specified delay. If the copy operation fails after all retries or is cancelled, the method will return the appropriate status.

// Example usage of retrying a file copy operation
var copyStatus = await RetryVerifyAndResumeFileCopyAsync("path/to/source.file", "path/to/destination.file");
if (copyStatus == VerifiedCopyStatus.Success)
{
    Console.WriteLine("File copy succeeded after retries.");
}
else
{
    Console.WriteLine($"File copy failed with status: {copyStatus}");
}
| Edit this page View Source

ScanFileSystemEntriesAsync(string, CancellationToken, bool, bool, List<string>?)

Asynchronously scans the file system entries starting from the specified path, optionally performing CRC32 checks and applying a blacklist filter on file names.

Declaration
Task<FileOperationsService.FileSystemInformation> ScanFileSystemEntriesAsync(string path, CancellationToken cancellationToken, bool failFast = false, bool crc32 = false, List<string>? fileNameBlacklist = null)
Parameters
Type Name Description
string path

The starting path from which to begin scanning for file system entries.

CancellationToken cancellationToken

A token to monitor for cancellation requests, which can abort the operation.

bool failFast

If set to true, the operation will stop at the first error encountered; otherwise, it will continue despite errors.

bool crc32

If set to true, a CRC32 checksum will be calculated for each file.

List<string> fileNameBlacklist

An optional list of file names to exclude from scanning and processing.

Returns
Type Description
Task<FileOperationsService.FileSystemInformation>

A FileSystemInformation object containing all scanned entries, including any errors encountered during the scan.

| Edit this page View Source

VerifyAndResumeFileCopyAsync(string, string, CancellationToken)

Verifies the integrity of a partially copied file and resumes the copy operation if integrity is confirmed.

Declaration
Task<FileOperationsService.VerifiedCopyStatus> VerifyAndResumeFileCopyAsync(string source, string destination, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string source

The source file path.

string destination

The destination file path.

CancellationToken cancellationToken

Token to monitor for cancellation requests.

Returns
Type Description
Task<FileOperationsService.VerifiedCopyStatus>

A task that represents the asynchronous operation, with a value indicating the result of the copy operation.

Remarks

This method uses a two-phase approach: first, it verifies the existing part of the file in the destination against the source. If the verification is successful, it resumes copying. If there is a mismatch, it truncates the destination file to the last verified position and resumes the copy.

var status = await VerifyAndResumeFileCopyAsync("path/to/source.file", "path/to/destination.file");
if (status == VerifiedCopyStatus.Success)
{
    Console.WriteLine("File copied successfully.");
}
  • Edit this page
  • View Source
In this article
Back to top