/// <summary> /// Froms the dashboard item. /// </summary> /// <param name="item">The item.</param> /// <param name="fullRights">if set to <c>true</c> [full rights].</param> /// <returns></returns> public static FileViewModel FromDashboardItem(DashboardItem item, bool fullRights = false) { return new FileViewModel { Date = item.AddedOn, Name = item.Name, Rights = fullRights ? Rights.Read | Rights.Write : Rights.Read, Size = item.File?.Size ?? 0, Type = item.IsFolder ? FileType.Dir : FileType.File }; }
/// <summary> /// Decrypts the item. /// </summary> /// <param name="item">The item.</param> /// <param name="withFileContent">if set to <c>true</c> [with file content].</param> /// <returns></returns> public DashboardItem Decrypt(DashboardItem item, bool withFileContent = false) { var newItem = new DashboardItem(); newItem.Name = EncryptionHelper.SymmetricDecryptInBase64(item.Name, this.key); newItem.Path = EncryptionHelper.SymmetricDecryptInBase64(item.Path, this.key); newItem.AddedOn = item.AddedOn; newItem.IsFolder = item.IsFolder; newItem.Id = item.Id; if (item.File != null && !item.IsFolder) { newItem.File = this.DecryptFile(item.File, withFileContent); } return newItem; }
/// <summary> /// Gets the encrypted file. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="path">The path.</param> /// <param name="fileData">The file data.</param> /// <param name="mime">The MIME.</param> /// <returns></returns> public DashboardItem Encrypt(string fileName, string path, byte[] fileData = null, string mime = "") { path = path ?? string.Empty; var item = new DashboardItem(); if (fileData != null) { var file = new DashboardFile(); file.Content = EncryptionHelper.SymmetricEncryptData(fileData, this.key); file.Size = fileData.Length; file.MediaType = EncryptionHelper.SymmetricEncryptInBase64(mime, key); item.File = file; } item.Name = EncryptionHelper.SymmetricEncryptInBase64(fileName, this.key); item.Path = EncryptionHelper.SymmetricEncryptInBase64(path, this.key); item.IsFolder = fileData == null; return item; }