Exemplo n.º 1
0
        private static void CreateAdminUser(UserManager <ApplicationUser> userManager)
        {
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new PartsUnlimitedContext()));

            if (!roleManager.RoleExists(AdminConstants.Role))
            {
                roleManager.Create(new IdentityRole(AdminConstants.Role));
            }

            var username = ConfigurationHelpers.GetString("Authentication.Administrator.UserName");
            var password = ConfigurationHelpers.GetString("Authentication.Administrator.Password");

            var user = userManager.FindByName(username);

            if (user == null)
            {
                user = new ApplicationUser {
                    UserName = username, Email = username
                };
                var result = userManager.Create(user, password);
                if (!result.Succeeded)
                {
                    throw new Exception(string.Format("Failed to create admin user: {0}", string.Join(",", result.Errors)));
                }

                user = userManager.FindByName(username);
                userManager.AddToRole(user.Id, AdminConstants.Role);
                userManager.AddClaim(user.Id, new Claim(AdminConstants.ManageStore.Name, AdminConstants.ManageStore.Allowed));
            }
        }
Exemplo n.º 2
0
        public ConfigurationLoginProviderCredentials(string providerName)
        {
            Key    = ConfigurationHelpers.GetString(string.Format("Authentication.{0}.Key", providerName));
            Secret = ConfigurationHelpers.GetString(string.Format("Authentication.{0}.Secret", providerName));

            Use = !string.IsNullOrWhiteSpace(Key) && !string.IsNullOrWhiteSpace(Secret);
        }
        public async Task <IEnumerable <string> > GetRecommendationsAsync(string productId)
        {
            string modelName = ConfigurationHelpers.GetString("MachineLearning.ModelName");
            //The Azure ML service takes in a recommendation model name (trained ahead of time) and a product id
            string uri = string.Format("https://api.datamarket.azure.com/data.ashx/amla/mba/v1/Score?Id=%27{0}%27&Item=%27{1}%27", modelName, productId);

            try
            {
                //The Azure ML service returns a set of numbers, which indicate the recommended product id
                var response = await client.GetStringAsync(uri);

                AzureMLFrequentlyBoughtTogetherServiceResponse deserializedResponse = JsonConvert.DeserializeObject <AzureMLFrequentlyBoughtTogetherServiceResponse>(response);
                //When there is no recommendation, The Azure ML service returns a JSON object that does not contain ItemSet
                var recommendation = deserializedResponse.ItemSet;
                if (recommendation == null)
                {
                    return(Enumerable.Empty <string>());
                }
                else
                {
                    return(recommendation);
                }
            }
            catch (HttpRequestException e)
            {
                telemetry.TrackException(e);

                return(Enumerable.Empty <string>());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Starts a SignalR client which listens for change notifications from the LOB app.
        /// Whenever match data is changed update notifications are automatically pushed to clients of this website.
        /// </summary>
        private static void StartGameDataListener()
        {
            Task.Run(() => {
                try
                {
                    Trace.TraceInformation("Connecting to Game Data notifications");

                    var serverUrl = ConfigurationHelpers.GetString("Contoso.Lob.Endpoint");

                    _lobHubConnection = new HubConnection(serverUrl);
                    _updatesDisposer  = _lobHubConnection.CreateHubProxy("UpdatesHub")
                                        .On <int>("NotifyGameDataUpdated", SendGameUpdateNotifications);

                    _lobHubConnection.Start().Wait();

                    Trace.TraceInformation("Connected");
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error in game data poller: {0}", ex);
                }
            });
        }