-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from abpframework/containerization-to-deploy
Deploy CMS Kit Demo application to cms-kit-demo.abpdemo.com
- Loading branch information
Showing
19 changed files
with
652 additions
and
21 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
.github/workflows/containerization-to-deploy_cms-kit-demo.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# # Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | ||
# # More GitHub Actions for Azure: https://github.com/Azure/actions | ||
|
||
# name: Build and deploy ASP.Net Core app to Azure Web App - cms-kit-demo | ||
|
||
# on: | ||
# push: | ||
# branches: | ||
# - containerization-to-deploy | ||
# workflow_dispatch: | ||
|
||
# jobs: | ||
# build: | ||
# runs-on: ubuntu-latest | ||
|
||
# steps: | ||
# - uses: actions/checkout@v2 | ||
|
||
# - name: Set up .NET Core | ||
# uses: actions/setup-dotnet@v1 | ||
# with: | ||
# dotnet-version: '7.x' | ||
# include-prerelease: true | ||
|
||
# - name: Build with dotnet | ||
# run: dotnet build --configuration Release | ||
|
||
# - name: dotnet publish | ||
# run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp | ||
|
||
# - name: Copy CmsKitDemo.db to publish directory | ||
# run: cp src/CmsKitDemo.db ${{env.DOTNET_ROOT}}/myapp | ||
|
||
# - name: Upload artifact for deployment job | ||
# uses: actions/upload-artifact@v2 | ||
# with: | ||
# name: .net-app | ||
# path: ${{env.DOTNET_ROOT}}/myapp | ||
|
||
# deploy: | ||
# runs-on: ubuntu-latest | ||
# needs: build | ||
# environment: | ||
# name: 'Production' | ||
# url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | ||
|
||
# steps: | ||
# - name: Download artifact from build job | ||
# uses: actions/download-artifact@v2 | ||
# with: | ||
# name: .net-app | ||
|
||
# - name: Deploy to Azure Web App | ||
# id: deploy-to-webapp | ||
# uses: azure/webapps-deploy@v2 | ||
# with: | ||
# app-name: 'cms-kit-demo' | ||
# slot-name: 'Production' | ||
# publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_B8EE580013C3409F9EA266AF29C41EAD }} | ||
# package: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.Extensions.Options; | ||
using Volo.Abp.Data; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Threading; | ||
|
||
namespace CmsKitDemo.Data; | ||
|
||
[Dependency(ReplaceServices = true)] | ||
public class CmsKitConnectionStringResolver : DefaultConnectionStringResolver | ||
{ | ||
private readonly CmsKitDemoUserIdResolver _demoNameResolver; | ||
private readonly IConfiguration _configuration; | ||
|
||
public CmsKitConnectionStringResolver( | ||
IOptionsMonitor<AbpDbConnectionOptions> options, | ||
CmsKitDemoUserIdResolver demoNameResolver, | ||
IConfiguration configuration) | ||
: base(options) | ||
{ | ||
_demoNameResolver = demoNameResolver; | ||
_configuration = configuration; | ||
} | ||
|
||
[Obsolete("Use ResolveAsync method.")] | ||
public override string Resolve(string connectionStringName = null) | ||
{ | ||
return AsyncHelper.RunSync(() => ResolveInternalAsync(connectionStringName)); | ||
} | ||
|
||
public async override Task<string> ResolveAsync(string connectionStringName = null) | ||
{ | ||
return await ResolveInternalAsync(connectionStringName); | ||
} | ||
|
||
private async Task<string> ResolveInternalAsync(string connectionStringName = null) | ||
{ | ||
var dbFolder = _configuration["App:DbFolderName"]?.EnsureEndsWith(Path.DirectorySeparatorChar); | ||
if (dbFolder.IsNullOrWhiteSpace()) | ||
{ | ||
return await base.ResolveAsync(connectionStringName); | ||
} | ||
|
||
var demoUserId = _demoNameResolver.GetDemoUserIdOrNull() ?? _configuration["App:DefaultDbName"]; | ||
|
||
var dbFilePath = $"{dbFolder}{demoUserId}.db"; | ||
if (!File.Exists(dbFilePath)) | ||
{ | ||
File.Copy(_configuration["App:DbFolderName"]?.EnsureEndsWith(Path.DirectorySeparatorChar) + _configuration["App:DefaultDbName"] + ".db", dbFilePath); | ||
} | ||
|
||
return $"Data Source={dbFilePath};Cache=Shared"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/CmsKitDemo/Data/CmsKitDemoSqliteMethodCallTranslatorProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
using Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; | ||
using System.Reflection; | ||
using Volo.Abp; | ||
|
||
namespace CmsKitDemo.Data | ||
{ | ||
public class CmsKitDemoSqliteMethodCallTranslatorProvider : SqliteMethodCallTranslatorProvider | ||
{ | ||
public CmsKitDemoSqliteMethodCallTranslatorProvider([NotNull] RelationalMethodCallTranslatorProviderDependencies dependencies) | ||
: base(dependencies) | ||
{ | ||
var sqlExpressionFactory = dependencies.SqlExpressionFactory; | ||
|
||
AddTranslators( | ||
new IMethodCallTranslator[] | ||
{ | ||
new SqliteMathTranslator(sqlExpressionFactory), | ||
new SqliteDateTimeAddTranslator(sqlExpressionFactory.As<SqliteSqlExpressionFactory>()), | ||
new CmsKitDemoSqliteStringMethodTranslator(sqlExpressionFactory) | ||
}); | ||
} | ||
} | ||
|
||
public class CmsKitDemoSqliteStringMethodTranslator : SqliteStringMethodTranslator | ||
{ | ||
private static readonly MethodInfo _containsMethodInfo | ||
= typeof(string).GetRuntimeMethod(nameof(string.Contains), new[] { typeof(string) }); | ||
|
||
private readonly ISqlExpressionFactory _sqlExpressionFactory; | ||
|
||
public CmsKitDemoSqliteStringMethodTranslator(ISqlExpressionFactory sqlExpressionFactory) : base(sqlExpressionFactory) | ||
{ | ||
_sqlExpressionFactory = sqlExpressionFactory; | ||
} | ||
|
||
public override SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger) | ||
{ | ||
Check.NotNull(method, nameof(method)); | ||
Check.NotNull(arguments, nameof(arguments)); | ||
|
||
if (_containsMethodInfo.Equals(method)) | ||
{ | ||
var pattern = arguments[0]; | ||
var stringTypeMapping = ExpressionExtensions.InferTypeMapping(instance, pattern); | ||
|
||
instance = _sqlExpressionFactory.ApplyTypeMapping(instance, stringTypeMapping); | ||
pattern = _sqlExpressionFactory.ApplyTypeMapping(pattern, stringTypeMapping); | ||
|
||
// this basically changes query to "instr(upper(left_expression), upper(right_expression))" | ||
return _sqlExpressionFactory.OrElse( | ||
_sqlExpressionFactory.Equal( | ||
pattern, | ||
_sqlExpressionFactory.Constant(string.Empty, stringTypeMapping)), | ||
_sqlExpressionFactory.GreaterThan( | ||
_sqlExpressionFactory.Function( | ||
"instr", | ||
new[] | ||
{ | ||
_sqlExpressionFactory.Function("upper", new[]{instance}, false, new []{ false }, typeof(string)), | ||
_sqlExpressionFactory.Function("upper", new[]{pattern}, false, new []{ false }, typeof(string)) | ||
}, | ||
false, | ||
new[] { false, false }, | ||
typeof(int)), _sqlExpressionFactory.Constant(0))); | ||
} | ||
|
||
return base.Translate(instance, method, arguments, logger); | ||
} | ||
} | ||
} |
Oops, something went wrong.