コード例 #1
0
        public ProcessInboundRulesResult GetUrlResults(string url, Database database, NameValueCollection serverVariables = null)
        {
            var rewriter = new InboundRewriter();

            var rulesEngine  = new RulesEngine(database);
            var inboundRules = rulesEngine.GetInboundRules();

            var requestUri  = new Uri(url);
            var siteContext = SiteContextFactory.GetSiteContext(requestUri.Host, requestUri.AbsolutePath,
                                                                requestUri.Port);

            rewriter.RequestServerVariables = serverVariables ?? new NameValueCollection();

            if (!rewriter.RequestServerVariables.AllKeys.Contains("HTTP_HOST"))
            {
                rewriter.RequestServerVariables.Add("HTTP_HOST", requestUri.Host);
            }

            if (!rewriter.RequestServerVariables.AllKeys.Contains("HTTPS"))
            {
                rewriter.RequestServerVariables.Add("HTTPS", requestUri.Scheme.Equals(Uri.UriSchemeHttps) ? "on" : "off");
            }

            if (!rewriter.RequestServerVariables.AllKeys.Contains("QUERY_STRING") && requestUri.Query.Length > 0)
            {
                rewriter.RequestServerVariables.Add("QUERY_STRING", requestUri.Query.Remove(0, 1));
            }

            var results = rewriter.ProcessRequestUrl(requestUri, inboundRules, siteContext, database);

            return(results);
        }
コード例 #2
0
        public ProcessInboundRulesResult GetUrlResults(string url, Database database, NameValueCollection serverVariables = null)
        {
            var rewriter = new InboundRewriter();

            var rulesEngine = new RulesEngine(database);
            var inboundRules = rulesEngine.GetInboundRules();

            var requestUri = new Uri(url);
            var siteContext = SiteContextFactory.GetSiteContext(requestUri.Host, requestUri.AbsolutePath,
                requestUri.Port);

            rewriter.RequestServerVariables = serverVariables ?? new NameValueCollection();

            if (!rewriter.RequestServerVariables.AllKeys.Contains("HTTP_HOST"))
            {
                rewriter.RequestServerVariables.Add("HTTP_HOST", requestUri.Host);
            }

            if (!rewriter.RequestServerVariables.AllKeys.Contains("HTTPS"))
            {
                rewriter.RequestServerVariables.Add("HTTPS", requestUri.Scheme.Equals(Uri.UriSchemeHttps) ? "on" : "off");
            }

            if (!rewriter.RequestServerVariables.AllKeys.Contains("QUERY_STRING") && requestUri.Query.Length > 0)
            {
                rewriter.RequestServerVariables.Add("QUERY_STRING", requestUri.Query.Remove(0, 1));
            }

            var results = rewriter.ProcessRequestUrl(requestUri, inboundRules, siteContext, database);

            return results;
        }
コード例 #3
0
        public IEnumerable<RewriteReportGroup> GetRewriteReportsGrouped(Database database)
        {
            var rewriteReports = GetRewriteReports(database);
            var rulesEngine = new RulesEngine(database);
            var rewriteReportsGrouped = rewriteReports
                .GroupBy(report => new { DatabaseName = report.DatabaseName, RulePath = report.RulePath })
                .Select(group => new RewriteReportGroup
                {
                    Name = string.Format("{0}::{1}", group.Key.DatabaseName, group.Key.RulePath),
                    Rule = GetInboundRule(group.Key.DatabaseName, group.Key.RulePath),
                    Reports = group.ToList()
                });

            var all = rulesEngine
                    .GetInboundRules()
                    .Where(rule => !rewriteReportsGrouped.Any(group => group.Rule.ItemId.Equals(rule.ItemId)))
                    .Select(rule => new RewriteReportGroup {
                        Name = string.Format("{0}::{1}", database.Name, rule.GetRuleItem(database).Paths.FullPath),
                        Rule = rule,
                        Reports = new List<RewriteReport>()
                    });

            var finalGroup = rewriteReportsGrouped.Concat(all)
                .OrderByDescending(group => group.Count);

            return finalGroup;
        }