PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/stable-1.1.0/Server/Handlers/HandlersCollection.cs

#
C# | 88 lines | 70 code | 10 blank | 8 comment | 8 complexity | 24bffcfe38e408532d2cf24ad87cdd3c MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //-----------------------------------------------------------------------
  2. // <copyright>
  3. // Copyright (C) Ruslan Yakushev for the PHP Manager for IIS project.
  4. //
  5. // This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
  6. // See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
  7. // </copyright>
  8. //-----------------------------------------------------------------------
  9. using System;
  10. using Microsoft.Web.Administration;
  11. namespace Web.Management.PHP.Handlers
  12. {
  13. internal class HandlersCollection : ConfigurationElementCollectionBase<HandlerElement>
  14. {
  15. public new HandlerElement this[string name]
  16. {
  17. get
  18. {
  19. for (int i = 0; (i < this.Count); i = (i + 1))
  20. {
  21. HandlerElement element = base[i];
  22. if ((string.Equals(element.Name, name, StringComparison.OrdinalIgnoreCase) == true))
  23. {
  24. return element;
  25. }
  26. }
  27. return null;
  28. }
  29. }
  30. public HandlerElement AddCopy(HandlerElement handler)
  31. {
  32. HandlerElement element = CreateElement();
  33. CopyAttributes(handler, element);
  34. return Add(element);
  35. }
  36. public HandlerElement AddCopyAt(int index, HandlerElement handler)
  37. {
  38. HandlerElement element = CreateElement();
  39. CopyAttributes(handler, element);
  40. return AddAt(index, element);
  41. }
  42. private static void CopyAttributes(ConfigurationElement source, ConfigurationElement destination)
  43. {
  44. foreach (ConfigurationAttribute attribute in source.Attributes)
  45. {
  46. if (!attribute.IsInheritedFromDefaultValue)
  47. {
  48. destination[attribute.Name] = attribute.Value;
  49. }
  50. }
  51. }
  52. public HandlerElement GetActiveHandler(string path)
  53. {
  54. for (int i = 0; i < Count; i++)
  55. {
  56. HandlerElement element = base[i];
  57. if (String.Equals(path, element.Path, StringComparison.OrdinalIgnoreCase))
  58. {
  59. return element;
  60. }
  61. }
  62. return null;
  63. }
  64. public HandlerElement GetHandler(string path, string scriptProcessor)
  65. {
  66. for (int i = 0; i < Count; i++)
  67. {
  68. HandlerElement element = base[i];
  69. if (String.Equals(path, element.Path, StringComparison.OrdinalIgnoreCase) &&
  70. String.Equals(scriptProcessor, element.ScriptProcessor, StringComparison.OrdinalIgnoreCase))
  71. {
  72. return element;
  73. }
  74. }
  75. return null;
  76. }
  77. }
  78. }