/// <summary> /// Stamps the asset thumbnail. /// </summary> private static void StampThumbnail(Asset asset) { AssetThumbnailInfo info = new AssetThumbnailInfo(asset); if (!info.FileExists) { return; } if (!AssetTypeChecker.IsImage(StringUtils.GetFileExtension(info.FilePath))) { return; } string description = asset.AssetType.Name.Replace(" ", string.Empty); string filename = string.Format("{0}.gif", description); string path = Path.Combine(Settings.ImageFolder, "Asset/Stamp_Icons/"); string stamp = Path.Combine(path, filename); if (!File.Exists(stamp)) { return; } ImageUtils.StampImage(info.FilePath, stamp); }
/// <summary> /// Saves the asset file to disk. /// Asset previews are automatically resized. /// Asset thumbnails are automatically resized and stamped. /// </summary> public static void SaveAssetFile(Asset asset, BinaryFile file, AssetFileType assetFileType) { // Check asset if (asset == null || asset.IsNull || asset.IsNew) { throw new InvalidAssetException("Asset is null or new"); } // Check we've got a file if (file == null || file.IsEmpty) { throw new InvalidAssetException("file is empty"); } // Check that we're not trying to save an asset file. This must be done // using a different overload of this method as it has more processes involved. if (assetFileType == AssetFileType.AssetFile) { throw new SystemException("This method cannot be used to save raw asset files; it is designed to save related asset files only"); } // Folder where this file will reside string folder = GetFolder(asset.AssetFilePath, assetFileType); // Delete the old file DeleteFiles(asset.FileReference, folder); // Construct path to file to be saved string filename = String.Concat(asset.FileReference, ".", file.FileExtension); string path = Path.Combine(folder, filename); // Save the file SavePostedFile(file, path); // Resize previews if (AssetTypeChecker.IsImage(file.FileExtension) && assetFileType == AssetFileType.AssetPreview) { ImageUtils.ResizeImage(path, path, 320, 300, true); } // Resize thumbnails if (AssetTypeChecker.IsImage(file.FileExtension) && assetFileType == AssetFileType.AssetThumbnail) { ImageUtils.ResizeImageDown(path, 100, 100); StampThumbnail(asset); } }
protected override void Render(HtmlTextWriter writer) { if (Asset.IsNull) { // No asset WriteImage(writer, "~/Images/Spacer.gif"); return; } if (!EntitySecurityManager.CanUserViewAssetPreview(SessionInfo.Current.User, Asset)) { // Access denied WriteImage(writer, "~/Images/Spacer.gif"); return; } // The asset has not been marked as processed, so show a 'processing' image placeholder // instead, even if the filepath is not empty. This is because the file may exist, but // may still have data being written to it by another process, so we don't have any // guarantee that it's safe to display to the user. if (!Asset.IsProcessed) { WriteImage(writer, "~/Images/Asset/Previews/Processing.gif"); return; } // Get asset File Info AssetPreviewInfo info = new AssetPreviewInfo(Asset); // If we don't have an asset preview file. Show a placeholder image instead. if (!info.FileExists) { WriteImage(writer, "~/Images/Asset/Previews/Unavailable.gif"); return; } // Setup variables to be replaced string assetPreviewFileExtension = StringUtils.GetFileExtension(info.FilePath); string assetPreviewUrl = AssetFileUrlHelper.GetPreviewUrl(Asset.AssetId); string assetPreviewRelativeUrl = ResolveUrl(assetPreviewUrl); string assetPreviewAbsoluteUrl = SiteUtils.GetWebsiteUrl(assetPreviewUrl); string playerId = ClientID + "_Preview"; string rtmpStreamingServer = ConfigurationManager.AppSettings.GetValue("RTMPStreamingServer"); // If the streaming server is enabled, then hack the file extension to get the correct markup if (assetPreviewFileExtension == "flv" && !StringUtils.IsBlank(rtmpStreamingServer)) { assetPreviewFileExtension += "-streaming"; } //get the plugin context type //use query string if specified otherwise use AdminSessionInfo ContextType contextType; if (HttpContext.Current.Request.QueryString["ctxt"] != null) { contextType = PluginManager.GetContextType(HttpContext.Current.Request.QueryString["ctxt"]); } else { contextType = SessionInfo.Current.AdminSessionInfo.AssetContext; } //get the plugin for the asset Plugin plugin = ContextInfo.PluginManager.GetPluginForAsset(Asset); //get the plugins relative URL string relativePluginUrl = ResolveUrl(plugin.RelativePath); // Get the HTML string markup = ContextInfo.PluginManager.GetMarkup(plugin, contextType); // We can override images if (StringUtils.IsBlank(markup) && AssetTypeChecker.IsImage(assetPreviewFileExtension)) { WriteImage(writer, assetPreviewUrl); return; } // Otherwise, ensure we have markup if (string.IsNullOrEmpty(markup)) { writer.Write(string.Format("[Unable to preview: {0}]", assetPreviewFileExtension)); return; } // Replace params markup = markup.Replace("[ASSET-PREVIEW-URL]", assetPreviewUrl); markup = markup.Replace("[RELATIVE-PREVIEW-URL]", assetPreviewRelativeUrl); markup = markup.Replace("[ABSOLUTE-PREVIEW-URL]", assetPreviewAbsoluteUrl); markup = markup.Replace("[FOCUSOPEN-PREVIEW-FILENAME]", Path.GetFileName(info.FilePath)); markup = markup.Replace("[PLAYER-ID]", playerId); markup = markup.Replace("[ASSET-ID]", Asset.AssetId.ToString()); markup = markup.Replace("[ASSET-REFERENCE]", info.Asset.FileReference); markup = markup.Replace("[STREAMING-SERVER-URL]", rtmpStreamingServer); markup = markup.Replace("[USER-ID]", SessionInfo.Current.User.UserId.GetValueOrDefault().ToString()); markup = markup.Replace("[PREVIEW-FILE-EXTENSION]", assetPreviewFileExtension); markup = markup.Replace("[ASSET-TYPE-ID]", Asset.AssetTypeId.ToString()); markup = markup.Replace("[ASSET-TYPE-NAME]", Asset.AssetType.Name); markup = markup.Replace("[PREVIEW-AVAILABLE]", (info.PreviewAvailable ? "true" : "false")); markup = markup.Replace("[PLUGIN-URL]", relativePluginUrl); markup = markup.Replace("[SESSIONAPITOKEN]", SessionInfo.Current.User.SessionAPIToken); markup = markup.Replace("~/", WebUtils.GetApplicationPath()); // Write the HTML to the page writer.Write(markup); }
protected void NextButton_Click(object sender, EventArgs e) { ErrorList errors = new ErrorList(); if (StringUtils.IsBlank(FtpHostTextBox.Text)) { errors.Add("Ftp host is required"); } if (NumericUtils.ParseInt32(FtpPortTextBox.Text, 0) == 0) { errors.Add("Ftp host port must be a number"); } if (StringUtils.IsBlank(FtpUsernameTextBox.Text)) { errors.Add("Username is required"); } if (errors.Count > 0) { FeedbackLabel1.SetErrorMessage("Please check the following and try again:", errors); return; } // List of files to upload List <FtpFile> assetFilePaths = new List <FtpFile>(); // Get all of the order items in the current order foreach (OrderItem orderItem in SelectedOrder.OrderItemList) { // Get the order item id int orderItemId = orderItem.OrderItemId.GetValueOrDefault(); // Check if the order item can be downloaded and is in the list of selected order items if (ViewOrders.CanDownload(orderItem) && SelectedOrderItems.Contains(orderItemId)) { // Get the asset Asset asset = orderItem.Asset; // Get the selected order item SelectedOrderItem soi = SelectedOrderItems.Get(orderItemId); // Initialise path and filename to FTP string path, filename; // Check if zip asset files is enabled and we're not doing any kind of transcoding. // If so, we want to FTP the zipped asset file instead, so set the path and filename accordingly. // However, if the zip file doesn't exist, then we want to FTP the original asset instead. if (AssetFileManager.ZipAssetFiles && soi.AssetImageSizeId == 0) { // First get the path to the zipped asset file ZippedAssetFileInfo zippedFileInfo = new ZippedAssetFileInfo(asset); if (zippedFileInfo.FileExists) { // Ensure that a path was returned, and if so, set the filename accordingly path = zippedFileInfo.FilePath; filename = Path.GetFileNameWithoutExtension(asset.Filename) + ".zip"; } else { // Otherwise, the zip file doesn't exist, so get the path to the original // asset file, and set the filename to the asset filename AssetFileInfo info = new AssetFileInfo(asset); path = info.FilePath; filename = asset.Filename; } } else { // Get the file path to the asset AssetFileInfo info = new AssetFileInfo(asset); path = info.FilePath; // For images, get the filepath to the resized image if (AssetTypeChecker.IsImage(asset.FileExtension)) { path = AssetImageManager.GetResizedAssetImage(asset, soi.AssetImageSizeId, soi.DownloadFormat, true); } // Construct the asset filename filename = Path.GetFileNameWithoutExtension(asset.Filename) + Path.GetExtension(path); } // Add the file path to the list FtpFile file = new FtpFile(path, filename); assetFilePaths.Add(file); } } try { // Instantiate FTP downloader FtpDownloader ftpDownloader = new FtpDownloader { BackgroundTransfer = true, Host = FtpHostTextBox.Text.Trim(), Port = NumericUtils.ParseInt32(FtpPortTextBox.Text, 0), PassiveMode = FtpPassiveModeCheckBox.Checked, Username = FtpUsernameTextBox.Text.Trim(), Password = FtpPasswordTextBox.Text.Trim(), RemoteFolder = FtpRemoteFolderTextBox.Text.Trim(), User = CurrentUser }; // Specify files to send to FTP server foreach (FtpFile file in assetFilePaths) { ftpDownloader.Files.Add(file); } // Wire up events ftpDownloader.UploadComplete += new FtpDownloadCompleteEventHandler(NotifyEngine.FtpDownloadComplete); // Go do it! ftpDownloader.Go(); // Log the assets as downloaded foreach (SelectedOrderItem soi in SelectedOrderItems) { OrderItem orderItem = OrderItem.Get(soi.OrderItemId); Asset asset = orderItem.Asset; AuditLogManager.LogAssetAction(asset, CurrentUser, AuditAssetAction.DownloadedAssetFile); AuditLogManager.LogUserAction(CurrentUser, AuditUserAction.DownloadAsset, string.Format("Downloaded AssetId: {0} as part of FTP download to: {1} for OrderId: {2}", asset.AssetId, ftpDownloader.Host, orderItem.OrderId)); } // Lets cookie the settings as well, so we can pre-populate // the form when the user returns to download more assets CookieManager.SetValue("FtpHost", ftpDownloader.Host); CookieManager.SetValue("FtpPort", ftpDownloader.Port); CookieManager.SetValue("FtpPassiveMode", FtpPassiveModeCheckBox.Checked ? "1" : "0"); CookieManager.SetValue("FtpUsername", ftpDownloader.Username); // Update UI FormPanel.Visible = false; SuccessPanel.Visible = true; } catch (FtpDownloadException fdex) { // Remove the error code from the start of the error message string message = Regex.Replace(fdex.Message, @"(\d+\s-\s)", string.Empty); // Display the error to the user FeedbackLabel1.SetErrorMessage("Error downloading assets", message); // Log the error m_Logger.Warn(string.Format("Error downloading files to FTP. User: {0}, Host: {1}. Error: {2}", CurrentUser.FullName, FtpHostTextBox.Text, message), fdex); } }
public static string GetResizedAssetImage(Asset asset, int assetImageSizeId, DownloadFormat downloadFormat, bool create) { //--------------------------------------------------------------------------------------------------------- // Get asset file info //--------------------------------------------------------------------------------------------------------- AssetFileInfo fileInfo = new AssetFileInfo(asset); //--------------------------------------------------------------------------------------------------------- // Ensure asset file exists //--------------------------------------------------------------------------------------------------------- if (!fileInfo.FileExists) { return(string.Empty); } //--------------------------------------------------------------------------------------------------------- // No options specified //--------------------------------------------------------------------------------------------------------- if (assetImageSizeId == 0 && downloadFormat == DownloadFormat.Original) { return(fileInfo.FilePath); } //--------------------------------------------------------------------------------------------------------- // Only images can be resized //--------------------------------------------------------------------------------------------------------- if (!AssetTypeChecker.IsImage(asset.FileExtension)) { return(fileInfo.FilePath); } //--------------------------------------------------------------------------------------------------------- // PDFs are an exception as they are classified as images but cant be resized //--------------------------------------------------------------------------------------------------------- if (StringUtils.GetFileExtension(asset.Filename) == "pdf") { return(fileInfo.FilePath); } //--------------------------------------------------------------------------------------------------------- // Get the requested image size //--------------------------------------------------------------------------------------------------------- AssetImageSize ais = AssetImageSizeCache.Instance.GetById(assetImageSizeId); //--------------------------------------------------------------------------------------------------------- // Construct the path to the output filename //--------------------------------------------------------------------------------------------------------- string suffix = (StringUtils.IsBlank(ais.FileSuffix)) ? "original" : ais.FileSuffix; string reference = Path.GetFileNameWithoutExtension(asset.Filename) + "_" + suffix; string extension = GetDownloadFormat(downloadFormat, asset.FileExtension); string cacheFolder = VirtualPathUtility.AppendTrailingSlash(Path.Combine(Settings.CachedAssetFilesFolder, asset.AssetId.ToString())); string outputFilename = Path.Combine(cacheFolder, reference) + "." + extension; if (File.Exists(outputFilename)) { return(outputFilename); } if (!create) { return(string.Empty); } //--------------------------------------------------------------------------------------------------------- // Create the cache folder if it doesn't exist //--------------------------------------------------------------------------------------------------------- if (!Directory.Exists(cacheFolder)) { Directory.CreateDirectory(cacheFolder); m_Logger.DebugFormat("Created cache folder: {0}", cacheFolder); } //------------------------------------------------------------------------------------------------ // Now we've verified that we need to do some work. //------------------------------------------------------------------------------------------------ string tempPath = Path.Combine(Settings.TempFolder, asset.AssetId + "_" + Guid.NewGuid() + Path.GetExtension(fileInfo.FilePath)); //--------------------------------------------------------------------------------------------------------- // Create resized image //--------------------------------------------------------------------------------------------------------- if (ais.Width > 0 && ais.Height > 0) { ImageProcessingJob job = new ImageProcessingJob { SourceFilePath = fileInfo.FilePath, TargetFilePath = tempPath, Width = ais.Width, Height = ais.Height }; job.Go(); m_Logger.DebugFormat("Generated resized image for asset id: {0}, assetImageSize: {1}, height: {2}, width: {3} at: {4}", asset.AssetId, ais.Description, ais.Height, ais.Width, job.TargetFilePath); } //--------------------------------------------------------------------------------------------------------- // Ensure we've got our image //--------------------------------------------------------------------------------------------------------- if (!File.Exists(tempPath)) { File.Copy(fileInfo.FilePath, tempPath); m_Logger.DebugFormat("Original asset copied to: {0}", tempPath); } //--------------------------------------------------------------------------------------------------------- // Now convert the DPI to the value requested //--------------------------------------------------------------------------------------------------------- if (ais.DotsPerInch > 0) { ImageUtils.ChangeDPI(tempPath, ais.DotsPerInch); m_Logger.DebugFormat("Changed DPI of file: {0} to: {1}", tempPath, ais.DotsPerInch); } //------------------------------------------------------------------------------------------------ // Do download format conversion //------------------------------------------------------------------------------------------------ if (StringUtils.GetFileExtension(tempPath) != StringUtils.GetFileExtension(outputFilename)) { ImageUtils.ConvertFormat(tempPath, outputFilename); } //------------------------------------------------------------------------------------------------ // Ensure we've got the output file now //------------------------------------------------------------------------------------------------ if (!File.Exists(outputFilename)) { File.Move(tempPath, outputFilename); } //--------------------------------------------------------------------------------------------------------- // All done, return path //--------------------------------------------------------------------------------------------------------- return(outputFilename); }
protected void OrderItemsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { switch (e.Item.ItemType) { case (ListItemType.Item): case (ListItemType.AlternatingItem): // Get the order item and its corresponding asset OrderItem orderItem = (OrderItem)e.Item.DataItem; Asset asset = orderItem.Asset; // Get all controls we'll be using HiddenField OrderItemIdHiddenField = (HiddenField)e.Item.FindControl("OrderItemIdHiddenField"); HiddenField AssetIdHiddenField = (HiddenField)e.Item.FindControl("AssetIdHiddenField"); AssetThumbnail AssetThumbnail1 = (AssetThumbnail)e.Item.FindControl("AssetThumbnail1"); AssetButtons AssetButtons1 = (AssetButtons)e.Item.FindControl("AssetButtons1"); FileSizeMessageLabel FileSizeLabel = (FileSizeMessageLabel)e.Item.FindControl("FileSizeLabel"); EmailHyperLink AssetContactHyperlink = (EmailHyperLink)e.Item.FindControl("AssetContactHyperlink"); HyperLink DownloadHyperlink = (HyperLink)e.Item.FindControl("DownloadHyperlink"); CheckBox SelectAssetCheckBox = (CheckBox)e.Item.FindControl("SelectAssetCheckBox"); DownloadFormatDropDownList DownloadFormatDropDownList1 = (DownloadFormatDropDownList)e.Item.FindControl("DownloadFormatDropDownList1"); AssetImageSizeDropDownList AssetImageSizeDropDownList1 = (AssetImageSizeDropDownList)e.Item.FindControl("AssetImageSizeDropDownList1"); FeedbackLabel OrderItemMessageLabel = (FeedbackLabel)e.Item.FindControl("OrderItemMessageLabel"); PlaceHolder ImageOptionsPlaceHolder = (PlaceHolder)e.Item.FindControl("ImageOptionsPlaceHolder"); HtmlTableRow FileSizeRow = (HtmlTableRow)e.Item.FindControl("FileSizeRow"); HtmlGenericControl SelectorContainer = (HtmlGenericControl)e.Item.FindControl("SelectorContainer"); HtmlGenericControl LinkButtonWrapper = (HtmlGenericControl)e.Item.FindControl("LinkButtonWrapper"); FileSizeMessageLabel ImageFileSizeMessageLabel = (FileSizeMessageLabel)e.Item.FindControl("ImageFileSizeMessageLabel"); // Populate table cells with basic information about the asset SetTableCellText(e.Item, "AssetReferenceCell", asset.AssetId.ToString()); SetTableCellHtml(e.Item, "DescriptionCell", SiteUtils.ConvertTextToHtml(asset.Description)); SetTableCellText(e.Item, "BrandCell", asset.Brand.Name); SetTableCellText(e.Item, "AssetTypeCell", asset.AssetType.Name); SetTableCellHtml(e.Item, "UsageRestrictionsCell", asset.UsageRestrictions); SetTableCellText(e.Item, "DateRequestedByCell", orderItem.RequiredByDate.HasValue ? orderItem.RequiredByDate.Value.ToString(Global.DateFormat) : "None"); SetTableCellText(e.Item, "DateOfDecisionCell", orderItem.OrderItemStatusDate.HasValue ? orderItem.OrderItemStatusDate.Value.ToString(Global.DateFormat) : "None"); SetTableCellText(e.Item, "NotesCell", orderItem.Notes); // Populate hidden fields as we'll need these for other stuff OrderItemIdHiddenField.Value = orderItem.OrderItemId.ToString(); AssetIdHiddenField.Value = asset.AssetId.ToString(); // Get/Initialise other objects we'll need here AssetStatus assetStatus = AssetManager.GetAssetStatusForUser(asset, CurrentUser); SelectedOrderItem soi = SelectedOrderItems.Get(orderItem.OrderItemId.GetValueOrDefault()); // Check if user can download this asset bool canDownload = CanDownload(orderItem); // Initialise the thumbnail and buttons AssetThumbnail1.Initialise(asset); AssetButtons1.Initialise(asset); // Populate other controls which are not dependent on the asset type AssetContactHyperlink.SetNameEmail(asset.UploadedByUser.FullName, asset.UploadedByUser.Email); SelectorContainer.Visible = canDownload; SelectAssetCheckBox.Checked = IsOrderItemSelected(orderItem.OrderItemId.GetValueOrDefault()); DownloadHyperlink.NavigateUrl = string.Format("javascript:downloadAsset('{0}','{1}','{2}', '{3}', '{4}')", orderItem.AssetId, orderItem.OrderId, orderItem.OrderItemId, DownloadFormatDropDownList1.ClientID, AssetImageSizeDropDownList1.ClientID); // Do processing dependent on asset type if (AssetTypeChecker.IsImage(asset.FileExtension)) { // Only show download resolution row if user can download ImageOptionsPlaceHolder.Visible = canDownload; // Only do the image size stuff if the download resolution row is visible if (ImageOptionsPlaceHolder.Visible) { // Populate the download format dropdown with the previously selected value (if any) DownloadFormatDropDownList1.SafeSelectValue(soi.DownloadFormat); // Populate the asset image size dropdown with the previously selected value (if any) AssetImageSizeDropDownList1.SafeSelectValue(soi.AssetImageSizeId); // Get the filename to the image *if it exists already* string filename = AssetImageManager.GetResizedAssetImage(asset, AssetImageSizeDropDownList1.SelectedId, DownloadFormatDropDownList1.SelectedDownloadFormat, false); // Only set the filesize if the scaled image already exists, as it will be too heavy to create a scaled image // of each asset as the page loads. Maybe we should do this when assets are uploaded... if (filename != string.Empty) { ImageFileSizeMessageLabel.SetFileSize(FileUtils.GetFileSize(filename)); } } } // Only show file size row if download resolution row is hidden and user can download this asset // (No point showing them the filesize for an asset they can't download) if (ImageOptionsPlaceHolder.Visible) { FileSizeRow.Visible = false; } else { FileSizeRow.Visible = canDownload; FileSizeLabel.SetFileSize(asset.FileSize); } // Only show the conversation row if we have a conversation HtmlTableRow ConversationRow = (HtmlTableRow)e.Item.FindControl("ConversationRow"); ConversationRow.Visible = (orderItem.OrderItemCommentList.Count > 0); // Bind conversation Repeater ConversationRepeater = (Repeater)e.Item.FindControl("ConversationRepeater"); ConversationRepeater.DataSource = orderItem.OrderItemCommentList; ConversationRepeater.DataBind(); // Hide the row to add notes, as this is only visible whilst an order item is awaiting approval HtmlTableRow AddNotesRow = (HtmlTableRow)e.Item.FindControl("AddNotesRow"); AddNotesRow.Visible = false; if (assetStatus == AssetStatus.Available) { switch (orderItem.OrderItemStatus) { case (OrderItemStatus.Preapproved): OrderItemMessageLabel.SetSuccessMessage("no approval required", "Approval is not required to download and use this asset."); LinkButtonWrapper.Visible = false; break; case (OrderItemStatus.Approved): OrderItemMessageLabel.SetSuccessMessage("approved", "Approval to use this asset has been granted. Refer to the response given in the approval details for any further information."); LinkButtonWrapper.Visible = true; break; case (OrderItemStatus.AwaitingApproval): OrderItemMessageLabel.MessageType = BaseMessageLabel.MessageTypes.Pending; OrderItemMessageLabel.Header = "approval pending"; OrderItemMessageLabel.Text = "Approval to use this asset is pending a decision. An email will be sent to you when a decision is made."; LinkButtonWrapper.Visible = true; AddNotesRow.Visible = true; break; case (OrderItemStatus.Rejected): OrderItemMessageLabel.SetErrorMessage("approval rejected", "Approval to use this asset has been rejected. Refer to the response given in the approval notes for further information."); LinkButtonWrapper.Visible = true; break; } } else { OrderItemMessageLabel.MessageType = BaseMessageLabel.MessageTypes.Withdrawn; OrderItemMessageLabel.Header = "asset withdrawn"; OrderItemMessageLabel.Text = "This asset has been withdrawn from the system and is no longer available to download."; LinkButtonWrapper.Visible = false; } if (WebUtils.GetIntRequestParam("OrderItemId", 0) == orderItem.OrderItemId) { Panel ApprovalDetailsPanel = (Panel)e.Item.FindControl("ApprovalDetailsPanel"); ApprovalDetailsPanel.Visible = true; LinkButton ToggleApprovalDetailsLinkButton = (LinkButton)e.Item.FindControl("ToggleApprovalDetailsLinkButton"); ToggleApprovalDetailsLinkButton.Text = "hide approval details [-]"; } break; } }
protected void CopyDownloadSettingsToAllButton_Click(object sender, EventArgs e) { bool found = false; Button btn = (Button)sender; int sourceAssetId = 0; DownloadFormat downloadFormat = DownloadFormat.Original; int assetImageSizeId = 0; foreach (RepeaterItem ri in OrderItemsRepeater.Items) { if (!GeneralUtils.ValueIsInList(ri.ItemType, ListItemType.Item, ListItemType.AlternatingItem)) { continue; } Button CopyDownloadSettingsToAllButton = (Button)ri.FindControl("CopyDownloadSettingsToAllButton"); if (CopyDownloadSettingsToAllButton.UniqueID != btn.UniqueID) { continue; } HiddenField AssetIdHiddenField = (HiddenField)ri.FindControl("AssetIdHiddenField"); DownloadFormatDropDownList DownloadFormatDropDownList1 = (DownloadFormatDropDownList)ri.FindControl("DownloadFormatDropDownList1"); AssetImageSizeDropDownList AssetImageSizeDropDownList1 = (AssetImageSizeDropDownList)ri.FindControl("AssetImageSizeDropDownList1"); sourceAssetId = Convert.ToInt32(AssetIdHiddenField.Value); downloadFormat = DownloadFormatDropDownList1.SelectedDownloadFormat; assetImageSizeId = AssetImageSizeDropDownList1.SelectedId; found = true; break; } if (!found) { return; } AssetFinder finder = new AssetFinder(); finder.AssetIdList.Add(0); finder.AssetIdList.AddRange(CurrentOrder.OrderItemList.Select(o => o.AssetId)); List <Asset> assetList = Asset.FindMany(finder); Asset sourceAsset = assetList.Where(a => a.AssetId == sourceAssetId).FirstOrDefault() ?? Asset.Empty; Debug.Assert(!sourceAsset.IsNull); foreach (OrderItem oi in CurrentOrder.OrderItemList) { // Get the asset for the order item Asset asset = assetList.Where(a => a.AssetId == oi.AssetId).FirstOrDefault() ?? Asset.Empty; // Non-images do not have download options so ignore them if (!AssetTypeChecker.IsImage(asset.FileExtension)) { continue; } // Update the selection SelectedOrderItems.AddUpdate(oi.OrderItemId.GetValueOrDefault(), downloadFormat, assetImageSizeId); } // Rebind the list Bind(CurrentPage); FeedbackLabel1.SetSuccessMessage("Download options updated successfully"); }
private void ZipSelectedAssetsAndSend() { int?currentOrderId = CurrentOrder.OrderId; m_Logger.DebugFormat("User: {0} has selected assets to zip from order: {1}", CurrentUser.FullName, currentOrderId); // The folder where the zip file should be stored string sessionFolder = SessionHelper.GetForCurrentSession().CreateSessionTempFolder(); // Unique filename strings string dateString = DateTime.Now.ToString("yyyyMMddHHmmss"); string guid = GeneralUtils.GetGuid(); // The actual filename of the zip file on disk string outputFilename = string.Format("assets_from_order_{0}_{1}_{2}.zip", currentOrderId, dateString, guid); // The full path to the zip file on disk string outputPath = Path.Combine(sessionFolder, outputFilename); m_Logger.DebugFormat("Zip file will be stored in: {0}", outputPath); using (ZipOutputStream zos = new ZipOutputStream(File.Create(outputPath))) { try { zos.SetLevel(9); zos.SetComment(string.Format("Selected assets from order {0} on {1}", CurrentOrder.OrderId, CurrentOrder.OrderDate.ToString(Global.DateFormat))); foreach (OrderItem orderItem in CurrentOrder.OrderItemList) { if (Response.IsClientConnected && ShouldDownload(orderItem)) { // Get the asset Asset asset = orderItem.Asset; // Get the path to the asset file AssetFileInfo info = new AssetFileInfo(asset); // Get actual path string path = info.FilePath; // Check if a different image format is being requested if (AssetTypeChecker.IsImage(asset.FileExtension)) { SelectedOrderItem soi = SelectedOrderItems.Get(orderItem.OrderItemId.GetValueOrDefault()); path = AssetImageManager.GetResizedAssetImage(asset, soi.AssetImageSizeId, soi.DownloadFormat, true); } // Filename string filename = string.Concat(Path.GetFileNameWithoutExtension(asset.Filename), "_", asset.FileReference, (Path.GetExtension(path) ?? ".unknown").ToLower()); // Add the file to the generated zip AddFileToZipOutputStream(filename, path, zos); // Log this download for reporting AuditLogManager.LogAssetAction(asset, CurrentUser, AuditAssetAction.DownloadedAssetFile); AuditLogManager.LogUserAction(CurrentUser, AuditUserAction.DownloadAsset, string.Format("Downloaded AssetId: {0} as part of zipped download for OrderId: {1}", asset.AssetId, CurrentOrder.OrderId)); } } } finally { zos.Finish(); zos.Close(); } } string downloadUrl = string.Format("~/GetZipDownload.ashx?OrderId={0}&d={1}&guid={2}", currentOrderId, dateString, guid); Response.Redirect(downloadUrl); }