PageRenderTime 31ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/Extensions/Settings.aspx.cs

#
C# | 56 lines | 45 code | 7 blank | 4 comment | 10 complexity | 8f4d65dd01655a72eefd71e120688244 MD5 | raw file
 1namespace Admin.Extensions
 2{
 3    using System;
 4    using System.Linq;
 5    using System.Collections.Generic;
 6    using BlogEngine.Core;
 7    using BlogEngine.Core.Web.Extensions;
 8
 9    public partial class Settings : System.Web.UI.Page
10    {
11        protected List<ManagedExtension> ExtensionList()
12        {
13            var extensions = ExtensionManager.Extensions.Where(x => x.Key != "MetaExtension").ToList();
14
15            if (!Blog.CurrentInstance.IsPrimary)
16                extensions = extensions.Where(x => x.Value.SubBlogEnabled == true).ToList();
17
18            extensions.Sort(
19                (e1, e2) => e1.Value.Priority == e2.Value.Priority ? string.CompareOrdinal(e1.Key, e2.Key) : e1.Value.Priority.CompareTo(e2.Value.Priority));
20
21            List<ManagedExtension> manExtensions = new List<ManagedExtension>();
22
23            foreach (KeyValuePair<string, ManagedExtension> ext in extensions)
24            {
25                var oExt = ExtensionManager.GetExtension(@ext.Key);
26                manExtensions.Add(oExt);
27            }
28            return manExtensions;
29        }
30        /// <summary>
31        /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event to initialize the page.
32        /// </summary>
33        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
34        protected override void OnInit(EventArgs e)
35        {
36            Security.DemandUserHasRight(Rights.AccessAdminPages, true);
37
38            var extname = Request.QueryString["ext"];
39            var extension = ExtensionList().Where(x => x.Name == extname).FirstOrDefault();
40
41            if (extension != null && extension.BlogSettings.Count > 0)
42            {
43                foreach (var s in extension.BlogSettings)
44                {
45                    if (!string.IsNullOrEmpty(s.Name) && !s.Hidden)
46                    {
47                        var uc = (UserControlSettings)Page.LoadControl("Settings.ascx");
48                        uc.ID = s.Name;
49                        ucPlaceHolder.Controls.Add(uc);
50                    }
51                }
52            }
53            base.OnInit(e);
54        }
55    }
56}