protected void DeletePreview_Click(object sender, EventArgs e) { AssetPreviewInfo info = new AssetPreviewInfo(Asset); if (info.FileExists) { try { File.Delete(info.FilePath); AssetPreview1.Asset = Asset; FeedbackLabel1.SetSuccessMessage("Preview deleted successfully"); ConfigurePreviewSettings(); PreviewExtensionLabel.Text = String.Empty; } catch (Exception ex) { ExceptionHandler.HandleException(ex, "Error deleting preview"); FeedbackLabel1.SetErrorMessage("Error deleting preview: " + ex.Message); } } else { FeedbackLabel1.SetErrorMessage("Preview file does not exist"); } }
public override void ProcessRequest() { int assetId = GetIdFromFilename(); Asset asset = Asset.Get(assetId); if (asset.IsNull) { throw new HttpException(500, "Asset does not exist"); } string filename = string.Empty; if (EntitySecurityManager.CanUserViewAssetPreview(SessionInfo.Current.User, asset)) { AssetPreviewInfo info = new AssetPreviewInfo(asset); filename = info.FilePath; } if (filename == string.Empty) { filename = (asset.IsProcessed) ? "Unavailable.gif" : "Processing.gif"; filename = Context.Server.MapPath("~/Images/Asset/Previews/" + filename); } WriteFileToResponseStream(filename); }
private void SetPreviewSettingsLabels() { if (IsSelectedPluginNonDefault()) { PluginStatusLabel.SetErrorMessage("User selected preview, this is not guaranteed to be compatible with this asset"); } else { PluginStatusLabel.SetSuccessMessage("Default Preview Plug-in for this file type"); } //preview file extension label AssetPreviewInfo info = new AssetPreviewInfo(Asset); string fileExtension = StringUtils.GetFileExtension(info.FilePath); PreviewExtensionLabel.Text = String.Format("Preview file type: {0}", fileExtension); //labels for accepted extensions string acceptExtensions = string.Join(",", m_AllowedPreviewExtensions.ToArray()); AcceptedPreviewFormatLabel.Text = String.Format("Accepted Preview File Formats: {0}", acceptExtensions); AcceptedPreviewFormatThumbnailLabel.Text = String.Format("Accepted Thumbnail File Formats: {0}", "JPEG"); }
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 override void Render(HtmlTextWriter writer) { if (Asset.IsNull) { // No asset WriteImage(writer, "~/Images/Asset/Previews/Unavailable.gif"); return; } if (!EntitySecurityManager.CanUserViewAssetPreview(SessionInfo.Current.User, Asset)) { // Access denied WriteImage(writer, "~/Images/Asset/Previews/Unavailable.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 fileExtension = StringUtils.GetFileExtension(info.FilePath); string assetPreviewUrl = AssetFileUrlHelper.GetPreviewUrl(Asset.AssetId); string relativePreviewUrl = ResolveUrl(assetPreviewUrl); string absolutePreviewUrl = 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 (fileExtension == "flv" && !StringUtils.IsBlank(rtmpStreamingServer)) { fileExtension += "-streaming"; } //gets the plugin to be tested Plugin plugin = ContextInfo.PluginManager.GetAnyPluginById(PluginId); if (!plugin.IsNull && plugin.HasPluginFile) { //ensure asset is of the right file type or force preview set if (!plugin.PluginFile.FileExtensions.Contains(fileExtension, StringComparer.OrdinalIgnoreCase) && !plugin.PluginFile.ForcePreviewFormat) { writer.Write(string.Format("[Plugin does not support file extension: {0}]", fileExtension)); return; } } else { writer.Write(string.Format("[Invalid plugin: {0}]", plugin.Name)); return; } //get the plugins relative URL string relativePluginUrl = ResolveUrl(plugin.RelativePath); // Get the HTML string markup = ContextInfo.PluginManager.GetMarkup(plugin, ContextType); // Otherwise, ensure we have markup if (string.IsNullOrEmpty(markup)) { writer.Write(string.Format("[Unable to preview asset: {0}]", Asset.AssetId)); return; } // Replace params markup = markup.Replace("[ASSET-PREVIEW-URL]", assetPreviewUrl); markup = markup.Replace("[RELATIVE-PREVIEW-URL]", relativePreviewUrl); markup = markup.Replace("[ABSOLUTE-PREVIEW-URL]", absolutePreviewUrl); 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]", fileExtension); 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("~/", WebUtils.GetApplicationPath()); // Write the HTML to the page writer.Write(markup); }