private string GetTableLines(List <IFileInfo> contents)
        {
            var builder = new StringBuilder();

            foreach (var subdir in contents.Where(info => info.IsDirectory && !_fileSystemHelper.IsHidden(info.PhysicalPath)))
            {
                builder.AppendFormat($@"
                    <tr>
                        <td><i class='fa fa-lg fa-folder-open'></i></td>
                        <td><a href='{HtmlEncode(subdir.Name)}/'>{HtmlEncode(subdir.Name)}/</a></td>
                        <td></td>
                        <td>{HtmlEncode(subdir.LastModified.LocalDateTime.ToString("dd/MM/yyyy HH:mm"))}</td>
                    </tr>
                    ");
            }
            foreach (var file in contents.Where(info => !info.IsDirectory && !_fileSystemHelper.IsHidden(info.PhysicalPath)))
            {
                builder.AppendFormat($@"
                  <tr>
                    <td><i class='fa fa-lg {GetFontAwesomeIcon(file.Name)}'></i></td>
                    <td><a href='{HtmlEncode(file.Name)}'>{HtmlEncode(file.Name)}</a></td>
                    <td>{GetLengthString(file.Length)}</td>
                    <td>{HtmlEncode(file.LastModified.LocalDateTime.ToString("dd/MM/yyyy HH:mm"))}</td>
                  </tr>
                ");
            }
            return(builder.ToString());
        }
Пример #2
0
        /// <inheritdoc/>
        public async Task <Dictionary <string, DateTime> > GetUpdatedFilesList(string userId, DateTime lastModifiedDate, bool mbTiles)
        {
            _logger.LogInformation($"Getting the list of offline files for user: {userId}, mbtiles: {mbTiles}");
            var filesDictionary = new Dictionary <string, DateTime>();

            if (!await _receiptValidationGateway.IsEntitled(userId))
            {
                return(new Dictionary <string, DateTime>());
            }
            var contents = _fileProvider.GetDirectoryContents(string.Empty);

            foreach (var content in contents)
            {
                if (_fileSystemHelper.IsHidden(content.PhysicalPath))
                {
                    continue;
                }
                if (lastModifiedDate != DateTime.MinValue && content.LastModified.DateTime - lastModifiedDate <= new TimeSpan(0, 0, 1))
                {
                    continue;
                }
                // HM TODO: 03.2020 - remove this when all requests are sending mbtiles true
                if ((mbTiles && (content.Name.EndsWith(".mbtiles") || content.Name.StartsWith("style"))) ||
                    !mbTiles && content.Name.EndsWith(".ihm"))
                {
                    filesDictionary[content.Name] = content.LastModified.DateTime;
                }
            }
            return(filesDictionary);
        }
Пример #3
0
        public void GenerateContentAsync_ForDeeperPath_ShouldReturnFiles()
        {
            var context = new DefaultHttpContext();

            context.Request.Path = "/path/to/file";
            var stream = new MemoryStream();

            context.Response.Body = stream;
            var fileNames = new[] { "zipfile.zip", "image.png", "xml.xml", "text.txt" };
            var content   = new List <IFileInfo>();

            _fileSystemHelper.IsHidden(Arg.Any <string>()).Returns(false);
            for (int index = 0; index < fileNames.Length; index++)
            {
                var file = Substitute.For <IFileInfo>();
                file.Name.Returns(fileNames[index]);
                file.Length.Returns((int)Math.Pow(1024, index) + 1);
                file.IsDirectory.Returns(false);
                content.Add(file);
            }
            var folder = Substitute.For <IFileInfo>();

            folder.IsDirectory.Returns(true);
            folder.Name.Returns("dir1");
            content.Add(folder);

            _formatter.GenerateContentAsync(context, content).Wait();
            var html = Encoding.UTF8.GetString(stream.ToArray());

            Assert.IsTrue(html.Contains("<a href='/path/to/file/'"));
            Assert.IsTrue(html.Contains("fa-file-zip"));
            Assert.IsTrue(html.Contains("fa-file-code"));
            Assert.IsTrue(html.Contains("fa-file-image"));
            Assert.IsTrue(html.Contains("fa-file-text"));
            Assert.IsTrue(html.Contains("fa-folder-open"));
            Assert.IsTrue(html.Contains("Gb"));
            Assert.IsTrue(html.Contains("Mb"));
            Assert.IsTrue(html.Contains("Kb"));
            Assert.IsTrue(html.Contains(" b"));
        }