WebViewPageExtensions.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 IHtmlString BabylonJSStyle(this WebViewPage page,
  36. string relPathToBabylonJSFolder)
  37. {
  38. if (page == null)
  39. return null;
  40. var type = "text/css";
  41. var src = page.BabylonJSFile(relPathToBabylonJSFolder);
  42. var script = new TagBuilder("link");
  43. script.Attributes.Add("href", src);
  44. script.Attributes.Add("type", type);
  45. script.Attributes.Add("rel", "stylesheet");
  46. return page.Html.Raw(script.ToString(TagRenderMode.Normal));
  47. }
  48. public static string BabylonJSSamplesFile(this WebViewPage page,
  49. string relPathToBabylonJSSamplesFolder)
  50. {
  51. if (page == null)
  52. return null;
  53. var babylonJSSamplesDirFullPath = Environment.GetEnvironmentVariable("BabylonJSSamplesDirFullPath");
  54. // relPath must be the last one so filename can be appended to it
  55. var url = page.Url.Action(BuildOurOwnBabylonJSController.GetFileContentActionName,
  56. "BuildOurOwnBabylonJS",
  57. new { rootPath = babylonJSSamplesDirFullPath, relPath = relPathToBabylonJSSamplesFolder },
  58. page.Request.Url.Scheme);
  59. return url;
  60. }
  61. public static string BabylonJSSamplesFolder(this WebViewPage page)
  62. {
  63. if (page == null)
  64. return null;
  65. var babylonJSSamplesDirFullPath = Environment.GetEnvironmentVariable("BabylonJSSamplesDirFullPath") + "\\Scenes";
  66. var url = page.Url.Action(BuildOurOwnBabylonJSController.GetBabylonScenesActionName,
  67. "BuildOurOwnBabylonJS",
  68. new { rootPath = babylonJSSamplesDirFullPath },
  69. page.Request.Url.Scheme);
  70. return url;
  71. }
  72. }
  73. }