private async Task <ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderContentInput> > > RemoveOrReplaceHeaderForOneFile(
            LicenseHeaderContentInput licenseHeaderInput,
            IProgress <ReplacerProgressContentReport> progress,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (TryCreateDocument(licenseHeaderInput, out var document) != CreateDocumentResult.DocumentCreated)
            {
                await ReportProgress(progress, cancellationToken, licenseHeaderInput.DocumentPath, licenseHeaderInput.DocumentContent);

                return(null);
            }

            string message;

            if (!await document.ValidateHeader() && !licenseHeaderInput.IgnoreNonCommentText)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await ReportProgress(progress, cancellationToken, licenseHeaderInput.DocumentPath, licenseHeaderInput.DocumentContent);

                var extension = Path.GetExtension(licenseHeaderInput.DocumentPath);
                message = string.Format(Resources.Warning_InvalidLicenseHeader, extension).ReplaceNewLines();
                return(new ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderContentInput> > (
                           new ReplacerError <LicenseHeaderContentInput> (licenseHeaderInput, ReplacerErrorType.NonCommentText, message)));
            }

            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                var newContent = await document.ReplaceHeaderIfNecessaryContent(cancellationToken);
                await ReportProgress(progress, cancellationToken, licenseHeaderInput.DocumentPath, newContent);

                return(new ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderContentInput> > (new ReplacerSuccess(licenseHeaderInput.DocumentPath, newContent)));
            }
            catch (ParseException)
            {
                message = string.Format(Resources.Error_InvalidLicenseHeader, licenseHeaderInput.DocumentPath).ReplaceNewLines();
                return(new ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderContentInput> > (
                           new ReplacerError <LicenseHeaderContentInput> (licenseHeaderInput, ReplacerErrorType.ParsingError, message)));
            }
        }
 /// <summary>
 ///   Updates license headers in a file based on its content, i. e. the new content is returned. Setting the new content is
 ///   the caller's responsibility.
 /// </summary>
 /// <param name="licenseHeaderInput">
 ///   An <see cref="LicenseHeaderContentInput" /> instance representing the file whose
 ///   license headers are to be updated.
 /// </param>
 /// <returns>
 ///   Returns a <see cref="ReplacerResult{TSuccess,TError}" /> instance containing information about the success or
 ///   error of the operation.
 /// </returns>
 public async Task <ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderContentInput> > > RemoveOrReplaceHeader(LicenseHeaderContentInput licenseHeaderInput)
 {
     return(await RemoveOrReplaceHeader(
                licenseHeaderInput,
                async (input, document) =>
     {
         var newContent = await document.ReplaceHeaderIfNecessaryContent(new CancellationToken());
         return new ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderContentInput> > (new ReplacerSuccess(licenseHeaderInput.DocumentPath, newContent));
     },
                (input, errorType, message) =>
                new ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderContentInput> > (new ReplacerError <LicenseHeaderContentInput> (input, errorType, message))));
 }