/2013_6_4__mobile_aspnet_mvc/MobileMVC/Global.asax.cs

https://github.com/Mallioch/Presentations · C# · 127 lines · 47 code · 17 blank · 63 comment · 0 complexity · 1e004ecb44bc9d9c4954684780d1a32b MD5 · raw file

  1. using System;
  2. using System.Web;
  3. using System.Web.Http;
  4. using System.Web.Mvc;
  5. using System.Web.Optimization;
  6. using System.Web.Routing;
  7. using System.Web.WebPages;
  8. using WURFL;
  9. using WURFL.Config;
  10. namespace MobileMVC
  11. {
  12. public class MvcApplication : System.Web.HttpApplication
  13. {
  14. private static IWURFLManager _wurflManager;
  15. protected void Application_Start()
  16. {
  17. AreaRegistration.RegisterAllAreas();
  18. WebApiConfig.Register(GlobalConfiguration.Configuration);
  19. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  20. RouteConfig.RegisterRoutes(RouteTable.Routes);
  21. #region WP8 Display Mode
  22. /*
  23. Func<HttpContextBase, bool> condition = (context) =>
  24. {
  25. return context.GetOverriddenUserAgent()
  26. .IndexOf("MSIE 10.0; Windows Phone 8.0", StringComparison.OrdinalIgnoreCase) >= 0;
  27. };
  28. var wp8DisplayMode = new DefaultDisplayMode("wp8");
  29. wp8DisplayMode.ContextCondition = condition;
  30. DisplayModeProvider.Instance.Modes.Insert(0, wp8DisplayMode);
  31. */
  32. #endregion
  33. #region Custom View Engine
  34. DisplayModeProvider.Instance.Modes.RemoveAt(0);
  35. ViewEngines.Engines.Clear();
  36. ViewEngines.Engines.Add(new CustomViewEngine());
  37. #endregion
  38. #region Setup Wurfl
  39. /*
  40. string wurflDataPath = Server.MapPath(@"~/App_Data/wurfl-latest.zip");
  41. var configurer = new InMemoryConfigurer().MainFile(wurflDataPath);
  42. _wurflManager = WURFLManagerBuilder.Build(configurer);
  43. #endregion
  44. #region Setup Wurfl-based Display Modes
  45. var superMode = new DefaultDisplayMode("super");
  46. superMode.ContextCondition = (context) =>
  47. {
  48. IDevice device = _wurflManager.GetDeviceForRequest(context.GetOverriddenUserAgent());
  49. string deviceOS = device.GetCapability("device_os").ToLower();
  50. string versionString = device.GetCapability("device_os_version");
  51. Version version = new Version();
  52. Version.TryParse(versionString, out version);
  53. bool isSupportedAndroid = deviceOS == "android" && version >= new Version("2.2");
  54. bool isSupportediOS = deviceOS == "ios" && version >= new Version("4.0");
  55. if (isSupportedAndroid || isSupportediOS)
  56. return true;
  57. else
  58. return false;
  59. };
  60. var basicMode = new DefaultDisplayMode("basic");
  61. basicMode.ContextCondition = (context) =>
  62. {
  63. IDevice device = _wurflManager.GetDeviceForRequest(context.GetOverriddenUserAgent());
  64. string deviceOS = device.GetCapability("device_os").ToLower();
  65. string versionString = device.GetCapability("device_os_version");
  66. Version version = new Version();
  67. Version.TryParse(versionString, out version);
  68. bool isSupportedAndroid = deviceOS == "android" && version < new Version("2.2");
  69. bool isSupportediOS = deviceOS == "ios" && version < new Version("4.0");
  70. if (isSupportedAndroid || isSupportediOS)
  71. return true;
  72. else
  73. return false;
  74. };
  75. DisplayModeProvider.Instance.Modes.Insert(0, basicMode);
  76. DisplayModeProvider.Instance.Modes.Insert(0, superMode);
  77. */
  78. #endregion
  79. #region System.Web.Optimization
  80. var css = new Bundle("~/content/allcss", new CssMinify());
  81. css.Include("~/content/minify/cssfile1.css",
  82. "~/content/minify/cssfile2.css",
  83. "~/content/minify/cssfile3.css");
  84. var js = new Bundle("~/content/alljs", new JsMinify());
  85. js.Include("~/content/minify/jsfile1.js",
  86. "~/content/minify/jsfile2.js",
  87. "~/content/minify/jsfile3.js",
  88. "~/content/minify/jquery.js",
  89. "~/content/minify/underscore.js",
  90. "~/content/minify/backbone.js");
  91. BundleTable.Bundles.Add(css);
  92. BundleTable.Bundles.Add(js);
  93. #endregion
  94. }
  95. }
  96. }