public async Task WhenUrlNotUnique_Throws() { var uniqueData = UNIQUE_PREFIX + nameof(WhenUrlNotUnique_Throws); using var app = _appFactory.Create(); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var page1Id = await app.TestData.Pages().AddAsync(uniqueData, directoryId); var page2Id = await app.TestData.Pages().AddAsync(uniqueData + "2", directoryId); var command = new UpdatePageUrlCommand() { PageId = page2Id, PageDirectoryId = directoryId, UrlPath = SlugFormatter.ToSlug(uniqueData) }; var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); await contentRepository .Awaiting(r => r.Pages().UpdateUrlAsync(command)) .Should() .ThrowAsync <UniqueConstraintViolationException>() .WithMemberNames(nameof(command.UrlPath)); }
public async Task WhenIncludeUnpublishedTrue_ReturnsUnpublishedCustomEntityPage() { var uniqueData = UNIQUE_PREFIX + "WhenIncUnpubTrue_ReturnsCEUnpubPage"; var sluggedUniqueData = SlugFormatter.ToSlug(uniqueData); using var app = _appFactory.Create(); var customEntityId = await app.TestData.CustomEntities().AddAsync(uniqueData); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var pageId = await app.TestData.Pages().AddCustomEntityPageDetailsAsync(uniqueData, directoryId, c => c.Publish = true); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var page = await contentRepository .Pages() .GetByPath() .AsRoutingInfo(new GetPageRoutingInfoByPathQuery() { Path = $"/{sluggedUniqueData}/{customEntityId}/{sluggedUniqueData}", IncludeUnpublished = true }) .ExecuteAsync(); page.Should().NotBeNull(); page.PageRoute.PageId.Should().Be(pageId); page.CustomEntityRoute.Should().NotBeNull(); page.CustomEntityRoute.CustomEntityId.Should().Be(customEntityId); }
public async Task WhenUnPublished_ReturnsNull() { var uniqueData = UNIQUE_PREFIX + nameof(WhenUnPublished_ReturnsNull); var sluggedUniqueData = SlugFormatter.ToSlug(uniqueData); using var app = _appFactory.Create(); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var pageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId, c => c.Publish = true); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); await contentRepository .Pages() .UnPublishAsync(new UnPublishPageCommand(pageId)); var page = await contentRepository .Pages() .GetByPath() .AsRoutingInfo(new GetPageRoutingInfoByPathQuery() { Path = $"/{sluggedUniqueData}/{sluggedUniqueData}" }) .ExecuteAsync(); page.Should().BeNull(); }
public async Task WhenCutomEntityRoute_Maps() { var uniqueData = UNIQUE_PREFIX + nameof(WhenCutomEntityRoute_Maps); var sluggedUniqueData = SlugFormatter.ToSlug(uniqueData); using var app = _appFactory.Create(); var customEntityId = await app.TestData.CustomEntities().AddAsync(uniqueData, c => c.Publish = true); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var pageId = await app.TestData.Pages().AddCustomEntityPageDetailsAsync(uniqueData, directoryId, c => c.Publish = true); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var page = await contentRepository .Pages() .GetByPath() .AsRoutingInfo(new GetPageRoutingInfoByPathQuery() { Path = $"/{sluggedUniqueData}/{customEntityId}/{sluggedUniqueData}" }) .ExecuteAsync(); using (new AssertionScope()) { page.Should().NotBeNull(); page.CustomEntityRoute.Should().NotBeNull(); page.CustomEntityRoute.CustomEntityId.Should().Be(customEntityId); page.CustomEntityRouteRule.Should().NotBeNull(); page.CustomEntityRouteRule.Should().BeOfType <IdAndUrlSlugCustomEntityRoutingRule>(); page.PageRoute.Should().NotBeNull(); page.PageRoute.PageId.Should().Be(pageId); } }
public async Task ExecuteAsync(AddImageAssetCommand command, IExecutionContext executionContext) { var imageAsset = new ImageAsset(); imageAsset.FileDescription = command.Title; imageAsset.FileName = SlugFormatter.ToSlug(command.Title); imageAsset.DefaultAnchorLocation = command.DefaultAnchorLocation; _entityTagHelper.UpdateTags(imageAsset.ImageAssetTags, command.Tags, executionContext); _entityAuditHelper.SetCreated(imageAsset, executionContext); using (var scope = _transactionScopeFactory.Create(_dbContext)) { // if adding, save this up front _dbContext.ImageAssets.Add(imageAsset); await _imageAssetFileService.SaveAsync(command.File, imageAsset, nameof(command.File)); command.OutputImageAssetId = imageAsset.ImageAssetId; scope.Complete(); } await _messageAggregator.PublishAsync(new ImageAssetAddedMessage() { ImageAssetId = imageAsset.ImageAssetId }); }
private async Task ProcessChildDirectories(Dictionary <string, DocumentationNode> resultNodes, DocumentationNode parentNode, string directoryPath) { foreach (var childDirectoryPath in Directory.GetDirectories(directoryPath)) { var directory = new DirectoryInfo(childDirectoryPath); var slug = SlugFormatter.ToSlug(directory.Name); var childNode = new DocumentationNode() { Title = directory.Name, Url = FilePathHelper.CombineVirtualPath(parentNode.Url, slug) }; childNode.UpdateDate = Directory.GetLastWriteTimeUtc(childDirectoryPath); await _fileWriterService.EnsureDirectoryExistsAsync(childNode.Url); await ProcessDirectory(childDirectoryPath, childNode); // Only add the node if it represents something in the document tree // i.e. skip static resource directories. if (childNode.Children.Any() || childNode.DocumentFilePath != null || childNode.RedirectTo != null) { resultNodes.Add(slug, childNode); } } }
public async Task WhenUrlUpdated_SendsCorrectMessage(bool isPublished) { var uniqueData = UNIQUE_PREFIX + nameof(WhenUrlUpdated_SendsCorrectMessage) + isPublished.ToString()[0]; var uniqueDataSlug = SlugFormatter.ToSlug(uniqueData); using var app = _appFactory.Create(); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var pageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId, c => c.Publish = isPublished); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); await contentRepository .Pages() .UpdateUrlAsync(new UpdatePageUrlCommand() { PageId = pageId, PageDirectoryId = directoryId, UrlPath = "copy" }); app.Mocks .CountMessagesPublished <PageUrlChangedMessage>(m => { return(m.PageId == pageId && m.HasPublishedVersionChanged == isPublished && m.OldFullUrlPath == $"/{uniqueDataSlug}/{uniqueDataSlug}"); }) .Should().Be(1); }
private static string DocumentAsset(int assetId, string fileName, string extension) { var fn = Path.ChangeExtension(assetId + "_" + SlugFormatter.ToSlug(fileName), extension); var url = "/assets/files/" + fn; return(url); }
public async Task ExecuteAsync(UpdateDocumentAssetCommand command, IExecutionContext executionContext) { bool hasNewFile = command.File != null; var documentAsset = await _dbContext .DocumentAssets .Include(a => a.DocumentAssetTags) .Include(a => a.DocumentAssetTags.Select(pt => pt.Tag)) .FilterById(command.DocumentAssetId) .SingleOrDefaultAsync(); documentAsset.Title = command.Title; documentAsset.Description = command.Description ?? string.Empty; documentAsset.FileName = SlugFormatter.ToSlug(command.Title); _entityTagHelper.UpdateTags(documentAsset.DocumentAssetTags, command.Tags, executionContext); _entityAuditHelper.SetUpdated(documentAsset, executionContext); using (var scope = _transactionScopeFactory.Create()) { if (hasNewFile) { await _documentAssetCommandHelper.SaveFile(command.File, documentAsset); } await _dbContext.SaveChangesAsync(); scope.Complete(); } }
public async Task ExecuteAsync(UpdateImageAssetCommand command, IExecutionContext executionContext) { bool hasNewFile = command.File != null; var imageAsset = await _dbContext .ImageAssets .Include(a => a.ImageAssetTags) .ThenInclude(a => a.Tag) .FilterById(command.ImageAssetId) .SingleOrDefaultAsync(); imageAsset.FileDescription = command.Title; imageAsset.FileName = SlugFormatter.ToSlug(command.Title); imageAsset.DefaultAnchorLocation = command.DefaultAnchorLocation; _entityTagHelper.UpdateTags(imageAsset.ImageAssetTags, command.Tags, executionContext); _entityAuditHelper.SetUpdated(imageAsset, executionContext); using (var scope = _transactionScopeFactory.Create(_dbContext)) { if (hasNewFile) { await _imageAssetFileService.SaveAsync(command.File, imageAsset, nameof(command.File)); } await _dbContext.SaveChangesAsync(); scope.QueueCompletionTask(() => OnTransactionComplete(hasNewFile, imageAsset)); await scope.CompleteAsync(); } }
internal static void AssertBasicDataMapping( string uniqueData, AddPageCommand addPageCommand, PageSummary page ) { var sluggedUniqueData = SlugFormatter.ToSlug(uniqueData); page.Should().NotBeNull(); page.PageId.Should().Be(addPageCommand.OutputPageId); page.AuditData.Should().NotBeNull(); page.AuditData.Creator.Should().NotBeNull(); page.AuditData.Creator.UserId.Should().BePositive(); page.FullUrlPath.Should().Be($"/{sluggedUniqueData}/{addPageCommand.UrlPath}"); page.Should().NotBeNull(); page.HasDraftVersion.Should().BeFalse(); page.Locale.Should().BeNull(); page.PageType.Should().Be(addPageCommand.PageType); page.PublishDate.Should().NotBeNull().And.NotBeDefault(); page.LastPublishDate.Should().NotBeNull().And.NotBeDefault(); page.PublishStatus.Should().Be(PublishStatus.Published); page.Tags.Should().ContainSingle(t => t == "Test"); page.Title.Should().Be(addPageCommand.Title); page.UrlPath.Should().Be(addPageCommand.UrlPath); }
public async Task WhenExistingPageAndPathNotUnique_ReturnsFalse() { var uniqueData = SlugFormatter.ToSlug(UNIQUE_PREFIX + "ExPagNotUniq_RetFalse"); using var app = _appFactory.Create(); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var pageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId); var page2Path = uniqueData + "a"; await app.TestData.Pages().AddAsync(page2Path, directoryId); var isUnique = await contentRepository .Pages() .IsPathUnique(new IsPagePathUniqueQuery() { PageId = pageId, PageDirectoryId = directoryId, UrlPath = page2Path }) .ExecuteAsync(); isUnique.Should().BeFalse(); }
public async Task WhenExistingDirectoryAndUnique_ReturnsTrue() { var uniqueData = SlugFormatter.ToSlug(UNIQUE_PREFIX + "ExDirUniq_RetTrue"); using var app = _appFactory.Create(); var parentDirectoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var childDirectoryId = await app.TestData.PageDirectories().AddAsync(uniqueData, parentDirectoryId); await app.TestData.PageDirectories().AddAsync(uniqueData + "a", parentDirectoryId); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var isUnique = await contentRepository .PageDirectories() .IsPathUnique(new IsPageDirectoryPathUniqueQuery() { ParentPageDirectoryId = parentDirectoryId, UrlPath = uniqueData + "b", PageDirectoryId = childDirectoryId }) .ExecuteAsync(); isUnique.Should().BeTrue(); }
public async Task WhenAdded_UpdatesPageDirectoryPathTable() { var directoryName = UNIQUE_PREFIX + "UpdPathTable"; var sluggedPath = SlugFormatter.ToSlug(directoryName); using var app = _appFactory.Create(); var dir1Id = await app.TestData.PageDirectories().AddAsync(directoryName); var dir2Id = await app.TestData.PageDirectories().AddAsync("red", dir1Id); var dir3Id = await app.TestData.PageDirectories().AddAsync("blue", dir2Id); var dir4Id = await app.TestData.PageDirectories().AddAsync("green", dir3Id); var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); var directoryPath = await dbContext .PageDirectoryPaths .AsNoTracking() .Where(d => d.PageDirectoryId == dir4Id) .SingleOrDefaultAsync(); using (new AssertionScope()) { directoryPath.Should().NotBeNull(); directoryPath.Depth.Should().Be(4); directoryPath.FullUrlPath.Should().Be($"{sluggedPath}/red/blue/green"); } }
public async Task ExecuteAsync(AddDocumentAssetCommand command, IExecutionContext executionContext) { var documentAsset = new DocumentAsset(); documentAsset.Title = command.Title; documentAsset.Description = command.Description ?? string.Empty; documentAsset.FileName = SlugFormatter.ToSlug(command.Title); _entityTagHelper.UpdateTags(documentAsset.DocumentAssetTags, command.Tags, executionContext); _entityAuditHelper.SetCreated(documentAsset, executionContext); using (var scope = _transactionScopeFactory.Create(_dbContext)) { _dbContext.DocumentAssets.Add(documentAsset); await _documentAssetCommandHelper.SaveFile(command.File, documentAsset); command.OutputDocumentAssetId = documentAsset.DocumentAssetId; scope.Complete(); } await _messageAggregator.PublishAsync(new DocumentAssetAddedMessage() { DocumentAssetId = documentAsset.DocumentAssetId }); }
public async Task ExecuteAsync(UpdateImageAssetCommand command, IExecutionContext executionContext) { bool hasNewFile = command.File != null; var imageAsset = await _dbContext .ImageAssets .Include(a => a.ImageAssetTags) .Include(a => a.ImageAssetTags.Select(pt => pt.Tag)) .FilterById(command.ImageAssetId) .SingleOrDefaultAsync(); imageAsset.FileDescription = command.Title; imageAsset.FileName = SlugFormatter.ToSlug(command.Title); imageAsset.DefaultAnchorLocation = command.DefaultAnchorLocation; _entityTagHelper.UpdateTags(imageAsset.ImageAssetTags, command.Tags, executionContext); _entityAuditHelper.SetUpdated(imageAsset, executionContext); using (var scope = _transactionScopeFactory.Create()) { if (hasNewFile) { await _imageAssetCommandHelper.SaveFile(command.File, imageAsset); } await _dbContext.SaveChangesAsync(); scope.Complete(); } if (hasNewFile) { _imageAssetFileCache.Clear(imageAsset.ImageAssetId); } _imageAssetCache.Clear(imageAsset.ImageAssetId); }
private async Task ProcessFiles( Dictionary <string, DocumentationNode> resultNodes, DocumentationNode parentNode, string[] allFilePaths, Dictionary <string, string> redirects) { foreach (var filePath in allFilePaths) { // slug path var fileExtension = Path.GetExtension(filePath); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); var sluggedFileName = SlugFormatter.ToSlug(fileNameWithoutExtension); var sluggedFileNameWithExtension = Path.ChangeExtension(sluggedFileName, fileExtension); // skip the file if there's already a redirect if (redirects.Any(r => SlugFormatter.ToSlug(r.Key) == sluggedFileName)) { continue; } if (fileExtension == MARKDOWN_FILE_EXTENSION) { var destinationFilePath = FilePathHelper.CombineVirtualPath(parentNode.Url, sluggedFileNameWithExtension); var updateDate = File.GetLastWriteTimeUtc(filePath); // if we have a custom index file, map this to the container directory if (sluggedFileName == "index") { parentNode.DocumentFilePath = destinationFilePath; parentNode.UpdateDate = updateDate; } else { var node = new DocumentationNode() { Title = fileNameWithoutExtension, Url = FilePathHelper.CombineVirtualPath(parentNode.Url, sluggedFileName), DocumentFilePath = destinationFilePath, UpdateDate = updateDate }; resultNodes.Add(sluggedFileName, node); } await _fileWriterService.CopyFile(filePath, destinationFilePath); } else if (fileExtension != ".json") { // static files are served out of a separate directory var destinationDirectory = FilePathHelper.CombineVirtualPath(STATIC_FOLDER_NAME, parentNode.Url); var destinationPath = FilePathHelper.CombineVirtualPath(destinationDirectory, sluggedFileNameWithExtension); await _fileWriterService.EnsureDirectoryExistsAsync(destinationDirectory); await _fileWriterService.CopyFile(filePath, destinationPath); } // json files ignore, they are assumed to be config } }
public IEnumerable <AdminModule> GetModules() { foreach (var userArea in _userAreaRepository.GetAll()) { var routeLibrary = new ModuleRouteLibrary(SlugFormatter.ToSlug(userArea.Name) + "-users"); var module = new AdminModule() { AdminModuleCode = "COFUSR" + userArea.UserAreaCode, Title = userArea.Name + " Users", Description = "Manage users in the " + userArea.Name + " user area.", MenuCategory = AdminModuleMenuCategory.Settings, PrimaryOrdering = AdminModuleMenuPrimaryOrdering.Secondry, Url = routeLibrary.CreateAngularRoute() }; if (userArea is CofoundryAdminUserArea) { module.RestrictedToPermission = new CofoundryUserAdminModulePermission(); } else { module.RestrictedToPermission = new NonCofoundryUserAdminModulePermission(); } yield return(module); } }
public async Task WhenRootParent_Adds() { var directoryName = UNIQUE_PREFIX + nameof(WhenRootParent_Adds); using var app = _appFactory.Create(); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); var addDirectoryCommand = await app.TestData.PageDirectories().CreateAddCommandAsync(directoryName); await contentRepository .PageDirectories() .AddAsync(addDirectoryCommand); var directory = await dbContext .PageDirectories .AsNoTracking() .FilterById(addDirectoryCommand.OutputPageDirectoryId) .SingleOrDefaultAsync(); using (new AssertionScope()) { addDirectoryCommand.OutputPageDirectoryId.Should().BePositive(); directory.Should().NotBeNull(); directory.PageDirectoryId.Should().Be(addDirectoryCommand.OutputPageDirectoryId); directory.Name.Should().Be(directoryName); directory.UrlPath.Should().Be(SlugFormatter.ToSlug(directoryName)); directory.ParentPageDirectoryId.Should().Be(addDirectoryCommand.ParentPageDirectoryId); directory.CreateDate.Should().NotBeDefault(); } }
public async Task WhenDeleted_SendsMessages() { var uniqueData = UNIQUE_PREFIX + nameof(WhenDeleted_SendsMessages); var uniqueDataSlug = SlugFormatter.ToSlug(uniqueData); using var app = _appFactory.Create(); var directory1Id = await app.TestData.PageDirectories().AddAsync(uniqueData); var directory2Id = await app.TestData.PageDirectories().AddAsync("2", directory1Id); var directory3Id = await app.TestData.PageDirectories().AddAsync("3", directory2Id); var directory1PageId = await app.TestData.Pages().AddAsync("d1p1", directory1Id, c => c.Publish = true); var directory3Page1Id = await app.TestData.Pages().AddAsync("d3p1", directory3Id, c => c.Publish = true); var directory3Page2Id = await app.TestData.Pages().AddAsync("d3p2", directory3Id, c => c.Publish = true); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); await contentRepository .PageDirectories() .DeleteAsync(directory1Id); var directoryMessages = new Dictionary <int, string>() { { directory1Id, $"/{uniqueDataSlug}" }, { directory2Id, $"/{uniqueDataSlug}/2" }, { directory3Id, $"/{uniqueDataSlug}/2/3" }, }; var pageMessages = new Dictionary <int, string>() { { directory1PageId, $"/{uniqueDataSlug}/d1p1" }, { directory3Page1Id, $"/{uniqueDataSlug}/2/3/d3p1" }, { directory3Page2Id, $"/{uniqueDataSlug}/2/3/d3p2" }, }; using (new AssertionScope()) { foreach (var message in pageMessages) { app.Mocks .CountMessagesPublished <PageDeletedMessage>(m => { return(m.PageId == message.Key && m.FullUrlPath == message.Value); }) .Should().Be(1); } foreach (var message in directoryMessages) { app.Mocks .CountMessagesPublished <PageDirectoryDeletedMessage>(m => { return(m.PageDirectoryId == message.Key && m.FullUrlPath == message.Value); }) .Should().Be(1); } } }
private string GetUserAreaRoute(IUserAreaDefinition definition, string route = null) { if (definition == null) { return(string.Empty); } return("/" + _adminSettings.DirectoryName + "/" + SlugFormatter.ToSlug(definition.Name) + "-users#/" + route); }
public string List(CustomEntityDefinitionSummary summary) { if (summary == null) { return(string.Empty); } return("/" + RouteConstants.AdminAreaPrefix + "/" + SlugFormatter.ToSlug(summary.NamePlural) + "#/"); }
private static string GetCustomEntityRoute(string namePlural, string route = null) { if (namePlural == null) { return(string.Empty); } return("/" + RouteConstants.AdminAreaPrefix + "/" + SlugFormatter.ToSlug(namePlural) + "#/" + route); }
private string GetCustomEntityRoute(string namePlural, string route = null) { if (namePlural == null) { return(string.Empty); } return("/" + _adminSettings.DirectoryName + "/" + SlugFormatter.ToSlug(namePlural) + "#/" + route); }
private static string GetUserAreaRoute(IUserAreaDefinition definition, string route = null) { if (definition == null) { return(string.Empty); } return("/" + RouteConstants.AdminAreaPrefix + "/" + SlugFormatter.ToSlug(definition.Name) + "-users#/" + route); }
public async Task MapsBasicData() { var uniqueData = UNIQUE_PREFIX + nameof(MapsBasicData); var sluggedUniqueData = SlugFormatter.ToSlug(uniqueData); using var app = _appFactory.Create(); var rootDirectoryId = await app.TestData.PageDirectories().GetRootDirectoryIdAsync(); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var page1Id = await app.TestData.Pages().AddAsync(uniqueData + "1", directoryId); var page2Id = await app.TestData.Pages().AddAsync(uniqueData + "2", directoryId); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var page2 = await contentRepository .Pages() .GetById(page2Id) .AsRoute() .ExecuteAsync(); using (new AssertionScope()) { page2.Should().NotBeNull(); page2.PageId.Should().Be(page2Id); page2.FullUrlPath.Should().Be($"/{sluggedUniqueData}/{sluggedUniqueData}2"); page2.HasDraftVersion.Should().BeTrue(); page2.HasPublishedVersion.Should().BeFalse(); page2.Locale.Should().BeNull(); page2.PageId.Should().Be(page2Id); page2.PageType.Should().Be(PageType.Generic); page2.PublishStatus.Should().Be(PublishStatus.Unpublished); page2.PublishDate.Should().BeNull(); page2.LastPublishDate.Should().BeNull(); page2.Title.Should().Be(uniqueData + "2"); page2.UrlPath.Should().Be(sluggedUniqueData + "2"); page2.Versions.Should().HaveCount(1); page2.PageDirectory.Should().NotBeNull(); page2.PageDirectory.PageDirectoryId.Should().Be(directoryId); page2.PageDirectory.FullUrlPath.Should().Be($"/{sluggedUniqueData}"); page2.PageDirectory.LocaleVariations.Should().BeEmpty(); page2.PageDirectory.Name.Should().Be(uniqueData); page2.PageDirectory.ParentPageDirectoryId.Should().Be(rootDirectoryId); page2.PageDirectory.UrlPath.Should().Be(sluggedUniqueData); var version = page2.Versions.FirstOrDefault(); version.CreateDate.Should().NotBeDefault(); version.HasCustomEntityRegions.Should().BeFalse(); version.HasPageRegions.Should().BeTrue(); version.IsLatestPublishedVersion.Should().BeFalse(); version.PageTemplateId.Should().Be(app.SeededEntities.TestPageTemplate.PageTemplateId); version.Title.Should().Be(uniqueData + "2"); version.VersionId.Should().BePositive(); version.WorkFlowStatus.Should().Be(WorkFlowStatus.Draft); } }
//[OutputCache(Duration = 60 * 60 * 24 * 30, Location = OutputCacheLocation.Downstream)] public async Task <ActionResult> Image(int assetId, string fileName, string extension, int?cropSizeId) { var settings = ImageResizeSettings.ParseFromQueryString(Request.Query); var getImageQuery = new GetImageAssetRenderDetailsByIdQuery(assetId); var asset = await _queryExecutor.ExecuteAsync(getImageQuery); if (asset == null) { return(FileAssetNotFound("Image could not be found")); } if (SlugFormatter.ToSlug(asset.FileName) != fileName) { var url = _imageAssetRouteLibrary.ImageAsset(asset, settings); return(RedirectPermanent(url)); } var lastModified = DateTime.SpecifyKind(asset.UpdateDate, DateTimeKind.Utc); // Round the ticks down (see http://stackoverflow.com/a/1005222/486434), because http headers are only accurate to seconds, so get rounded down lastModified = lastModified.AddTicks(-(lastModified.Ticks % TimeSpan.TicksPerSecond)); if (!string.IsNullOrEmpty(Request.Headers["If-Modified-Since"])) { DateTime ifModifiedSince; if (DateTime.TryParse(Request.Headers["If-Modified-Since"], out ifModifiedSince) && lastModified <= ifModifiedSince.ToUniversalTime()) { return(StatusCode(304)); } } Stream stream = null; try { stream = await _resizedImageAssetFileService.GetAsync(asset, settings); } catch (FileNotFoundException ex) { // If the file exists but the file has gone missing, log and return a 404 _logger.LogError(0, ex, "Image Asset exists, but has no file: {0}", assetId); return(FileAssetNotFound("File not found")); } // Expire the image, so browsers always check with the server, but also send a last modified date so we can check for If-Modified-Since on the next request and return a 304 Not Modified. var headers = Response.GetTypedHeaders(); headers.Expires = DateTime.UtcNow.AddMonths(-1); headers.LastModified = lastModified; var contentType = _mimeTypeService.MapFromFileName("." + asset.Extension); return(new FileStreamResult(stream, contentType)); }
private IsCustomEntityUrlSlugUniqueQuery GetUniquenessQuery(UpdateCustomEntityDraftVersionCommand command, ICustomEntityDefinition definition, CustomEntityVersion dbVersion) { var query = new IsCustomEntityUrlSlugUniqueQuery(); query.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode; query.LocaleId = dbVersion.CustomEntity.LocaleId; query.UrlSlug = SlugFormatter.ToSlug(command.Title); query.CustomEntityId = command.CustomEntityId; return(query); }
private IsCustomEntityPathUniqueQuery GetUniquenessQuery(CustomEntityVersion dbVersion, ICustomEntityDefinition definition) { var query = new IsCustomEntityPathUniqueQuery(); query.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode; query.LocaleId = dbVersion.CustomEntity.LocaleId; query.UrlSlug = SlugFormatter.ToSlug(dbVersion.Title); query.CustomEntityId = dbVersion.CustomEntityId; return(query); }
public void RegisterRoutes(IEndpointRouteBuilder routeBuilder) { foreach (var definition in _customEntityDefinition) { var routePrefix = SlugFormatter.ToSlug(definition.NamePlural); routeBuilder .ForAdminController <CustomEntityModuleController>(routePrefix) .MapIndexRoute(new { Definition = definition }); } }