public void Exported(dynamic context)
        {
            if (!((IEnumerable <string>)context.ExportOptions.CustomSteps).Contains("Rules"))
            {
                return;
            }

            var allRules = _rulesServices.GetRules().ToList();

            if (!allRules.Any())
            {
                return;
            }

            var root = new XElement("Rules");

            context.Document.Element("Orchard").Add(root);

            foreach (var rule in allRules)
            {
                root.Add(new XElement("Rule",
                                      new XAttribute("Name", rule.Name),
                                      new XAttribute("Enabled", rule.Enabled.ToString(CultureInfo.InvariantCulture)),
                                      new XElement("Actions", rule.Actions.Select(action =>
                                                                                  new XElement("Action",
                                                                                               new XAttribute("Type", action.Type ?? string.Empty),
                                                                                               new XAttribute("Category", action.Category ?? string.Empty),
                                                                                               new XAttribute("Parameters", action.Parameters ?? string.Empty),
                                                                                               new XAttribute("Position", action.Position)
                                                                                               )
                                                                                  )),
                                      new XElement("Events", rule.Events.Select(e =>
                                                                                new XElement("Event",
                                                                                             new XAttribute("Type", e.Type ?? string.Empty),
                                                                                             new XAttribute("Category", e.Category ?? string.Empty),
                                                                                             new XAttribute("Parameters", e.Parameters ?? string.Empty)
                                                                                             )
                                                                                ))
                                      ));
            }
        }
        public override void Build(BuildContext context)
        {
            var allRules = _rulesServices.GetRules().ToList();

            if (!allRules.Any())
            {
                return;
            }

            var root = new XElement("Rules");

            context.RecipeDocument.Element("Orchard").Add(root);

            foreach (var rule in allRules)
            {
                root.Add(new XElement("Rule",
                                      new XAttribute("Name", rule.Name),
                                      new XAttribute("Enabled", rule.Enabled.ToString(CultureInfo.InvariantCulture)),
                                      new XElement("Actions", rule.Actions.Select(action =>
                                                                                  new XElement("Action",
                                                                                               new XAttribute("Type", action.Type ?? string.Empty),
                                                                                               new XAttribute("Category", action.Category ?? string.Empty),
                                                                                               new XAttribute("Parameters", action.Parameters ?? string.Empty),
                                                                                               new XAttribute("Position", action.Position)
                                                                                               )
                                                                                  )),
                                      new XElement("Events", rule.Events.Select(e =>
                                                                                new XElement("Event",
                                                                                             new XAttribute("Type", e.Type ?? string.Empty),
                                                                                             new XAttribute("Category", e.Category ?? string.Empty),
                                                                                             new XAttribute("Parameters", e.Parameters ?? string.Empty)
                                                                                             )
                                                                                ))
                                      ));
            }
        }
示例#3
0
        public ActionResult Index(RulesIndexOptions options, PagerParameters pagerParameters)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to list rules")))
            {
                return(new HttpUnauthorizedResult());
            }

            var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);

            // default options
            if (options == null)
            {
                options = new RulesIndexOptions();
            }

            var rules = _rulesServices.GetRules();

            switch (options.Filter)
            {
            case RulesFilter.Disabled:
                rules = rules.Where(r => r.Enabled == false);
                break;

            case RulesFilter.Enabled:
                rules = rules.Where(u => u.Enabled);
                break;
            }

            if (!String.IsNullOrWhiteSpace(options.Search))
            {
                rules = rules.Where(r => r.Name.Contains(options.Search));
            }

            var pagerShape = Shape.Pager(pager).TotalItemCount(rules.Count());

            switch (options.Order)
            {
            case RulesOrder.Name:
                rules = rules.OrderBy(u => u.Name);
                break;
            }

            var results = rules
                          .Skip(pager.GetStartIndex())
                          .Take(pager.PageSize)
                          .ToList();

            var model = new RulesIndexViewModel {
                Rules = results.Select(x => new RulesEntry {
                    Rule      = x,
                    IsChecked = false,
                    RuleId    = x.Id
                }).ToList(),
                Options = options,
                Pager   = pagerShape
            };

            // maintain previous route data when generating page links
            var routeData = new RouteData();

            routeData.Values.Add("Options.Filter", options.Filter);
            routeData.Values.Add("Options.Search", options.Search);
            routeData.Values.Add("Options.Order", options.Order);

            pagerShape.RouteData(routeData);

            return(View(model));
        }