Ejemplo n.º 1
0
        public void OptionNames()
        {
            var s     = new AvatarOptions();
            var names = s.GetOptionNames();

            Assert.AreEqual(propertyNames.Count, names.Count);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="options">Generator options to use</param>
 public AvatarGenerator(AvatarOptions options)
 {
     // https://www.materialpalette.com
     if (options?.Palette is null || options.Palette.Count == 0)
     {
         _backgroundColours = new[] {
             new AvatarColor("f44336", "ffffff"), // red
             new AvatarColor("e91e63", "ffffff"), // pink
             new AvatarColor("9c27b0", "ffffff"), // purple
             new AvatarColor("673ab7", "ffffff"), // deep-purple
             new AvatarColor("3f51b5", "ffffff"), // indigo
             new AvatarColor("2196f3", "ffffff"), // blue
             new AvatarColor("03a9f4", "ffffff"), // light-blue
             new AvatarColor("00bcd4", "ffffff"), // cyan
             new AvatarColor("009688", "ffffff"), // teal
             new AvatarColor("4caf50", "ffffff"), // green
             new AvatarColor("8bc34a", "ffffff"), // light-green
             new AvatarColor("cddc39", "000000"), // lime
             new AvatarColor("ffeb3b", "000000"), // yellow
             new AvatarColor("ffc107", "000000"), // amber
             new AvatarColor("ff9800", "000000"), // orange
             new AvatarColor("ff5722", "ffffff"), // deep-orange
             new AvatarColor("795548", "ffffff"), // brown
             new AvatarColor("bdbdbd", "000000"), // grey
             new AvatarColor("607d8b", "ffffff"), // blue-grey
         };
     }
Ejemplo n.º 3
0
        /// <summary>
        /// Add the Avatar feature to MVC.
        /// </summary>
        /// <param name="mvcBuilder">An interface for configuring MVC services.</param>
        /// <param name="configureOptions">Action to configure the available options</param>
        public static IMvcBuilder AddAvatars(this IMvcBuilder mvcBuilder, Action <AvatarOptions> configureOptions)
        {
            var options = new AvatarOptions();

            configureOptions?.Invoke(options);
            mvcBuilder.ConfigureApplicationPartManager(apm => apm.FeatureProviders.Add(new AvatarFeatureProvider()));
            mvcBuilder.Services.AddResponseCaching();
            mvcBuilder.Services.AddSingleton(options);
            mvcBuilder.Services.AddSingleton(sp => new AvatarGenerator(options));
            return(mvcBuilder);
        }
Ejemplo n.º 4
0
        public void BackgroundColorUserCustom()
        {
            var propertyIndex = 0;
            var expectedValue = EnumHelpers.GetRandomValue <KnownColor>().ToString();

            var aa = new AvatarOptions {
                BackgroundColor = expectedValue
            };
            var so = PopulateOptions(aa);

            AssertPopulatedProperty(so, propertyIndex, expectedValue);
        }
Ejemplo n.º 5
0
        public void InitialsUserCustom()
        {
            var propertyIndex = 2;
            var expectedValue = "ABC";

            var src = new AvatarOptions {
                Initials = expectedValue
            };
            var so = PopulateOptions(src);

            AssertPopulatedProperty(so, propertyIndex, expectedValue);
        }
Ejemplo n.º 6
0
        public void ImageUserCustom()
        {
            var propertyIndex = 1;
            var expectedValue = "https://virtualworkfriendbotz7sw.blob.core.windows.net/images/BotInitials.png";

            var src = new AvatarOptions {
                Image = expectedValue
            };
            var so = PopulateOptions(src);

            AssertPopulatedProperty(so, propertyIndex, expectedValue);
        }
Ejemplo n.º 7
0
        private AvatarOptions GetAvatarOptions(int?width, int?height)
        {
            var options = new AvatarOptions();

            options.Size = new Size(width ?? 40, height ?? 40);

            var fontSize = (int)Math.Floor(Math.Min(options.Size.Width, options.Size.Height) / 2.8);

            options.Font = new Font("Arial", fontSize, FontStyle.Bold);

            return(options);
        }
Ejemplo n.º 8
0
        public void ImageUserDefault()
        {
            var    propertyIndex = 1;
            string expectedValue = null;
            var    src           = new AvatarOptions {
            };

            var so = PopulateOptions(src);

            AssertEmptyProperty(so, propertyIndex);

            so = PopulateOptions(src, true);
            AssertPopulatedProperty(so, propertyIndex, expectedValue);
        }
Ejemplo n.º 9
0
        public void BackgroundColorUserDefault()
        {
            var    propertyIndex = 0;
            string expectedValue = null;
            var    aa            = new AvatarOptions {
            };

            var so = PopulateOptions(aa);

            AssertEmptyProperty(so, propertyIndex);

            so = PopulateOptions(aa, true);
            AssertPopulatedProperty(so, propertyIndex, expectedValue);
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            // 1. simple case: email in, gravatar-style output
            var uri = AvatarUri.FromEmail("*****@*****.**");

            Console.WriteLine(uri);

            // 2. use a different hash
            var uri2 = AvatarUri.FromEmail("*****@*****.**",
                                           new AvatarOptions {
                UseSHA256 = true
            });

            Console.WriteLine(uri2);

            // 3. you can also use HTTPS
            var uri3 = AvatarUri.FromEmail("*****@*****.**",
                                           new AvatarOptions {
                PreferHttps = true
            });

            Console.WriteLine(uri3);

            // 4. AvatarOptions is just a normal C# object,
            // so you can create one for the options you
            // want, and store it / give it a name:
            var favoriteOptions = new AvatarOptions {
                UseSHA256 = true, PreferHttps = true
            };
            var uri4 = AvatarUri.FromEmail("*****@*****.**",
                                           favoriteOptions);

            Console.WriteLine(uri4);

            // 5. You can do monsters, wavatars, identicons, etc:
            var uri5 = AvatarUri.FromEmail("*****@*****.**",
                                           new AvatarOptions {
                DefaultImage = AvatarDefaultImages.MonsterID
            });

            Console.WriteLine(uri5);

            // 6. If you need a size other than the default, you can specify that:
            var uri6 = AvatarUri.FromEmail("*****@*****.**",
                                           new AvatarOptions {
                Size = 32
            });

            Console.WriteLine(uri6);
        }
Ejemplo n.º 11
0
 public ManageController(UserManager <TUser> userManager, SignInManager <TUser> signInManager,
                         IEmailSender emailSender, ILogger <ManageController <TUser, TKey> > logger,
                         IGenericControllerLocalizer <ManageController <TUser, TKey> > localizer, UrlEncoder urlEncoder,
                         ISmsSender smsSender, IOptions <SmsOptions> smsOptions, IOptions <AvatarOptions> avatarOptions)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _logger        = logger;
     _localizer     = localizer;
     _urlEncoder    = urlEncoder;
     _smsSender     = smsSender;
     _smsOptions    = smsOptions.Value;
     _avatarOptions = avatarOptions.Value;
 }
Ejemplo n.º 12
0
            static AvatarOptions PopulateAvatarOptions(Random r, bool isBot)
            {
                var ba = new AvatarOptions(isBot)
                {
                    BackgroundColor = EnumHelpers.GetRandomValue <KnownColor>().ToString()
                };

                switch (r.Next(1, 4))
                {
                case 1:
                    ba.Image = "https://sharecarebot-qa.azurewebsites.net/img/loup-sharecare.svg";
                    break;

                case 2:
                    ba.Image = "https://virtualworkfriendbotz7sw.blob.core.windows.net/images/BotInitials.png";
                    break;

                default:
                    ba.Initials = "ABC";
                    break;
                }
                return(ba);
            }