public byte[] GetImageFile(AttachedFile[] attachedFiles, bool isPep) { int dicDocTypeImageDeclarantId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicDocumentType), DicDocumentTypeCodes._001_001_1A); if (isPep) { return(attachedFiles .Where(x => x.Type.UID == dicDocTypeImageDeclarantId) .Select(x => ShepFileDownload(x.File.ShepFile)) .FirstOrDefault() ?? attachedFiles .Where(x => FileTypeHelper.GetFileExtension(x.File.ShepFile?.Name) .Equals(FileTypes.Png, StringComparison.CurrentCultureIgnoreCase) || FileTypeHelper.GetFileExtension(x.File.ShepFile?.Name).Equals(FileTypes.Jpeg, StringComparison.CurrentCultureIgnoreCase)) .Select(x => ShepFileDownload(x.File.ShepFile)) .FirstOrDefault()); } return(attachedFiles .Where(x => x.Type.UID == dicDocTypeImageDeclarantId) .Select(x => x.File.Content) .FirstOrDefault() ?? attachedFiles .Where(x => FileTypeHelper.GetFileExtension(x.File.Name) .Equals(FileTypes.Png, StringComparison.CurrentCultureIgnoreCase) || FileTypeHelper.GetFileExtension(x.File.Name) .Equals(FileTypes.Jpeg, StringComparison.CurrentCultureIgnoreCase)) .Select(x => x.File.Content) .FirstOrDefault()); }
private bool ShowSaveDialog() { using (var dialog = new SaveFileDialog()) { dialog.Filter = FileTypeHelper.GetAllFilters(); if (Template != null) { dialog.FilterIndex = FileTypeHelper.GetFilterIndex(GetExtensionByLanguage(Template.Syntax)); } else if (!string.IsNullOrEmpty(FileName)) { var info1 = new FileInfo(FileName); dialog.InitialDirectory = info1.DirectoryName; dialog.FilterIndex = FileTypeHelper.GetFilterIndex(info1.Extension); } if (dialog.ShowDialog() != DialogResult.OK) { return(false); } FileName = dialog.FileName; return(true); } }
public ActionResult ShowAttachment(int id) { //List<AttachmentDTO> attachments = InputDAC.GetAttachments(216); //MemoryStream ms = new MemoryStream(attachments[0].BinaryData); AttachmentDTO attachment = InputDAC.GetAttachment(id); MemoryStream ms = new MemoryStream(attachment.BinaryData); return(new ImageResult(ms, FileTypeHelper.GetContentType(attachment.Filename))); }
private void mnuOpen_Click(object sender, EventArgs e) { using (var dialog = new OpenFileDialog()) { dialog.Filter = FileTypeHelper.GetAllFilters(); if (dialog.ShowDialog() == DialogResult.OK) { OpenFileName(dialog.FileName); } } }
public void AttachFilesToDocuments(List <Document> documents, NiisWebContextMigration niisWebContext, ref int migratedFilesCount) { var documentFiles = _oldNiisDocumentDataService.GetDdDocumentDatas(documents.Select(r => r.Barcode).ToList()); if (documentFiles.Any() == false) { return; } foreach (var document in documents) { var documentData = documentFiles.SingleOrDefault(d => d.Id == document.Barcode); if (documentData == null) { continue; } if (documentData.FileName == null) { return; } var validFileName = $"{document.Barcode}.{Path.GetExtension(documentData.FileName)}"; var attachment = new Attachment { DocumentId = document.Id, AuthorId = _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-document-{document.Barcode}", IsMain = true, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = validFileName, Hash = _generateHash.GenerateFileHash(documentData.File) }; niisWebContext.Attachments.Add(attachment); niisWebContext.SaveChanges(); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); document.MainAttachmentId = attachment.Id; niisWebContext.SaveChanges(); migratedFilesCount++; } }
private async Task <Attachment> CreateAttachment(DocumentData oldAttachment, int newDocumentId) { try { var fileName = oldAttachment.FileName; var file = oldAttachment.File; var documentInfo = SavedDocuments.FirstOrDefault(d => d.Id == newDocumentId); if (documentInfo == null) { return(null); } var extentionPath = GetDocumentTypeName((byte)documentInfo.DocumentType); var bucketName = GetBucketName(null, newDocumentId, null); if (string.IsNullOrWhiteSpace(fileName)) { fileName = $"{Guid.NewGuid()}.{FileTypes.Pdf}"; } var originalName = GetFolderWithOriginalName(null, newDocumentId, null, fileName, extentionPath); var validName = fileName.MakeValidFileName(); var contentType = FileTypeHelper.GetContentType(fileName); await _fileStorage.AddAsync(bucketName, originalName, file, contentType); var attachment = new Attachment { AuthorId = DeveloperUserId, ContentType = contentType, BucketName = bucketName, IsMain = true, CopyCount = documentInfo.CopyCount, PageCount = documentInfo.PageCount, DateCreate = DateTimeOffset.Now, DateUpdate = DateTimeOffset.Now, OriginalName = originalName, Length = file.Length, ValidName = validName, Hash = _generateHash.GenerateFileHash(file), ExternalId = documentInfo.ExternalId, DocumentId = newDocumentId, IsDeleted = false }; return(attachment); } catch (Exception) { return(null); } }
private FileType GetAssetFileType(IAsset asset) { var files = asset.Files.ToList().Where(f => FileTypeHelper.GetFileType(f.Name) != FileType.XML).ToList(); if (files.Count == 1) { return(FileTypeHelper.GetFileType(files[0].Name)); } else { return(FileType.Unknown); } }
public void AttachFilesToRequests(List <Request> requests, NiisWebContextMigration niisWebContext, ref int migratedFilesCount) { var documentFiles = _oldNiisDocumentDataService.GetDdDocumentDatas(requests.Select(r => r.Barcode).ToList()); if (documentFiles.Any() == false) { return; } foreach (var request in requests) { var documentData = documentFiles.SingleOrDefault(d => d.Id == request.Barcode); if (documentData == null) { continue; } if (string.IsNullOrWhiteSpace(documentData.FileName)) { documentData.FileName = $"{request.Barcode}.{FileTypes.Pdf}"; } var attachment = new Attachment { AuthorId = request.UserId ?? _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-request-{request.Barcode}", IsMain = true, CopyCount = request.CopyCount, PageCount = request.PageCount, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = documentData.FileName.MakeValidFileName(), Hash = _generateHash.GenerateFileHash(documentData.File) }; _newNiisAttachmentFileService = new NewNiisAttachmentFileService(niisWebContext); _newNiisAttachmentFileService.CreateAttachment(attachment); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); request.MainAttachmentId = attachment.Id; niisWebContext.SaveChanges(); migratedFilesCount++; } }
/// <summary> /// Gets all media /// </summary> public Page <MediaMap> GetMediaPaged(long page = 1, int pageSize = 3, string name = null, int?id = null, int?mediaTypeId = null, string orderBy = "Id", string orderByDir = "ASC") { string tempExt; IQuery <IMedia> criteria = new Query <IMedia>(scopeProvider.SqlContext); if (!string.IsNullOrEmpty(name)) { criteria = criteria.Where(m => m.Name.Contains(name)); } if (id.HasValue) { criteria = criteria.Where(m => m.Id == id.Value); } if (mediaTypeId.HasValue) { criteria = criteria.Where(m => m.ContentTypeId == mediaTypeId); } var order = new Ordering(orderBy, orderByDir == "ASC" ? Umbraco.Core.Persistence.DatabaseModelDefinitions.Direction.Ascending : Umbraco.Core.Persistence.DatabaseModelDefinitions.Direction.Descending); var media = this.mediaService.GetPagedDescendants(-1, page - 1, pageSize, out long totalRecords, filter: criteria, ordering: order). Select(x => new MediaMap() { Id = x.Id, Name = x.Name, Alias = x.ContentType.Name, Ext = tempExt = FileTypeHelper.GetExtensionFromMedia(x), Type = FileTypeHelper.GetFileTypeName(tempExt), Size = FileTypeHelper.GetFileSize(x), Udi = x.Key, CreateDate = x.CreateDate, } ).ToList(); var paged = new Page <MediaMap>() { CurrentPage = page, Items = media, ItemsPerPage = pageSize, TotalItems = totalRecords, TotalPages = totalRecords / pageSize }; return(paged); }
private IDocumentProvider GetDocumentProvider(string sourceFilePath) { var fileType = FileTypeHelper.GetFileType(sourceFilePath); switch (fileType) { case FileType.Html: case FileType.Text: return(ServiceProvider.GetService <HtmlProvider>()); case FileType.Word: return(ServiceProvider.GetService <WordProvider>()); default: throw new NotSupportedException(fileType.ToString()); } }
private void ListView_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right && e.Clicks == 1) { var item = this.listView.FocusedItem; if (item.Bounds.Contains(e.Location)) { var searchResults = this.listView.SelectedResults; this.favoriteContextMenuItem.CheckState = searchResults.All(r => r.Tags.Contains("favorite")) ? CheckState.Checked : CheckState.Unchecked; this.favoriteContextMenuItem.Tag = searchResults; this.editTagsContextMenuItem.Tag = searchResults; this.addPeopleContextMenuItem.Tag = searchResults; this.findSimilarMenuItem.Enabled = searchResults.All(r => FileTypeHelper.IsImage(r.FileType)); this.itemContextMenu.Show(Cursor.Position); } } }
public override IDocumentProvider GetProvider(FileDocumentId document) { var fileType = FileTypeHelper.GetFileType(document.FilePath); switch (fileType) { case FileType.Html: case FileType.Text: return(this.serviceProvider.GetService <HtmlProvider>()); case FileType.Word: return(this.serviceProvider.GetService <WordProvider>()); case FileType.Pdf: return(this.serviceProvider.GetService <PdfProvider>()); default: throw new NotSupportedException(fileType.ToString()); } }
public void AttachFile(AttachedFileModel attachedFile, int requestId) { var attachment = new Attachment { DateCreate = DateTimeOffset.Now, RequestId = requestId, IsMain = attachedFile.IsMain, CopyCount = attachedFile.CopyCount, Length = attachedFile.Length, AuthorId = _configuration.AuthorAttachmentDocumentId, PageCount = attachedFile.PageCount, OriginalName = "integration/" + requestId + "/" + Guid.NewGuid(), //attachedFile.Name, ValidName = attachedFile.Name.MakeValidFileName(), ContentType = FileTypeHelper.GetContentType(attachedFile.Name), Hash = _generateHash.GenerateFileHash(attachedFile.File), BucketName = "requests" }; CreateAttachment(attachment); Task.Run(() => _fileStorage.AddAsync(attachment.BucketName, attachment.OriginalName, attachedFile.File, attachment.ContentType)).Wait(); }
public int?GetMainAttachmentId(int oldDocumentId, NiisWebContextMigration niisWebContext) { var documentData = _oldNiisDocumentDataService.GetDocumentData(oldDocumentId); if (documentData == null) { return(null); } if (string.IsNullOrWhiteSpace(documentData.FileName)) { documentData.FileName = $"{oldDocumentId}.{FileTypes.Pdf}"; } var attachment = new Attachment { AuthorId = _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-document-{oldDocumentId}", IsMain = true, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = documentData.FileName.MakeValidFileName(), Hash = _generateHash.GenerateFileHash(documentData.File) }; _newNiisAttachmentFileService = new NewNiisAttachmentFileService(niisWebContext); _newNiisAttachmentFileService.CreateAttachment(attachment); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); return(attachment.Id); }
/// <summary> /// Gets all media (this can potentially return a lot - add pagination??) /// </summary> public IEnumerable <MediaMap> GetMedia() { var ms = services.MediaService; List <MediaMap> mediaMap = new List <MediaMap>(); var rootMedia = ms.GetRootMedia(); string tempExt; foreach (var m in rootMedia) { mediaMap.AddRange(ms.GetDescendants(m). Select(x => new MediaMap() { Id = x.Id, Name = x.Name, Alias = x.ContentType.Name, Ext = tempExt = FileTypeHelper.GetExtensionFromMedia(x), Type = FileTypeHelper.GetFileTypeName(tempExt), Size = FileTypeHelper.GetFileSize(x) } )); } return(mediaMap); }
public ImageResult(string sourceFilename) { SourceFilename = sourceFilename; ContentType = FileTypeHelper.GetContentType(SourceFilename); }
static TemplateProvider() { FileTypeHelper.Register(".vm", "Velocity模板文件|*.vm"); }
static TemplateProvider() { FileTypeHelper.Register(".tt", "TT模板文件|*.tt"); }
/// <summary> /// 获取图片类型扩展名列表 /// </summary> public static string GetExtensions(this ImageType fileType) { var name = Util.Helpers.Enum.GetName <ImageType>(fileType); return(FileTypeHelper.GetExtensions(name)); }
public void GetTypeTest() { string fileName = @"C:\Windows\System32\cmd.exe"; FileTypeHelper.FileTypeInfo(fileName).Should().Be("Application"); }
public static void MapType_Throws(string path) { Assert.That(() => FileTypeHelper.MapType(path), Throws.ArgumentException); }
/// <summary> /// 获取文档类型扩展名列表 /// </summary> public static string GetExtensions(this DocumentType fileType) { var name = Bing.Utils.Helpers.Enum.GetName <DocumentType>(fileType); return(FileTypeHelper.GetExtensions(name)); }
static TemplateProvider() { FileTypeHelper.Register(".cshtml", "Razor模板文件|*.cshtml"); }
public static void MapType_ReturnsExpectedResult(string path, FileType expectedResult) { var result = FileTypeHelper.MapType(path); Assert.That(result, Is.EqualTo(expectedResult)); }