* Run code cleanup * Run dotnet format * Start manual fixes * Manual fixing of warnings * Fix nullability in columnalias * Fix tests * Fix up after merge * Start updating after review * Update editorconfig to contain new static & const rules * Fix up editorconfig to not contain duplicate rules * Fix up static member names * Fix up according to review * Update src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.DistributedCache.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Examine/ContentIndexPopulator.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Examine/ContentIndexPopulator.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Examine/PublishedContentIndexPopulator.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Extensions/InstanceIdentifiableExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/HostedServices/ReportSiteTask.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Logging/Serilog/LoggerConfigExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Logging/Serilog/LoggerConfigExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Macros/MacroTagParser.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Macros/MacroTagParser.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Macros/MacroTagParser.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Migrations/Expressions/Alter/Table/IAlterTableColumnOptionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Migrations/Upgrade/V_10_0_0/AddMemberPropertiesAsColumns.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/ModelsBuilder/Building/TextBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/ModelsBuilder/Building/TextBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/ModelsBuilder/Building/TextBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/ModelsBuilder/Building/TextBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/ModelsBuilder/Building/TextBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/ModelsBuilder/Building/TextBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/ModelsBuilder/Building/TextBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Dtos/ExternalLoginDto.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/AccessMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/AuditEntryMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/MediaMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/MemberMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/PropertyGroupMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/PropertyGroupMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/PropertyTypeMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/PropertyTypeMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/RelationTypeMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Mappers/RelationTypeMapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/NPocoMapperCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Querying/ExpressionVisitorBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ExternalLoginRepository.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix [..] to substring * Fix after merge with 10/dev * Fox ContentValueSetValidator.cs * Update LoggerConfigExtensions Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
143 lines
4.0 KiB
C#
143 lines
4.0 KiB
C#
using System.Text;
|
|
using Umbraco.Cms.Core.IO;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
|
using Umbraco.Extensions;
|
|
|
|
namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
|
|
|
|
internal class PartialViewRepository : FileRepository<string, IPartialView>, IPartialViewRepository
|
|
{
|
|
public PartialViewRepository(FileSystems fileSystems)
|
|
: base(fileSystems.PartialViewsFileSystem)
|
|
{
|
|
}
|
|
|
|
protected PartialViewRepository(IFileSystem? fileSystem)
|
|
: base(fileSystem)
|
|
{
|
|
}
|
|
|
|
protected virtual PartialViewType ViewType => PartialViewType.PartialView;
|
|
|
|
public override IPartialView? Get(string? id)
|
|
{
|
|
if (FileSystem is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
// get the relative path within the filesystem
|
|
// (though... id should be relative already)
|
|
var path = FileSystem.GetRelativePath(id!);
|
|
|
|
if (FileSystem.FileExists(path) == false)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
// content will be lazy-loaded when required
|
|
DateTime created = FileSystem.GetCreated(path).UtcDateTime;
|
|
DateTime updated = FileSystem.GetLastModified(path).UtcDateTime;
|
|
|
|
// var content = GetFileContent(path);
|
|
var view = new PartialView(ViewType, path, file => GetFileContent(file.OriginalPath))
|
|
{
|
|
// id can be the hash
|
|
Id = path.GetHashCode(),
|
|
Key = path.EncodeAsGuid(),
|
|
|
|
// Content = content,
|
|
CreateDate = created,
|
|
UpdateDate = updated,
|
|
VirtualPath = FileSystem.GetUrl(id),
|
|
};
|
|
|
|
// reset dirty initial properties (U4-1946)
|
|
view.ResetDirtyProperties(false);
|
|
|
|
return view;
|
|
}
|
|
|
|
public override void Save(IPartialView entity)
|
|
{
|
|
var partialView = entity as PartialView;
|
|
if (partialView != null)
|
|
{
|
|
partialView.ViewType = ViewType;
|
|
}
|
|
|
|
base.Save(entity);
|
|
|
|
// ensure that from now on, content is lazy-loaded
|
|
if (partialView != null && partialView.GetFileContent == null)
|
|
{
|
|
partialView.GetFileContent = file => GetFileContent(file.OriginalPath);
|
|
}
|
|
}
|
|
|
|
public override IEnumerable<IPartialView> GetMany(params string[]? ids)
|
|
{
|
|
// ensure they are de-duplicated, easy win if people don't do this as this can cause many excess queries
|
|
ids = ids?.Distinct().ToArray();
|
|
|
|
if (ids?.Any() ?? false)
|
|
{
|
|
foreach (var id in ids)
|
|
{
|
|
IPartialView? partialView = Get(id);
|
|
if (partialView is not null)
|
|
{
|
|
yield return partialView;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
IEnumerable<string> files = FindAllFiles(string.Empty, "*.*");
|
|
foreach (var file in files)
|
|
{
|
|
IPartialView? partialView = Get(file);
|
|
if (partialView is not null)
|
|
{
|
|
yield return partialView;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public Stream GetFileContentStream(string filepath)
|
|
{
|
|
if (FileSystem?.FileExists(filepath) == false)
|
|
{
|
|
return Stream.Null;
|
|
}
|
|
|
|
try
|
|
{
|
|
return FileSystem?.OpenFile(filepath) ?? Stream.Null;
|
|
}
|
|
catch
|
|
{
|
|
return Stream.Null; // deal with race conds
|
|
}
|
|
}
|
|
|
|
public void SetFileContent(string filepath, Stream content) => FileSystem?.AddFile(filepath, content, true);
|
|
|
|
/// <summary>
|
|
/// Gets a stream that is used to write to the file
|
|
/// </summary>
|
|
/// <param name="content"></param>
|
|
/// <returns></returns>
|
|
/// <remarks>
|
|
/// This ensures the stream includes a utf8 BOM
|
|
/// </remarks>
|
|
protected override Stream GetContentStream(string content)
|
|
{
|
|
var data = Encoding.UTF8.GetBytes(content);
|
|
var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
|
|
return new MemoryStream(withBom);
|
|
}
|
|
}
|