Ejemplo n.º 1
0
        public Task <IActionResult> ListLogs([FromQuery] int?page, [FromQuery] int?pageSize, CancellationToken cancellationToken)
        => Paginated(
            async() =>
        {
            var path = fileLoggingConfiguration.GetFullLogDirectory(ioManager, assemblyInformationProvider, platformIdentifier);
            try
            {
                var files = await ioManager.GetFiles(path, cancellationToken).ConfigureAwait(false);
                var tasks = files.Select(
                    async file => new LogFileResponse
                {
                    Name         = ioManager.GetFileName(file),
                    LastModified = await ioManager
                                   .GetLastModified(
                        ioManager.ConcatPath(path, file),
                        cancellationToken)
                                   .ConfigureAwait(false),
                })
                            .ToList();

                await Task.WhenAll(tasks).ConfigureAwait(false);

                return(new PaginatableResult <LogFileResponse>(
                           tasks
                           .AsQueryable()
                           .Select(x => x.Result)
                           .OrderByDescending(x => x.Name)));
            }
            catch (IOException ex)
            {
                return(new PaginatableResult <LogFileResponse>(
                           Conflict(new ErrorMessageResponse(ErrorCode.IOError)
                {
                    AdditionalData = ex.ToString(),
                })));
            }
        },
            null,
            page,
            pageSize,
            cancellationToken);
Ejemplo n.º 2
0
        public async Task <IActionResult> ListLogs(CancellationToken cancellationToken)
        {
            var path = fileLoggingConfiguration.GetFullLogDirectory(ioManager, assemblyInformationProvider, platformIdentifier);

            try
            {
                var files = await ioManager.GetFiles(path, cancellationToken).ConfigureAwait(false);

                var tasks = files.Select(
                    async file => new LogFile
                {
                    Name         = ioManager.GetFileName(file),
                    LastModified = await ioManager.GetLastModified(
                        ioManager.ConcatPath(path, file),
                        cancellationToken)
                                   .ConfigureAwait(false)
                })
                            .ToList();

                await Task.WhenAll(tasks).ConfigureAwait(false);

                var result = tasks
                             .Select(x => x.Result)
                             .OrderByDescending(x => x.Name)
                             .ToList();

                return(Ok(result));
            }
            catch (IOException ex)
            {
                return(Conflict(new ErrorMessage(ErrorCode.IOError)
                {
                    AdditionalData = ex.ToString()
                }));
            }
        }