public static void DeleteFileByMetadata(FileMetadata metadata, CerebelloEntitiesAccessFilterWrapper db, IBlobStorageManager storage) { // deleting dependent files var relatedFiles = db.FileMetadatas.Where(f => f.RelatedFileMetadataId == metadata.Id).ToList(); foreach (var relatedFile in relatedFiles) { DeleteFileByMetadata(relatedFile, db, storage); } // deleting file metadata and storage entries storage.DeleteFileFromStorage(metadata.ContainerName, metadata.BlobName); db.FileMetadatas.DeleteObject(metadata); }
/// <summary> /// Create a new FileMetadata object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="containerName">Initial value of the ContainerName property.</param> /// <param name="createdOn">Initial value of the CreatedOn property.</param> /// <param name="practiceId">Initial value of the PracticeId property.</param> /// <param name="sourceFileName">Initial value of the SourceFileName property.</param> /// <param name="blobName">Initial value of the BlobName property.</param> public static FileMetadata CreateFileMetadata(global::System.Int32 id, global::System.String containerName, global::System.DateTime createdOn, global::System.Int32 practiceId, global::System.String sourceFileName, global::System.String blobName) { FileMetadata fileMetadata = new FileMetadata(); fileMetadata.Id = id; fileMetadata.ContainerName = containerName; fileMetadata.CreatedOn = createdOn; fileMetadata.PracticeId = practiceId; fileMetadata.SourceFileName = sourceFileName; fileMetadata.BlobName = blobName; return fileMetadata; }
/// <summary> /// Deprecated Method for adding a new object to the FileMetadatas EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToFileMetadatas(FileMetadata fileMetadata) { base.AddObject("FileMetadatas", fileMetadata); }
/// <summary> /// Creates an action result with a thumbnail image of a file in the storage. /// </summary> /// <param name="originalMetadata">Metadata of the original image file.</param> /// <param name="storage">The storage service used to store files.</param> /// <param name="dateTimeService">Date time service used to get current date and time.</param> /// <param name="maxWidth">Maximum width of the thumbnail image.</param> /// <param name="maxHeight">Maximum height of the thumbnail image.</param> /// <param name="useCache">Whether to use a cached thumbnail or not.</param> /// <returns>The ActionResult containing the thumbnail image.</returns> protected ActionResult GetOrCreateThumb( FileMetadata originalMetadata, IBlobStorageManager storage, IDateTimeService dateTimeService, int maxWidth, int maxHeight, bool useCache = true) { if (originalMetadata == null) throw new ArgumentNullException("originalMetadata"); if (originalMetadata.OwnerUserId == this.DbUser.Id) { var fileNamePrefix = Path.GetDirectoryName(originalMetadata.BlobName) + "\\"; var normalFileName = StringHelper.NormalizeFileName(originalMetadata.SourceFileName); var thumbName = string.Format( "{0}\\{1}file-{2}-thumb-{4}x{5}-{3}", originalMetadata.ContainerName, fileNamePrefix, originalMetadata.Id, normalFileName, maxWidth, maxHeight); var fileName = string.Format("{0}\\{1}", originalMetadata.ContainerName, originalMetadata.BlobName); int originalMetadataId = originalMetadata.Id; var metadataProvider = new DbFileMetadataProvider(this.db, dateTimeService, this.DbUser.PracticeId); var thumbResult = ImageHelper.TryGetOrCreateThumb( originalMetadataId, maxWidth, maxHeight, fileName, thumbName, useCache, storage, metadataProvider); switch (thumbResult.Status) { case CreateThumbStatus.Ok: return this.File(thumbResult.Data, thumbResult.ContentType); case CreateThumbStatus.SourceFileNotFound: return new StatusCodeResult(HttpStatusCode.NotFound); case CreateThumbStatus.SourceIsNotImage: return this.Redirect(this.Url.Content("~/Content/Images/App/FileIcons/generic-outline.png")); case CreateThumbStatus.SourceImageTooLarge: return this.Redirect(this.Url.Content("~/Content/Images/App/FileIcons/generic-outline.png")); default: throw new NotImplementedException(); } } return new StatusCodeResult(HttpStatusCode.NotFound); }
private FileMetadata Create( string containerName, string sourceFileName, string blobName, int? relatedMetadataId, string relationType, DateTime? expirationDate, int? ownerUserId, string tag = null) { var md = new FileMetadata { CreatedOn = this.dateTimeService.UtcNow, PracticeId = this.practiceId, ContainerName = containerName, SourceFileName = sourceFileName, ExpirationDate = expirationDate, BlobName = blobName, RelatedFileMetadataId = relatedMetadataId, RelationType = relationType, OwnerUserId = ownerUserId, Tag = tag, }; this.actionsToSave.Enqueue(() => this.db.FileMetadatas.AddObject(md)); return md; }