<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Tags.Services;
using Orchard.Localization;
using Orchard.Tags.Models;
using System.Web.Routing;

namespace Orchard.Tags.Providers {
    public class TagPatterns {

        private readonly ITagService _tagService;

        public TagPatterns(
            ITagService tagService
            ) {
                _tagService = tagService;
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }
        
        public void Describe(dynamic describe) {
            describe.For<TagRecord>("Tags", T("Tags"), T("Tags url patterns"), (Func<TagRecord, string>)GetId, (Func<string, TagRecord>)GetTag)
                .Pattern("Tags", T("View all tags"), T("A list of all tags are displayed on this page"), (Func<TagRecord, RouteValueDictionary>)GetTagsRouteValues)
                .Pattern("View", T("View tagged content"), T("Tagged content will be listed on this Url for each tag"), (Func<TagRecord, RouteValueDictionary>)GetRouteValues);
        }

        protected RouteValueDictionary GetRouteValues(TagRecord tag) {
            return new RouteValueDictionary(new{
                area = "Orchard.Tags",
                controller = "Home",
                action = "Search",
                tagName = tag.TagName
            });
        }

        protected RouteValueDictionary GetTagsRouteValues(TagRecord tag) {
            return new RouteValueDictionary(new {
                area = "Orchard.Tags",
                controller = "Home",
                action = "Index"
            });
        }

        protected string GetId(TagRecord tag) {
            return tag.Id.ToString();
        }

        protected TagRecord GetTag(string id) {
            return _tagService.GetTag(Convert.ToInt32(id));
        }

        public void Suggest(dynamic suggest) {
            suggest.For("Tags")
                .Suggest("View", "tags/tag-name", "{Tag.Name.Slug}", T("Slugified tag name"))
                .Suggest("Tags", "tags", "tags", T("Plain /tags url"));
        }


    }
}<commit_msg>TagPatterns use event bus<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Tags.Services;
using Orchard.Localization;
using Orchard.Tags.Models;
using System.Web.Routing;
using Orchard.Events;

namespace Orchard.Tags.Providers {

    public interface IRoutePatternProvider : IEventHandler {
        void Describe(dynamic describe);
        void Suggest(dynamic suggest);
    }
    public class TagPatterns : IRoutePatternProvider {

        private readonly ITagService _tagService;

        public TagPatterns(
            ITagService tagService
            ) {
                _tagService = tagService;
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }
        
        public void Describe(dynamic describe) {
            describe.For<TagRecord>("Tags", T("Tags"), T("Tags url patterns"), (Func<TagRecord, string>)GetId, (Func<string, TagRecord>)GetTag)
                .Pattern("Tags", T("View all tags"), T("A list of all tags are displayed on this page"), (Func<TagRecord, RouteValueDictionary>)GetTagsRouteValues)
                .Pattern("View", T("View tagged content"), T("Tagged content will be listed on this Url for each tag"), (Func<TagRecord, RouteValueDictionary>)GetRouteValues);
        }

        public RouteValueDictionary GetRouteValues(TagRecord tag) {
            return new RouteValueDictionary(new{
                area = "Orchard.Tags",
                controller = "Home",
                action = "Search",
                tagName = tag.TagName
            });
        }

        public RouteValueDictionary GetTagsRouteValues(TagRecord tag) {
            return new RouteValueDictionary(new {
                area = "Orchard.Tags",
                controller = "Home",
                action = "Index"
            });
        }

        public string GetId(TagRecord tag) {
            return tag.Id.ToString();
        }

        public TagRecord GetTag(string id) {
            return _tagService.GetTag(Convert.ToInt32(id));
        }

        public void Suggest(dynamic suggest) {
            suggest.For("Tags")
                .Suggest("View", "tags/tag-name", "{Tag.Name.Slug}", T("Slugified tag name"))
                .Suggest("Tags", "tags", "tags", T("Plain /tags url"));
        }


    }
}
{'fraction_non_alphanumeric': 0.10660124888492417, 'fraction_numerical': 0.0008920606601248885, 'mean_word_length': 2.165137614678899, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2274725', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1148, 'n_words': 298}