示例#1
0
        public async Task CreateRacksAsync(RackRangeQuery query)
        {
            query = query.ToUpper();
            await _rackRepository.CreateRacksInRangeAsync(query.StartRow, query.StartCol, query.EndRow, query.EndCol, query.DatacenterId);

            await _auditEventLogger.LogEventAsync(new RackCreatedEvent(query));
        }
        public virtual async Task <LogsDto> GetLogsAsync(string search, int page = 1, int pageSize = 10)
        {
            var pagedList = await Repository.GetLogsAsync(search, page, pageSize);

            var logs = pagedList.ToModel();

            await AuditEventLogger.LogEventAsync(new LogsRequestedEvent());

            return(logs);
        }
示例#3
0
        public virtual async Task <EncryptionKeyDto> GetEncryptionKeyByClientIdAsync(int clientId)
        {
            var encryptionKey = await Repository.GetEncryptionKeyByClientIdAsync(clientId);

            var encryptionKeyDto = encryptionKey.ToModel();

            await AuditEventLogger.LogEventAsync(new EncryptionKeyRequestedEvent());

            return(encryptionKeyDto);
        }
        public virtual async Task <PersistedGrantsDto> GetPersistedGrantsByUsersAsync(string search, int page = 1, int pageSize = 10)
        {
            var pagedList = await PersistedGrantAspNetIdentityRepository.GetPersistedGrantsByUsersAsync(search, page, pageSize);

            var persistedGrantsDto = pagedList.ToModel();

            await AuditEventLogger.LogEventAsync(new PersistedGrantsIdentityByUsersRequestedEvent(persistedGrantsDto));

            return(persistedGrantsDto);
        }
示例#5
0
        public virtual async Task <IdentityResourcesDto> GetIdentityResourcesAsync(string search, int page = 1, int pageSize = 10)
        {
            var pagedList = await IdentityResourceRepository.GetIdentityResourcesAsync(search, page, pageSize);

            var identityResourcesDto = pagedList.ToModel();

            await AuditEventLogger.LogEventAsync(new IdentityResourcesRequestedEvent(identityResourcesDto));

            return(identityResourcesDto);
        }
示例#6
0
        public virtual async Task <ApiScopesDto> GetApiScopesAsync(string search, int page = 1, int pageSize = 10)
        {
            var pagedList = await ApiScopeRepository.GetApiScopesAsync(search, page, pageSize);

            var apiScopesDto = pagedList.ToModel();

            await AuditEventLogger.LogEventAsync(new ApiScopesRequestedEvent(apiScopesDto));

            return(apiScopesDto);
        }
示例#7
0
        public async Task <ActionResult> Get()
        {
            // Create fake product
            var productDto = new ProductDto
            {
                Id       = Guid.NewGuid().ToString(),
                Name     = Guid.NewGuid().ToString(),
                Category = Guid.NewGuid().ToString()
            };

            // Log this action
            var productGetUserEvent = new ProductGetEvent
            {
                Category = nameof(ProductGetEvent),
                Product  = productDto
            };

            var productGetMachineEvent = new ProductGetEvent
            {
                Category          = nameof(ProductGetEvent),
                Product           = productDto,
                SubjectType       = AuditSubjectTypes.Machine,
                SubjectName       = Environment.MachineName,
                SubjectIdentifier = Environment.MachineName,
                Action            = new { Method = nameof(Get), Class = nameof(AuditController) }
            };

            await _auditEventLogger.LogEventAsync(productGetMachineEvent, options =>
            {
                options.UseDefaultSubject = false;
                options.UseDefaultAction  = false;
            });

            await _auditEventLogger.LogEventAsync(productGetUserEvent);

            var genericProductEvent = new GenericProductEvent <int, string, ProductDto>
            {
                Category = nameof(ProductGetEvent),
                Product  = productDto
            };

            await _auditEventLogger.LogEventAsync(genericProductEvent);

            return(Ok(productDto));
        }
示例#8
0
        public async Task <int> CreateModelAsync(ModelDto model)
        {
            var entity = _mapper.Map <Model>(model);
            var added  = await _repository.AddModelAsync(entity);

            await _auditEventLogger.LogEventAsync(new ModelCreatedEvent(model));

            return(added);
        }
示例#9
0
        public async Task <Guid> CreateAssetAsync(AssetDto asset)
        {
            var entity = _mapper.Map <Asset>(asset);
            await _repository.AddAssetAsync(entity);

            await _auditEventLogger.LogEventAsync(new AssetCreatedEvent(asset));

            return(entity.Id);
        }
        public async Task <Guid> CreateDatacenterAsync(DatacenterDto datacenter)
        {
            var entity = _mapper.Map <Datacenter>(datacenter);
            await _repository.AddDatacenterAsync(entity);

            if (entity.IsOffline)
            {
                Rack rack = new Rack {
                    Row = "A", Column = 0, DatacenterId = entity.Id, Assets = new List <Asset>()
                };
                await _rackRepository.AddRackAsync(rack);
            }
            await _auditEventLogger.LogEventAsync(new DatacenterCreatedEvent(datacenter));

            return(entity.Id);
        }
示例#11
0
        public async Task <ClientsDto> GetManagedClients(string userId, string searchText, int page, int pageSize)
        {
            var managedClients = await ClientManagedAsync(userId);

            var pagedList = new PagedList <Client>();

            Expression <Func <Client, bool> > searchCondition =
                x => x.ClientId.Contains(searchText) || x.ClientName.Contains(searchText);
            var listClients = await _context.Clients.Where(c => managedClients.Contains(c.Id))
                              .WhereIf(!string.IsNullOrEmpty(searchText), searchCondition)
                              .PageBy(x => x.Id, page, pageSize).ToListAsync();

            pagedList.Data.AddRange(listClients);
            pagedList.TotalCount =
                await _context.Clients.WhereIf(!string.IsNullOrEmpty(searchText), searchCondition).CountAsync();

            pagedList.PageSize = pageSize;
            var result = pagedList.ToModel();

            await _auditEventLogger.LogEventAsync(new ClientsRequestedEvent(result));

            return(result);
        }
示例#12
0
        /// <summary>
        /// Add new client, this method doesn't save client secrets, client claims, client properties
        /// </summary>
        /// <param name="client"></param>
        /// <returns>This method return new client id</returns>
        public virtual async Task <int> AddClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(ClientServiceResources.ClientExistsValue().Description, client.ClientId), ClientServiceResources.ClientExistsKey().Description, client);
            }

            PrepareClientTypeForNewClient(client);
            var clientEntity = client.ToEntity();

            var added = await ClientRepository.AddClientAsync(clientEntity);

            await AuditEventLogger.LogEventAsync(new ClientAddedEvent(client));

            return(added);
        }
        public virtual async Task <TUsersDto> GetUsersAsync(string search, int page = 1, int pageSize = 10)
        {
            var pagedList = await IdentityRepository.GetUsersAsync(search, page, pageSize);

            var usersDto = Mapper.Map <TUsersDto>(pagedList);

            await AuditEventLogger.LogEventAsync(new UsersRequestedEvent <TUsersDto>(usersDto));

            return(usersDto);
        }
        public virtual async Task <ApiResourceDto> GetApiResourceAsync(int apiResourceId)
        {
            var apiResource = await ApiResourceRepository.GetApiResourceAsync(apiResourceId);

            if (apiResource == null)
            {
                throw new UserFriendlyErrorPageException(ApiResourceServiceResources.ApiResourceDoesNotExist().Description, ApiResourceServiceResources.ApiResourceDoesNotExist().Description);
            }
            var apiResourceDto = apiResource.ToModel();

            await AuditEventLogger.LogEventAsync(new ApiResourceRequestedEvent(apiResourceId, apiResourceDto));

            return(apiResourceDto);
        }
示例#15
0
        /// <summary>
        /// Add new client, this method doesn't save client secrets, client claims, client properties
        /// </summary>
        /// <param name="client"></param>
        /// <returns>This method return new client id</returns>
        public virtual async Task <int> AddClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(ClientServiceResources.ClientExistsValue().Description, client.ClientId), ClientServiceResources.ClientExistsKey().Description, client);
            }

            PrepareClientTypeForNewClient(client);
            var clientEntity = client.ToEntity();

            try
            {
                var added = await ClientRepository.AddClientAsync(clientEntity);

                if (client.EncryptionKey?.Length > 0)
                {
                    var encryptionKey = await EncryptionKeyRepository.AddEncryptionKeyAsync(new EncryptionKey { ClientId = clientEntity.Id, EncryptionSecret = client.EncryptionKey, Enable = true });
                }
                await AuditEventLogger.LogEventAsync(new ClientAddedEvent(client));

                return(added);
            }
            catch
            {
                throw;
            }
        }