예제 #1
0
        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;
            }
        }
예제 #2
0
        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);
        }