Exemple #1
0
        public List<InboundRule> GetInboundRules()
        {
            if (db == null)
            {
                return null;
            }

            var redirectFolderItems = GetRedirectFolderItems();

            if (redirectFolderItems == null)
            {
                return null;
            }

            var inboundRules = new List<InboundRule>();

            foreach (var redirectFolderItem in redirectFolderItems)
            {
                Log.Debug(this, db, "Loading Inbound Rules from RedirectFolder: {0}", redirectFolderItem.Name);

                var folderDescendants = redirectFolderItem.Axes.GetDescendants()
                    .Where(x => x.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId)) ||
                                x.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId)));

                foreach (var descendantItem in folderDescendants)
                {
                    if (descendantItem.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId)))
                    {
                        var simpleRedirectItem = new SimpleRedirectItem(descendantItem);

                        Log.Debug(this, db, "Loading SimpleRedirect: {0}", simpleRedirectItem.Name);

                        var inboundRule = CreateInboundRuleFromSimpleRedirectItem(simpleRedirectItem, redirectFolderItem);

                        if (inboundRule != null && inboundRule.Enabled)
                        {
                            inboundRules.Add(inboundRule);
                        }
                    }
                    else if (descendantItem.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId)))
                    {
                        var inboundRuleItem = new InboundRuleItem(descendantItem);

                        Log.Debug(this, db, "Loading InboundRule: {0}", inboundRuleItem.Name);

                        var inboundRule = CreateInboundRuleFromInboundRuleItem(inboundRuleItem, redirectFolderItem);

                        if (inboundRule != null && inboundRule.Enabled)
                        {
                            inboundRules.Add(inboundRule);
                        }
                    }
                }
            }

            return inboundRules;
        }
Exemple #2
0
        public List<InboundRule> GetInboundRules()
        {
            if (db == null)
            {
                return null;
            }
            var urlRewriteFolderItemId = new ID("{0DA6100D-E4FB-4ADD-AD4C-373F410A1952}");
            var redirectFolderItem = db.GetItem(urlRewriteFolderItemId); //GetRedirectFolderItems();

            if (redirectFolderItem == null)
            {
               return null;
            }
           
            var inboundRules = new List<InboundRule>();

                Log.Info(this, db, "Loading Inbound Rules from RedirectFolder: {0}", redirectFolderItem.Name);

                var folderDescendants = redirectFolderItem.Axes.GetDescendants()
                    .Where(x => x.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId)) ||
                                x.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId)));

                foreach (var descendantItem in folderDescendants)
                {
                    if (descendantItem.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId)))
                    {
                        var simpleRedirectItem = new SimpleRedirectItem(descendantItem);

                        Log.Info(this, db, "Loading SimpleRedirect: {0}", simpleRedirectItem.Name);

                        var inboundRule = CreateInboundRuleFromSimpleRedirectItem(simpleRedirectItem, redirectFolderItem);

                        if (inboundRule != null && inboundRule.Enabled)
                        {
                            inboundRules.Add(inboundRule);
                        }
                    }
                    else if (descendantItem.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId)))
                    {
                        var inboundRuleItem = new InboundRuleItem(descendantItem);

                        Log.Info(this, db, "Loading InboundRule: {0}", inboundRuleItem.Name);

                        var inboundRule = CreateInboundRuleFromInboundRuleItem(inboundRuleItem, redirectFolderItem);

                        if (inboundRule != null && inboundRule.Enabled)
                        {
                            inboundRules.Add(inboundRule);
                        }
                    }
                }

            return inboundRules;
        }
Exemple #3
0
        internal InboundRule CreateInboundRuleFromInboundRuleItem(InboundRuleItem inboundRuleItem, RedirectFolderItem redirectFolderItem)
        {
            var siteNameRestriction = GetSiteNameRestriction(redirectFolderItem);
            var inboundRule = inboundRuleItem.ToInboundRule(siteNameRestriction);

            return inboundRule;
        }
        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);
            }

        }