public static HtmlString ResourceViewer(UrlHelper url, Resource resource, int width, int height, string resourceHandler, bool constrain, bool crop, bool preview) { if (resource != null) { if (IsExternalResource(resource)) { return ExternalResourceViewer(url, resource, width, height); } else { switch (resource.MimeType) { case "application/x-shockwave-flash": return FlashResourceViewer(url, width, height, resource, resourceHandler, preview); case "video/flv": case "video/x-flv": return VideoResourceViewer(url, width, height, resource, resourceHandler, preview); case "audio/basic": case "audio/mpeg": case "audio/mp3": case "audio/ogg": case "audio/x-wav": return AudioResourcePlayer(url, width, height, resource, resourceHandler, preview); case "audio/x-ms-wma": case "audio/x-ms-wmv": return MicrosoftAudioResourcePlayer(url, width, height, resource, resourceHandler, preview); case "image/x-png": case "image/png": case "image/jpeg": case "image/jpg": case "image/pjpeg": case "image/gif": case "image/bmp": string imageUrl = GetResourceUrl(resource, resourceHandler); string constrainParam = constrain ? "&Constrain=true" : ""; string cropParam = crop ? "&Crop=true" : ""; imageUrl = String.Format("{0}&Width={1}&Height={2}{3}{4}", imageUrl, width, height, constrainParam, cropParam); return new HtmlString(String.Format("<img src=\"{0}\" {1} {2} class=\"{3}\" alt=\"{4}\" title=\"{4}\" />", imageUrl, width == -1 || constrain ? "" : string.Format("width=\"{0}\"", width), height == -1 || constrain ? "" : string.Format("height=\"{0}\"", height), "Resource ImageViewer", resource.OriginalFileName)); default: return new HtmlString(String.Format("<a href=\"{0}\">{1}</a>", GetResourceUrl(resource, resourceHandler), resource.OriginalFileName)); } } } return new HtmlString(""); }
public static HtmlString ResourceViewer(UrlHelper url, Resource resource, int width, int height, bool constrain, bool crop) { return ResourceViewer(url, resource, width, height, url.Content("~/ResourceLoader.ashx"), constrain, crop); }
public static HtmlString ResourceViewer(UrlHelper url, Resource resource, int width, int height) { return ResourceViewer(url, resource, width, height, url.Content("~/ResourceLoader.ashx")); }
public static HtmlString ResourceViewer(UrlHelper url, Resource resource, string resourceHandler) { return ResourceViewer(url, resource, -1, -1, resourceHandler); }
public static HtmlString ResourceViewer(UrlHelper url, Resource resource) { return ResourceViewer(url, resource, -1, -1); }
private static HtmlString VideoResourceViewer(UrlHelper url, int width, int height, Resource resource, string resourceHandler, bool preview) { if (preview) { return new HtmlString(String.Format("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" title=\"{3}\"/>", url.Content("~/Content/images/video.png"), width, height, resource.OriginalFileName)); } string flvOptions = "{" + "clip: {" + "autoPlay: false," + "autoBuffering: true" + "}" + "}"; string format = "<a class=\"{4}\" id=\"player{0}\" style=\"display:block;width:{1}px;height:{2}px\" href=\"{3}\"></a>"+ "<script type=\"text/javascript\">" + " flowplayer(\"player{0}\", \"{5}\", {6});" + "</script>"; return new HtmlString(string.Format(format, resource.Id, width, height, GetResourceUrl(resource, resourceHandler), "Resource FlvViewer", url.Content("~/Scripts/flowplayer/flowplayer-3.2.8.swf"), flvOptions)); }
private static HtmlString AudioResourcePlayer(UrlHelper url, int width, int height, Resource resource, string resourceHandler, bool preview) { if (preview) { return new HtmlString(String.Format("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" title=\"{3}\" class=\"Resource Preview\"/>", url.Content("~/Content/images/audio.png"), width, height, resource.OriginalFileName)); } string format = "<div class=\"Resource MusicViewer\">" + "<object data=\"{0}\" width=\"250\" height=\"65\" name=\"dewplayer\" id=\"dewplayer\" type=\"application/x-shockwave-flash\">" + "<param name=\"movie\" value=\"{0}\" />" + "<param name=\"flashvars\" value=\"mp3={1}\" />" + "<param name=\"wmode\" value=\"transparent\" />" + "</object>" + "</div>"; return new HtmlString(string.Format(format, url.Content("~/Content/swf/dewplayer-bubble.swf"), url.Encode(GetResourceUrl(resource, resourceHandler)))); }
private static HtmlString MicrosoftAudioResourcePlayer(UrlHelper url, int width, int height, Resource resource, string resourceHandler, bool preview) { if (preview) { return new HtmlString(String.Format("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" title=\"{3}\" class=\"Resource Preview\"/>", url.Content("~/Content/images/audio.png"), width, height, resource.OriginalFileName)); } string format = "<div class=\"Resource MusicViewer\">" + "<object id=\"mediaplayer\" classid=\"clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701\" standby=\"loading microsoft windows media player components...\" type=\"application/x-oleobject\" width=\"320\" height=\"100\">" + "<param name=\"filename\" value=\"{0}\" />" + "<param name=\"animationatstart\" value=\"true\" />" + "<param name=\"transparentatstart\" value=\"true\" />" + "<param name=\"autostart\" value=\"true\" />" + "<param name=\"showcontrols\" value=\"true\" />" + "<param name=\"showStatusBar\" value=\"true\" />" + "<param name=\"windowlessvideo\" value=\"true\" />" + "<param name=\"wmode\" value=\"transparent\" />" + "<embed src=\"{0}\" autostart=\"true\" showcontrols=\"true\" showstatusbar=\"1\" bgcolor=\"white\" width=\"320\" height=\"100\" wmode=\"transparent\" />" + "</object>" + "</div>"; return new HtmlString(string.Format(format, url.Encode(GetResourceUrl(resource, resourceHandler)))); }
private static bool IsExternalResource(Resource resource) { return externalResourceRegex.IsMatch(resource.OriginalFileName); }
private static HtmlString MicrosoftAudioResourcePlayer(UrlHelper url, int width, int height, Resource resource, string resourceHandler) { return MicrosoftAudioResourcePlayer(url, width, height, resource, resourceHandler, false); }
private static string GetResourceUrl(Resource resource, string resourceHandler) { if (IsExternalResource(resource)) { return resource.OriginalFileName; } else { return String.Format("{0}?Id={1}&LastUpdated={2}", resourceHandler, resource.Id, resource.UpdatedTime.Ticks.ToString("x")); } }
private static HtmlString FlashResourceViewer(UrlHelper url, int width, int height, Resource resource, string resourceHandler, bool preview) { if (preview) { return new HtmlString(String.Format("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" title=\"{3}\"/>", url.Content("~/Content/images/flash.png"), width, height, resource.OriginalFileName)); } return new HtmlString(String.Format( "<div class=\"5\"><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"" + " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\"" + " width=\"{1}\" height=\"{2}\" id=\"{3}\">" + " <param name=\"movie\" value=\"{0}\">" + " <param name=\"quality\" value=\"high\">" + " <param name=\"bgcolor\" value=\"{4}\">" + " <param name=\"wmode\" value=\"transparent\">" + " <embed src=\"{0}\" quality=\"high\" bgcolor=\"{4}\" width=\"{1}\" height=\"{2}\"" + "name=\"{3}\" align=\"\" type=\"application/x-shockwave-flash\"" + "wmode=\"transparent\"" + "pluginspace=\"http://www.macromedia.com/go/getflashplayer\" />" + "</object></div>", GetResourceUrl(resource, resourceHandler), width, height, "flashResourceView" + resource.Id, "#ffffff", "Resource FlashViewer")); }
private static HtmlString ExternalResourceViewer(UrlHelper url, Resource resource, int width, int height) { //IExternalResourceRenderer renderer = ExternalResourceRendererRegistry.Lookup(resource.OriginalFileName); // Don't support external resource return new HtmlString(""); }
public static HtmlString ResourceViewer(UrlHelper url, Resource resource, int width, int height, string resourceHandler) { return ResourceViewer(url, resource, width, height, resourceHandler, false, false); }
public static string OriginalResourceUrl(UrlHelper url, Resource resource) { return GetResourceUrl(resource, url.Content("~/ResourceLoader.ashx")); }
public static HtmlString ResourceViewer(UrlHelper url, Resource resource, int width, int height, string resourceHandler, bool constrain, bool crop) { return ResourceViewer(url, resource, width, height, resourceHandler, constrain, crop, false); }
private static HtmlString VideoResourceViewer(UrlHelper url, int width, int height, Resource resource, string resourceHandler) { return VideoResourceViewer(url, width, height, resource, resourceHandler, false); }
public virtual void CopyTo(Resource dest) { if (dest != null) { dest.MimeType = this.MimeType; dest.OriginalFileName = this.OriginalFileName; dest.InputStream = new MemoryStream((int)this.InputStream.Length); long currentPos = this.InputStream.Position; byte[] buffer = new byte[32768]; while (true) { int read = this.InputStream.Read(buffer, 0, buffer.Length); if (read <= 0) break; dest.InputStream.Write(buffer, 0, read); } dest.InputStream.Position = 0; this.InputStream.Position = currentPos; } }
private int UpdateResource(Resource current, Resource updated) { if (current != null) { updated.CopyTo(current); resourceService.UpdateResource(current); } else { resourceService.CreateResource(updated); current = repository.GetById<Resource>(updated.Id); } return current.Id; }