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.
61 lines
1.7 KiB
61 lines
1.7 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Xml.Linq;
|
|
using Microsoft.AspNetCore.DataProtection.Repositories;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.States;
|
|
|
|
namespace Squidex.Domain.Users
|
|
{
|
|
public sealed class DefaultXmlRepository : IXmlRepository
|
|
{
|
|
private readonly ISnapshotStore<State> store;
|
|
|
|
[CollectionName("Identity_Xml")]
|
|
public sealed class State
|
|
{
|
|
public string Xml { get; set; }
|
|
|
|
public State()
|
|
{
|
|
}
|
|
|
|
public State(XElement xml)
|
|
{
|
|
Xml = xml.ToString();
|
|
}
|
|
|
|
public XElement ToXml()
|
|
{
|
|
return XElement.Parse(Xml);
|
|
}
|
|
}
|
|
|
|
public DefaultXmlRepository(ISnapshotStore<State> store)
|
|
{
|
|
this.store = store;
|
|
}
|
|
|
|
public IReadOnlyCollection<XElement> GetAllElements()
|
|
{
|
|
return GetAllElementsAsync().Result;
|
|
}
|
|
|
|
public void StoreElement(XElement element, string friendlyName)
|
|
{
|
|
var state = new State(element);
|
|
|
|
store.WriteAsync(new SnapshotWriteJob<State>(DomainId.Create(friendlyName), state, 0));
|
|
}
|
|
|
|
private async Task<IReadOnlyCollection<XElement>> GetAllElementsAsync()
|
|
{
|
|
return await store.ReadAllAsync().Select(x => x.Value.ToXml()).ToListAsync();
|
|
}
|
|
}
|
|
}
|
|
|