/source/Glimpse.MVC3/Plugin/Views.cs

https://github.com/adamflanagan/Glimpse
C# | 109 lines | 93 code | 16 blank | 0 comment | 12 complexity | f77d634c68f218ebfeb780b3ac21ce00 MD5 | raw file
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Web;
  4. using System.Web.Mvc;
  5. using Glimpse.Core;
  6. using Glimpse.Core.Extensibility;
  7. using Glimpse.Core.Extensions;
  8. using Glimpse.Mvc3.Plumbing;
  9. namespace Glimpse.Mvc3.Plugin
  10. {
  11. [GlimpsePlugin(ShouldSetupInInit = true)]
  12. internal class Views : IGlimpsePlugin, IProvideGlimpseHelp
  13. {
  14. public string Name
  15. {
  16. get { return "Views"; }
  17. }
  18. public object GetData(HttpContextBase context)
  19. {
  20. var store = context.Items;
  21. var data = store[GlimpseConstants.ViewEngine] as IList<GlimpseViewEngineCallMetadata>;
  22. if (data == null) return null;
  23. var result = new List<object[]>
  24. {
  25. new[]
  26. {
  27. "Ordinal", "Requested View", "Master Override", "Partial", "View Engine",
  28. "Check Cache", "Found", "Details"
  29. }
  30. };
  31. foreach (var callMetadata in data)
  32. {
  33. bool isFound = true;
  34. string viewEngineName = callMetadata.ViewEngineName;
  35. var locations = new List<object[]> {new[] {"Not Found In"}};
  36. if (callMetadata.ViewEngineResult.View == null)
  37. {
  38. isFound = false;
  39. if (callMetadata.UseCache)
  40. locations.Add(new object[] {"_" + viewEngineName + " cache_"});
  41. else
  42. locations.AddRange(
  43. callMetadata.ViewEngineResult.SearchedLocations.Select(location => new object[] {location}));
  44. result.Add(new object[]
  45. {
  46. result.Count, callMetadata.ViewName, callMetadata.MasterName,
  47. callMetadata.IsPartial.ToString(), viewEngineName,
  48. callMetadata.UseCache.ToString(), isFound.ToString(), locations
  49. });
  50. }
  51. else
  52. {
  53. object model = null;
  54. if (callMetadata.GlimpseView != null)
  55. {
  56. var viewContext = callMetadata.GlimpseView.ViewContext;
  57. object modelResult = null;
  58. var vd = viewContext.ViewData.Flatten();
  59. var td = viewContext.TempData.Flatten();
  60. var vm = viewContext.ViewData.Model;
  61. if (vm != null) modelResult = new {ModelType = vm.GetType().ToString(), Value = vm};
  62. model = new
  63. {
  64. ViewData = vd.Count > 0 ? vd : null,
  65. Model = vm != null ? modelResult : null,
  66. TempData = td.Count > 0 ? td : null,
  67. };
  68. }
  69. result.Add(new[]
  70. {
  71. result.Count, callMetadata.ViewName, callMetadata.MasterName,
  72. callMetadata.IsPartial.ToString(), viewEngineName,
  73. callMetadata.UseCache.ToString(), isFound.ToString(), model, "selected"
  74. });
  75. }
  76. }
  77. return result;
  78. }
  79. public void SetupInit()
  80. {
  81. var engines = ViewEngines.Engines;
  82. for (var i = 0; i < engines.Count; i++)
  83. {
  84. if (!(engines[i] is GlimpseViewEngine))
  85. engines[i] = new GlimpseViewEngine(engines[i]);
  86. }
  87. }
  88. public string HelpUrl
  89. {
  90. get { return "http://getGlimpse.com/Help/Plugin/Views"; }
  91. }
  92. }
  93. }