private void FillImageInfo(Stream fileStream, ref Services.FileSystem.FileInfo fileInfo) { var imageExtensions = new FileExtensionWhitelist(Common.Globals.glbImageFileTypes); if (imageExtensions.IsAllowedExtension(fileInfo.Extension)) { System.Drawing.Image img = null; try { img = System.Drawing.Image.FromStream(fileStream); fileInfo.Size = fileStream.Length > int.MaxValue ? int.MaxValue : int.Parse(fileStream.Length.ToString(CultureInfo.InvariantCulture)); fileInfo.Width = img.Width; fileInfo.Height = img.Height; } catch { // error loading image file fileInfo.ContentType = "application/octet-stream"; } finally { if (img != null) { img.Dispose(); } } } }
public FileExtensionWhitelist RestrictBy(FileExtensionWhitelist parentList) { var filter = parentList._extensions; return(new FileExtensionWhitelist(string.Join(",", this._extensions.Where(x => filter.Contains(x)).Select(s => s.Substring(1))))); }