/*
         * /// <summary>
         * /// Initializes a new instance of the <see cref="WebSiteControllerConfig"/> class.
         * /// </summary>
         * /// <param name="persisted"></param>
         * public WebSiteControllerConfig(SPWebApplication webApp)//
         *  : base(OBJECTNAME, webApp, ID)
         * {
         *  try
         *  {
         *      this.rules = new WebSiteControllerRulesCollection(this);
         *      this.modules = new WebSiteControllerModulesCollection(this);
         *  }
         *  catch (Exception ex)
         *  {
         *      ex.ToString();
         *  }
         * }
         */

        public WebSiteControllerConfig(SPPersistedObject persisted, Guid guid) : base(OBJECTNAME, persisted, guid)
        {
            try
            {
                this.rules   = new WebSiteControllerRulesCollection(this);
                this.modules = new WebSiteControllerModulesCollection(this);
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //ex.ToString();
            }
        }
        public static List <WebSiteControllerRule> GetRulesForPage(SPWebApplication Webapp, Uri url, string ruleType, SPUser user)
        {
            WebApp = Webapp;
            List <WebSiteControllerRule> list = new List <WebSiteControllerRule>();

            if (url == null)
            {
                return(list);
            }

            WebSiteControllerModulesCollection modules = GetFromConfigDB().modules;

            foreach (PersistedWebSiteControllerModule module in modules)
            {
                IWebSiteControllerModule imodule = GetModule(Webapp, module.Id);
                if (imodule.AlwaysRun)
                {
                    try
                    {
                        WebSiteControllerRule _rule = GetRule(imodule.RuleType);
                        if (_rule == null)
                        {
                            _rule = new WebSiteControllerRule();
                        }
                        //WebSiteControllerRule temp = new WebSiteControllerRule(SPContext.Current.Site.Url, url.ToString(), ruleType, String.Empty, WebSiteControllerPrincipalType.None, false, true, 0, _rule.Parent);
                        list.Add(_rule);
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                        //ex.ToString();
                    }
                }
            }

            WebSiteControllerRulesCollection rules = GetFromConfigDB().rules;

            foreach (WebSiteControllerRule rule in rules)
            {
                if (IsSinglePageControlled(rule, url, ruleType, user))
                {
                    list.Add(rule);
                }
            }

            list.Sort(WebSiteControllerRule.CompareBySequence);
            return(list);
        }