Skip to content

Commit

Permalink
Iatsuta/58 di db session (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
iatsuta authored Jul 22, 2022
1 parent ee67d29 commit 1a10a21
Show file tree
Hide file tree
Showing 469 changed files with 3,534 additions and 6,202 deletions.
6 changes: 3 additions & 3 deletions src/Framework.AutomationCore/Framework.AutomationCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<PackageReference Include="ClosedXML.Report" Version="0.2.4" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="MartinCostello.SqlLocalDb" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="MartinCostello.SqlLocalDb" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="161.46521.71" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="161.47021.0" />
</ItemGroup>
</Project>
32 changes: 17 additions & 15 deletions src/Framework.Cap/Auth/CapAuthenticationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Encodings.Web;
using System;
using System.Text.Encodings.Web;
using System.Threading.Tasks;

using Framework.Authorization.BLL;
Expand All @@ -15,16 +16,23 @@ namespace Framework.Cap.Auth;
public class CapAuthenticationHandler<TBllContext> : AuthenticationHandler<AuthenticationSchemeOptions>
where TBllContext : IAuthorizationBLLContextContainer<IAuthorizationBLLContext>
{
private readonly IServiceEnvironment<TBllContext> environment;
private readonly TBllContext context;

private readonly IDBSession dbSession;

public CapAuthenticationHandler(
IServiceProvider rootServiceProvider,
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock,
IServiceEnvironment<TBllContext> environment)
: base(options, logger, encoder, clock) =>
this.environment = environment;
TBllContext context,
IDBSession dbSession)
: base(options, logger, encoder, clock)
{
this.context = context;
this.dbSession = dbSession;
}

protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
Expand All @@ -35,22 +43,16 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
return Task.FromResult(AuthenticateResult.NoResult());
}

var isAdmin = this.environment
.GetContextEvaluator()
.Evaluate(
DBSessionMode.Read,
z => z.Authorization.Logics.BusinessRole.HasAdminRole());
this.dbSession.AsReadOnly();

var isAdmin = this.context.Authorization.Logics.BusinessRole.HasAdminRole();

if (!isAdmin)
{
return Task.FromResult(AuthenticateResult.NoResult());
}

var authenticationTicket = new AuthenticationTicket(
httpContext.User,
DependencyInjections
.CapAuthenticationScheme);
var authenticationTicket = new AuthenticationTicket(httpContext.User, DependencyInjections.CapAuthenticationScheme);
return Task.FromResult(AuthenticateResult.Success(authenticationTicket));

}
}
6 changes: 3 additions & 3 deletions src/Framework.Cap/Framework.Cap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Compile Include="..\__SolutionItems\CommonAssemblyInfo.cs" Link="Properties\CommonAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="6.0.1" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="6.0.1" />
<PackageReference Include="DotNetCore.CAP.SqlServer" Version="6.0.1" />
<PackageReference Include="DotNetCore.CAP" Version="6.1.0" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="6.1.0" />
<PackageReference Include="DotNetCore.CAP.SqlServer" Version="6.1.0" />
<PackageReference Include="Savorboard.CAP.InMemoryMessageQueue" Version="6.0.0" />
<PackageReference Include="MediatR" Version="10.0.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Framework.Core.Delegate/Framework.Core.Delegate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Framework.Core.String/Framework.Core.String.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/Framework.Core.Tests.Unit/Framework.Core.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="FluentAssertions" Version="6.5.1" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.15.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.15.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="OpenCover" Version="4.7.1221" />
<PackageReference Include="ReportGenerator" Version="5.0.4" />
<PackageReference Include="ReportGenerator" Version="5.1.9" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\__SolutionItems\CommonAssemblyInfo.cs" Link="Properties\CommonAssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions src/Framework.Core/Extensions/CoreExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ from property in (member as PropertyInfo).ToMaybe()
return request.GetValue(() => new System.ArgumentException("not property expression", nameof(expr)));
}

public static FieldInfo GetField<TSource, TResult>(this Expression<Func<TSource, TResult>> expr)
{
if (expr == null) throw new ArgumentNullException(nameof(expr));

var request = from member in expr.Body.GetMember()

from field in (member as FieldInfo).ToMaybe()

select field;

return request.GetValue(() => new System.ArgumentException("not field expression", nameof(expr)));
}

/// <summary>
/// Получение полного пути из Expression
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Framework.Core/Framework.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Compile Include="..\__SolutionItems\CommonAssemblyInfo.cs" Link="Properties\CommonAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/Framework.Core/MessageSender/IMessageSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public interface IMessageSender<in TMessage>
/// Sends message
/// </summary>
/// <param name="message">Message to send</param>
/// <param name="sendMessageMode">Message send mode</param>
void Send(TMessage message, TransactionMessageMode sendMessageMode = TransactionMessageMode.Auto);
void Send(TMessage message);
}
}
10 changes: 5 additions & 5 deletions src/Framework.Core/MessageSender/MessageSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Framework.Core
{
public abstract class MessageSender<TMessage> : IMessageSender<TMessage>
{
public abstract void Send(TMessage message, TransactionMessageMode transactionMessageMode);
public abstract void Send(TMessage message);


public static readonly IMessageSender<TMessage> Empty = new EmptyMessageSender();
Expand All @@ -19,7 +19,7 @@ public static IMessageSender<TMessage> Create(TextWriter writer)
{
if (writer == null) throw new ArgumentNullException(nameof(writer));

return Empty.WithWrite((obj, transactionMessageMode) => writer.WriteLine(obj));
return Empty.WithWrite((obj) => writer.WriteLine(obj));
}

private class EmptyMessageSender : MessageSender<TMessage>
Expand All @@ -29,7 +29,7 @@ public EmptyMessageSender()

}

public override void Send(TMessage message, TransactionMessageMode transactionMessageMode)
public override void Send(TMessage message)
{

}
Expand All @@ -42,10 +42,10 @@ public NotImplementedMessageSender()

}

public override void Send(TMessage message, TransactionMessageMode transactionMessageMode)
public override void Send(TMessage message)
{
throw new NotImplementedException();
}
}
}
}
}
28 changes: 14 additions & 14 deletions src/Framework.Core/MessageSender/MessageSenderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static IMessageSender<TNewSource> OverrideInput<TBaseSource, TNewSource>(
if (messageSender == null) throw new ArgumentNullException(nameof(messageSender));
if (selector == null) throw new ArgumentNullException(nameof(selector));

return new ActionMessageSender<TNewSource>((newSource, transactionMode)=> messageSender.Send(selector(newSource), transactionMode));
return new ActionMessageSender<TNewSource>((newSource) => messageSender.Send(selector(newSource)));
}


Expand All @@ -19,13 +19,13 @@ public static IMessageSender<TMessage> WithCatchFault<TMessage>(this IMessageSen
{
if (messageSender == null) throw new ArgumentNullException(nameof(messageSender));

return new ActionMessageSender<TMessage>((message, transactionMessageMode) =>
return new ActionMessageSender<TMessage>((message) =>
{
if (message == null) throw new ArgumentNullException(nameof(message));

try
{
messageSender.Send(message, transactionMessageMode);
messageSender.Send(message);
}
catch
{
Expand All @@ -34,48 +34,48 @@ public static IMessageSender<TMessage> WithCatchFault<TMessage>(this IMessageSen
});
}

public static IMessageSender<TMessage> WithWrite<TMessage>(this IMessageSender<TMessage> messageSender, Action<TMessage, TransactionMessageMode> write)
public static IMessageSender<TMessage> WithWrite<TMessage>(this IMessageSender<TMessage> messageSender, Action<TMessage> write)
{
if (messageSender == null) throw new ArgumentNullException(nameof(messageSender));
if (write == null) throw new ArgumentNullException(nameof(write));

return new ActionMessageSender<TMessage>((message, transactionMessageMode) =>
return new ActionMessageSender<TMessage>((message) =>
{
if (message == null) throw new ArgumentNullException(nameof(message));

write(message, transactionMessageMode);
write(message);

messageSender.Send(message, transactionMessageMode);
messageSender.Send(message);
});
}

public static IMessageSender<TMessage> WithTrace<TMessage>(this IMessageSender<TMessage> messageSender)
{
if (messageSender == null) throw new ArgumentNullException(nameof(messageSender));

return messageSender.WithWrite((message, transactionMessageMode) => System.Diagnostics.Trace.Write(
$"Sending: mode:{transactionMessageMode} message: {message}"));
return messageSender.WithWrite((message) => System.Diagnostics.Trace.Write(
$"Sending: message: {message}"));
}



private class ActionMessageSender<TMessage> : IMessageSender<TMessage>
{
private readonly Action<TMessage, TransactionMessageMode> _sendAction;
private readonly Action<TMessage> _sendAction;


public ActionMessageSender(Action<TMessage, TransactionMessageMode> sendAction)
public ActionMessageSender(Action<TMessage> sendAction)
{
if (sendAction == null) throw new ArgumentNullException(nameof(sendAction));

this._sendAction = sendAction;
}


public void Send(TMessage message, TransactionMessageMode transactionMessageMode)
public void Send(TMessage message)
{
this._sendAction(message, transactionMessageMode);
this._sendAction(message);
}
}
}
}
}
26 changes: 0 additions & 26 deletions src/Framework.Core/MessageSender/TransactionMessageMode.cs

This file was deleted.

Loading

0 comments on commit 1a10a21

Please sign in to comment.