Пример #1
0
        public void Configure(IWebJobsBuilder builder)
        {
            string environment = Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT");

            builder.Services.AddSingleton(_ => ElasticClientFactory.Create());
            builder.Services.AddSingleton(_ => DocumentClientFactory.Create());
            builder.Services.AddSingleton <IAttemptService, AttemptService>();
            builder.Services.AddSingleton <IZoneService, ZoneService>();
            builder.Services.AddSingleton <IToyDistributionProblemRepository, ToyDistributionProblemRepository>();

            if (!string.Equals(environment, "Development", StringComparison.OrdinalIgnoreCase))
            {
                builder.Services.AddLogging(loggingBuilder => loggingBuilder
                                            .AddSerilog(new LoggerConfiguration()
                                                        .WriteTo
                                                        .Elasticsearch(new ElasticsearchSinkOptions(ElasticClientFactory.Url)
                {
                    AutoRegisterTemplate        = true,
                    AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
                    MinimumLogEventLevel        = LogEventLevel.Information,
                    ModifyConnectionSettings    = connection =>
                    {
                        connection.BasicAuthentication(ElasticClientFactory.Username, ElasticClientFactory.Password);

                        return(connection);
                    }
                })
                                                        .CreateLogger()));
            }
        }
Пример #2
0
        /// <summary>
        /// Configures the identity builder with ElasticIdentity components,
        /// and registers dependencies for that component which have not already been
        /// registered.
        /// </summary>
        /// <param name="serverName">
        /// The server:port combination which the <see cref="ElasticUserStore"/> will connect to. E.g. localhost:9200
        /// </param>
        /// <param name="indexName">
        /// The index which will contain the user information.
        /// </param>
        public static IdentityBuilder AddElasticIdentity(
            this IdentityBuilder identityBuilder,
            string serverName,
            string indexName = DEFAULT_INDEX_NAME)
        {
            var node = new Uri("http://" + serverName.Replace("http://", ""));

            IElasticClient elasticClient = ElasticClientFactory.Create(node, indexName);

            return(AddElasticIdentity(identityBuilder, elasticClient));
        }
Пример #3
0
        public ElasticUserStoreTest()
        {
            _indexName = $"{nameof(ElasticUserStoreTest)}_{Guid.NewGuid()}".ToLowerInvariant();
            var node = new Uri("http://localhost:9200");

            _elasticClient = ElasticClientFactory.Create(node, _indexName);

            _store = new ElasticUserStore(_elasticClient);

            // the generic store refreshes immediately
            var store = new ElasticUserStore <string, ElasticIdentityUser>(_elasticClient);

            store.CreateAsync(_user1, CancellationToken.None).GetAwaiter().GetResult();

            _elasticClient.Indices.Refresh(_indexName);
        }
        public async Task Can_join_channel()
        {
            ////Arrange
            var client = ElasticClientFactory.Create();
            var user   = TestExtensions.RandomUser();

            await new UserService().EnsureUser(user);

            ////Act
            await new ChannelService().Join(user, "global");

            ////Assert
            await client.Indices.RefreshAsync(Indices.Index <UserAccount>());

            var userAccount = await new UserService().FindById(user.UserId());

            Assert.IsTrue(userAccount.Channels.Contains("global"));
        }
        public async Task Can_join_private_channel()
        {
            ////Arrange
            var client = ElasticClientFactory.Create();
            var user1  = TestExtensions.RandomUser();
            var user2  = TestExtensions.RandomUser();

            await new UserService().EnsureUser(user1);
            await new UserService().EnsureUser(user2);

            ////Act
            var channel = await new ChannelService().Create(user1, "tester", false, new[] { user1.UserId(), user2.UserId() });

            await new ChannelService().Join(user1, channel.Id);

            ////Assert
            await client.Indices.RefreshAsync(Indices.Index <UserAccount>());

            var userAccount = await new UserService().FindById(user1.UserId());

            Assert.IsTrue(userAccount.Channels.Contains(channel.Id));
        }
Пример #6
0
 public ChatService(IElasticClient client = null, UserService userService = null)
 {
     _client      = client ?? ElasticClientFactory.Create();
     _userService = userService ?? new UserService();
 }
 protected ElasticRepository()
 {
     _esClient = ElasticClientFactory.Create();
 }
Пример #8
0
 public UserService(IElasticClient client = null)
 {
     _client = client ?? ElasticClientFactory.Create();
 }