PageRenderTime 62ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/CmsData/QueryBuilder/CategoryClass.cs

https://github.com/vs06/bvcms
C# | 80 lines | 72 code | 2 blank | 6 comment | 6 complexity | 870392cab12f4d9979e043f56bfcf77b MD5 | raw file
  1. /* Author: David Carroll
  2. * Copyright (c) 2008, 2009 Bellevue Baptist Church
  3. * Licensed under the GNU General Public License (GPL v2)
  4. * you may not use this code except in compliance with the License.
  5. * You may obtain a copy of the License at http://bvcms.codeplex.com/license
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Web;
  13. using System.Xml.Linq;
  14. using Community.CsharpSqlite;
  15. using IronPython.Modules;
  16. using UtilityExtensions;
  17. using System.Web.Caching;
  18. namespace CmsData
  19. {
  20. public class CategoryClass
  21. {
  22. public string Title { get; set; }
  23. public string Name
  24. {
  25. get
  26. {
  27. return Title.Replace(" ", "");
  28. }
  29. }
  30. public IEnumerable<FieldClass> Fields { get; set; }
  31. public static List<CategoryClass> Categories
  32. {
  33. get
  34. {
  35. var categories = (List<CategoryClass>)HttpRuntime.Cache["FieldCategories"];
  36. if (categories == null)
  37. {
  38. var xdoc = XDocument.Parse(Properties.Resources.FieldMap2);
  39. var q = from c in xdoc.Descendants("Category")
  40. select new CategoryClass
  41. {
  42. Title = c.Attribute("Title").Value,
  43. Fields = from f in c.Descendants("Field")
  44. select new FieldClass
  45. {
  46. CategoryTitle = (string)c.Attribute("Title").Value,
  47. Name = (string)f.Attribute("Name"),
  48. Title = (string)f.Attribute("Title"),
  49. QuartersTitle = (string)f.Attribute("QuartersLabel"),
  50. DisplayAs = (string)f.Attribute("DisplayAs"),
  51. Type = FieldClass.Convert((string)f.Attribute("Type")),
  52. Params = (string)f.Attribute("Params"),
  53. DataSource = (string)f.Attribute("DataSource"),
  54. DataValueField = (string)f.Attribute("DataValueField"),
  55. Description = f.Value,
  56. }
  57. };
  58. categories = q.ToList();
  59. HttpRuntime.Cache.Insert("FieldCategories", categories, null,
  60. DateTime.Now.AddMinutes(10), Cache.NoSlidingExpiration);
  61. #if DEBUG2
  62. foreach(var e in Enum.GetValues(typeof(QueryType)).Cast<QueryType>())
  63. if(!categories.Any(cc => cc.Fields.Any(ff => ff.Name == e.ToString())))
  64. Debug.WriteLine(e.ToString());
  65. #endif
  66. }
  67. return categories;
  68. }
  69. }
  70. private static string Attr(XElement e, string name)
  71. {
  72. var a = e.Attribute(name);
  73. if (a != null)
  74. return a.Value;
  75. return null;
  76. }
  77. }
  78. }