mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Orleans;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.Log;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Contents.Queries
|
|
{
|
|
public sealed class ContentLoader : IContentLoader
|
|
{
|
|
private readonly IGrainFactory grainFactory;
|
|
|
|
public ContentLoader(IGrainFactory grainFactory)
|
|
{
|
|
Guard.NotNull(grainFactory, nameof(grainFactory));
|
|
|
|
this.grainFactory = grainFactory;
|
|
}
|
|
|
|
public async Task<IContentEntity> GetAsync(Guid id, long version)
|
|
{
|
|
using (Profiler.TraceMethod<ContentLoader>())
|
|
{
|
|
var grain = grainFactory.GetGrain<IContentGrain>(id);
|
|
|
|
var content = await grain.GetStateAsync(version);
|
|
|
|
if (content.Value == null || (version > EtagVersion.Any && content.Value.Version != version))
|
|
{
|
|
throw new DomainObjectNotFoundException(id.ToString(), typeof(IContentEntity));
|
|
}
|
|
|
|
return content.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|