mirror of https://github.com/abpframework/abp.git
47 changed files with 459 additions and 776 deletions
@ -0,0 +1,3 @@ |
|||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
|
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
|
</Weavers> |
||||
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
||||
|
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
||||
|
<xs:element name="Weavers"> |
||||
|
<xs:complexType> |
||||
|
<xs:all> |
||||
|
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
||||
|
<xs:complexType> |
||||
|
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:all> |
||||
|
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
||||
|
<xs:annotation> |
||||
|
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
||||
|
</xs:annotation> |
||||
|
</xs:attribute> |
||||
|
</xs:complexType> |
||||
|
</xs:element> |
||||
|
</xs:schema> |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System; |
||||
|
using System.Globalization; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting |
||||
|
{ |
||||
|
public static class AbpServerHostBuilderExtensions |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
||||
|
|
||||
|
<Import Project="..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net5.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.AspNetCore.Components.Server</AssemblyName> |
||||
|
<PackageId>Volo.Abp.AspNetCore.Components.Server</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc.Client.Common\Volo.Abp.AspNetCore.Mvc.Client.Common.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.UI\Volo.Abp.UI.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.AspNetCore.Components\Volo.Abp.AspNetCore.Components.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(MicrosoftPackageVersion)" /> |
||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="$(MicrosoftPackageVersion)" /> |
||||
|
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,185 @@ |
|||||
|
var abp = abp || {}; |
||||
|
(function () { |
||||
|
abp.utils = abp.utils || {}; |
||||
|
|
||||
|
// DOM READY /////////////////////////////////////////////////////
|
||||
|
|
||||
|
abp.domReady = function (fn) { |
||||
|
if (document.readyState === "complete" || document.readyState === "interactive") { |
||||
|
setTimeout(fn, 1); |
||||
|
} else { |
||||
|
document.addEventListener("DOMContentLoaded", fn); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// COOKIES ///////////////////////////////////////////////////////
|
||||
|
|
||||
|
/** |
||||
|
* Sets a cookie value for given key. |
||||
|
* This is a simple implementation created to be used by ABP. |
||||
|
* Please use a complete cookie library if you need. |
||||
|
* @param {string} key |
||||
|
* @param {string} value |
||||
|
* @param {string} expireDate (optional). If not specified the cookie will expire at the end of session. |
||||
|
* @param {string} path (optional) |
||||
|
* @param {bool} secure (optional) |
||||
|
*/ |
||||
|
abp.utils.setCookieValue = function (key, value, expireDate, path, secure) { |
||||
|
var cookieValue = encodeURIComponent(key) + '='; |
||||
|
if (value) { |
||||
|
cookieValue = cookieValue + encodeURIComponent(value); |
||||
|
} |
||||
|
|
||||
|
if (expireDate) { |
||||
|
cookieValue = cookieValue + "; expires=" + expireDate; |
||||
|
} |
||||
|
|
||||
|
if (path) { |
||||
|
cookieValue = cookieValue + "; path=" + path; |
||||
|
} |
||||
|
|
||||
|
if (secure) { |
||||
|
cookieValue = cookieValue + "; secure"; |
||||
|
} |
||||
|
|
||||
|
document.cookie = cookieValue; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Gets a cookie with given key. |
||||
|
* This is a simple implementation created to be used by ABP. |
||||
|
* Please use a complete cookie library if you need. |
||||
|
* @param {string} key |
||||
|
* @returns {string} Cookie value or null |
||||
|
*/ |
||||
|
abp.utils.getCookieValue = function (key) { |
||||
|
var equalities = document.cookie.split('; '); |
||||
|
for (var i = 0; i < equalities.length; i++) { |
||||
|
if (!equalities[i]) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
var splitted = equalities[i].split('='); |
||||
|
if (splitted.length != 2) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (decodeURIComponent(splitted[0]) === key) { |
||||
|
return decodeURIComponent(splitted[1] || ''); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Deletes cookie for given key. |
||||
|
* This is a simple implementation created to be used by ABP. |
||||
|
* Please use a complete cookie library if you need. |
||||
|
* @param {string} key |
||||
|
* @param {string} path (optional) |
||||
|
*/ |
||||
|
abp.utils.deleteCookie = function (key, path) { |
||||
|
var cookieValue = encodeURIComponent(key) + '='; |
||||
|
|
||||
|
cookieValue = cookieValue + "; expires=" + (new Date(new Date().getTime() - 86400000)).toUTCString(); |
||||
|
|
||||
|
if (path) { |
||||
|
cookieValue = cookieValue + "; path=" + path; |
||||
|
} |
||||
|
|
||||
|
document.cookie = cookieValue; |
||||
|
} |
||||
|
|
||||
|
// DOM MANIPULATION
|
||||
|
|
||||
|
abp.utils.addClassToTag = function (tagName, className) { |
||||
|
var tags = document.getElementsByTagName(tagName); |
||||
|
for (var i = 0; i < tags.length; i++) { |
||||
|
tags[i].classList.add(className); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
abp.utils.removeClassFromTag = function (tagName, className) { |
||||
|
var tags = document.getElementsByTagName(tagName); |
||||
|
for (var i = 0; i < tags.length; i++) { |
||||
|
tags[i].classList.remove(className); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
abp.utils.hasClassOnTag = function (tagName, className) { |
||||
|
var tags = document.getElementsByTagName(tagName); |
||||
|
if (tags.length) { |
||||
|
return tags[0].classList.contains(className); |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
}; |
||||
|
|
||||
|
abp.utils.replaceLinkHrefById = function (linkId, hrefValue) { |
||||
|
var link = document.getElementById(linkId); |
||||
|
|
||||
|
if (link && link.href !== hrefValue) { |
||||
|
link.href = hrefValue; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// FULL SCREEN /////////////////
|
||||
|
|
||||
|
abp.utils.toggleFullscreen = function() { |
||||
|
var elem = document.documentElement; |
||||
|
if (!document.fullscreenElement && !document.mozFullScreenElement && |
||||
|
!document.webkitFullscreenElement && !document.msFullscreenElement) { |
||||
|
if (elem.requestFullscreen) { |
||||
|
elem.requestFullscreen(); |
||||
|
} else if (elem.msRequestFullscreen) { |
||||
|
elem.msRequestFullscreen(); |
||||
|
} else if (elem.mozRequestFullScreen) { |
||||
|
elem.mozRequestFullScreen(); |
||||
|
} else if (elem.webkitRequestFullscreen) { |
||||
|
elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); |
||||
|
} |
||||
|
} else { |
||||
|
if (document.exitFullscreen) { |
||||
|
document.exitFullscreen(); |
||||
|
} else if (document.msExitFullscreen) { |
||||
|
document.msExitFullscreen(); |
||||
|
} else if (document.mozCancelFullScreen) { |
||||
|
document.mozCancelFullScreen(); |
||||
|
} else if (document.webkitExitFullscreen) { |
||||
|
document.webkitExitFullscreen(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
abp.utils.requestFullscreen = function() { |
||||
|
var elem = document.documentElement; |
||||
|
if (!document.fullscreenElement && !document.mozFullScreenElement && |
||||
|
!document.webkitFullscreenElement && !document.msFullscreenElement) { |
||||
|
if (elem.requestFullscreen) { |
||||
|
elem.requestFullscreen(); |
||||
|
} else if (elem.msRequestFullscreen) { |
||||
|
elem.msRequestFullscreen(); |
||||
|
} else if (elem.mozRequestFullScreen) { |
||||
|
elem.mozRequestFullScreen(); |
||||
|
} else if (elem.webkitRequestFullscreen) { |
||||
|
elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
abp.utils.exitFullscreen = function() { |
||||
|
if (!(!document.fullscreenElement && !document.mozFullScreenElement && |
||||
|
!document.webkitFullscreenElement && !document.msFullscreenElement)) { |
||||
|
if (document.exitFullscreen) { |
||||
|
document.exitFullscreen(); |
||||
|
} else if (document.msExitFullscreen) { |
||||
|
document.msExitFullscreen(); |
||||
|
} else if (document.mozCancelFullScreen) { |
||||
|
document.mozCancelFullScreen(); |
||||
|
} else if (document.webkitExitFullscreen) { |
||||
|
document.webkitExitFullscreen(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
})(); |
||||
@ -0,0 +1,7 @@ |
|||||
|
@page "/authentication/{action}" |
||||
|
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication |
||||
|
<RemoteAuthenticatorView Action="@Action" /> |
||||
|
|
||||
|
@code{ |
||||
|
[Parameter] public string Action { get; set; } |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
using System; |
||||
|
using System.Globalization; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.AspNetCore.Components.UI; |
||||
|
using Volo.Abp.AspNetCore.Components.UI.DependencyInjection; |
||||
|
using Volo.Abp.AspNetCore.Mvc.Client; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.Components.UI.Hosting |
||||
|
{ |
||||
|
public static class AbpComponentsBuilderExtensions |
||||
|
{ |
||||
|
//public static IAbpApplicationWithExternalServiceProvider AddApplication<TStartupModule>(
|
||||
|
// [NotNull] this IServiceCollection services
|
||||
|
// /*Action<AbpWebAssemblyApplicationCreationOptions> options*/)
|
||||
|
// where TStartupModule : IAbpModule
|
||||
|
//{
|
||||
|
// Check.NotNull(services, nameof(services));
|
||||
|
|
||||
|
// // Related this commit(https://github.com/dotnet/aspnetcore/commit/b99d805bc037fcac56afb79abeb7d5a43141c85e)
|
||||
|
// // Microsoft.AspNetCore.Blazor.BuildTools has been removed in net 5.0.
|
||||
|
// // This call may be removed when we find a suitable solution.
|
||||
|
// // System.Runtime.CompilerServices.AsyncStateMachineAttribute
|
||||
|
// Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add<AsyncStateMachineAttribute>();
|
||||
|
|
||||
|
// services.AddSingleton<IConfiguration>(builder.Configuration);
|
||||
|
// services.AddSingleton(builder);
|
||||
|
|
||||
|
// var application = services.AddApplication<TStartupModule>(opts =>
|
||||
|
// {
|
||||
|
// options?.Invoke(new AbpAspNetCoreApplicationCreationOptions(builder, opts));
|
||||
|
// });
|
||||
|
|
||||
|
// return application;
|
||||
|
//}
|
||||
|
|
||||
|
public static async Task InitializeAsync( |
||||
|
[NotNull] this IAbpApplicationWithExternalServiceProvider application, |
||||
|
[NotNull] IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
Check.NotNull(application, nameof(application)); |
||||
|
Check.NotNull(serviceProvider, nameof(serviceProvider)); |
||||
|
|
||||
|
var serviceProviderAccessor = (ComponentsClientScopeServiceProviderAccessor) |
||||
|
serviceProvider.GetRequiredService<IClientScopeServiceProviderAccessor>(); |
||||
|
serviceProviderAccessor.ServiceProvider = serviceProvider; |
||||
|
|
||||
|
application.Initialize(serviceProvider); |
||||
|
|
||||
|
using (var scope = serviceProvider.CreateScope()) |
||||
|
{ |
||||
|
await InitializeModulesAsync(scope.ServiceProvider); |
||||
|
await SetCurrentLanguageAsync(scope); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static async Task InitializeModulesAsync(IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
foreach (var service in serviceProvider.GetServices<IAsyncInitialize>()) |
||||
|
{ |
||||
|
await service.InitializeAsync(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static async Task SetCurrentLanguageAsync(IServiceScope scope) |
||||
|
{ |
||||
|
var configurationClient = scope.ServiceProvider.GetRequiredService<ICachedApplicationConfigurationClient>(); |
||||
|
var utilsService = scope.ServiceProvider.GetRequiredService<IAbpUtilsService>(); |
||||
|
var configuration = configurationClient.Get(); |
||||
|
var cultureName = configuration.Localization?.CurrentCulture?.CultureName; |
||||
|
if (!cultureName.IsNullOrEmpty()) |
||||
|
{ |
||||
|
var culture = new CultureInfo(cultureName); |
||||
|
CultureInfo.DefaultThreadCurrentCulture = culture; |
||||
|
CultureInfo.DefaultThreadCurrentUICulture = culture; |
||||
|
} |
||||
|
|
||||
|
if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft) |
||||
|
{ |
||||
|
await utilsService.AddClassToTagAsync("body", "rtl"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
namespace Volo.Abp.AspNetCore.Components.UI |
||||
|
{ |
||||
|
public class AbpAspNetCoreApplicationCreationOptions |
||||
|
{ |
||||
|
public AbpApplicationCreationOptions ApplicationCreationOptions { get; } |
||||
|
|
||||
|
public AbpAspNetCoreApplicationCreationOptions( |
||||
|
AbpApplicationCreationOptions applicationCreationOptions) |
||||
|
{ |
||||
|
ApplicationCreationOptions = applicationCreationOptions; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,41 +1,41 @@ |
|||||
using Microsoft.AspNetCore.Components; |
//using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.DependencyInjection; |
//using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions; |
//using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging; |
//using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp.AspNetCore.Components.DependencyInjection; |
//using Volo.Abp.AspNetCore.Components.DependencyInjection;
|
||||
using Volo.Abp.AspNetCore.Components.UI.ExceptionHandling; |
//using Volo.Abp.AspNetCore.Components.UI.ExceptionHandling;
|
||||
using Volo.Abp.AspNetCore.Mvc.Client; |
//using Volo.Abp.AspNetCore.Mvc.Client;
|
||||
using Volo.Abp.Http.Client; |
//using Volo.Abp.Http.Client;
|
||||
using Volo.Abp.Modularity; |
//using Volo.Abp.Modularity;
|
||||
using Volo.Abp.UI; |
//using Volo.Abp.UI;
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.UI |
//namespace Volo.Abp.AspNetCore.Components.UI
|
||||
{ |
//{
|
||||
[DependsOn( |
// [DependsOn(
|
||||
typeof(AbpAspNetCoreMvcClientCommonModule), |
// typeof(AbpAspNetCoreMvcClientCommonModule),
|
||||
typeof(AbpUiModule), |
// typeof(AbpUiModule),
|
||||
typeof(AbpAspNetCoreComponentsModule) |
// typeof(AbpAspNetCoreComponentsModule)
|
||||
)] |
// )]
|
||||
public class AbpAspNetCoreComponentsUIModule : AbpModule |
// public class AbpAspNetCoreComponentsUIModule : AbpModule
|
||||
{ |
// {
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context) |
// public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
{ |
// {
|
||||
PreConfigure<AbpHttpClientBuilderOptions>(options => |
// PreConfigure<AbpHttpClientBuilderOptions>(options =>
|
||||
{ |
// {
|
||||
options.ProxyClientBuildActions.Add((_, builder) => |
// options.ProxyClientBuildActions.Add((_, builder) =>
|
||||
{ |
// {
|
||||
builder.AddHttpMessageHandler<AbpBlazorClientHttpMessageHandler>(); |
// builder.AddHttpMessageHandler<AbpBlazorClientHttpMessageHandler>();
|
||||
}); |
// });
|
||||
}); |
// });
|
||||
} |
// }
|
||||
|
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
// public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{ |
// {
|
||||
context.Services.Replace(ServiceDescriptor.Transient<IComponentActivator, ServiceProviderComponentActivator>()); |
// context.Services.Replace(ServiceDescriptor.Transient<IComponentActivator, ServiceProviderComponentActivator>());
|
||||
|
|
||||
//context.Services
|
// //context.Services
|
||||
// .GetHostBuilder().Logging
|
// // .GetHostBuilder().Logging
|
||||
// .AddProvider(new AbpExceptionHandlingLoggerProvider(context.Services));
|
// // .AddProvider(new AbpExceptionHandlingLoggerProvider(context.Services));
|
||||
} |
// }
|
||||
} |
// }
|
||||
} |
//}
|
||||
|
|||||
@ -1,98 +0,0 @@ |
|||||
using System; |
|
||||
using System.Net.Http; |
|
||||
using System.Net.Http.Headers; |
|
||||
using System.Threading; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.AspNetCore.Components; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.JSInterop; |
|
||||
using Volo.Abp.AspNetCore.Components.Progression; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public class AbpBlazorClientHttpMessageHandler : DelegatingHandler, ITransientDependency |
|
||||
{ |
|
||||
private readonly IJSRuntime _jsRuntime; |
|
||||
|
|
||||
private readonly ICookieService _cookieService; |
|
||||
|
|
||||
private readonly NavigationManager _navigationManager; |
|
||||
|
|
||||
private readonly IUiPageProgressService _uiPageProgressService; |
|
||||
|
|
||||
private const string AntiForgeryCookieName = "XSRF-TOKEN"; |
|
||||
|
|
||||
private const string AntiForgeryHeaderName = "RequestVerificationToken"; |
|
||||
|
|
||||
public AbpBlazorClientHttpMessageHandler( |
|
||||
IJSRuntime jsRuntime, |
|
||||
ICookieService cookieService, |
|
||||
NavigationManager navigationManager, |
|
||||
IClientScopeServiceProviderAccessor clientScopeServiceProviderAccessor) |
|
||||
{ |
|
||||
_jsRuntime = jsRuntime; |
|
||||
_cookieService = cookieService; |
|
||||
_navigationManager = navigationManager; |
|
||||
_uiPageProgressService = clientScopeServiceProviderAccessor.ServiceProvider.GetRequiredService<IUiPageProgressService>(); |
|
||||
} |
|
||||
|
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) |
|
||||
{ |
|
||||
try |
|
||||
{ |
|
||||
await _uiPageProgressService.Go(null, options => |
|
||||
{ |
|
||||
options.Type = UiPageProgressType.Info; |
|
||||
}); |
|
||||
|
|
||||
await SetLanguageAsync(request, cancellationToken); |
|
||||
await SetAntiForgeryTokenAsync(request); |
|
||||
|
|
||||
return await base.SendAsync(request, cancellationToken); |
|
||||
} |
|
||||
finally |
|
||||
{ |
|
||||
await _uiPageProgressService.Go(-1); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private async Task SetLanguageAsync(HttpRequestMessage request, CancellationToken cancellationToken) |
|
||||
{ |
|
||||
var selectedLanguage = await _jsRuntime.InvokeAsync<string>( |
|
||||
"localStorage.getItem", |
|
||||
cancellationToken, |
|
||||
"Abp.SelectedLanguage" |
|
||||
); |
|
||||
|
|
||||
if (!selectedLanguage.IsNullOrWhiteSpace()) |
|
||||
{ |
|
||||
request.Headers.AcceptLanguage.Clear(); |
|
||||
request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(selectedLanguage)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private async Task SetAntiForgeryTokenAsync(HttpRequestMessage request) |
|
||||
{ |
|
||||
if (request.Method == HttpMethod.Get || request.Method == HttpMethod.Head || |
|
||||
request.Method == HttpMethod.Trace || request.Method == HttpMethod.Options) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
var selfUri = new Uri(_navigationManager.Uri); |
|
||||
|
|
||||
if (request.RequestUri.Host != selfUri.Host || request.RequestUri.Port != selfUri.Port) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
var token = await _cookieService.GetAsync(AntiForgeryCookieName); |
|
||||
|
|
||||
if (!token.IsNullOrWhiteSpace()) |
|
||||
{ |
|
||||
request.Headers.Add(AntiForgeryHeaderName, token); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,48 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using JetBrains.Annotations; |
|
||||
using Microsoft.Extensions.Localization; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public class AbpBlazorMessageLocalizerHelper<T> |
|
||||
{ |
|
||||
private readonly IStringLocalizer<T> stringLocalizer; |
|
||||
|
|
||||
public AbpBlazorMessageLocalizerHelper(IStringLocalizer<T> stringLocalizer) |
|
||||
{ |
|
||||
this.stringLocalizer = stringLocalizer; |
|
||||
} |
|
||||
|
|
||||
public string Localize(string message, [CanBeNull] IEnumerable<string> arguments) |
|
||||
{ |
|
||||
try |
|
||||
{ |
|
||||
return arguments?.Count() > 0 |
|
||||
? stringLocalizer[message, LocalizeMessageArguments(arguments)?.ToArray()] |
|
||||
: stringLocalizer[message]; |
|
||||
} |
|
||||
catch |
|
||||
{ |
|
||||
return stringLocalizer[message]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private IEnumerable<string> LocalizeMessageArguments(IEnumerable<string> arguments) |
|
||||
{ |
|
||||
foreach (var argument in arguments) |
|
||||
{ |
|
||||
// first try to localize with "DisplayName:{Name}"
|
|
||||
var localization = stringLocalizer[$"DisplayName:{argument}"]; |
|
||||
|
|
||||
if (localization.ResourceNotFound) |
|
||||
{ |
|
||||
// then try to localize with just "{Name}"
|
|
||||
localization = stringLocalizer[argument]; |
|
||||
} |
|
||||
|
|
||||
yield return localization; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,51 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Microsoft.JSInterop; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public class AbpUtilsService : IAbpUtilsService, ITransientDependency |
|
||||
{ |
|
||||
protected IJSRuntime JsRuntime { get; } |
|
||||
|
|
||||
public AbpUtilsService(IJSRuntime jsRuntime) |
|
||||
{ |
|
||||
JsRuntime = jsRuntime; |
|
||||
} |
|
||||
|
|
||||
public ValueTask AddClassToTagAsync(string tagName, string className) |
|
||||
{ |
|
||||
return JsRuntime.InvokeVoidAsync("abp.utils.addClassToTag", tagName, className); |
|
||||
} |
|
||||
|
|
||||
public ValueTask RemoveClassFromTagAsync(string tagName, string className) |
|
||||
{ |
|
||||
return JsRuntime.InvokeVoidAsync("abp.utils.removeClassFromTag", tagName, className); |
|
||||
} |
|
||||
|
|
||||
public ValueTask<bool> HasClassOnTagAsync(string tagName, string className) |
|
||||
{ |
|
||||
return JsRuntime.InvokeAsync<bool>("abp.utils.hasClassOnTag", tagName, className); |
|
||||
} |
|
||||
|
|
||||
public ValueTask ReplaceLinkHrefByIdAsync(string linkId, string hrefValue) |
|
||||
{ |
|
||||
return JsRuntime.InvokeVoidAsync("abp.utils.replaceLinkHrefById", linkId, hrefValue); |
|
||||
} |
|
||||
|
|
||||
public ValueTask ToggleFullscreenAsync() |
|
||||
{ |
|
||||
return JsRuntime.InvokeVoidAsync("abp.utils.toggleFullscreen"); |
|
||||
} |
|
||||
|
|
||||
public ValueTask RequestFullscreenAsync() |
|
||||
{ |
|
||||
return JsRuntime.InvokeVoidAsync("abp.utils.requestFullscreen"); |
|
||||
} |
|
||||
|
|
||||
public ValueTask ExitFullscreenAsync() |
|
||||
{ |
|
||||
return JsRuntime.InvokeVoidAsync("abp.utils.exitFullscreen"); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,15 +0,0 @@ |
|||||
using Volo.Abp.AspNetCore.Components.Alerts; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Alerts |
|
||||
{ |
|
||||
public class AlertManager : IAlertManager, IScopedDependency |
|
||||
{ |
|
||||
public AlertList Alerts { get; } |
|
||||
|
|
||||
public AlertManager() |
|
||||
{ |
|
||||
Alerts = new AlertList(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,20 +0,0 @@ |
|||||
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public class ApplicationConfigurationCache : ISingletonDependency |
|
||||
{ |
|
||||
protected ApplicationConfigurationDto Configuration { get; set; } |
|
||||
|
|
||||
public virtual ApplicationConfigurationDto Get() |
|
||||
{ |
|
||||
return Configuration; |
|
||||
} |
|
||||
|
|
||||
internal void Set(ApplicationConfigurationDto configuration) |
|
||||
{ |
|
||||
Configuration = configuration; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,17 +0,0 @@ |
|||||
using Volo.Abp.Bundling; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public class ComponentsWebAssemblyBundleContributor : IBundleContributor |
|
||||
{ |
|
||||
public void AddScripts(BundleContext context) |
|
||||
{ |
|
||||
context.Add("_content/Volo.Abp.AspNetCore.Components.WebAssembly/libs/abp/js/abp.js"); |
|
||||
} |
|
||||
|
|
||||
public void AddStyles(BundleContext context) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
using System; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public class CookieOptions |
|
||||
{ |
|
||||
public DateTimeOffset? ExpireDate { get; set; } |
|
||||
public string Path { get; set; } |
|
||||
public bool Secure { get; set; } |
|
||||
} |
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Microsoft.JSInterop; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
[Dependency(ReplaceServices = true)] |
|
||||
public class CookieService : ICookieService, ITransientDependency |
|
||||
{ |
|
||||
public IJSRuntime JsRuntime { get; } |
|
||||
|
|
||||
public CookieService(IJSRuntime jsRuntime) |
|
||||
{ |
|
||||
JsRuntime = jsRuntime; |
|
||||
} |
|
||||
|
|
||||
public async ValueTask SetAsync(string key, string value, CookieOptions options) |
|
||||
{ |
|
||||
await JsRuntime.InvokeVoidAsync("abp.utils.setCookieValue", key, value, options?.ExpireDate?.ToString("r"), options?.Path, options?.Secure); |
|
||||
} |
|
||||
|
|
||||
public async ValueTask<string> GetAsync(string key) |
|
||||
{ |
|
||||
return await JsRuntime.InvokeAsync<string>("abp.utils.getCookieValue", key); |
|
||||
} |
|
||||
|
|
||||
public async ValueTask DeleteAsync(string key, string path = null) |
|
||||
{ |
|
||||
await JsRuntime.InvokeVoidAsync("abp.utils.deleteCookie", key); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,12 +0,0 @@ |
|||||
using System; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.DependencyInjection |
|
||||
{ |
|
||||
public class WebAssemblyClientScopeServiceProviderAccessor : |
|
||||
IClientScopeServiceProviderAccessor, |
|
||||
ISingletonDependency |
|
||||
{ |
|
||||
public IServiceProvider ServiceProvider { get; set; } |
|
||||
} |
|
||||
} |
|
||||
@ -1,65 +0,0 @@ |
|||||
using System; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|
||||
{ |
|
||||
public class AbpExceptionHandlingLogger : ILogger |
|
||||
{ |
|
||||
private readonly IServiceCollection _serviceCollection; |
|
||||
private IUserExceptionInformer _userExceptionInformer; |
|
||||
|
|
||||
public AbpExceptionHandlingLogger(IServiceCollection serviceCollection) |
|
||||
{ |
|
||||
_serviceCollection = serviceCollection; |
|
||||
} |
|
||||
|
|
||||
public virtual void Log<TState>( |
|
||||
LogLevel logLevel, |
|
||||
EventId eventId, |
|
||||
TState state, |
|
||||
Exception exception, |
|
||||
Func<TState, Exception, string> formatter) |
|
||||
{ |
|
||||
if (exception == null) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
if (logLevel != LogLevel.Critical && logLevel != LogLevel.Error) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
TryInitialize(); |
|
||||
|
|
||||
if (_userExceptionInformer == null) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
_userExceptionInformer.Inform(new UserExceptionInformerContext(exception)); |
|
||||
} |
|
||||
|
|
||||
protected virtual void TryInitialize() |
|
||||
{ |
|
||||
var serviceProvider = _serviceCollection.GetServiceProviderOrNull(); |
|
||||
if (serviceProvider == null) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
_userExceptionInformer = serviceProvider.GetRequiredService<IUserExceptionInformer>(); |
|
||||
} |
|
||||
|
|
||||
public virtual bool IsEnabled(LogLevel logLevel) |
|
||||
{ |
|
||||
return logLevel == LogLevel.Critical || logLevel == LogLevel.Error; |
|
||||
} |
|
||||
|
|
||||
public virtual IDisposable BeginScope<TState>(TState state) |
|
||||
{ |
|
||||
return NullDisposable.Instance; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|
||||
{ |
|
||||
public class AbpExceptionHandlingLoggerProvider : ILoggerProvider |
|
||||
{ |
|
||||
private AbpExceptionHandlingLogger _logger; |
|
||||
private static readonly object SyncObj = new object(); |
|
||||
private readonly IServiceCollection _serviceCollection; |
|
||||
|
|
||||
public AbpExceptionHandlingLoggerProvider(IServiceCollection serviceCollection) |
|
||||
{ |
|
||||
_serviceCollection = serviceCollection; |
|
||||
} |
|
||||
|
|
||||
public ILogger CreateLogger(string categoryName) |
|
||||
{ |
|
||||
if (_logger == null) |
|
||||
{ |
|
||||
lock (SyncObj) |
|
||||
{ |
|
||||
if (_logger == null) |
|
||||
{ |
|
||||
_logger = new AbpExceptionHandlingLogger(_serviceCollection); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return _logger; |
|
||||
} |
|
||||
|
|
||||
public void Dispose() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,7 +0,0 @@ |
|||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|
||||
{ |
|
||||
public interface IUserExceptionInformer |
|
||||
{ |
|
||||
void Inform(UserExceptionInformerContext context); |
|
||||
} |
|
||||
} |
|
||||
@ -1,52 +0,0 @@ |
|||||
using System; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
using Microsoft.Extensions.Logging.Abstractions; |
|
||||
using Volo.Abp.AspNetCore.Components.Messages; |
|
||||
using Volo.Abp.AspNetCore.ExceptionHandling; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.Http; |
|
||||
using Volo.Abp.Http.Client; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|
||||
{ |
|
||||
public class UserExceptionInformer : IUserExceptionInformer, ITransientDependency |
|
||||
{ |
|
||||
public ILogger<UserExceptionInformer> Logger { get; set; } |
|
||||
protected IUiMessageService MessageService { get; } |
|
||||
protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; } |
|
||||
|
|
||||
public UserExceptionInformer( |
|
||||
IUiMessageService messageService, |
|
||||
IExceptionToErrorInfoConverter exceptionToErrorInfoConverter) |
|
||||
{ |
|
||||
MessageService = messageService; |
|
||||
ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter; |
|
||||
Logger = NullLogger<UserExceptionInformer>.Instance; |
|
||||
} |
|
||||
|
|
||||
public void Inform(UserExceptionInformerContext context) |
|
||||
{ |
|
||||
var errorInfo = GetErrorInfo(context); |
|
||||
|
|
||||
if (errorInfo.Details.IsNullOrEmpty()) |
|
||||
{ |
|
||||
//TODO: Should we introduce MessageService.Error (sync) method instead of such a usage (without await)..?
|
|
||||
MessageService.Error(errorInfo.Message); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
MessageService.Error(errorInfo.Details, errorInfo.Message); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerContext context) |
|
||||
{ |
|
||||
if (context.Exception is AbpRemoteCallException remoteCallException) |
|
||||
{ |
|
||||
return remoteCallException.Error; |
|
||||
} |
|
||||
|
|
||||
return ExceptionToErrorInfoConverter.Convert(context.Exception, false); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
using System; |
|
||||
using JetBrains.Annotations; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling |
|
||||
{ |
|
||||
public class UserExceptionInformerContext |
|
||||
{ |
|
||||
[NotNull] |
|
||||
public Exception Exception { get; } |
|
||||
|
|
||||
public UserExceptionInformerContext(Exception exception) |
|
||||
{ |
|
||||
Exception = exception; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,21 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public interface IAbpUtilsService |
|
||||
{ |
|
||||
ValueTask AddClassToTagAsync(string tagName, string className); |
|
||||
|
|
||||
ValueTask RemoveClassFromTagAsync(string tagName, string className); |
|
||||
|
|
||||
ValueTask<bool> HasClassOnTagAsync(string tagName, string className); |
|
||||
|
|
||||
ValueTask ReplaceLinkHrefByIdAsync(string linkId, string hrefValue); |
|
||||
|
|
||||
ValueTask ToggleFullscreenAsync(); |
|
||||
|
|
||||
ValueTask RequestFullscreenAsync(); |
|
||||
|
|
||||
ValueTask ExitFullscreenAsync(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,12 +0,0 @@ |
|||||
using System; |
|
||||
using System.Threading.Tasks; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|
||||
{ |
|
||||
public interface ICookieService |
|
||||
{ |
|
||||
public ValueTask SetAsync(string key, string value, CookieOptions options = null); |
|
||||
public ValueTask<string> GetAsync(string key); |
|
||||
public ValueTask DeleteAsync(string key, string path = null); |
|
||||
} |
|
||||
} |
|
||||
@ -1,43 +0,0 @@ |
|||||
using System; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.JSInterop; |
|
||||
using Volo.Abp.AspNetCore.Components.Messages; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Messages |
|
||||
{ |
|
||||
public class SimpleUiMessageService : IUiMessageService, ITransientDependency |
|
||||
{ |
|
||||
protected IJSRuntime JsRuntime { get; } |
|
||||
|
|
||||
public SimpleUiMessageService(IJSRuntime jsRuntime) |
|
||||
{ |
|
||||
JsRuntime = jsRuntime; |
|
||||
} |
|
||||
|
|
||||
public async Task Info(string message, string title = null, Action<UiMessageOptions> options = null) |
|
||||
{ |
|
||||
await JsRuntime.InvokeVoidAsync("alert", message); |
|
||||
} |
|
||||
|
|
||||
public async Task Success(string message, string title = null, Action<UiMessageOptions> options = null) |
|
||||
{ |
|
||||
await JsRuntime.InvokeVoidAsync("alert", message); |
|
||||
} |
|
||||
|
|
||||
public async Task Warn(string message, string title = null, Action<UiMessageOptions> options = null) |
|
||||
{ |
|
||||
await JsRuntime.InvokeVoidAsync("alert", message); |
|
||||
} |
|
||||
|
|
||||
public async Task Error(string message, string title = null, Action<UiMessageOptions> options = null) |
|
||||
{ |
|
||||
await JsRuntime.InvokeVoidAsync("alert", message); |
|
||||
} |
|
||||
|
|
||||
public async Task<bool> Confirm(string message, string title = null, Action<UiMessageOptions> options = null) |
|
||||
{ |
|
||||
return await JsRuntime.InvokeAsync<bool>("confirm", message); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.MultiTenancy; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MultiTenancy |
|
||||
{ |
|
||||
[Dependency(ReplaceServices = true)] |
|
||||
public class WebAssemblyCurrentTenantAccessor : ICurrentTenantAccessor, ISingletonDependency |
|
||||
{ |
|
||||
public BasicTenantInfo Current { get; set; } |
|
||||
} |
|
||||
} |
|
||||
@ -1,70 +0,0 @@ |
|||||
using System; |
|
||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.AspNetCore.Mvc.MultiTenancy; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.Http.Client.DynamicProxying; |
|
||||
using Volo.Abp.MultiTenancy; |
|
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MultiTenancy |
|
||||
{ |
|
||||
public class WebAssemblyRemoteTenantStore : ITenantStore, ITransientDependency |
|
||||
{ |
|
||||
protected IHttpClientProxy<IAbpTenantAppService> Proxy { get; } |
|
||||
protected WebAssemblyRemoteTenantStoreCache Cache { get; } |
|
||||
|
|
||||
public WebAssemblyRemoteTenantStore( |
|
||||
IHttpClientProxy<IAbpTenantAppService> proxy, |
|
||||
WebAssemblyRemoteTenantStoreCache cache) |
|
||||
{ |
|
||||
Proxy = proxy; |
|
||||
Cache = cache; |
|
||||
} |
|
||||
|
|
||||
public async Task<TenantConfiguration> FindAsync(string name) |
|
||||
{ |
|
||||
var cached = Cache.Find(name); |
|
||||
if (cached != null) |
|
||||
{ |
|
||||
return cached; |
|
||||
} |
|
||||
|
|
||||
var tenant = CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name)); |
|
||||
Cache.Set(tenant); |
|
||||
return tenant; |
|
||||
} |
|
||||
|
|
||||
public async Task<TenantConfiguration> FindAsync(Guid id) |
|
||||
{ |
|
||||
var cached = Cache.Find(id); |
|
||||
if (cached != null) |
|
||||
{ |
|
||||
return cached; |
|
||||
} |
|
||||
|
|
||||
var tenant = CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id)); |
|
||||
Cache.Set(tenant); |
|
||||
return tenant; |
|
||||
} |
|
||||
|
|
||||
public TenantConfiguration Find(string name) |
|
||||
{ |
|
||||
return AsyncHelper.RunSync(() => FindAsync(name)); |
|
||||
} |
|
||||
|
|
||||
public TenantConfiguration Find(Guid id) |
|
||||
{ |
|
||||
return AsyncHelper.RunSync(() => FindAsync(id)); |
|
||||
} |
|
||||
|
|
||||
protected virtual TenantConfiguration CreateTenantConfiguration(FindTenantResultDto tenantResultDto) |
|
||||
{ |
|
||||
if (!tenantResultDto.Success || tenantResultDto.TenantId == null) |
|
||||
{ |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
return new TenantConfiguration(tenantResultDto.TenantId.Value, tenantResultDto.Name); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.MultiTenancy; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.MultiTenancy |
|
||||
{ |
|
||||
public class WebAssemblyRemoteTenantStoreCache : IScopedDependency |
|
||||
{ |
|
||||
protected readonly List<TenantConfiguration> CachedTenants = new List<TenantConfiguration>(); |
|
||||
|
|
||||
public virtual TenantConfiguration Find(string name) |
|
||||
{ |
|
||||
return CachedTenants.FirstOrDefault(t => t.Name == name); |
|
||||
} |
|
||||
|
|
||||
public virtual TenantConfiguration Find(Guid id) |
|
||||
{ |
|
||||
return CachedTenants.FirstOrDefault(t => t.Id == id); |
|
||||
} |
|
||||
|
|
||||
public virtual void Set(TenantConfiguration tenant) |
|
||||
{ |
|
||||
var existingTenant = Find(tenant.Id); |
|
||||
if (existingTenant != null) |
|
||||
{ |
|
||||
existingTenant.Name = tenant.Name; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
CachedTenants.Add(tenant); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
using System.Security.Claims; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.AspNetCore.Components.Authorization; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Security |
|
||||
{ |
|
||||
[ExposeServices( |
|
||||
typeof(AbpWebAssemblyClaimsCache), |
|
||||
typeof(IAsyncInitialize) |
|
||||
)] |
|
||||
public class AbpWebAssemblyClaimsCache : ISingletonDependency, IAsyncInitialize |
|
||||
{ |
|
||||
public ClaimsPrincipal Principal { get; private set; } |
|
||||
|
|
||||
private readonly AuthenticationStateProvider _authenticationStateProvider; |
|
||||
|
|
||||
public AbpWebAssemblyClaimsCache(AuthenticationStateProvider authenticationStateProvider) |
|
||||
{ |
|
||||
_authenticationStateProvider = authenticationStateProvider; |
|
||||
} |
|
||||
|
|
||||
public virtual async Task InitializeAsync() |
|
||||
{ |
|
||||
var authenticationState = await _authenticationStateProvider.GetAuthenticationStateAsync(); |
|
||||
Principal = authenticationState.User; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue