WebViewPageExtensions.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Web.Mvc;
  2. using System.IO;
  3. using System.Text;
  4. using System.Web;
  5. using BuildOurOwnBabylonJSServer.Controllers;
  6. using System;
  7. namespace BuildOurOwnBabylonJSServer.Extensions
  8. {
  9. public static class WebViewPageExtensions
  10. {
  11. public static string BabylonJSFile(this WebViewPage page,
  12. string relPathToBabylonJSFolder)
  13. {
  14. if (page == null)
  15. return null;
  16. // relPath must be the last one so filename can be appended to it
  17. var url = page.Url.Action(BuildOurOwnBabylonJSController.GetFileContentActionName,
  18. "BuildOurOwnBabylonJS",
  19. new { rootPath = page.ViewBag.BabylonJSFolder, relPath = relPathToBabylonJSFolder },
  20. page.Request.Url.Scheme);
  21. return url;
  22. }
  23. public static IHtmlString BabylonJSScript(this WebViewPage page,
  24. string relPathToBabylonJSFolder)
  25. {
  26. if (page == null)
  27. return null;
  28. var type = "text/javascript";
  29. var src = page.BabylonJSFile(relPathToBabylonJSFolder);
  30. var script = new TagBuilder("script");
  31. script.Attributes.Add("src", src);
  32. script.Attributes.Add("type", type);
  33. return page.Html.Raw(script.ToString(TagRenderMode.Normal));
  34. }
  35. public static string BabylonJSSamplesFile(this WebViewPage page,
  36. string relPathToBabylonJSSamplesFolder)
  37. {
  38. if (page == null)
  39. return null;
  40. var babylonJSSamplesDirFullPath = Environment.GetEnvironmentVariable("BabylonJSSamplesDirFullPath");
  41. // relPath must be the last one so filename can be appended to it
  42. var url = page.Url.Action(BuildOurOwnBabylonJSController.GetFileContentActionName,
  43. "BuildOurOwnBabylonJS",
  44. new { rootPath = babylonJSSamplesDirFullPath, relPath = relPathToBabylonJSSamplesFolder },
  45. page.Request.Url.Scheme);
  46. return url;
  47. }
  48. }
  49. }