public void Process(PipelineArgs args)
        {
            Log.Info(this, "Initializing URL Rewrite.");

            try
            {
                using (new SecurityDisabler())
                {

                    // cache all of the rules

                    foreach (var db in Factory.GetDatabases().Where(e => e.HasContentItem))
                    {
                        var rulesEngine = new RulesEngine(db);
                        rulesEngine.GetCachedInboundRules();
                    }

                    // make sure that the page event has been deployed
                    DeployEventIfNecessary();
                }
            }
            catch (Exception ex)
            {
                Hi.UrlRewrite.Log.Error(this, ex, "Exception during initialization.");
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
        public void Process(PipelineArgs args)
        {
            Log.Info(this, "Initializing URL Rewrite.");

            using (new SecurityDisabler())
            {
                foreach (var db in Factory.GetDatabases().Where(e => e.HasContentItem))
                {
                    var rulesEngine = new RulesEngine(db);
                    rulesEngine.GetCachedInboundRules();
                }
            }
        }
        private List<OutboundRule> GetOutboundRules(Database db)
        {
            var cache = RulesCacheManager.GetCache(db);
            var outboundRules = cache.GetOutboundRules();

            if (outboundRules != null) return outboundRules;

            Log.Info(this, db, "Initializing Outbound Rules.");

            using (new SecurityDisabler())
            {
                var rulesEngine = new RulesEngine(db);
                outboundRules = rulesEngine.GetCachedOutboundRules();
            }

            return outboundRules;
        }
        private List<InboundRule> GetInboundRules(Database db)
        {
            var cache = RulesCacheManager.GetCache(db);
            var inboundRules = cache.GetInboundRules();

            if (inboundRules != null) return inboundRules;

            Log.Info(this, db, "Initializing Inbound Rules.");

            using (new SecurityDisabler())
            {
                var rulesEngine = new RulesEngine(db);
                var setup = new Setup();
                setup.InstallItems();
                inboundRules = rulesEngine.GetCachedInboundRules();
            }

            return inboundRules;
        }
Exemplo n.º 7
0
        private List <InboundRule> GetInboundRules(Database db)
        {
            var cache        = RulesCacheManager.GetCache(db);
            var inboundRules = cache.GetInboundRules();

            if (inboundRules != null)
            {
                return(inboundRules);
            }

            Log.Info(this, db, "Initializing Inbound Rules.");

            using (new SecurityDisabler())
            {
                var rulesEngine = new RulesEngine(db);
                inboundRules = rulesEngine.GetCachedInboundRules();
            }

            return(inboundRules);
        }
Exemplo n.º 8
0
        private void RunItemDeleted(Item item, ID formerParentId)
        {
            var rulesEngine = new RulesEngine(item.Database);

            try
            {
                using (new SecurityDisabler())
                {
                    if (item.IsInboundRuleItem() || item.IsSimpleRedirectItem())
                    {
                        Log.Info(this, item.Database, "Clearing inbound rules cache after delete event");

                        rulesEngine.DeleteRule(item, null);
                        //rulesEngine.ClearInboundRuleCache();
                    }
                    else if (item.IsInboundRuleItemChild(formerParentId))
                    {
                        Item itemParent = item.Parent;
                        if (itemParent == null && formerParentId != (ID)null)
                        {
                            itemParent = item.Database.GetItem(formerParentId);
                        }
                        Log.Info(this, item.Database, "Updating parent inbound rule ({0}) after child delete event", itemParent.Paths.Path);

                        rulesEngine.RefreshRule(itemParent, GetRedirectFolderItem(itemParent));
                    }
                    else if (item.IsOutboundRuleItem() || item.IsOutboundRuleItemChild())
                    {
                        Log.Info(this, item.Database, "Clearing outbound rules cache after delete event",
                                 item.Parent.Paths.FullPath);

                        rulesEngine.ClearOutboundRuleCache();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(this, ex, item.Database, "Exception occured which deleting item after publish Item ID: {0} Item Path: {1}", item.ID, item.Paths.FullPath);
            }
        }
        private void RunItemDeleted(Item item)
        {
            var rulesEngine = new RulesEngine(item.Database);

            try
            {

                using (new SecurityDisabler())
                {

                    var redirectFolderItem = item.Axes.GetAncestors()
                        .FirstOrDefault(a => a.TemplateID.Equals(new ID(RedirectFolderItem.TemplateId)));

                    if (redirectFolderItem != null)
                    {
                        if (item.IsInboundRuleItem() || item.IsSimpleRedirectItem() || item.IsOutboundRuleItem())
                        {
                            Log.Info(this, item.Database, "Removing Rule [{0}] after delete event",
                                item.Paths.FullPath);

                            rulesEngine.DeleteRule(item, redirectFolderItem);
                        }
                        else if (item.IsInboundRuleItemChild() || item.IsOutboundRuleItemChild())
                        {
                            Log.Info(this, item.Database, "Removing Rule [{0}] after delete event",
                                item.Parent.Paths.FullPath);

                            rulesEngine.RefreshRule(item.Parent, redirectFolderItem);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(this, ex, item.Database, "Exception occured which deleting item after publish Item ID: {0} Item Path: {1}", item.ID, item.Paths.FullPath);
            }
        }
        private void RunItemSaved(Item item, ItemChanges itemChanges)
        {
            var db          = item.Database;
            var rulesEngine = new RulesEngine(db);

            try
            {
                using (new SecurityDisabler())
                {
                    var redirectFolderItem = item.Axes.GetAncestors()
                                             .FirstOrDefault(a => a.TemplateID.Equals(new ID(RedirectFolderItem.TemplateId)));

                    if (redirectFolderItem == null)
                    {
                        return;
                    }

                    if (item.IsRedirectFolderItem())
                    {
                        Log.Info(this, db, "Refreshing Redirect Folder [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.GetCachedInboundRules();
                    }
                    else if (item.IsOutboundRuleItem())
                    {
                        Log.Info(this, db, "Refreshing Outbound Rule [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.RefreshRule(item, redirectFolderItem);
                    }
                    else if (item.IsSimpleRedirectItem())
                    {
                        Log.Info(this, db, "Refreshing Simple Redirect [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.RefreshRule(item, redirectFolderItem);
                    }
                    else if (item.IsInboundRuleItem())
                    {
                        Log.Info(this, db, "Refreshing Inbound Rule [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.RefreshRule(item, redirectFolderItem);
                    }
                    else if (item.IsRedirectType() && item.IsInboundRuleItemChild() && db.Name.Equals("web", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var inboundRuleItem = item.Parent;
                        var inboundRule     = new InboundRuleItem(inboundRuleItem);

                        inboundRule.BeginEdit();
                        inboundRule.Action.InnerField.SetValue(item.ID.ToString(), false);
                        inboundRule.EndEdit();
                    }
                    else if (item.IsInboundRuleItemChild())
                    {
                        Log.Info(this, db, "Refreshing Inbound Rule [{0}] after save event", item.Parent.Paths.FullPath);

                        rulesEngine.RefreshRule(item.Parent, redirectFolderItem);
                    }
                    else if (item.IsOutboundRuleItemChild())
                    {
                        Log.Info(this, db, "Refreshing Outbound Rule [{0}] after save event", item.Parent.Paths.FullPath);

                        rulesEngine.RefreshRule(item.Parent, redirectFolderItem);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(this, ex, db, "Exception occured when saving item after save - Item ID: {0} Item Path: {1}", item.ID, item.Paths.FullPath);
            }
        }
        private void RunItemSaved(Item item, ItemChanges itemChanges)
        {
            var db = item.Database;
            var rulesEngine = new RulesEngine(db);

            try
            {
                using (new SecurityDisabler())
                {
                    var redirectFolderItem = item.Axes.GetAncestors()
                        .FirstOrDefault(a => a.TemplateID.Equals(new ID(RedirectFolderItem.TemplateId)));

                    if (redirectFolderItem == null) return;

                    if (item.IsRedirectFolderItem())
                    {
                        Log.Info(this, db, "Refreshing Redirect Folder [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.GetCachedInboundRules();
                    }
                    else if (item.IsOutboundRuleItem())
                    {
                        Log.Info(this, db, "Refreshing Outbound Rule [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.RefreshRule(item, redirectFolderItem);
                    }
                    else if (item.IsSimpleRedirectItem())
                    {
                        Log.Info(this, db, "Refreshing Simple Redirect [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.RefreshRule(item, redirectFolderItem);
                    }
                    else if (item.IsInboundRuleItem())
                    {
                        Log.Info(this, db, "Refreshing Inbound Rule [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.RefreshRule(item, redirectFolderItem);
                    }
                    else if (item.IsRedirectType() && item.IsInboundRuleItemChild() && db.Name.Equals("master", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var inboundRuleItem = item.Parent;
                        var inboundRule = new InboundRuleItem(inboundRuleItem);

                        inboundRule.BeginEdit();
                        inboundRule.Action.InnerField.SetValue(item.ID.ToString(), false);
                        inboundRule.EndEdit();
                    }
                    else if (item.IsInboundRuleItemChild())
                    {
                        Log.Info(this, db, "Refreshing Inbound Rule [{0}] after save event", item.Parent.Paths.FullPath);

                        rulesEngine.RefreshRule(item.Parent, redirectFolderItem);
                    }
                    else if (item.IsOutboundRuleItemChild())
                    {
                        Log.Info(this, db, "Refreshing Outbound Rule [{0}] after save event", item.Parent.Paths.FullPath);

                        rulesEngine.RefreshRule(item.Parent, redirectFolderItem);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(this, ex, db, "Exception occured when saving item after save - Item ID: {0} Item Path: {1}", item.ID, item.Paths.FullPath);
            }

        }
        private void RunItemDeleted(Item item)
        {

            var rulesEngine = new RulesEngine(item.Database);

            try
            {

                using (new SecurityDisabler())
                {

                    if (item.IsInboundRuleItem() || item.IsSimpleRedirectItem() || item.IsInboundRuleItemChild())
                    {
                        Log.Info(this, item.Database, "Refreshing inbound rules cache after delete event",
                            item.Paths.FullPath);

                        rulesEngine.GetCachedInboundRules();
                    }
                    else if (item.IsOutboundRuleItem() || item.IsOutboundRuleItemChild())
                    {
                        Log.Info(this, item.Database, "Refreshing outbound rules cache after delete event",
                            item.Parent.Paths.FullPath);

                        rulesEngine.GetCachedOutboundRules();
                    }

                }
            }
            catch (Exception ex)
            {
                Log.Error(this, ex, item.Database, "Exception occured which deleting item after publish Item ID: {0} Item Path: {1}", item.ID, item.Paths.FullPath);
            }
        }
Exemplo n.º 13
0
        private List<InboundRule> GetInboundRules(Database db)
        {
            Log.Info(this, db, "Start GetInboundRules.");
            var cache = RulesCacheManager.GetCache(db);
            var inboundRules = cache.GetInboundRules();
            Log.Info(this, db, "Stop GetInboundRules.");
            if (inboundRules != null)
            {
                Log.Info(this, db, "inboundRules!=null");
                Log.Info(this, db, "inboundRules.Any()=={0}", inboundRules.Any());
                if (inboundRules.Any())
                {
                    Log.Info(this, db, "inboundRules.Count()=={0}", inboundRules.Count);
                }
                return inboundRules;
            }
            else
            {
                Log.Info(this, db, "inboundRules==null");
            }

            Log.Info(this, db, "Initializing Inbound Rules.");

            using (new SecurityDisabler())
            {
                var rulesEngine = new RulesEngine(db);
                inboundRules = rulesEngine.GetCachedInboundRules();
            }

            return inboundRules;
        }
        private void RunItemSaved(Item item, ItemChanges itemChanges)
        {
            var db          = item.Database;
            var rulesEngine = new RulesEngine(db);

            try
            {
                using (new SecurityDisabler())
                {
                    var redirectFolderItem = GetRedirectFolderItem(item);

                    if (redirectFolderItem == null)
                    {
                        return;
                    }

                    if (item.IsRedirectFolderItem())
                    {
                        Log.Info(this, db, "Clearing cached inbound rules (reason: Redirect Folder [{0}] saves)",
                                 item.Paths.FullPath);

                        rulesEngine.ClearInboundRuleCache();
                    }
                    else if (item.IsOutboundRuleItem())
                    {
                        Log.Info(this, db, "Refreshing Outbound Rule [{0}] after save event", item.Paths.FullPath);

                        rulesEngine.RefreshRule(item, redirectFolderItem);
                    }
                    else if (item.IsSimpleRedirectItem())
                    {
                        if (rulesEngine.CanRefreshInboundRule(item, redirectFolderItem))
                        {
                            Log.Info(this, db, "Refreshing Simple Redirect [{0}] after save event", item.Paths.FullPath);

                            rulesEngine.RefreshRule(item, redirectFolderItem);
                        }
                        else
                        {
                            Log.Info(this, db,
                                     "Simple Redirect [{0}] cannot be individually refreshed after save event. Clearing inbound rule cache.",
                                     item.Paths.FullPath);

                            rulesEngine.ClearInboundRuleCache();
                            ;
                        }
                    }
                    else if (item.IsInboundRuleItem())
                    {
                        if (rulesEngine.CanRefreshInboundRule(item, redirectFolderItem))
                        {
                            Log.Info(this, db, "Refreshing Inbound Rule [{0}] after save event", item.Paths.FullPath);

                            rulesEngine.RefreshRule(item, redirectFolderItem);
                        }
                        else
                        {
                            Log.Info(this, db,
                                     "Inbound Rule [{0}] cannot be individually refreshed after save event. Clearing inbound rule cache.",
                                     item.Paths.FullPath);

                            rulesEngine.ClearInboundRuleCache();
                        }
                    }
                    else if (item.IsRedirectType() && item.IsInboundRuleItemChild() &&
                             db.Name.Equals("master", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var inboundRuleItem = item.Parent;
                        var inboundRule     = new InboundRuleItem(inboundRuleItem);

                        inboundRule.BeginEdit();
                        inboundRule.Action.InnerField.SetValue(item.ID.ToString(), false);
                        inboundRule.EndEdit();
                    }
                    else if (item.IsInboundRuleItemChild())
                    {
                        if (rulesEngine.CanRefreshInboundRule(item.Parent, redirectFolderItem))
                        {
                            Log.Info(this, db, "Refreshing Inbound Rule [{0}] after save event", item.Parent.Paths.FullPath);

                            rulesEngine.RefreshRule(item.Parent, redirectFolderItem);
                        }
                        else
                        {
                            Log.Info(this, db,
                                     "Inbound Rule [{0}] cannot be individually refreshed after save event. Clearing inbound rule cache.",
                                     item.Parent.Paths.FullPath);

                            rulesEngine.ClearInboundRuleCache();
                        }
                    }
                    else if (item.IsOutboundRuleItemChild())
                    {
                        Log.Info(this, db, "Refreshing Outbound Rule [{0}] after save event", item.Parent.Paths.FullPath);

                        rulesEngine.RefreshRule(item.Parent, redirectFolderItem);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(this, ex, db, "Exception occured when saving item after save - Item ID: {0} Item Path: {1}", item.ID,
                          item.Paths.FullPath);
            }
        }
Exemplo n.º 15
0
        private InboundRule GetInboundRule(string reportDatabaseName, string rewriteReportItemPath)
        {
            var reportDatabase = Database.GetDatabase(reportDatabaseName);
            var rulesEngine = new RulesEngine(reportDatabase);
            var rewriteReportItem = reportDatabase.GetItem(rewriteReportItemPath);
            var redirectFolderItem = rewriteReportItem.Axes.GetAncestors()
                .FirstOrDefault(a => a.TemplateID.Equals(new ID(RedirectFolderItem.TemplateId)));

            InboundRule rule;

            if (rewriteReportItem.TemplateID.Equals(new ID(SimpleRedirectItem.TemplateId)))
            {
                rule = rulesEngine.CreateInboundRuleFromSimpleRedirectItem(rewriteReportItem, redirectFolderItem);
            }
            else if (rewriteReportItem.TemplateID.Equals(new ID(InboundRuleItem.TemplateId)))
            {
                rule = rulesEngine.CreateInboundRuleFromInboundRuleItem(rewriteReportItem, redirectFolderItem);
            }
            else
            {
                return null;
            }

            return rule;
        }