Documentations IPersistedGrantStore interface
Всем привет. Обращаюсь за советом. Я начинающий разработчик и ещё не совсем понял, как справляться с такого рода трудностями, может быть сможете подсказать. В моем задании необходимо реализовать интерфейс (IPersistedGrantStore). Там есть 5 методов, но что они делают я могу догадываться только из названий(GetAllAsync, GetAsync, RemoveAllAsync, RemoveAsync, StoreAsync). Реализовать, наверное, тоже смогу, но я не совсем понимаю что делает этот интерфейс и документации по нему я не нашел, пытаюсь разобраться сам, но пока что сложно идёт. Изначально мой подход был таков:
- найти документацию и разобраться что там происходит (не нашел)
- попробовать реализовать и под дебагером глянуть что там происходит (тут я остановился на реализации метода StoreAsync и не знаю как его реализовать)
- stackowerflow
Может быть можете подсказать где можно найти какую-то документацию по данному интерфейсу и в целом буду признателен, если поделитесь опытом, как вы решаете подобного рода задачи - когда необходимо реализовать то - непонятно что, так - непонятно как. Спасибо заранее. My code:
using IdentityServer4.Models;
using IdentityServer4.Stores;
using innRoad.Pms.Identity.Api.Core.Entities.Identity;
using innRoad.Pms.Identity.Api.Core.Static;
using ServiceStack.Data;
using ServiceStack.OrmLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ssssss
{
public class IdentityPersistedGrantStore : IPersistedGrantStore
{
private readonly IDbConnectionFactory _dbConnectionFactory;
public IdentityPersistedGrantStore(IDbConnectionFactory dbConnectionFactory)
{
_dbConnectionFactory = dbConnectionFactory;
}
public async Task<IEnumerable<PersistedGrant>> GetAllAsync(PersistedGrantFilter filter) //PersistedGrantEntity
{
IEnumerable<PersistedGrantEntity> persistedGrantEntities;
using (var identityConnection = await _dbConnectionFactory.OpenAsync(DbConnectionNames.Identity))
{
persistedGrantEntities = await identityConnection.LoadSelectAsync<PersistedGrantEntity>(x => x.ClientId == filter.ClientId);
}
return MapPersistedEntityToPersisted(persistedGrantEntities);
}
public async Task<PersistedGrant> GetAsync(string key)
{
IEnumerable<PersistedGrantEntity> persistedGrantEntities;
using (var identityConnection = await _dbConnectionFactory.OpenAsync(DbConnectionNames.Identity))
{
persistedGrantEntities = await identityConnection.LoadSelectAsync<PersistedGrantEntity>(x => x.Id == key);
}
return MapPersistedGrant(persistedGrantEntities.FirstOrDefault());
}
public async Task RemoveAllAsync(PersistedGrantFilter filter)
{
IEnumerable<PersistedGrantEntity> persistedGrantEntities;
using (var identityConnection = await _dbConnectionFactory.OpenAsync(DbConnectionNames.Identity))
{
persistedGrantEntities = await identityConnection.LoadSelectAsync<PersistedGrantEntity>(x => x.ClientId == filter.ClientId);
}
}
public async Task RemoveAsync(string key)
{
IEnumerable<PersistedGrantEntity> persistedGrantEntities;
using (var identityConnection = await _dbConnectionFactory.OpenAsync(DbConnectionNames.Identity))
{
persistedGrantEntities = await identityConnection.LoadSelectAsync<PersistedGrantEntity>(x => x.Id == key);
}
}
public Task StoreAsync(PersistedGrant grant)
{
throw new NotImplementedException();
}
private PersistedGrant MapPersistedGrant(PersistedGrantEntity persistedGrantEntity)
{
return new PersistedGrant
{
Key = persistedGrantEntity.Id,
ClientId = persistedGrantEntity.ClientId,
SessionId = persistedGrantEntity.SessionId,
ConsumedTime = persistedGrantEntity.ConsumedTime,
CreationTime = persistedGrantEntity.CreationTime,
Expiration = persistedGrantEntity.Expiration,
Data = persistedGrantEntity.Data,
Description = persistedGrantEntity.Description,
SubjectId = persistedGrantEntity.SubjectId,
Type = persistedGrantEntity.Type
};
}
private IEnumerable<PersistedGrant> MapPersistedEntityToPersisted(IEnumerable<PersistedGrantEntity> persistedGrantEntities)
{
List<PersistedGrant> persistedGrant = new List<PersistedGrant>();
foreach (var entityPersisted in persistedGrantEntities)
{
var persisted = new PersistedGrant
{
Key = entityPersisted.Id,
Type = entityPersisted.Type,
SubjectId = entityPersisted.SubjectId,
SessionId = entityPersisted.SessionId,
ClientId = entityPersisted.ClientId,
Description = entityPersisted.Description,
CreationTime = entityPersisted.CreationTime,
Expiration = entityPersisted.Expiration,
ConsumedTime = entityPersisted.ConsumedTime,
Data = entityPersisted.Data
};
persistedGrant.Add(persisted);
}
return persistedGrant;
}
}
}