PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 88 lines | 70 code | 10 blank | 8 comment | 8 complexity | 24bffcfe38e408532d2cf24ad87cdd3c MD5 | raw file
 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
10using System;
11using Microsoft.Web.Administration;
12
13namespace Web.Management.PHP.Handlers
14{
15
16    internal class HandlersCollection : ConfigurationElementCollectionBase<HandlerElement>
17    {
18
19        public new HandlerElement this[string name]
20        {
21            get
22            {
23                for (int i = 0; (i < this.Count); i = (i + 1))
24                {
25                    HandlerElement element = base[i];
26                    if ((string.Equals(element.Name, name, StringComparison.OrdinalIgnoreCase) == true))
27                    {
28                        return element;
29                    }
30                }
31                return null;
32            }
33        }
34
35        public HandlerElement AddCopy(HandlerElement handler)
36        {
37            HandlerElement element = CreateElement();
38            CopyAttributes(handler, element);
39            return Add(element);
40        }
41
42        public HandlerElement AddCopyAt(int index, HandlerElement handler)
43        {
44            HandlerElement element = CreateElement();
45            CopyAttributes(handler, element);
46            return AddAt(index, element);
47        }
48
49        private static void CopyAttributes(ConfigurationElement source, ConfigurationElement destination)
50        {
51            foreach (ConfigurationAttribute attribute in source.Attributes)
52            {
53                if (!attribute.IsInheritedFromDefaultValue)
54                {
55                    destination[attribute.Name] = attribute.Value;
56                }
57            }
58        }
59
60        public HandlerElement GetActiveHandler(string path)
61        {
62            for (int i = 0; i < Count; i++)
63            {
64                HandlerElement element = base[i];
65                if (String.Equals(path, element.Path, StringComparison.OrdinalIgnoreCase))
66                {
67                    return element;
68                }
69            }
70            return null;
71        }
72
73        public HandlerElement GetHandler(string path, string scriptProcessor)
74        {
75            for (int i = 0; i < Count; i++)
76            {
77                HandlerElement element = base[i];
78                if (String.Equals(path, element.Path, StringComparison.OrdinalIgnoreCase) &&
79                    String.Equals(scriptProcessor, element.ScriptProcessor, StringComparison.OrdinalIgnoreCase))
80                {
81                            return element;
82                }
83            }
84            return null;
85        }
86
87    }
88}