mirror of https://github.com/Squidex/squidex.git
8 changed files with 62 additions and 78 deletions
@ -1,24 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using MongoDB.Bson; |
|
||||
using MongoDB.Bson.Serialization.Attributes; |
|
||||
|
|
||||
namespace Squidex.Domain.Users.MongoDb |
|
||||
{ |
|
||||
public sealed class MongoXmlDocument |
|
||||
{ |
|
||||
[BsonId] |
|
||||
[BsonElement] |
|
||||
[BsonRepresentation(BsonType.String)] |
|
||||
public string Id { get; set; } |
|
||||
|
|
||||
[BsonRequired] |
|
||||
[BsonElement] |
|
||||
public string Xml { get; set; } |
|
||||
} |
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Xml.Linq; |
|
||||
using Microsoft.AspNetCore.DataProtection.Repositories; |
|
||||
using MongoDB.Bson; |
|
||||
using MongoDB.Driver; |
|
||||
using Squidex.Infrastructure.MongoDb; |
|
||||
|
|
||||
namespace Squidex.Domain.Users.MongoDb |
|
||||
{ |
|
||||
public sealed class MongoXmlRepository : MongoRepositoryBase<MongoXmlDocument>, IXmlRepository |
|
||||
{ |
|
||||
public MongoXmlRepository(IMongoDatabase database) |
|
||||
: base(database) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
protected override string CollectionName() |
|
||||
{ |
|
||||
return "Identity_XmlRepository"; |
|
||||
} |
|
||||
|
|
||||
public IReadOnlyCollection<XElement> GetAllElements() |
|
||||
{ |
|
||||
var elements = Collection.Find(new BsonDocument()).ToList(); |
|
||||
|
|
||||
return elements.Select(x => XElement.Parse(x.Xml)).ToList(); |
|
||||
} |
|
||||
|
|
||||
public void StoreElement(XElement element, string friendlyName) |
|
||||
{ |
|
||||
Collection.UpdateOne(x => x.Id == friendlyName, |
|
||||
Update.Set(x => x.Xml, element.ToString()), |
|
||||
Upsert); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,53 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Xml.Linq; |
||||
|
using Microsoft.AspNetCore.DataProtection.Repositories; |
||||
|
using Squidex.Infrastructure; |
||||
|
using Squidex.Infrastructure.States; |
||||
|
using Squidex.Infrastructure.Tasks; |
||||
|
|
||||
|
namespace Squidex.Domain.Users |
||||
|
{ |
||||
|
public sealed class DefaultXmlRepository : IXmlRepository |
||||
|
{ |
||||
|
private readonly ISnapshotStore<State, string> store; |
||||
|
|
||||
|
[CollectionName("XmlRepository")] |
||||
|
public sealed class State |
||||
|
{ |
||||
|
public string Xml { get; set; } |
||||
|
} |
||||
|
|
||||
|
public DefaultXmlRepository(ISnapshotStore<State, string> store) |
||||
|
{ |
||||
|
Guard.NotNull(store, nameof(store)); |
||||
|
|
||||
|
this.store = store; |
||||
|
} |
||||
|
|
||||
|
public IReadOnlyCollection<XElement> GetAllElements() |
||||
|
{ |
||||
|
var result = new List<XElement>(); |
||||
|
|
||||
|
store.ReadAllAsync((state, version) => |
||||
|
{ |
||||
|
result.Add(XElement.Parse(state.Xml)); |
||||
|
|
||||
|
return TaskHelper.Done; |
||||
|
}).Wait(); |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public void StoreElement(XElement element, string friendlyName) |
||||
|
{ |
||||
|
store.WriteAsync(friendlyName, new State { Xml = element.ToString() }, EtagVersion.Any, EtagVersion.Any).Wait(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue