Ejemplo n.º 1
0
        public static void AutoRegisterMemesByFile(MemeConfiguration memes, string[] filenames)
        {
            var usedAliases = new HashSet <string>();

            foreach (var filename in filenames.OrderBy(f => f))
            {
                var lowerFilename = filename.ToLowerInvariant();

                var name = Path.GetFileNameWithoutExtension(lowerFilename);

                if (name == null)
                {
                    throw new NullReferenceException("name cannot be null");
                }
                // strip off number prefix (used for ordering)
                name = name.Substring(lowerFilename.IndexOf("-", StringComparison.Ordinal) + 1);

                var extension = Path.GetExtension(lowerFilename);

                if (extension == null)
                {
                    throw new NullReferenceException("extension cannot be null");
                }
                extension = extension.Substring(1); // strip off the dot

                var aliases = new List <string>
                {
                    name.ToInitialism(),
                    NonWordStripCharacters.Replace(name, ""),
                };

                var memeName = name.ToTitleString();

                var filteredAliases =
                    aliases.Where(a => a.Length > 1) // don't use single character aliases
                    .Distinct()
                    .ToList();

                var survivingAliases = new List <string>();
                // Note: don't follow resharper's advice on this loop. It be cray cray
                foreach (var alias in filteredAliases)
                {
                    if (usedAliases.Add(alias))
                    {
                        survivingAliases.Add(alias);
                    }
                }

                // TODO: image/jpg isn't acutally valid. Fix this or get rid of it
                var imageType = "image/" + extension;

                memes.Add(new Meme(memeName, filename, survivingAliases, imageType));
            }
        }
Ejemplo n.º 2
0
 public void Init()
 {
     _MemeConfig = new MemeConfiguration();
     _MemeConfig.Add(new Meme("Success Kid", "", new[] { "sk", "successkid" }));
     _MemeConfig.Add(new Meme("I'll Have You Know", "", new[] { "ihyk", "illhaveyouknow" }));
     _MemeConfig.Add(new Meme("Foo", "", new[] { "f", "foo" }));
     _MemeConfig.Add(new Meme("All The Things", "", new[] { "att", "allthethings" }));
     _MemeConfig.Add(new Meme("Chubby Bubbles Girl", "", new[] { "cbg", "chubbybubblesgirl" }));
     _MemeConfig.Add(new Meme("Confession Bear", "", new[] { "cb", "confessionbear" }));
 }