Exemplo n.º 1
0
        public IEnumerable <string> GetFiles(string[] inputFolders = null)
        {
            const string IMG_FILE_PATTERN  = "Img_*.*";
            var          allowedExtensions = new[] { ".png", ".jpg", ".jpeg", ".bmp" };
            var          files             = new List <string>();

            foreach (var folder in inputFolders ?? _inputFolders)
            {
                _logger.LogInfo("GetFiles from: " + folder);
                var filesToAdd = _fileSystemHelper.GetFiles(folder, IMG_FILE_PATTERN, allowedExtensions);
                files.AddRange(filesToAdd);
            }
            return(files.OrderBy(Path.GetFileName).ToList());
        }
Exemplo n.º 2
0
        public override ValidationResult Validate(RepositoryInfo repositoryInfo, Action <ValidationResult> notify = null)
        {
            var result    = new ValidationResult(this);
            var fileNames = _fileSystemHelper.GetFiles(repositoryInfo.RepositoryRootPath, _fileNamePattern, _sourceFileFilters).ToList();

            string message;

            var backupFileName = string.Empty;

            if (_isBackupEnabled)
            {
                try
                {
                    backupFileName = Backup(repositoryInfo.RepositoryRootPath, fileNames);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_rule_can_not_create_backup_file, TransformMessage.ToLower());
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    return(result);
                }
            }

            foreach (var fileName in fileNames)
            {
                string code;
                try
                {
                    code = _fileSystemHelper.ReadAllText(fileName);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_Can_not_read_file, TransformingMessage.ToLower(), fileName);
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    continue;
                }

                if (_isBackupEnabled)
                {
                    if (!BackupExists(backupFileName, fileName, code))
                    {
                        message = string.Format(Resources.TransformRule_Validate_Not_file_because_can_not_verify_backup, TransformingMessage.ToLower(), fileName);
                        result.AddResult(ResultLevel.Error, message, notify);
                        Logger.Error(message);
                        continue;
                    }
                }

                string transformedCode;
                try
                {
                    transformedCode = Transform(code, fileName, notify);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_error_in_file, TransformerMessage, e.Message, fileName);
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    continue;
                }
                try
                {
                    _fileSystemHelper.WriteAllText(fileName, transformedCode, Encoding.UTF8);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_Code_error_in_file, TransformingMessage.ToLower(), fileName);
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    continue;
                }

                message = string.Format(Resources.TransformRule_Validate_File_successfully, TransformedMessage.ToLower(), fileName);
                result.AddResult(ResultLevel.Passed, message, notify);
            }
            return(result);
        }