public override int Run(string[] remainingArguments)
        {
            try
            {
                var redirects          = new List <Redirect>(FileHelper.ReadFile <Redirect>(Out, "redirects"));
                var optimizedRedirects = new List <Redirect>();

                foreach (Redirect r in redirects)
                {
                    var @from = RedirectHelper.NormalizeAndMakeCaseInsensitive(r.From);

                    if (!optimizedRedirects.Any(o => string.Equals(RedirectHelper.NormalizeFrom(o.From), RedirectHelper.NormalizeFrom(r.From), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        optimizedRedirects.Add(r);
                    }
                }

                FileHelper.WriteFile(Out, "redirects", optimizedRedirects.ToArray(), Overwrite);
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(-1);
            }
        }
        private IEnumerable <Redirect> GetRedirectForTagMappingRecursive(TagMapping tag)
        {
            foreach (string bloggerTag in tag.BloggerTag)
            {
                yield return(new Redirect
                {
                    From = RedirectHelper.NormalizeAndMakeCaseInsensitive("/search/label/" + bloggerTag),
                    To = string.IsNullOrWhiteSpace(tag.Slug) ? "/" : "/tag/" + tag.Slug
                });

                if (tag.ChildTags != null && tag.ChildTags.Any())
                {
                    foreach (var childTag in tag.ChildTags)
                    {
                        foreach (var redirect in GetRedirectForTagMappingRecursive(childTag))
                        {
                            yield return(redirect);
                        }
                    }
                }
            }
        }
        private void GenerateRedirects()
        {
            var redirects = _urlMappings.Where(url => url.FromUrl != url.ToUrl)
                            .Select(url =>
                                    new Redirect
            {
                From      = RedirectHelper.NormalizeAndMakeCaseInsensitive(new Uri(url.FromUrl).AbsolutePath),
                To        = "/" + url.ToUrl + "/",
                Permanent = RedirectPermanent
            }
                                    ).ToArray();

            var tagRedirect = _tagMappings.SelectMany(GetRedirectForTagMappingRecursive).Distinct().ToArray();

            var rssRedirect = new Redirect
            {
                From      = "^/feeds/posts/default$",
                To        = "/rss/",
                Permanent = false
            };

            var dateRedirect = new Redirect
            {
                From      = @"^/\d{4}/?(\d{2}/?)?$",
                To        = "/",
                Permanent = false
            };

            var indexRedirect = new Redirect
            {
                From      = @"^/index\.html$",
                To        = "/",
                Permanent = false
            };

            WriteFile("redirects", redirects.Concat(tagRedirect).Concat(new [] { rssRedirect, dateRedirect, indexRedirect }));
        }