private async Task RemoveOrReplaceHeaderForOneFile(
            LicenseHeaderPathInput licenseHeaderInput,
            IProgress <ReplacerProgressReport> progress,
            CancellationToken cancellationToken,
            ConcurrentQueue <ReplacerError <LicenseHeaderPathInput> > errors)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (TryCreateDocument(licenseHeaderInput, out var document) != CreateDocumentResult.DocumentCreated)
            {
                await ReportProgress(progress, licenseHeaderInput.DocumentPath, cancellationToken);

                return;
            }

            string message;

            if (!await document.ValidateHeader() && !licenseHeaderInput.IgnoreNonCommentText)
            {
                var extension = Path.GetExtension(licenseHeaderInput.DocumentPath);
                message = string.Format(Resources.Warning_InvalidLicenseHeader, extension).ReplaceNewLines();
                errors.Enqueue(new ReplacerError <LicenseHeaderPathInput> (licenseHeaderInput, ReplacerErrorType.NonCommentText, message));

                cancellationToken.ThrowIfCancellationRequested();
                await ReportProgress(progress, licenseHeaderInput.DocumentPath, cancellationToken);

                return;
            }

            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                await document.ReplaceHeaderIfNecessaryPath(cancellationToken);
            }
            catch (ParseException)
            {
                message = string.Format(Resources.Error_InvalidLicenseHeader, licenseHeaderInput.DocumentPath).ReplaceNewLines();
                errors.Enqueue(new ReplacerError <LicenseHeaderPathInput> (licenseHeaderInput, ReplacerErrorType.ParsingError, message));
            }

            await ReportProgress(progress, licenseHeaderInput.DocumentPath, cancellationToken);
        }
 public async Task <ReplacerResult <ReplacerError <LicenseHeaderPathInput> > > RemoveOrReplaceHeader(LicenseHeaderPathInput licenseHeaderInput)
 {
     return(await RemoveOrReplaceHeader(
                licenseHeaderInput,
                async (input, document) =>
     {
         await document.ReplaceHeaderIfNecessaryPath(new CancellationToken());
         return new ReplacerResult <ReplacerError <LicenseHeaderPathInput> >();
     },
                (input, errorType, message) =>
                new ReplacerResult <ReplacerSuccess, ReplacerError <LicenseHeaderPathInput> > (new ReplacerError <LicenseHeaderPathInput> (input, errorType, message))));
 }