mirror of https://github.com/abpframework/abp.git
128 changed files with 2398 additions and 191 deletions
@ -0,0 +1,67 @@ |
|||
# Switch to EF Core Oracle Provider |
|||
|
|||
This document explains how to switch to the **Oracle** database provider for **[the application startup template](Startup-Templates/Application.md)** which comes with SQL Server provider pre-configured. |
|||
|
|||
> This document uses a paid library of [Devart](https://www.devart.com/dotconnect/oracle/) company, because it is the only library for Oracle that supports EF Core 3.x. |
|||
|
|||
## Replace the Volo.Abp.EntityFrameworkCore.SqlServer Package |
|||
|
|||
`.EntityFrameworkCore` project in the solution depends on the [Volo.Abp.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.SqlServer) NuGet package. Remove this package and add the same version of the [Volo.Abp.EntityFrameworkCore.Oracle.Devart](https://www.nuget.org/packages/Volo.Abp.EntityFrameworkCore.Oracle.Devart) package. |
|||
|
|||
## Replace the Module Dependency |
|||
|
|||
Find ***YourProjectName*EntityFrameworkCoreModule** class inside the `.EntityFrameworkCore` project, remove `typeof(AbpEntityFrameworkCoreSqlServerModule)` from the `DependsOn` attribute, add `typeof(AbpEntityFrameworkCoreOracleDevartModule)` (also replace `using Volo.Abp.EntityFrameworkCore.SqlServer;` with `using Volo.Abp.EntityFrameworkCore.Oracle.Devart;`). |
|||
|
|||
## UseOracle() |
|||
|
|||
Find `UseSqlServer()` calls in your solution, replace with `UseOracle()`. Check the following files: |
|||
|
|||
* *YourProjectName*EntityFrameworkCoreModule.cs inside the `.EntityFrameworkCore` project. |
|||
* *YourProjectName*MigrationsDbContextFactory.cs inside the `.EntityFrameworkCore.DbMigrations` project. |
|||
|
|||
|
|||
In the `CreateDbContext()` method of the *YourProjectName*MigrationsDbContextFactory.cs, replace the following code block |
|||
|
|||
``` |
|||
var builder = new DbContextOptionsBuilder<YourProjectNameMigrationsDbContext>() |
|||
.UseSqlServer(configuration.GetConnectionString("Default")); |
|||
``` |
|||
|
|||
with this one |
|||
``` |
|||
var builder = (DbContextOptionsBuilder<YourProjectNameMigrationsDbContext>) |
|||
new DbContextOptionsBuilder<YourProjectNameMigrationsDbContext>().UseOracle |
|||
( |
|||
configuration.GetConnectionString("Default") |
|||
); |
|||
``` |
|||
|
|||
> Depending on your solution structure, you may find more code files need to be changed. |
|||
|
|||
## Change the Connection Strings |
|||
|
|||
Oracle connection strings are different than SQL Server connection strings. So, check all `appsettings.json` files in your solution and replace the connection strings inside them. See the [connectionstrings.com]( https://www.connectionstrings.com/mysql/ ) for details of Oracle connection string options. |
|||
|
|||
You typically will change the `appsettings.json` inside the `.DbMigrator` and `.Web` projects, but it depends on your solution structure. |
|||
|
|||
A sample connection string for Oracle: |
|||
``` |
|||
Data Source=localhost;User Id=myuser;Password=mypassword; |
|||
``` |
|||
|
|||
## Re-Generate the Migrations |
|||
|
|||
The startup template uses [Entity Framework Core's Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/) by default. |
|||
EF Core Migrations depend on the selected DBMS provider. Changing the DBMS provider, may not work with the existing migrations. |
|||
|
|||
* Delete the `Migrations` folder under the `.EntityFrameworkCore.DbMigrations` project and re-build the solution. |
|||
* Run `Add-Migration "Initial"` on the Package Manager Console window (select the `.DbMigrator` (or `.Web`) project as the startup project in the Solution Explorer and select the `.EntityFrameworkCore.DbMigrations` project as the default project in the Package Manager Console). |
|||
|
|||
This will scaffold a new migration for Oracle. |
|||
|
|||
Run the `.DbMigrator` project to create the database, apply the changes and seed the initial data. |
|||
|
|||
## Run the Application |
|||
|
|||
It is ready. Just run the application and enjoy coding. |
|||
|
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations |
|||
{ |
|||
public class ClockDto |
|||
{ |
|||
public string Kind { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations |
|||
{ |
|||
public class TimingDto |
|||
{ |
|||
public TimeZone TimeZone { get; set; } |
|||
} |
|||
|
|||
public class TimeZone |
|||
{ |
|||
public IanaTimeZone Iana { get; set; } |
|||
|
|||
public WindowsTimeZone Windows { get; set; } |
|||
} |
|||
|
|||
public class WindowsTimeZone |
|||
{ |
|||
public string TimeZoneId { get; set; } |
|||
} |
|||
|
|||
public class IanaTimeZone |
|||
{ |
|||
public string TimeZoneName { get; set; } |
|||
} |
|||
} |
|||
@ -1,9 +1,32 @@ |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Localization.Resources.AbpLocalization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Settings; |
|||
using Volo.Abp.Timing.Localization.Resources.AbpTiming; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
|
|||
namespace Volo.Abp.Timing |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpVirtualFileSystemModule), |
|||
typeof(AbpSettingsModule) |
|||
)] |
|||
public class AbpTimingModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpVirtualFileSystemOptions>(options => |
|||
{ |
|||
options.FileSets.AddEmbedded<AbpTimingModule>(); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options |
|||
.Resources |
|||
.Add<AbpTimingResource>("en") |
|||
.AddVirtualJson("/Volo/Abp/Timing/Localization"); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.Timing |
|||
{ |
|||
public interface ITimezoneProvider |
|||
{ |
|||
List<NameValue> GetWindowsTimezones(); |
|||
|
|||
List<NameValue> GetIanaTimezones(); |
|||
|
|||
string WindowsToIana(string windowsTimeZoneId); |
|||
|
|||
string IanaToWindows(string ianaTimeZoneName); |
|||
|
|||
TimeZoneInfo GetTimeZoneInfo(string windowsOrIanaTimeZoneId); |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.Abp.Timing.Localization.Resources.AbpTiming |
|||
{ |
|||
[LocalizationResourceName("AbpTiming")] |
|||
public class AbpTimingResource |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"DisplayName:Abp.Timing.Timezone": "Timezone", |
|||
"Description:Abp.Timing.Timezone": "Application time zone" |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
{ |
|||
"culture": "tr", |
|||
"texts": { |
|||
"DisplayName:Abp.Timing.Timezone": "saat dilimi", |
|||
"Description:Abp.Timing.Timezone": "Uygulama saat dilimi" |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
"DisplayName:Abp.Timing.Timezone": "时区", |
|||
"Description:Abp.Timing.Timezone": "应用程序的时区" |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
{ |
|||
"culture": "zh-Hant", |
|||
"texts": { |
|||
"DisplayName:Abp.Timing.Timezone": "時區", |
|||
"Description:Abp.Timing.Timezone": "應用程序的時區" |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using TimeZoneConverter; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Timing |
|||
{ |
|||
public class TZConvertTimezoneProvider : ITimezoneProvider, ITransientDependency |
|||
{ |
|||
public virtual List<NameValue> GetWindowsTimezones() |
|||
{ |
|||
return TZConvert.KnownIanaTimeZoneNames.OrderBy(x => x).Select(x => new NameValue(x, x)).ToList(); |
|||
} |
|||
|
|||
public virtual List<NameValue> GetIanaTimezones() |
|||
{ |
|||
return TZConvert.KnownIanaTimeZoneNames.OrderBy(x => x).Select(x => new NameValue(x, x)).ToList(); |
|||
} |
|||
|
|||
public virtual string WindowsToIana(string windowsTimeZoneId) |
|||
{ |
|||
return TZConvert.WindowsToIana(windowsTimeZoneId); |
|||
} |
|||
|
|||
public virtual string IanaToWindows(string ianaTimeZoneName) |
|||
{ |
|||
return TZConvert.IanaToWindows(ianaTimeZoneName); |
|||
} |
|||
|
|||
public virtual TimeZoneInfo GetTimeZoneInfo(string windowsOrIanaTimeZoneId) |
|||
{ |
|||
return TZConvert.GetTimeZoneInfo(windowsOrIanaTimeZoneId); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.Timing |
|||
{ |
|||
public static class TimingSettingNames |
|||
{ |
|||
public const string TimeZone = "Abp.Timing.TimeZone"; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Settings; |
|||
using Volo.Abp.Timing.Localization.Resources.AbpTiming; |
|||
|
|||
namespace Volo.Abp.Timing |
|||
{ |
|||
public class TimingSettingProvider : SettingDefinitionProvider |
|||
{ |
|||
public override void Define(ISettingDefinitionContext context) |
|||
{ |
|||
context.Add( |
|||
new SettingDefinition(TimingSettingNames.TimeZone, |
|||
"UTC", |
|||
L("DisplayName:Abp.Timing.Timezone"), |
|||
L("Description:Abp.Timing.Timezone"), |
|||
isVisibleToClients: true) |
|||
); |
|||
} |
|||
|
|||
private static LocalizableString L(string name) |
|||
{ |
|||
return LocalizableString.Create<AbpTimingResource>(name); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00 |
|||
# Visual Studio Version 16 |
|||
VisualStudioVersion = 16.0.29001.49 |
|||
MinimumVisualStudioVersion = 10.0.40219.1 |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.Domain.Shared", "src\Volo.Abp.BlobStoring.Database.Domain.Shared\Volo.Abp.BlobStoring.Database.Domain.Shared.csproj", "{D64C1577-4929-4B60-939E-96DE1534891A}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.Domain", "src\Volo.Abp.BlobStoring.Database.Domain\Volo.Abp.BlobStoring.Database.Domain.csproj", "{F2840BC7-0188-4606-9126-DADD0F5ABF7A}" |
|||
EndProject |
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{649A3FFA-182F-4E56-9717-E6A9A2BEC545}" |
|||
EndProject |
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.EntityFrameworkCore", "src\Volo.Abp.BlobStoring.Database.EntityFrameworkCore\Volo.Abp.BlobStoring.Database.EntityFrameworkCore.csproj", "{0CE86223-D31D-4315-A1F5-87BA3EE1B844}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.MongoDB", "src\Volo.Abp.BlobStoring.Database.MongoDB\Volo.Abp.BlobStoring.Database.MongoDB.csproj", "{F1C58097-4C08-4D88-8976-6B3389391481}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.TestBase", "test\Volo.Abp.BlobStoring.Database.TestBase\Volo.Abp.BlobStoring.Database.TestBase.csproj", "{C5BB573D-3030-4BCB-88B7-F6A85C32766C}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests", "test\Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests\Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests.csproj", "{527F645C-C1FC-406E-8479-81386C8ECF13}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.MongoDB.Tests", "test\Volo.Abp.BlobStoring.Database.MongoDB.Tests\Volo.Abp.BlobStoring.Database.MongoDB.Tests.csproj", "{D0AD9179-125C-40B2-A8EE-CD4C1EE24BB6}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Database.Domain.Tests", "test\Volo.Abp.BlobStoring.Database.Domain.Tests\Volo.Abp.BlobStoring.Database.Domain.Tests.csproj", "{E60895E5-79C4-447D-88B7-85CB5BA336A4}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
Debug|Any CPU = Debug|Any CPU |
|||
Release|Any CPU = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{D64C1577-4929-4B60-939E-96DE1534891A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{D64C1577-4929-4B60-939E-96DE1534891A}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{D64C1577-4929-4B60-939E-96DE1534891A}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{D64C1577-4929-4B60-939E-96DE1534891A}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{F2840BC7-0188-4606-9126-DADD0F5ABF7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{F2840BC7-0188-4606-9126-DADD0F5ABF7A}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{F2840BC7-0188-4606-9126-DADD0F5ABF7A}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{F2840BC7-0188-4606-9126-DADD0F5ABF7A}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{0CE86223-D31D-4315-A1F5-87BA3EE1B844}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{0CE86223-D31D-4315-A1F5-87BA3EE1B844}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{0CE86223-D31D-4315-A1F5-87BA3EE1B844}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{0CE86223-D31D-4315-A1F5-87BA3EE1B844}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{F1C58097-4C08-4D88-8976-6B3389391481}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{F1C58097-4C08-4D88-8976-6B3389391481}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{F1C58097-4C08-4D88-8976-6B3389391481}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{F1C58097-4C08-4D88-8976-6B3389391481}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{C5BB573D-3030-4BCB-88B7-F6A85C32766C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{C5BB573D-3030-4BCB-88B7-F6A85C32766C}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{C5BB573D-3030-4BCB-88B7-F6A85C32766C}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{C5BB573D-3030-4BCB-88B7-F6A85C32766C}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{527F645C-C1FC-406E-8479-81386C8ECF13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{527F645C-C1FC-406E-8479-81386C8ECF13}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{527F645C-C1FC-406E-8479-81386C8ECF13}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{527F645C-C1FC-406E-8479-81386C8ECF13}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{D0AD9179-125C-40B2-A8EE-CD4C1EE24BB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{D0AD9179-125C-40B2-A8EE-CD4C1EE24BB6}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{D0AD9179-125C-40B2-A8EE-CD4C1EE24BB6}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{D0AD9179-125C-40B2-A8EE-CD4C1EE24BB6}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{E60895E5-79C4-447D-88B7-85CB5BA336A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{E60895E5-79C4-447D-88B7-85CB5BA336A4}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{E60895E5-79C4-447D-88B7-85CB5BA336A4}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{E60895E5-79C4-447D-88B7-85CB5BA336A4}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
GlobalSection(NestedProjects) = preSolution |
|||
{D64C1577-4929-4B60-939E-96DE1534891A} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545} |
|||
{F2840BC7-0188-4606-9126-DADD0F5ABF7A} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545} |
|||
{0CE86223-D31D-4315-A1F5-87BA3EE1B844} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545} |
|||
{F1C58097-4C08-4D88-8976-6B3389391481} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545} |
|||
{C5BB573D-3030-4BCB-88B7-F6A85C32766C} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D} |
|||
{527F645C-C1FC-406E-8479-81386C8ECF13} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D} |
|||
{D0AD9179-125C-40B2-A8EE-CD4C1EE24BB6} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D} |
|||
{E60895E5-79C4-447D-88B7-85CB5BA336A4} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D} |
|||
EndGlobalSection |
|||
GlobalSection(ExtensibilityGlobals) = postSolution |
|||
SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD} |
|||
EndGlobalSection |
|||
EndGlobal |
|||
@ -0,0 +1,23 @@ |
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
|||
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/UpgradedFromVSSettings/@EntryValue">True</s:Boolean> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceDoWhileStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceFixedStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceForeachStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceForStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceIfStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceLockStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceUsingStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceWhileStatementBraces/@EntryIndexedValue">WARNING</s:String> |
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOR/@EntryValue">Required</s:String> |
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOREACH/@EntryValue">Required</s:String> |
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_IFELSE/@EntryValue">Required</s:String> |
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_WHILE/@EntryValue">Required</s:String> |
|||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_REDUNDANT/@EntryValue">False</s:Boolean> |
|||
<s:Boolean x:Key="/Default/CodeStyle/Generate/=Implementations/@KeyIndexDefined">True</s:Boolean> |
|||
<s:String x:Key="/Default/CodeStyle/Generate/=Implementations/Options/=Async/@EntryIndexedValue">False</s:String> |
|||
<s:String x:Key="/Default/CodeStyle/Generate/=Implementations/Options/=Mutable/@EntryIndexedValue">False</s:String> |
|||
<s:Boolean x:Key="/Default/CodeStyle/Generate/=Overrides/@KeyIndexDefined">True</s:Boolean> |
|||
<s:String x:Key="/Default/CodeStyle/Generate/=Overrides/Options/=Async/@EntryIndexedValue">False</s:String> |
|||
<s:String x:Key="/Default/CodeStyle/Generate/=Overrides/Options/=Mutable/@EntryIndexedValue">False</s:String> |
|||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQL/@EntryIndexedValue">SQL</s:String> |
|||
</wpf:ResourceDictionary> |
|||
@ -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,20 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.Validation\Volo.Abp.Validation.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="Volo\Abp\BlobStoring\Database\Localization\Database\*.json" /> |
|||
<Content Remove="Volo\Abp\BlobStoring\Database\Localization\Database\*.json" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public static class BlobConsts |
|||
{ |
|||
public const int MaxNameLength = 256; |
|||
|
|||
public const int MaxContentLength = 2_000_000_000; // 2 GB
|
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.BlobStoring.Database.Localization; |
|||
using Volo.Abp.Localization.ExceptionHandling; |
|||
using Volo.Abp.Validation; |
|||
using Volo.Abp.Validation.Localization; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpValidationModule) |
|||
)] |
|||
public class BlobStoringDatabaseDomainSharedModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpVirtualFileSystemOptions>(options => |
|||
{ |
|||
options.FileSets.AddEmbedded<BlobStoringDatabaseDomainSharedModule>("Volo.Abp.BlobStoring.Database"); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Resources |
|||
.Add<BlobStoringDatabaseResource>("en") |
|||
.AddBaseTypes(typeof(AbpValidationResource)) |
|||
.AddVirtualJson("/Localization/BlobStoringDatabase"); |
|||
}); |
|||
|
|||
Configure<AbpExceptionLocalizationOptions>(options => |
|||
{ |
|||
options.MapCodeNamespace("BlobStoringDatabase", typeof(BlobStoringDatabaseResource)); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public static class BlobStoringDatabaseErrorCodes |
|||
{ |
|||
//Add your business exception error codes here...
|
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public static class ContainerConsts |
|||
{ |
|||
public const int MaxNameLength = 128; |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "cs", |
|||
"texts": { |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"ManageYourProfile": "Manage your profile" |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "pl-PL", |
|||
"texts": { |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "pt-BR", |
|||
"texts": { |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "sl", |
|||
"texts": { |
|||
"ManageYourProfile": "Upravljajte svojim profilom" |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "tr", |
|||
"texts": { |
|||
"ManageYourProfile": "Profil yönetimi" |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "vi", |
|||
"texts": { |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
"ManageYourProfile": "管理个人资料" |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "zh-Hant", |
|||
"texts": { |
|||
"ManageYourProfile": "管理個人資料" |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.Localization |
|||
{ |
|||
[LocalizationResourceName("BlobStoringDatabase")] |
|||
public class BlobStoringDatabaseResource |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -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,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.Ddd.Domain\Volo.Abp.Ddd.Domain.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.BlobStoring\Volo.Abp.BlobStoring.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BlobStoring.Database.Domain.Shared\Volo.Abp.BlobStoring.Database.Domain.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,44 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public class Blob : AggregateRoot<Guid>, IMultiTenant |
|||
{ |
|||
public virtual Guid ContainerId { get; protected set; } |
|||
|
|||
public virtual Guid? TenantId { get; protected set; } |
|||
|
|||
public virtual string Name { get; protected set; } |
|||
|
|||
public virtual byte[] Content { get; protected set; } |
|||
|
|||
public Blob(Guid id, Guid containerId, [NotNull] string name, [NotNull] byte[] content, Guid? tenantId = null) |
|||
: base(id) |
|||
{ |
|||
Name = Check.NotNullOrWhiteSpace(name, nameof(name), BlobConsts.MaxNameLength); |
|||
ContainerId = containerId; |
|||
Content = CheckContentLength(content); |
|||
TenantId = tenantId; |
|||
} |
|||
|
|||
public virtual void SetContent(byte[] content) |
|||
{ |
|||
Content = CheckContentLength(content); |
|||
} |
|||
|
|||
protected virtual byte[] CheckContentLength(byte[] content) |
|||
{ |
|||
Check.NotNull(content, nameof(content)); |
|||
|
|||
if (content.Length >= BlobConsts.MaxContentLength) |
|||
{ |
|||
throw new AbpException($"Blob content size cannot be more than {BlobConsts.MaxContentLength} Bytes."); |
|||
} |
|||
|
|||
return content; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public static class BlobStoringDatabaseDbProperties |
|||
{ |
|||
public static string DbTablePrefix { get; set; } = AbpCommonDbProperties.DbTablePrefix; |
|||
|
|||
public static string DbSchema { get; set; } = AbpCommonDbProperties.DbSchema; |
|||
|
|||
public const string ConnectionStringName = "AbpBlobStoring"; |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using Volo.Abp.Domain; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpDddDomainModule), |
|||
typeof(AbpBlobStoringModule), |
|||
typeof(BlobStoringDatabaseDomainSharedModule) |
|||
)] |
|||
public class BlobStoringDatabaseDomainModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public class Container : AggregateRoot<Guid>, IMultiTenant //TODO: Rename to BlobContainer
|
|||
{ |
|||
public virtual Guid? TenantId { get; protected set; } |
|||
|
|||
public virtual string Name { get; protected set; } |
|||
|
|||
public Container(Guid id, [NotNull] string name, Guid? tenantId = null) |
|||
: base(id) |
|||
{ |
|||
Name = Check.NotNullOrWhiteSpace(name, nameof(name), ContainerConsts.MaxNameLength); |
|||
TenantId = tenantId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public static class DatabaseBlobContainerConfigurationExtensions |
|||
{ |
|||
public static DatabaseBlobProviderConfiguration GetDatabaseConfiguration( |
|||
this BlobContainerConfiguration containerConfiguration) |
|||
{ |
|||
return new DatabaseBlobProviderConfiguration(containerConfiguration); |
|||
} |
|||
|
|||
public static BlobContainerConfiguration UseDatabase( |
|||
this BlobContainerConfiguration containerConfiguration, |
|||
Action<DatabaseBlobProviderConfiguration> databaseConfigureAction) |
|||
{ |
|||
containerConfiguration.ProviderType = typeof(DatabaseBlobProvider); |
|||
|
|||
databaseConfigureAction(new DatabaseBlobProviderConfiguration(containerConfiguration)); |
|||
|
|||
return containerConfiguration; |
|||
} |
|||
|
|||
public static BlobContainerConfiguration UseDatabase(this BlobContainerConfiguration containerConfiguration) |
|||
{ |
|||
containerConfiguration.ProviderType = typeof(DatabaseBlobProvider); |
|||
|
|||
return containerConfiguration; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
using System; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public class DatabaseBlobProvider : BlobProviderBase, ITransientDependency |
|||
{ |
|||
protected IBlobRepository BlobRepository { get; } |
|||
protected IContainerRepository ContainerRepository { get; } |
|||
|
|||
public DatabaseBlobProvider(IBlobRepository blobRepository, IContainerRepository containerRepository) |
|||
{ |
|||
BlobRepository = blobRepository; |
|||
ContainerRepository = containerRepository; |
|||
} |
|||
|
|||
public override async Task SaveAsync(BlobProviderSaveArgs args) |
|||
{ |
|||
var container = await ContainerRepository.CreateIfNotExistAsync(args.ContainerName, args.TenantId, args.CancellationToken); |
|||
|
|||
var blob = await BlobRepository.FindAsync(container.Id, args.BlobName, args.TenantId, args.CancellationToken); |
|||
|
|||
var content = await args.BlobStream.GetAllBytesAsync(args.CancellationToken); |
|||
|
|||
if (blob != null) |
|||
{ |
|||
if (!args.OverrideExisting) |
|||
{ |
|||
throw new BlobAlreadyExistsException($"Saving BLOB '{args.BlobName}' does already exists in the container '{args.ContainerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten."); |
|||
} |
|||
|
|||
blob.SetContent(content); |
|||
await BlobRepository.UpdateAsync(blob); |
|||
} |
|||
else |
|||
{ |
|||
blob = new Blob(Guid.NewGuid(), container.Id, args.BlobName, content, args.TenantId); |
|||
await BlobRepository.InsertAsync(blob); |
|||
} |
|||
} |
|||
|
|||
public override async Task<bool> DeleteAsync(BlobProviderDeleteArgs args) |
|||
{ |
|||
var container = await ContainerRepository.FindAsync(args.ContainerName, args.TenantId, args.CancellationToken); |
|||
|
|||
if (container == null) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return await BlobRepository.DeleteAsync(container.Id, args.BlobName, args.TenantId, args.CancellationToken); |
|||
} |
|||
|
|||
public override async Task<bool> ExistsAsync(BlobProviderExistsArgs args) |
|||
{ |
|||
var container = await ContainerRepository.FindAsync(args.ContainerName, args.TenantId, args.CancellationToken); |
|||
|
|||
if (container == null) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
return await BlobRepository.ExistsAsync(container.Id, args.BlobName, args.TenantId, args.CancellationToken); |
|||
} |
|||
|
|||
public override async Task<Stream> GetOrNullAsync(BlobProviderGetArgs args) |
|||
{ |
|||
var container = await ContainerRepository.FindAsync(args.ContainerName, args.TenantId, args.CancellationToken); |
|||
|
|||
if (container == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
var blob = await BlobRepository.FindAsync(container.Id, args.BlobName, args.TenantId, args.CancellationToken); |
|||
|
|||
if (blob == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return new MemoryStream(blob.Content); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public class DatabaseBlobProviderConfiguration |
|||
{ |
|||
private readonly BlobContainerConfiguration _containerConfiguration; |
|||
|
|||
public DatabaseBlobProviderConfiguration(BlobContainerConfiguration containerConfiguration) |
|||
{ |
|||
_containerConfiguration = containerConfiguration; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public interface IBlobRepository : IBasicRepository<Blob, Guid> |
|||
{ |
|||
Task<Blob> FindAsync(Guid containerId, [NotNull] string name, Guid? tenantId = null, CancellationToken cancellationToken = default); |
|||
|
|||
Task<bool> ExistsAsync(Guid containerId, [NotNull] string name, Guid? tenantId = null, CancellationToken cancellationToken = default); |
|||
|
|||
Task<bool> DeleteAsync(Guid containerId, [NotNull] string name, Guid? tenantId = null, CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public interface IContainerRepository : IBasicRepository<Container, Guid> |
|||
{ |
|||
Task<Container> CreateIfNotExistAsync([NotNull] string name, Guid? tenantId = null, CancellationToken cancellationToken = default); |
|||
|
|||
Task<Container> FindAsync([NotNull] string name, Guid? tenantId = null, CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
@ -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,16 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BlobStoring.Database.Domain\Volo.Abp.BlobStoring.Database.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,28 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
[ConnectionStringName(BlobStoringDatabaseDbProperties.ConnectionStringName)] |
|||
public class BlobStoringDatabaseDbContext : AbpDbContext<BlobStoringDatabaseDbContext>, IBlobStoringDatabaseDbContext |
|||
{ |
|||
public DbSet<Container> Containers { get; set; } |
|||
|
|||
public DbSet<Blob> Blobs { get; set; } |
|||
|
|||
public BlobStoringDatabaseDbContext(DbContextOptions<BlobStoringDatabaseDbContext> options) |
|||
: base(options) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder builder) |
|||
{ |
|||
base.OnModelCreating(builder); |
|||
|
|||
builder.ConfigureDatabaseBlobStoring(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using Volo.Abp.EntityFrameworkCore.Modeling; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
public static class BlobStoringDatabaseDbContextModelCreatingExtensions |
|||
{ |
|||
public static void ConfigureDatabaseBlobStoring( |
|||
this ModelBuilder builder, |
|||
Action<BlobStoringDatabaseModelBuilderConfigurationOptions> optionsAction = null) |
|||
{ |
|||
Check.NotNull(builder, nameof(builder)); |
|||
|
|||
var options = new BlobStoringDatabaseModelBuilderConfigurationOptions( |
|||
BlobStoringDatabaseDbProperties.DbTablePrefix, |
|||
BlobStoringDatabaseDbProperties.DbSchema |
|||
); |
|||
|
|||
optionsAction?.Invoke(options); |
|||
|
|||
builder.Entity<Container>(b => |
|||
{ |
|||
b.ToTable(options.TablePrefix + "Containers", options.Schema); |
|||
|
|||
b.ConfigureByConvention(); |
|||
|
|||
b.Property(p => p.Name).IsRequired().HasMaxLength(ContainerConsts.MaxNameLength); |
|||
|
|||
b.HasIndex(x => x.Name); |
|||
}); |
|||
|
|||
builder.Entity<Blob>(b => |
|||
{ |
|||
b.ToTable(options.TablePrefix + "Blobs", options.Schema); |
|||
|
|||
b.ConfigureByConvention(); |
|||
|
|||
b.Property(p => p.Name).IsRequired().HasMaxLength(BlobConsts.MaxNameLength); |
|||
b.Property(p => p.ContainerId).IsRequired(); |
|||
b.Property(p => p.Content).HasMaxLength(BlobConsts.MaxContentLength); |
|||
|
|||
b.HasIndex(x => x.Name); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
[DependsOn( |
|||
typeof(BlobStoringDatabaseDomainModule), |
|||
typeof(AbpEntityFrameworkCoreModule) |
|||
)] |
|||
public class BlobStoringDatabaseEntityFrameworkCoreModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddAbpDbContext<BlobStoringDatabaseDbContext>(options => |
|||
{ |
|||
options.AddRepository<Container, EfCoreContainerRepository>(); |
|||
|
|||
options.AddRepository<Blob, EfCoreBlobRepository>(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.EntityFrameworkCore.Modeling; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
public class BlobStoringDatabaseModelBuilderConfigurationOptions : AbpModelBuilderConfigurationOptions |
|||
{ |
|||
public BlobStoringDatabaseModelBuilderConfigurationOptions( |
|||
[NotNull] string tablePrefix = "", |
|||
[CanBeNull] string schema = null) |
|||
: base( |
|||
tablePrefix, |
|||
schema) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
public class EfCoreBlobRepository : EfCoreRepository<IBlobStoringDatabaseDbContext, Blob, Guid>, IBlobRepository |
|||
{ |
|||
public EfCoreBlobRepository(IDbContextProvider<IBlobStoringDatabaseDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<Blob> FindAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await DbSet.FirstOrDefaultAsync( |
|||
x => x.ContainerId == containerId && |
|||
x.Name == name && |
|||
x.TenantId == tenantId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> ExistsAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await DbSet.AnyAsync( |
|||
x => x.ContainerId == containerId && |
|||
x.Name == name && |
|||
x.TenantId == tenantId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> DeleteAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
var blob = await FindAsync(containerId, name, tenantId, cancellationToken); |
|||
|
|||
if (blob == null) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
await base.DeleteAsync(blob.Id, cancellationToken: GetCancellationToken(cancellationToken)); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
public class EfCoreContainerRepository : EfCoreRepository<IBlobStoringDatabaseDbContext, Container, Guid>, IContainerRepository |
|||
{ |
|||
public EfCoreContainerRepository(IDbContextProvider<IBlobStoringDatabaseDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<Container> CreateIfNotExistAsync(string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
var container = await FindAsync(name, tenantId, cancellationToken); |
|||
if (container != null) |
|||
{ |
|||
return container; |
|||
} |
|||
|
|||
container = new Container(Guid.NewGuid(), name, tenantId); |
|||
await base.InsertAsync(container, true, GetCancellationToken(cancellationToken)); |
|||
|
|||
return container; |
|||
} |
|||
|
|||
public virtual async Task<Container> FindAsync(string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await DbSet.WhereIf(tenantId != null, x => x.TenantId == tenantId) |
|||
.FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
[ConnectionStringName(BlobStoringDatabaseDbProperties.ConnectionStringName)] |
|||
public interface IBlobStoringDatabaseDbContext : IEfCoreDbContext |
|||
{ |
|||
DbSet<Container> Containers { get; } |
|||
|
|||
DbSet<Blob> Blobs { get; } |
|||
} |
|||
} |
|||
@ -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,16 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BlobStoring.Database.Domain\Volo.Abp.BlobStoring.Database.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,21 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
[ConnectionStringName(BlobStoringDatabaseDbProperties.ConnectionStringName)] |
|||
public class BlobStoringDatabaseMongoDbContext : AbpMongoDbContext, IBlobStoringDatabaseMongoDbContext |
|||
{ |
|||
public IMongoCollection<Container> Containers => Collection<Container>(); |
|||
|
|||
public IMongoCollection<Blob> Blobs => Collection<Blob>(); |
|||
|
|||
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
|||
{ |
|||
base.CreateModel(modelBuilder); |
|||
|
|||
modelBuilder.ConfigureDatabaseBlobStoring(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
public static class BlobStoringDatabaseMongoDbContextExtensions |
|||
{ |
|||
public static void ConfigureDatabaseBlobStoring( |
|||
this IMongoModelBuilder builder, |
|||
Action<AbpMongoModelBuilderConfigurationOptions> optionsAction = null) |
|||
{ |
|||
Check.NotNull(builder, nameof(builder)); |
|||
|
|||
var options = new BlobStoringDatabaseMongoModelBuilderConfigurationOptions( |
|||
BlobStoringDatabaseDbProperties.DbTablePrefix |
|||
); |
|||
|
|||
optionsAction?.Invoke(options); |
|||
|
|||
builder.Entity<Container>(b => |
|||
{ |
|||
b.CollectionName = options.CollectionPrefix + "Containers"; |
|||
}); |
|||
|
|||
builder.Entity<Blob>(b => |
|||
{ |
|||
b.CollectionName = options.CollectionPrefix + "Blobs"; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(BlobStoringDatabaseDomainModule), |
|||
typeof(AbpMongoDbModule) |
|||
)] |
|||
public class BlobStoringDatabaseMongoDbModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddMongoDbContext<BlobStoringDatabaseMongoDbContext>(options => |
|||
{ |
|||
options.AddRepository<Container, MongoDbContainerRepository>(); |
|||
options.AddRepository<Blob, MongoDbBlobRepository>(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
public class BlobStoringDatabaseMongoModelBuilderConfigurationOptions : AbpMongoModelBuilderConfigurationOptions |
|||
{ |
|||
public BlobStoringDatabaseMongoModelBuilderConfigurationOptions( |
|||
[NotNull] string collectionPrefix = "") |
|||
: base(collectionPrefix) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
[ConnectionStringName(BlobStoringDatabaseDbProperties.ConnectionStringName)] |
|||
public interface IBlobStoringDatabaseMongoDbContext : IAbpMongoDbContext |
|||
{ |
|||
IMongoCollection<Container> Containers { get; } |
|||
|
|||
IMongoCollection<Blob> Blobs { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using MongoDB.Driver.Linq; |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
public class MongoDbBlobRepository : MongoDbRepository<IBlobStoringDatabaseMongoDbContext, Blob, Guid>, IBlobRepository |
|||
{ |
|||
public MongoDbBlobRepository(IMongoDbContextProvider<IBlobStoringDatabaseMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<Blob> FindAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable().FirstOrDefaultAsync( |
|||
x => x.ContainerId == containerId && |
|||
x.Name == name && |
|||
x.TenantId == tenantId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> ExistsAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable().AnyAsync( |
|||
x => x.ContainerId == containerId && |
|||
x.Name == name && |
|||
x.TenantId == tenantId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> DeleteAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
var blob = await FindAsync(containerId, name, tenantId, cancellationToken); |
|||
|
|||
if (blob == null) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
await base.DeleteAsync(blob, cancellationToken: GetCancellationToken(cancellationToken)); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
public class MongoDbContainerRepository : MongoDbRepository<IBlobStoringDatabaseMongoDbContext, Container, Guid>, IContainerRepository |
|||
{ |
|||
public MongoDbContainerRepository(IMongoDbContextProvider<IBlobStoringDatabaseMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<Container> CreateIfNotExistAsync(string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
var container = await FindAsync(name, tenantId, cancellationToken); |
|||
|
|||
if (container != null) |
|||
{ |
|||
return container; |
|||
} |
|||
|
|||
container = new Container(Guid.NewGuid(), name, tenantId); |
|||
await InsertAsync(container, true, GetCancellationToken(cancellationToken)); |
|||
|
|||
return container; |
|||
} |
|||
|
|||
public virtual async Task<Container> FindAsync(string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await base.FindAsync(x => x.Name == name, cancellationToken: GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
/* Inherit from this class for your domain layer tests. |
|||
* See SampleManager_Tests for example. |
|||
*/ |
|||
public abstract class BlobStoringDatabaseDomainTestBase : BlobStoringDatabaseTestBase<BlobStoringDatabaseDomainTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.BlobStoring.Database.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
[DependsOn( |
|||
typeof(BlobStoringDatabaseEntityFrameworkCoreTestModule) |
|||
)] |
|||
public class BlobStoringDatabaseDomainTestModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<RootNamespace>Volo.Abp.BlobStoring.Database</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> |
|||
<ProjectReference Include="..\Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests\Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
public abstract class BlobStoringDatabaseEntityFrameworkCoreTestBase : BlobStoringDatabaseTestBase<BlobStoringDatabaseEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using Microsoft.Data.Sqlite; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Storage; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
[DependsOn( |
|||
typeof(BlobStoringDatabaseTestBaseModule), |
|||
typeof(BlobStoringDatabaseEntityFrameworkCoreModule) |
|||
)] |
|||
public class BlobStoringDatabaseEntityFrameworkCoreTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var sqliteConnection = CreateDatabaseAndGetConnection(); |
|||
|
|||
Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.Configure(abpDbContextConfigurationContext => |
|||
{ |
|||
abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
private static SqliteConnection CreateDatabaseAndGetConnection() |
|||
{ |
|||
var connection = new SqliteConnection("Data Source=:memory:"); |
|||
connection.Open(); |
|||
|
|||
new BlobStoringDatabaseDbContext( |
|||
new DbContextOptionsBuilder<BlobStoringDatabaseDbContext>().UseSqlite(connection).Options |
|||
).GetService<IRelationalDatabaseCreator>().CreateTables(); |
|||
|
|||
return connection; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
|||
{ |
|||
public class EfCoreContainer_Test : BlobContainer_Tests<BlobStoringDatabaseEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<RootNamespace>Volo.Abp.BlobStoring.Database</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> |
|||
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.1.0" /> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" /> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.0" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.BlobStoring.Database.EntityFrameworkCore\Volo.Abp.BlobStoring.Database.EntityFrameworkCore.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BlobStoring.Database.TestBase\Volo.Abp.BlobStoring.Database.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
public abstract class BlobStoringDatabaseMongoDbTestBase : BlobStoringDatabaseTestBase<BlobStoringDatabaseMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(BlobStoringDatabaseTestBaseModule), |
|||
typeof(BlobStoringDatabaseMongoDbModule) |
|||
)] |
|||
public class BlobStoringDatabaseMongoDbTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var connectionString = MongoDbFixture.ConnectionString.EnsureEndsWith('/') + |
|||
"Db_" + |
|||
Guid.NewGuid().ToString("N"); |
|||
|
|||
Configure<AbpDbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = connectionString; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using Mongo2Go; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
public class MongoDbFixture : IDisposable |
|||
{ |
|||
private static readonly MongoDbRunner MongoDbRunner = MongoDbRunner.Start(); |
|||
public static readonly string ConnectionString = MongoDbRunner.ConnectionString; |
|||
|
|||
public void Dispose() |
|||
{ |
|||
MongoDbRunner?.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.MongoDB |
|||
{ |
|||
[CollectionDefinition(Name)] |
|||
public class MongoTestCollection : ICollectionFixture<MongoDbFixture> |
|||
{ |
|||
public const string Name = "MongoDB Collection"; |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<RootNamespace>Volo.Abp.BlobStoring.Database</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> |
|||
<PackageReference Include="Mongo2Go" Version="2.2.12" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.BlobStoring.Database.MongoDB\Volo.Abp.BlobStoring.Database.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BlobStoring.Database.TestBase\Volo.Abp.BlobStoring.Database.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,59 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Uow; |
|||
using Volo.Abp.Testing; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
public abstract class BlobStoringDatabaseTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
|
|||
protected virtual Task WithUnitOfWorkAsync(Func<Task> func) |
|||
{ |
|||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); |
|||
} |
|||
|
|||
protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action) |
|||
{ |
|||
using (var scope = ServiceProvider.CreateScope()) |
|||
{ |
|||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>(); |
|||
|
|||
using (var uow = uowManager.Begin(options)) |
|||
{ |
|||
await action(); |
|||
|
|||
await uow.CompleteAsync(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func) |
|||
{ |
|||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); |
|||
} |
|||
|
|||
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func) |
|||
{ |
|||
using (var scope = ServiceProvider.CreateScope()) |
|||
{ |
|||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>(); |
|||
|
|||
using (var uow = uowManager.Begin(options)) |
|||
{ |
|||
var result = await func(); |
|||
await uow.CompleteAsync(); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Authorization; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpTestBaseModule), |
|||
typeof(AbpAuthorizationModule), |
|||
typeof(BlobStoringDatabaseDomainModule), |
|||
typeof(AbpBlobStoringTestModule) |
|||
)] |
|||
public class BlobStoringDatabaseTestBaseModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddAlwaysAllowAuthorization(); |
|||
|
|||
Configure<AbpBlobStoringOptions>(options => |
|||
{ |
|||
options.Containers.ConfigureAll((containerName, containerConfiguration) => |
|||
{ |
|||
containerConfiguration.UseDatabase(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
using System.Collections.Generic; |
|||
using System.Security.Claims; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Database.Security |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor |
|||
{ |
|||
public override ClaimsPrincipal GetClaimsPrincipal() |
|||
{ |
|||
return GetPrincipal(); |
|||
} |
|||
|
|||
private ClaimsPrincipal _principal; |
|||
|
|||
private ClaimsPrincipal GetPrincipal() |
|||
{ |
|||
if (_principal == null) |
|||
{ |
|||
lock (this) |
|||
{ |
|||
if (_principal == null) |
|||
{ |
|||
_principal = new ClaimsPrincipal( |
|||
new ClaimsIdentity( |
|||
new List<Claim> |
|||
{ |
|||
new Claim(AbpClaimTypes.UserId,"2e701e62-0953-4dd3-910b-dc6cc93ccb0d"), |
|||
new Claim(AbpClaimTypes.UserName,"admin"), |
|||
new Claim(AbpClaimTypes.Email,"admin@abp.io") |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
|
|||
return _principal; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<RootNamespace>Volo.Abp.BlobStoring.Database</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> |
|||
<PackageReference Include="NSubstitute" Version="4.2.1" /> |
|||
<PackageReference Include="Shouldly" Version="3.0.2" /> |
|||
<PackageReference Include="xunit" Version="2.4.1" /> |
|||
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" /> |
|||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\test\Volo.Abp.BlobStoring.Tests\Volo.Abp.BlobStoring.Tests.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.BlobStoring.Database.Domain\Volo.Abp.BlobStoring.Database.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue