コード例 #1
0
        public UsersController(SlackIntegrationClient slackClient, UserService userService)
        {
            _userService = userService;

            _clientDictionary = new Dictionary <Guid, IUserClient> {
                { Constants.SlackIntegrationId, slackClient }
            };

            // Just for testing. Primes the DB with one entry
            if (_userService.GetAllUsers().Count == 0)
            {
                _userService.AddUser(new UserEntity {
                    FirstName  = "Luke",
                    LastName   = "Dieter",
                    IsActive   = true,
                    Title      = "Mr.",
                    TimeZoneId = 22
                });
            }
        }
コード例 #2
0
        static void AddSlackIntegrationClient(IServiceCollection services, HttpClient httpClient)
        {
            Console.WriteLine("Populating metadata from Slack");
            var slackIntegrationClient = new SlackIntegrationClient(httpClient);
            var policyResult           = Policy
                                         .Handle <Exception>()
                                         .WaitAndRetryAsync(new[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(4)
            }).ExecuteAndCaptureAsync(slackIntegrationClient.PopulateMetaData).GetAwaiter().GetResult();

            if (policyResult.FinalException != null)
            {
                Console.WriteLine($"Failed to populate metadata in slackIntegrationClient {policyResult.FinalException}");
            }

            Console.WriteLine("Getting users from Slack");
            var usersResult = Policy
                              .Handle <Exception>()
                              .WaitAndRetryAsync(new[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(4)
            }).ExecuteAndCaptureAsync(slackIntegrationClient.GetUsers).GetAwaiter().GetResult();

            if (policyResult.FinalException == null)
            {
                var users = new Users(usersResult.Result);
                services.AddSingleton(users);
            }
            else
            {
                Console.WriteLine($"Failed to get users from Slack {policyResult.FinalException}");
                services.AddSingleton(new Users(new User[0]));
            }

            services.AddSingleton <ISlackClient>(slackIntegrationClient);
        }
コード例 #3
0
 public UserService(UserContext userContext,
                    SlackIntegrationClient slackClient)
 {
     _userContext = userContext;
     _slackClient = slackClient;
 }