protected void SavePreviewButton_Click(object sender, EventArgs e) { BinaryFile file = new BinaryFile(PreviewFileUpload.PostedFile); if (file.IsEmpty) { FeedbackLabel1.SetErrorMessage("No file uploaded"); return; } bool feedbackSet = false; if (!m_AllowedPreviewExtensions.Contains(file.FileExtension)) { string acceptExtensions = string.Join(",", m_AllowedPreviewExtensions.ToArray()); if (m_ForcePreviewFormat) { //allow upload but display warning FeedbackLabel1.SetErrorMessage(String.Format("You have supplied a file with the extension {0}, but only files with {1} extensions are supported by this viewer. Your file may not display correctly.", file.FileExtension, acceptExtensions)); feedbackSet = true; } else { //prevent upload and display warning FeedbackLabel1.SetErrorMessage(String.Format("You have supplied a file with the extension {0}, but only files with {1} extensions are supported by this viewer. Please choose another.", file.FileExtension, acceptExtensions)); return; } } try { // Save the preview AssetFileManager.SaveAssetFile(Asset, file, AssetFileType.AssetPreview); // Mark asset as processed Asset.IsProcessed = true; Asset.Update(Asset); // Update preview AssetPreview1.Asset = Asset; // Update UI if (!feedbackSet) { FeedbackLabel1.SetSuccessMessage("Preview updated successfully"); } ConfigurePreviewSettings(); } catch (Exception ex) { ExceptionHandler.HandleException(ex, "Error saving preview"); FeedbackLabel1.SetErrorMessage("Error saving preview: " + ex.Message); } }
protected void SaveThumbnailButton_Click(object sender, EventArgs e) { BinaryFile file = new BinaryFile(ThumbnailFileUpload.PostedFile); if (file.IsEmpty) { FeedbackLabel1.SetErrorMessage("No file uploaded"); return; } if (!m_AllowedThumbnailExtensions.Contains(file.FileExtension)) { FeedbackLabel1.SetErrorMessage("Invalid file uploaded"); return; } try { // Save the thumbnail AssetFileManager.SaveAssetFile(Asset, file, AssetFileType.AssetThumbnail); // Mark asset as processed Asset.IsProcessed = true; Asset.Update(Asset); // Update thumbnail display AssetThumbnail1.Initialise(Asset); // Update UI FeedbackLabel1.SetSuccessMessage("Thumbnail updated successfully"); } catch (Exception ex) { FeedbackLabel1.SetErrorMessage("Error saving thumbnail: " + ex.Message); ExceptionHandler.HandleException(ex, "Error saving thumbnail"); } }
protected override void ProcessFiles() { if (!StringUtils.IsBlank(AdditionalData.AssetBitmapReference)) { Context.Response.Write("ERROR - Asset Bitmap Reference is not blank. Use BitmapProcessingCallbackHandler instead."); return; } if (Asset.IsProcessed) { Context.Response.Write("ERROR - Asset has already been processed"); return; } List <String> warningsList = new List <String>(); #if DEBUG // Save the returned metadata XML string metadataXmlPath = Path.GetTempFileName() + "_" + AssetId + ".xml"; File.WriteAllText(metadataXmlPath, MetadataXml); m_Logger.DebugFormat("Saved Metadata XML to: {0}", metadataXmlPath); #endif try { // Ensure we're saving valid metadata XML by trying to load it before saving XmlDocument doc = new XmlDocument(); doc.LoadXml(MetadataXml); // Save Asset metadata XML Asset.MetadataXml = MetadataXml; Asset.MetadataSearchVals = GetMetadataString(Asset.GetFileMetadata(true)); } catch (Exception ex) { Asset.MetadataXml = string.Empty; Asset.MetadataSearchVals = string.Empty; string error = string.Format("Error parsing metadata returned from APS for Asset: {0}. Error: {1}", AssetId, ex.Message); ExceptionHandler.HandleException(ex, error); warningsList.Add(error); } // Mark Asset as processed Asset.IsProcessed = true; // Save other FileDataItems (FDI) Asset.Height = WebUtils.GetIntRequestParam("FDI_Height", 0); Asset.Width = WebUtils.GetIntRequestParam("FDI_Width", 0); Asset.Duration = WebUtils.GetIntRequestParam("FDI_Duration", 0); // Update database Asset.Update(Asset); Asset.SaveAssetMetadata(Asset); m_Logger.Debug("Updated Asset data"); // Save preview if (StringUtils.IsBlank(PreviewPath)) { m_Logger.Debug("No preview file to save"); warningsList.Add("No preview file to save"); } else if (File.Exists(PreviewPath)) { try { AssetFileManager.SaveAssetFile(Asset, new BinaryFile(PreviewPath, BinaryFile.SaveMode.Move), AssetFileType.AssetPreview); m_Logger.Debug("Saved Asset preview file"); } catch (Exception ex) { string error = string.Format("Error saving preview file {0}. Error: {1}", PreviewPath, ex.Message); m_Logger.Warn(error, ex); warningsList.Add(error); } } else { string error = string.Format("Preview file supplied does not exist: {0}", PreviewPath); m_Logger.Warn(error); warningsList.Add(error); } // Save thumbnail if (StringUtils.IsBlank(ThumbnailPath)) { m_Logger.Warn("No thumbnail file to save"); warningsList.Add("No thumbnail file to save"); } else if (File.Exists(ThumbnailPath)) { try { AssetFileManager.SaveAssetFile(Asset, new BinaryFile(ThumbnailPath, BinaryFile.SaveMode.Move), AssetFileType.AssetThumbnail); m_Logger.Debug("Saved Asset thumbnail file"); } catch (Exception ex) { string error = string.Format("Error saving thumbnail file {0}. Error: {1}", ThumbnailPath, ex.Message); m_Logger.Warn(error, ex); warningsList.Add(error); } } else { string error = string.Format("Thumbnail file supplied does not exist: {0}", ThumbnailPath); m_Logger.Warn(error); warningsList.Add(error); } // Republish the Asset if (ExternalPublisher.Instance.IsPublished(AssetId)) { ExternalPublisher.Instance.Publish(AssetId); } // Notify uploader if required if (AdditionalData.Notify) { NotifyEngine.AssetProcessingComplete(Asset); } // All done WriteLine("OK"); WriteLine(Environment.NewLine); // Write some debug info WriteLine("Date: {0}", DateTime.Now); WriteLine("Server: {0}", Context.Server.MachineName); WriteLine("Notify: {0}", AdditionalData.Notify); WriteLine(Environment.NewLine); // Write warning count WriteLine("Warning Message Count: {0}", warningsList.Count); // Write warning messages if (warningsList.Count > 0) { WriteLine(Environment.NewLine); warningsList.ForEach(WriteLine); } }