/// <inheritdoc/> public void ExecuteAllRules(IFileServiceConfig fileServiceConfig, byte[] inputBytes, string fileType, string fileName = null) { foreach (var rule in _rules) { rule.Execute(fileServiceConfig, inputBytes, fileType, fileName); } }
/// <summary> /// Generate file metadata from bytes by writing it on to the FileSystem /// </summary> /// <param name="fileServiceConfig">>Associated File Handler's Configuration</param> /// <param name="stream">The stream of the file</param> /// <param name="fileName">The Name of the file on the FileSystem in the Root Directory (Including extension)</param> /// <param name="fileType">The Extension of the file (without '.'). eg:zip</param> /// <param name="throwOnException">Indicates whether an Exception should be thrown when the file is not found. Default: true</param> public FileMetaData(IFileServiceConfig fileServiceConfig, Stream stream, string fileName, string fileType, bool?throwOnException = true) { char seperator = Path.DirectorySeparatorChar; this.Root = fileServiceConfig.RootDirectory.LastOrDefault() == seperator?fileServiceConfig.RootDirectory.Remove(fileServiceConfig.RootDirectory.Length - 1, 1) : fileServiceConfig.RootDirectory; this.FileType = fileType; this.FileName = fileName; try { if (File.Exists(AbsolutePath)) { File.Delete(AbsolutePath); } Init(ref stream); } catch (Exception ex) { if (throwOnException.Value) { throw ex; } } }
public static void Initialize(TestContext context) { if (!Directory.Exists(_filesPath)) { Directory.CreateDirectory(_filesPath); } _allowedExtensions = new string[] { "bin" }; _config = new FileServiceConfig(stream => "application/octet-stream", 5.0d, Configuration.FileSizeUnit.KB, _filesPath, _allowedExtensions); _fileService = new FileService(_config); }
private void Validate(IFileServiceConfig fileServiceConfig, string fileName) { if (string.IsNullOrEmpty(fileName) || !fileName.Contains('.')) { return; } var extension = Path.GetExtension(fileName)?.ToLower()?.Remove(0, 1); var isValid = string.IsNullOrEmpty(extension) ? true : fileServiceConfig?.AllowedExtensions?.Any(x => x == extension) ?? false; if (!isValid) { throw new InvalidExtensionException(extension, fileServiceConfig.AllowedExtensions); } }
/// <summary> /// Generate file meta data from a file on the filesystem /// </summary> /// <param name="fileName">The Name of the file on the FileSystem in the Root Directory (Including extension)</param> /// <param name="fileType">The type of the File</param> /// <param name="fileServiceConfig">Associated File Handler's Configuration</param> /// <param name="throwOnNotFound">Indicates whether an Exception should be thrown when the file is not found. Default: true</param> public FileMetaData(IFileServiceConfig fileServiceConfig, string fileName, string fileType, bool?throwOnNotFound = true) { char seperator = Path.DirectorySeparatorChar; this.Root = fileServiceConfig.RootDirectory.LastOrDefault() == seperator?fileServiceConfig.RootDirectory.Remove(fileServiceConfig.RootDirectory.Length - 1, 1) : fileServiceConfig.RootDirectory; this.FileType = fileType; this.FileName = fileName; if (File.Exists(AbsolutePath)) { SetFileInfo(); } else { if (throwOnNotFound.Value) { throw new FileNotFoundException("The specified file does not exist on the File System", this.AbsolutePath); } } }
/// <summary> /// Generate file metadata from bytes by writing it on to the FileSystem /// </summary> /// <param name="fileServiceConfig">>Associated File Handler's Configuration</param> /// <param name="bytes">The bytes of the file</param> /// <param name="fileName">The Name of the file on the FileSystem in the Root Directory (Including extension)</param> /// <param name="fileType">The Extension of the file (without '.'). eg:zip</param> /// <param name="throwOnException">Indicates whether an Exception should be thrown when the file is not found. Default: true</param> public FileMetaData(IFileServiceConfig fileServiceConfig, byte[] bytes, string fileName, string fileType, bool?throwOnException = true) { char seperator = Path.DirectorySeparatorChar; this.Root = fileServiceConfig.RootDirectory.LastOrDefault() == seperator?fileServiceConfig.RootDirectory.Remove(fileServiceConfig.RootDirectory.Length - 1, 1) : fileServiceConfig.RootDirectory; this.FileType = fileType; this.FileName = fileName; try { File.WriteAllBytes(AbsolutePath, bytes); SetFileInfo(); } catch (Exception ex) { if (throwOnException.Value) { throw ex; } } }
private void ValidateRules(IFileServiceConfig fileServiceConfig, byte[] inputBytes, string fileType, string fileName = null) { fileServiceConfig?.Rules?.ExecuteAllRules(fileServiceConfig, inputBytes, fileType, fileName); }
private void ValidateRules(IFileServiceConfig fileServiceConfig, Stream inputStream, string fileType, string fileName = null) { fileServiceConfig?.Rules?.ExecuteAllRules(fileServiceConfig, inputStream, fileType, fileName); }
/// <summary> /// The configuration for a File Handler / Service /// </summary> /// <param name="fileServiceConfig">The configuration to be used</param> public FileService(IFileServiceConfig fileServiceConfig) { this._fileServiceConfig = fileServiceConfig; }
public void Execute(IFileServiceConfig fileServiceConfig, byte[] inputBytes, string fileType, string fileName = null) { Validate(fileType); }
public void Execute(IFileServiceConfig fileServiceConfig, Stream inputStream, string fileType, string fileName = null) { Validate(fileType); }