Exemple #1
0
        private void RegisterMetaData()
        {
            DateTime now = DateTime.Now;

            string currentUsername = _currentUserAccessor.GetUsername();
            string username        = !string.IsNullOrEmpty(currentUsername) ? currentUsername : "******";

            var addedEntities = ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();

            addedEntities.ForEach(ae =>
            {
                ae.Property("Creation").CurrentValue       = now;
                ae.Property("CreatedBy").CurrentValue      = username;
                ae.Property("LastModified").CurrentValue   = now;
                ae.Property("LastModifiedBy").CurrentValue = username;
            });

            var updatedEntities = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified).ToList();

            updatedEntities.ForEach(ue =>
            {
                ue.Property("LastModified").CurrentValue   = now;
                ue.Property("LastModifiedBy").CurrentValue = username;
            });
        }
Exemple #2
0
        public Task Process(TRequest request, CancellationToken cancellationToken)
        {
            var name = typeof(TRequest).Name;

            string username = _currentUserAccessor.GetUsername();

            username = string.IsNullOrEmpty(username) ? string.Empty : username;

            _logger.LogInformation($"\nRequest: {name} {request} User: {username}");

            return(Task.CompletedTask);
        }
Exemple #3
0
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            if (request is IAuthorizedRequest)
            {
                string username = _currentUserAccessor.GetUsername();

                if (string.IsNullOrWhiteSpace(username))
                {
                    throw new NotAuthorizedException();
                }
            }

            var response = await next();

            return(response);
        }
Exemple #4
0
        public async Task <IActionResult> RefreshToken()
        {
            string username = _currentUserAccessor.GetUsername();

            string token = await _authenticateService.GenerateTokenAsync(username);

            string refreshToken = _authenticateService.GenerateRefreshToken(username);

            if (!string.IsNullOrEmpty(token))
            {
                return(Ok(
                           new
                {
                    token,
                    refreshToken
                }));
            }

            return(BadRequest("Invalid Request"));
        }
Exemple #5
0
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            _timer.Start();

            var response = await next();

            _timer.Stop();

            if (_timer.ElapsedMilliseconds > 500)
            {
                var    name     = typeof(TRequest).Name;
                string userName = _currentUserAccessor.GetUsername();
                string userText = "";

                if (!string.IsNullOrWhiteSpace(userName))
                {
                    userText = $"Username: {userName}";
                }

                _logger.LogWarning($"Long Running Request: {name} ({_timer.ElapsedMilliseconds} milliseconds) {userText} { request.ToString() }");
            }

            return(response);
        }
        public ActionResult <IEnumerable <string> > Get()
        {
            var username = _currentUserAccessor.GetUsername();

            return(new string[] { "value1", "value2" });
        }