Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace Framework.Application.Events;
using System.Collections.Immutable;

public record EventModel(Type DomainType, IReadOnlyList<Guid> DomainObjectIdents, EventOperation EventOperation, long? Revision);
namespace Framework.Application.Events;

public record EventModel(Type DomainType, ImmutableArray<Guid> DomainObjectIdents, EventOperation EventOperation, long? Revision);
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Framework.Core.TypeResolving;
using Framework.Core;
using Framework.Core.TypeResolving;

namespace Framework.Application.Events;

public interface IEventSystem
{
ITypeResolver<string> TypeResolver { get; }
ITypeResolver<TypeNameIdentity> TypeResolver { get; }

IDomainObjectEventMetadata DomainObjectEventMetadata { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Framework.BLL.Domain.IdentityObject;
namespace Framework.Application.Domain;

public interface IVersionObject<out TVersion>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ public Task<TResult> EvaluateAsync<TResult>(
/// <summary>
/// Отчистка списка нотифицаций
/// </summary>
public override void ClearNotifications() => this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove)));
public override void ClearNotifications() =>
this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove)));

/// <summary>
/// Получение списка модификаций
/// </summary>
/// <returns></returns>
protected virtual List<ObjectModificationInfoDTO<Guid>> GetModifications() =>
this.EvaluateRead(
context =>

this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.GetFullList()
.ToList(
mod => new ObjectModificationInfoDTO<Guid>
{
Identity = mod.DomainObjectId,
ModificationType = mod.Type,
Revision = mod.Revision,
TypeInfoDescription = new TypeInfoDescriptionDTO(mod.DomainType)
}));
this.EvaluateRead(context =>

this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.GetFullList()
.ToList(mod => new ObjectModificationInfoDTO<Guid>
{
Identity = mod.DomainObjectId,
ModificationType = mod.Type,
Revision = mod.Revision,
TypeInfoDescription = new TypeInfoDescriptionDTO { Name = mod.DomainType.Name, Namespace = mod.DomainType.Namespace }
}));

/// <summary>
/// Отчистка списка модификаций
/// </summary>
protected virtual void ClearModifications() => this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove)));
protected virtual void ClearModifications() =>
this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove)));

/// <summary>
/// Отчистка интеграционных евентов
Expand All @@ -74,7 +74,8 @@ public override void ClearIntegrationEvents()
});
}

protected int GetIntegrationEventCount() => this.EvaluateRead(ctx => ctx.ServiceProvider.GetRequiredService<IRepositoryFactory<DomainObjectEvent>>().Create().GetQueryable().Count());
protected int GetIntegrationEventCount() =>
this.EvaluateRead(ctx => ctx.ServiceProvider.GetRequiredService<IRepositoryFactory<DomainObjectEvent>>().Create().GetQueryable().Count());


/// <summary>
Expand All @@ -85,18 +86,16 @@ protected virtual List<T> GetIntegrationEvents<T>(string queueTag = "default")
{
var serializeType = typeof(T).FullName;

return this.EvaluateRead(
context => this.GetConfigurationBLLContext(context).Logics.DomainObjectEvent
.GetListBy(v => v.SerializeType == serializeType && v.QueueTag == queueTag)
.ToList(obj => DataContractSerializerHelper.Deserialize<T>(obj.SerializeData)));
return this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectEvent
.GetListBy(v => v.SerializeType == serializeType && v.QueueTag == queueTag)
.ToList(obj => DataContractSerializerHelper.Deserialize<T>(obj.SerializeData)));
}

/// <summary>
/// Получение списка нотификаций
/// </summary>
/// <returns></returns>
protected virtual List<NotificationEventDTO> GetNotifications() =>
this.EvaluateRead(
context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.GetFullList()
.ToList(obj => DataContractSerializerHelper.Deserialize<NotificationEventDTO>(obj.SerializeData)));
this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.GetFullList()
.ToList(obj => DataContractSerializerHelper.Deserialize<NotificationEventDTO>(obj.SerializeData)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class StreamExtensions
{
public static void Save(this Stream stream, string folder, string fileName = null, string extension = "xlsx")
public static void Save(this Stream stream, string folder, string? fileName = null, string extension = "xlsx")
{
fileName = fileName != null ? $"{fileName}.{extension}" : $"report_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.{extension}";
var filePath = Path.Combine(folder, fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Framework.AutomationCore.Utils.DatabaseUtils;

public static partial class CoreDatabaseUtil
{
public static void ExecuteSqlFromFolder(string connectionString, string folder, string initialCatalog = null)
public static void ExecuteSqlFromFolder(string connectionString, string folder, string? initialCatalog = null)
{
string[] filePaths;

Expand Down Expand Up @@ -114,7 +114,7 @@ public static void ExecuteSql(SqlConnection connection, string sqlFileOrText)
}
}

public static void ExecuteSql(string connectionString, string sqlFileOrText, string initialCatalog = null)
public static void ExecuteSql(string connectionString, string sqlFileOrText, string? initialCatalog = null)
{
var builder = new SqlConnectionStringBuilder(connectionString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public DatabaseItem(
string connectionString,
string databaseCollation,
string dbDataDirectory,
string initialCatalog = null,
string? initialCatalog = null,
bool randomizeDatabaseName = false)
{
this.DbDataDirectory = dbDataDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using Framework.Application.Domain;
using Framework.BLL.Domain.Exceptions;
using Framework.BLL.Domain.IdentityObject;
using Framework.BLL.Domain.Persistent.IdentityObject;
using Framework.Core;

Expand All @@ -15,16 +14,6 @@ namespace Framework.BLL;

public static class DefaultDomainBLLBaseExtensions
{
public static TDomainObject? GetById<TPersistentDomainObjectBase, TDomainObject>(this IDefaultDomainBLLQueryBase<TPersistentDomainObjectBase, TDomainObject, Guid> bll, string id)
where TDomainObject : class, TPersistentDomainObjectBase
where TPersistentDomainObjectBase : class, IIdentityObject<Guid>
{
if (bll == null) throw new ArgumentNullException(nameof(bll));
if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id));

return bll.GetById(Guid.Parse(id), true);
}

public static TDomainObject? GetByIdOrCreate<TPersistentDomainObjectBase, TDomainObject, TIdent>(this IDefaultDomainBLLQueryBase<TPersistentDomainObjectBase, TDomainObject, TIdent> bll, TIdent id)
where TDomainObject : class, TPersistentDomainObjectBase, new()
where TPersistentDomainObjectBase : class, IIdentityObject<TIdent>
Expand Down Expand Up @@ -102,22 +91,6 @@ public static class DefaultDomainBLLBaseExtensions
where TDomainObject : class, TPersistentDomainObjectBase, ICodeObject<TCode> =>
bll.GetByCode(code, throwOnNotFound, FetchRule<TDomainObject>.Empty);

public static TDomainObject? GetByDomainType<TDomainObject>(this IBLLQueryBase<TDomainObject> bll, IDomainType domainType, bool throwOnNotFound = true)
where TDomainObject : class, IDomainType
{
if (bll == null) throw new ArgumentNullException(nameof(bll));
if (domainType == null) throw new ArgumentNullException(nameof(domainType));

var result = bll.GetObjectBy(domainObject => domainObject.Name == domainType.Name && domainObject.NameSpace == domainType.NameSpace);

if (null == result && throwOnNotFound)
{
throw new BusinessLogicException($"{typeof(TDomainObject).Name} with name = {domainType.Name} and namespace = {domainType.NameSpace} not found");
}

return result;
}

public static void Insert<TDomainObject, TIdent>(this IDefaultDomainBLLBase<TDomainObject, TIdent> bll, TDomainObject domainObject)
where TDomainObject : class, IIdentityObject<TIdent>
{
Expand Down
14 changes: 14 additions & 0 deletions src/BLL/Framework.BLL.Abstractions/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Framework.BLL.Extensions;

public static class TypeExtensions
{
internal static bool SafeEquals(this Type t1, Type t2)
{
return t1.IsGenericTypeDefinition == t2.IsGenericTypeDefinition && t1 == t2;
}

internal static bool SafeIsAssignableFrom(this Type t1, Type t2)
{
return t1.SafeEquals(t2) || t1.IsAssignableFrom(t2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\..\Database\Framework.Database.Legacy.Domain\Framework.Database.Legacy.Domain.csproj" />
<ProjectReference Include="..\..\ExtendedMetadata\Framework.ExtendedMetadata.Abstractions\Framework.ExtendedMetadata.Abstractions.csproj" />
<ProjectReference Include="..\Framework.BLL.Domain\Framework.BLL.Domain.csproj" />

<ProjectReference Include="..\..\Application\Framework.Application.Abstractions\Framework.Application.Abstractions.csproj" />
Expand Down
6 changes: 0 additions & 6 deletions src/BLL/Framework.BLL.Abstractions/IPathBLL.cs

This file was deleted.

11 changes: 4 additions & 7 deletions src/BLL/Framework.BLL.Abstractions/ISecurityBLLContext.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using Framework.Application.Domain;
using SecuritySystem.Providers;

namespace Framework.BLL;

public interface ISecurityBLLContext<in TPersistentDomainObjectBase, TIdent> :

IDefaultBLLContext<TPersistentDomainObjectBase, TIdent>

where TPersistentDomainObjectBase : class, IIdentityObject<TIdent>
{
ISecurityProvider<TDomainObject> GetDisabledSecurityProvider<TDomainObject>()
where TDomainObject : TPersistentDomainObjectBase;
}
where TPersistentDomainObjectBase : class, IIdentityObject<TIdent>;


public interface ISecurityBLLContext<out TAuthorizationBLLContext, in TPersistentDomainObjectBase, TIdent> :

public interface ISecurityBLLContext<out TAuthorizationBLLContext, in TPersistentDomainObjectBase, TIdent> : ISecurityBLLContext<TPersistentDomainObjectBase, TIdent>,
ISecurityBLLContext<TPersistentDomainObjectBase, TIdent>,

IAuthorizationBLLContextContainer<TAuthorizationBLLContext>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Framework.Core;
using Framework.Core.TypeResolving;

namespace Framework.BLL;

public interface ITargetSystemTypeResolverContainer
{
ITypeResolver<TypeNameIdentity> TypeResolver { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Immutable;
using System.Reflection;

using Framework.BLL.Domain.Persistent.Attributes;
using Framework.Core;

namespace Framework.BLL.Services;

public interface IPropertyPathService
{
PropertyPath? TryGetPropertyPath<TAttribute>(PropertyInfo property, bool recurse)
where TAttribute : Attribute, IPathAttribute;

ImmutableArray<PropertyPath> GetPropertyPaths<TAttribute>(PropertyInfo property)
where TAttribute : Attribute, IPathAttribute;

PropertyPath? TryGetExpandPath(PropertyInfo property);

PropertyPath GetExpandPathOrSelf(PropertyInfo property);

PropertyPath WithExpand(PropertyPath propertyPath);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Framework.BLL.Domain.TargetSystem;

namespace Framework.BLL.Services;

public interface ITargetSystemInfoService
{
PersistentTargetSystemInfo GetPersistentTargetSystemInfo(Type domainType);
}
84 changes: 84 additions & 0 deletions src/BLL/Framework.BLL.Abstractions/Services/PropertyPathService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Collections.Concurrent;
using System.Collections.Immutable;

using System.Reflection;

using CommonFramework;

using Framework.BLL.Domain.Persistent.Attributes;
using Framework.BLL.Extensions;
using Framework.Core;
using Framework.ExtendedMetadata;

namespace Framework.BLL.Services;

public class PropertyPathService(IMetadataProxyProvider metadataProxyProvider) : IPropertyPathService
{
private readonly ConcurrentDictionary<Type, ConcurrentDictionary<Tuple<PropertyInfo, bool>, PropertyPath?>> singlePathCache = [];

private readonly ConcurrentDictionary<Type, ConcurrentDictionary<PropertyInfo, ImmutableArray<PropertyPath>>> manyPathCache = [];

private readonly ConcurrentDictionary<PropertyInfo, PropertyPath?> expandPathCache = [];

public PropertyPath? TryGetPropertyPath<TAttribute>(PropertyInfo property, bool recurse)
where TAttribute : Attribute, IPathAttribute =>

this.singlePathCache
.GetOrAdd(typeof(TAttribute), _ => [])
.GetOrAdd(
Tuple.Create(property, recurse),
_ =>
{
var pathRequest =

from pathAttribute in metadataProxyProvider.Wrap(property).GetCustomAttribute<TAttribute>().ToMaybe()

let basePath = pathAttribute.GetPropertyPath(property.ReflectedType!)

select recurse && !basePath.SequenceEqual([property])
? new PropertyPath(
basePath.SelectMany(prop => (IEnumerable<PropertyInfo>?)this.TryGetPropertyPath<TAttribute>(prop, true) ?? [prop]))
: basePath;

return pathRequest.GetValueOrDefault();
});

public ImmutableArray<PropertyPath> GetPropertyPaths<TAttribute>(PropertyInfo property)
where TAttribute : Attribute, IPathAttribute =>

this.manyPathCache
.GetOrAdd(typeof(TAttribute), _ => [])
.GetOrAdd(
property,
_ =>
[
.. metadataProxyProvider.Wrap(property).GetCustomAttributes<TAttribute>()
.Select(pathAttribute => pathAttribute.GetPropertyPath(property.ReflectedType!))
]);

public PropertyPath? TryGetExpandPath(PropertyInfo property) =>
this.expandPathCache.GetOrAdd(
property,
_ =>
{
var expandPath = this.TryGetPropertyPath<ExpandPathAttribute>(property, true);

if (expandPath is not null)
{
var isValid = expandPath.IsEmpty
? property.PropertyType.SafeEquals(property.ReflectedType!)
: property.PropertyType.SafeIsAssignableFrom(expandPath.Last().PropertyType);

if (!isValid)
{
throw new Exception($"Property \"{property.Name}\" of Type \"{property.ReflectedType!.Name}\" has invalid ExpandPath");
}
}

return expandPath;
});

public PropertyPath GetExpandPathOrSelf(PropertyInfo property) => this.TryGetExpandPath(property) ?? new PropertyPath([property]);

public PropertyPath WithExpand(PropertyPath propertyPath) => propertyPath.SelectMany(this.GetExpandPathOrSelf).ToPropertyPath();
}
Loading
Loading